Skip to content

Commit 3ef3d6d

Browse files
authored
Merge pull request #3 from wortelus/sanity
Sanity checks
2 parents 1a1ac22 + 40478d9 commit 3ef3d6d

File tree

7 files changed

+214
-38
lines changed

7 files changed

+214
-38
lines changed

B737-800X/actions.yaml

+10-5
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ actions:
3838
command-release: FlyWithLua/streamdeck_handler/fmc_prst_end
3939
- index: 5
4040
name: speedbrake armed
41-
type: single
41+
type: none
4242
icon: speedbrakearmed
4343
dataref: laminar/B738/annunciator/speedbrake_armed
4444
dataref-multiplier: 1.5
4545
- index: 6
4646
name: speedbrake do not arm
47-
type: single
47+
type: none
4848
icon: speedbrakedonotarm
4949
dataref: laminar/B738/annunciator/speedbrake_extend
5050
dataref-multiplier: 1.5
5151
- index: 7
5252
name: stab out of trim
53-
type: single
53+
type: none
5454
icon: staboutoftrim
5555
dataref: laminar/B738/annunciator/stab_out_of_trim
5656
dataref-multiplier: 1.5
@@ -72,13 +72,13 @@ actions:
7272
step: 1
7373
- index: 28
7474
name: le flaps transit
75-
type: single
75+
type: none
7676
icon: leflapstransit
7777
dataref: laminar/B738/annunciator/slats_transit
7878
dataref-multiplier: 1.5
7979
- index: 29
8080
name: le flaps ext
81-
type: single
81+
type: none
8282
icon: leflapsext
8383
dataref: laminar/B738/annunciator/slats_extend
8484
dataref-multiplier: 1.5
@@ -133,6 +133,11 @@ actions:
133133
type: dir
134134
icon: dir
135135
label: MCP
136+
- index: 17
137+
name: mcpctl
138+
type: dir
139+
icon: dir
140+
label: MCP CTL
136141
- index: 8
137142
name: efis
138143
type: dir

B737-800X/ctr.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ actions:
4848
dataref: laminar/B738/autobrake/autobrake_pos
4949
- index: 7
5050
name: autobrake disarm
51-
type: single
51+
type: none
5252
icon: autobrakedisarm
5353
dataref: laminar/B738/annunciator/auto_brake_disarm
5454
dataref-multiplier: 1.5
5555
- index: 23
5656
name: anti skid inop
57-
type: single
57+
type: none
5858
icon: antiskidinop
5959
dataref: laminar/B738/annunciator/anti_skid_inop
6060
dataref-multiplier: 1.5
@@ -101,13 +101,13 @@ actions:
101101
command: laminar/B738/alert/below_gs_pilot
102102
- index: 1
103103
name: takeoff config
104-
type: single
104+
type: none
105105
icon: takeoffconfig
106106
dataref: laminar/B738/annunciator/takeoff_config
107107
dataref-multiplier: 1.5
108108
- index: 2
109109
name: cabin altitude
110-
type: single
110+
type: none
111111
icon: cabinaltitude
112112
dataref: laminar/B738/annunciator/cabin_alt
113113
dataref-multiplier: 1.5

B737-800X/efis.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ actions:
6565
# align: center
6666
- index: 1
6767
name: mins
68-
type: single
68+
type: none
6969
icon: mins
7070
dataref: laminar/B738/EFIS_control/cpt/minimums
7171
- index: 2
@@ -108,7 +108,7 @@ actions:
108108
command: laminar/B738/EFIS_control/capt/map_mode_dn
109109
- index: 17
110110
name: map mode
111-
type: single
111+
type: none
112112
icon: mapmode
113113
dataref-states:
114114
- 0.0
@@ -137,7 +137,7 @@ actions:
137137
command: laminar/B738/EFIS_control/capt/baro_in_hpa_dn
138138
- index: 6
139139
name: baro
140-
type: single
140+
type: none
141141
icon: baro
142142
dataref: laminar/B738/EFIS_control/capt/baro_in_hpa
143143
- index: 7
@@ -178,7 +178,7 @@ actions:
178178
command: laminar/B738/EFIS_control/capt/map_range_dn
179179
- index: 22
180180
name: map range
181-
type: single
181+
type: none
182182
icon: maprange
183183
dataref-states:
184184
- 0.0

B737-800X/lowerovhd.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ actions:
175175
- 2.0
176176
- index: 8
177177
name: apu egt
178-
type: single
178+
type: none
179179
dataref: laminar/B738/electrical/apu_temp
180180
gauge:
181181
name: apuegt
@@ -256,7 +256,7 @@ actions:
256256
command-off: laminar/B738/toggle_switch/eng_start_source_left
257257
- index: 5
258258
name: arm emer exit lights ann
259-
type: single
259+
type: none
260260
icon: notarmed
261261
dataref: laminar/B738/annunciator/emer_exit
262262
dataref-multiplier: 1.5

main.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import math
22
import pickle
3+
import sys
34
import time
45
from os.path import exists
56

@@ -8,6 +9,7 @@
89
from StreamDeck.DeviceManager import DeviceManager
910
from yaml import load
1011
import pyxpudpserver as XPUDP
12+
import logging
1113

