Skip to content

Commit

Permalink
Merge pull request #3 from wortelus/sanity
Browse files Browse the repository at this point in the history
Sanity checks
  • Loading branch information
wortelus authored Aug 1, 2022
2 parents 1a1ac22 + 40478d9 commit 3ef3d6d
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 38 deletions.
15 changes: 10 additions & 5 deletions B737-800X/actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ actions:
command-release: FlyWithLua/streamdeck_handler/fmc_prst_end
- index: 5
name: speedbrake armed
type: single
type: none
icon: speedbrakearmed
dataref: laminar/B738/annunciator/speedbrake_armed
dataref-multiplier: 1.5
- index: 6
name: speedbrake do not arm
type: single
type: none
icon: speedbrakedonotarm
dataref: laminar/B738/annunciator/speedbrake_extend
dataref-multiplier: 1.5
- index: 7
name: stab out of trim
type: single
type: none
icon: staboutoftrim
dataref: laminar/B738/annunciator/stab_out_of_trim
dataref-multiplier: 1.5
Expand All @@ -72,13 +72,13 @@ actions:
step: 1
- index: 28
name: le flaps transit
type: single
type: none
icon: leflapstransit
dataref: laminar/B738/annunciator/slats_transit
dataref-multiplier: 1.5
- index: 29
name: le flaps ext
type: single
type: none
icon: leflapsext
dataref: laminar/B738/annunciator/slats_extend
dataref-multiplier: 1.5
Expand Down Expand Up @@ -133,6 +133,11 @@ actions:
type: dir
icon: dir
label: MCP
- index: 17
name: mcpctl
type: dir
icon: dir
label: MCP CTL
- index: 8
name: efis
type: dir
Expand Down
8 changes: 4 additions & 4 deletions B737-800X/ctr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ actions:
dataref: laminar/B738/autobrake/autobrake_pos
- index: 7
name: autobrake disarm
type: single
type: none
icon: autobrakedisarm
dataref: laminar/B738/annunciator/auto_brake_disarm
dataref-multiplier: 1.5
- index: 23
name: anti skid inop
type: single
type: none
icon: antiskidinop
dataref: laminar/B738/annunciator/anti_skid_inop
dataref-multiplier: 1.5
Expand Down Expand Up @@ -101,13 +101,13 @@ actions:
command: laminar/B738/alert/below_gs_pilot
- index: 1
name: takeoff config
type: single
type: none
icon: takeoffconfig
dataref: laminar/B738/annunciator/takeoff_config
dataref-multiplier: 1.5
- index: 2
name: cabin altitude
type: single
type: none
icon: cabinaltitude
dataref: laminar/B738/annunciator/cabin_alt
dataref-multiplier: 1.5
Expand Down
8 changes: 4 additions & 4 deletions B737-800X/efis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ actions:
# align: center
- index: 1
name: mins
type: single
type: none
icon: mins
dataref: laminar/B738/EFIS_control/cpt/minimums
- index: 2
Expand Down Expand Up @@ -108,7 +108,7 @@ actions:
command: laminar/B738/EFIS_control/capt/map_mode_dn
- index: 17
name: map mode
type: single
type: none
icon: mapmode
dataref-states:
- 0.0
Expand Down Expand Up @@ -137,7 +137,7 @@ actions:
command: laminar/B738/EFIS_control/capt/baro_in_hpa_dn
- index: 6
name: baro
type: single
type: none
icon: baro
dataref: laminar/B738/EFIS_control/capt/baro_in_hpa
- index: 7
Expand Down Expand Up @@ -178,7 +178,7 @@ actions:
command: laminar/B738/EFIS_control/capt/map_range_dn
- index: 22
name: map range
type: single
type: none
icon: maprange
dataref-states:
- 0.0
Expand Down
4 changes: 2 additions & 2 deletions B737-800X/lowerovhd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ actions:
- 2.0
- index: 8
name: apu egt
type: single
type: none
dataref: laminar/B738/electrical/apu_temp
gauge:
name: apuegt
Expand Down Expand Up @@ -256,7 +256,7 @@ actions:
command-off: laminar/B738/toggle_switch/eng_start_source_left
- index: 5
name: arm emer exit lights ann
type: single
type: none
icon: notarmed
dataref: laminar/B738/annunciator/emer_exit
dataref-multiplier: 1.5
Expand Down
10 changes: 7 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import math
import pickle
import sys
import time
from os.path import exists

Expand All @@ -8,6 +9,7 @@
from StreamDeck.DeviceManager import DeviceManager
from yaml import load
import pyxpudpserver as XPUDP
import logging

try:
from yaml import CLoader as Loader, CDumper as Dumper
Expand All @@ -17,7 +19,9 @@
import preprocessing
except ImportError:
print("You don't seem to have preprocessing.py near its main.py. correct your installation")
exit(1)
sys.exit(1)

logging.basicConfig(encoding='utf-8')


# 0 is to move down, 1 to move up
Expand Down Expand Up @@ -178,7 +182,7 @@ def main():

if not current_deck:
print("Deck for current session NOT FOUND, verify the serial in config.yaml and index specified")
exit(1)
sys.exit(1)

# loading info and check for connected SD count == config.yaml SD count
print("configuration for {} decks, {} connected".format(len(global_cfg["stream-decks"]), deck_count))
Expand All @@ -195,7 +199,7 @@ def main():