1214
try:
1315
from yaml import CLoader as Loader, CDumper as Dumper
@@ -17,7 +19,9 @@
1719
import preprocessing
1820
except ImportError:
1921
print("You don't seem to have preprocessing.py near its main.py. correct your installation")
20-
exit(1)
22+
sys.exit(1)
23+
24+
logging.basicConfig(encoding='utf-8')
2125

2226

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

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

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

196200
# for now the software works only for one panel
197201
panel = global_cfg["stream-decks"][0]
198-
keys_dir = panel["directory"]
202+
keys_dir = str(panel["directory"])
199203
key_count = panel["keys"]
200204

201205
try:

preprocessing.py

+44-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import logging
12
import os.path
3+
import sys
24

35
import numpy as np
46
import yaml
@@ -10,11 +12,17 @@
1012
from yaml import CLoader as Loader, CDumper as Dumper
1113
except ImportError:
1214
from yaml import Loader, Dumper
15+
1316
try:
1417
import dynamic
1518
except ImportError:
1619
print("You don't seem to have dynamic.py near its main.py and preprocessing.py. correct your installation")
17-
exit(1)
20+
sys.exit(1)
21+
try:
22+
import sanity
23+
except ImportError:
24+
print("You don't seem to have sanity.py near its main.py and preprocessing.py. correct your installation")
25+
sys.exit(1)
1826

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

61-
self.name = name
62-
if self.name is None or self.name == "":
63-
print("ERROR: button with index {} has no set name, quitting...".format(index))
64-
quit(1)
65+
sanity.vital_check(index, name)
6566

67+
self.index = index
68+
self.name = name
6669
self.icon = icon
6770

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

7373
# verify string type
74-
if label:
75-
label = str(label)
76-
self.label = label
74+
self.label = sanity.label_check(index, name, label)
7775

7876
self.dataref = dataref
7977
if dataref_multiplier is None:
@@ -101,6 +99,10 @@ def __init__(self, index, name, icon, cmd_type, label=None, dataref=None, datare
10199
else:
102100
self.auto_switch = auto_switch
103101

102+
# generate warnings for weird commands
103+
sanity.cmd2_check(index, name, cmd_type, cmd, cmd_mul, cmd_release, cmd_release_mul,
104+
cmd_on, cmd_off, cmd_on_mul, cmd_off_mul)
105+
104106
self.cmd = cmd
105107
self.cmd_mul = cmd_mul
106108
self.cmd_release = cmd_release
@@ -118,10 +120,16 @@ def __init__(self, index, name, icon, cmd_type, label=None, dataref=None, datare
118120
self.display = None
119121
self.special_label = None
120122
if file_names is not None:
123+
# sanity check file_names corresponding to dataref_states
124+
sanity.file_names_check(index, name, file_names, self.dataref_states)
125+
121126
self.file_names = np.empty(len(file_names), dtype=object)
122127
for i, fn in enumerate(file_names):
123128
self.file_names[i] = get_filename_button_static_png(fn)
124129
elif gauge:
130+
# sanity check for gauge (if it contains everything)
131+
sanity.gauge_check(index, name, gauge)
132+
125133
# overwrite default dataref_states
126134
self.dataref_states = dynamic.get_dataref_states(gauge)
127135
# special case - gauge with needles :)
@@ -134,6 +142,9 @@ def __init__(self, index, name, icon, cmd_type, label=None, dataref=None, datare
134142
# so we pregenerate them artificial names for the use in main global images dict
135143
self.file_names = dynamic.create_dynamic_filenames(self.gauge["name"], self.dataref_states)
136144
elif display:
145+
# sanity check for display (if it contains everything)
146+
sanity.display_check(index, name, display)
147+
137148
# overwrite default dataref_states
138149
self.dataref_states = dynamic.get_dataref_states(display)
139150
# special case - display of number values
@@ -150,14 +161,21 @@ def __init__(self, index, name, icon, cmd_type, label=None, dataref=None, datare
150161
# todo
151162
pass
152163
elif self.dataref_states is not None:
164+
if icon is None:
165+
logging.error("#{} {} is trying to set dataref_states without the 'icon' parameter, quitting..."
166+
.format(index, name))
167+
sys.exit(1)
168+
153169
self.file_names = np.empty(len(self.dataref_states), dtype=object)
154170
for i, state in enumerate(self.dataref_states):
155171
self.file_names[i] = get_filename_button_dataref_png(icon, state)
156172
else:
157-
self.file_names = np.empty(1, dtype=object)
158173
if icon is None:
159-
print("static icon is not present on {} button".format(name))
160-
exit(1)
174+
logging.error("#{} {} is trying to set static icon without the 'icon' parameter, quitting..."
175+
.format(index, name))
176+
sys.exit(1)
177+
178+
self.file_names = np.empty(1, dtype=object)
161179
self.file_names[0] = get_filename_button_static_png(icon)
162180

163181

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

172190
keys = preset_cfg["actions"]
173191
# key_count = len(keys)
@@ -178,6 +196,12 @@ def load_preset(target_dir, yaml_keyset, deck_key_count, preload_labels=False):
178196
for _, key in enumerate(keys):
179197
index = key.get("index")
180198
name = key.get("name")
199+
# try to convert to int because it is used as array index
200+
try:
201+
index = int(index)
202+
except ValueError:
203+
logging.error("button with name {} has index non-convertable to integer, quitting...".format(name))
204+
sys.exit(1)
181205
cmd_type = key.get("type")
182206
preset[index] = Button(
183207
index,

0 commit comments

Comments
 (0)