# for now the software works only for one panel
panel = global_cfg["stream-decks"][0]
keys_dir = panel["directory"]
keys_dir = str(panel["directory"])
key_count = panel["keys"]

try:
Expand Down
64 changes: 44 additions & 20 deletions preprocessing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import logging
import os.path
import sys

import numpy as np
import yaml
Expand All @@ -10,11 +12,17 @@
from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
from yaml import Loader, Dumper

try:
import dynamic
except ImportError:
print("You don't seem to have dynamic.py near its main.py and preprocessing.py. correct your installation")
exit(1)
sys.exit(1)
try:
import sanity
except ImportError:
print("You don't seem to have sanity.py near its main.py and preprocessing.py. correct your installation")
sys.exit(1)

ACTION_CFG = "actions.yaml"
ACTION_CFG_NAME = "actions"
Expand Down Expand Up @@ -53,27 +61,17 @@ def __init__(self, index, name, icon, cmd_type, label=None, dataref=None, datare
cmd_on=None, cmd_off=None, cmd_on_mul=None, cmd_off_mul=None,
gauge=None, display=None, special_label=None):
# Constants
self.index = index
if self.index is None:
print("ERROR: button with name {} has no set index, quitting...".format(name))
quit(1)

self.name = name
if self.name is None or self.name == "":
print("ERROR: button with index {} has no set name, quitting...".format(index))
quit(1)
sanity.vital_check(index, name)

self.index = index
self.name = name
self.icon = icon

self.cmd_type = cmd_type
if cmd_type is None or cmd_type == "":
print("WARN: {} has no set type, setting none as default (no press action)".format(name))
self.cmd_type = "none"
self.cmd_type = sanity.cmd_check(index, name, cmd_type)

# verify string type
if label:
label = str(label)
self.label = label
self.label = sanity.label_check(index, name, label)

self.dataref = dataref
if dataref_multiplier is None:
Expand Down Expand Up @@ -101,6 +99,10 @@ def __init__(self, index, name, icon, cmd_type, label=None, dataref=None, datare
else:
self.auto_switch = auto_switch

# generate warnings for weird commands
sanity.cmd2_check(index, name, cmd_type, cmd, cmd_mul, cmd_release, cmd_release_mul,
cmd_on, cmd_off, cmd_on_mul, cmd_off_mul)

self.cmd = cmd
self.cmd_mul = cmd_mul
self.cmd_release = cmd_release
Expand All @@ -118,10 +120,16 @@ def __init__(self, index, name, icon, cmd_type, label=None, dataref=None, datare
self.display = None
self.special_label = None
if file_names is not None:
# sanity check file_names corresponding to dataref_states
sanity.file_names_check(index, name, file_names, self.dataref_states)

self.file_names = np.empty(len(file_names), dtype=object)
for i, fn in enumerate(file_names):
self.file_names[i] = get_filename_button_static_png(fn)
elif gauge:
# sanity check for gauge (if it contains everything)
sanity.gauge_check(index, name, gauge)

# overwrite default dataref_states
self.dataref_states = dynamic.get_dataref_states(gauge)
# special case - gauge with needles :)
Expand All @@ -134,6 +142,9 @@ def __init__(self, index, name, icon, cmd_type, label=None, dataref=None, datare
# so we pregenerate them artificial names for the use in main global images dict
self.file_names = dynamic.create_dynamic_filenames(self.gauge["name"], self.dataref_states)
elif display:
# sanity check for display (if it contains everything)
sanity.display_check(index, name, display)

# overwrite default dataref_states
self.dataref_states = dynamic.get_dataref_states(display)
# special case - display of number values
Expand All @@ -150,14 +161,21 @@ def __init__(self, index, name, icon, cmd_type, label=None, dataref=None, datare
# todo
pass
elif self.dataref_states is not None:
if icon is None:
logging.error("#{} {} is trying to set dataref_states without the 'icon' parameter, quitting..."
.format(index, name))
sys.exit(1)

self.file_names = np.empty(len(self.dataref_states), dtype=object)
for i, state in enumerate(self.dataref_states):
self.file_names[i] = get_filename_button_dataref_png(icon, state)
else:
self.file_names = np.empty(1, dtype=object)
if icon is None:
print("static icon is not present on {} button".format(name))
exit(1)
logging.error("#{} {} is trying to set static icon without the 'icon' parameter, quitting..."
.format(index, name))
sys.exit(1)

self.file_names = np.empty(1, dtype=object)
self.file_names[0] = get_filename_button_static_png(icon)


Expand All @@ -167,7 +185,7 @@ def load_preset(target_dir, yaml_keyset, deck_key_count, preload_labels=False):
preset_cfg = safe_load(stream)
except yaml.YAMLError as err:
print("cannot load {}, ensure you have proper syntax config {}".format(yaml_keyset, err))
exit(1)
sys.exit(1)

keys = preset_cfg["actions"]
# key_count = len(keys)
Expand All @@ -178,6 +196,12 @@ def load_preset(target_dir, yaml_keyset, deck_key_count, preload_labels=False):
for _, key in enumerate(keys):
index = key.get("index")
name = key.get("name")
# try to convert to int because it is used as array index
try:
index = int(index)
except ValueError:
logging.error("button with name {} has index non-convertable to integer, quitting...".format(name))
sys.exit(1)
cmd_type = key.get("type")
preset[index] = Button(
index,
Expand Down
Loading

0 comments on commit 3ef3d6d

Please sign in to comment.