diff --git a/B737-800X/flaps.yaml b/B737-800X/flaps.yaml index 738689a..78663d5 100644 --- a/B737-800X/flaps.yaml +++ b/B737-800X/flaps.yaml @@ -19,67 +19,67 @@ actions: name: move flaps up type: single icon: red-button - label: Move Up + label: MOVE UP command: FlyWithLua/B738/Cmd_MP_Flaps_Up - index: 19 name: flaps up type: single icon: orange-button - label: Flaps Up + label: UP command: laminar/B738/push_button/flaps_0 - index: 20 name: flaps 1 type: single icon: orange-button - label: Flaps 1 + label: 1 command: laminar/B738/push_button/flaps_1 - index: 21 name: flaps 5 type: single icon: orange-button - label: Flaps 5 + label: 5 command: laminar/B738/push_button/flaps_5 - index: 22 name: flaps 15 type: single icon: orange-button - label: Flaps 15 + label: 15 command: laminar/B738/push_button/flaps_15 - index: 23 name: flaps 30 type: single icon: orange-button - label: Flaps 30 + label: 30 command: laminar/B738/push_button/flaps_30 - index: 26 name: move flaps down type: single icon: blue-button - label: Move Down + label: MOVE DOWN command: FlyWithLua/B738/Cmd_MP_Flaps_Dn - index: 28 name: flaps 2 type: single icon: orange-button - label: Flaps 2 + label: 2 command: laminar/B738/push_button/flaps_2 - index: 29 name: flaps 10 type: single icon: orange-button - label: Flaps 10 + label: 10 command: laminar/B738/push_button/flaps_10 - index: 30 name: flaps 25 type: single icon: orange-button - label: Flaps 25 + label: 25 command: laminar/B738/push_button/flaps_25 - index: 31 name: flaps 40 type: single icon: orange-button - label: Flaps 40 + label: 40 command: laminar/B738/push_button/flaps_40 diff --git a/B737-800X/lowerovhd.yaml b/B737-800X/lowerovhd.yaml index 6252344..0281625 100644 --- a/B737-800X/lowerovhd.yaml +++ b/B737-800X/lowerovhd.yaml @@ -70,7 +70,7 @@ actions: file-names: - red0 - blue2 - label: TAXI LIGHTS + label: TAXI LT dataref: laminar/B738/toggle_switch/taxi_light_brightness_pos dataref-states: - 0.0 @@ -91,7 +91,7 @@ actions: file-names: - red0 - blue2 - label: WING LIGHTS + label: WING LT dataref: sim/cockpit2/switches/generic_lights_switch[0] command: laminar/B738/switch/wing_light_toggle - index: 21 @@ -109,7 +109,7 @@ actions: file-names: - red0 - blue2 - label: BEACON LIGHTS + label: BEACON LT dataref: sim/cockpit/electrical/beacon_lights_on command: sim/lights/beacon_lights_toggle - index: 20 @@ -133,7 +133,7 @@ actions: file-names: - red0 - blue2 - label: LOGO LIGHTS + label: LOGO LT dataref: laminar/B738/toggle_switch/logo_light command: laminar/B738/switch/logo_light_toggle - index: 13 diff --git a/config.yaml b/config.yaml index 4303d93..79d1ea6 100644 --- a/config.yaml +++ b/config.yaml @@ -1,16 +1,19 @@ -aircraft: B738X +# X-Plane server UDP settings xp-ip: 127.0.0.1 xp-port: 49000 server-ip: 127.0.0.1 server-port: 49008 +# font used for labels (displays use different one) default-font: IBMPlexMono-Bold.ttf default-font-size: 13 +# set False if you want lower case labels +always-upper-case: True # comment out following line to disable image caching # the images will have to load for several seconds every time, but it is suitable for tweaking cache-path: ./img-cache.pkl brightness: 75 # the first one is taken as active for the session stream-decks: - - serial: CL41I1A00651 - keys: 32 + - serial: CL41I1A00651 # ! CHANGE THIS VALUE ! + keys: 32 # ! VERIFY THIS VALUE ! directory: B737-800X diff --git a/main.py b/main.py index 7e166e8..9df9798 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,5 @@ import math import pickle -import threading import time from os.path import exists @@ -182,7 +181,6 @@ def main(): exit(1) # loading info and check for connected SD count == config.yaml SD count - print("config loaded for: {}".format(global_cfg["aircraft"])) print("configuration for {} decks, {} connected".format(len(global_cfg["stream-decks"]), deck_count)) if len(global_cfg["stream-decks"]) != deck_count: print("WARN: configuration is for {} decks, but {} connected" @@ -229,7 +227,8 @@ def main(): if not caching_enabled: print("note: caching is disabled, loading will be noticeably slower") print("you can enable it by setting the field 'cache-path' in config.yaml") - images_all = preprocessing.load_images_datarefs_all(current_deck, presets_all) + images_all = preprocessing.load_images_datarefs_all( + current_deck, presets_all, global_cfg["always-upper-case"]) elif load_cached_img: # images are stored as cache, open and load print("cache file {} is present, skipping pre-generation.".format(cache_path)) @@ -242,7 +241,8 @@ def main(): else: # caching is enabled, but cache file not found print("cache file {} not found, starting the pre-generation.".format(cache_path)) - images_all = preprocessing.load_images_datarefs_all(current_deck, presets_all) + images_all = preprocessing.load_images_datarefs_all( + current_deck, presets_all, global_cfg["always-upper-case"]) # save images to cache-path print("saving the pregen to {}".format(cache_path)) with open(cache_path, 'wb') as f: diff --git a/preprocessing.py b/preprocessing.py index d45e5a0..5239f7c 100644 --- a/preprocessing.py +++ b/preprocessing.py @@ -70,7 +70,11 @@ def __init__(self, index, name, icon, cmd_type, label=None, dataref=None, datare print("WARN: {} has no set type, setting none as default (no press action)".format(name)) self.cmd_type = "none" + # verify string type + if label: + label = str(label) self.label = label + self.dataref = dataref if dataref_multiplier is None: self.dataref_multiplier = 1.0 @@ -283,7 +287,7 @@ def load_datarefs(presets_all): # taken from https://python-elgato-streamdeck.readthedocs.io/en/stable/examples/basic.html -def render_key_image(deck, icon_filename, label_text): +def render_key_image(deck, icon_filename, label_text, only_uppercase=False): # Resize the source image asset to best-fit the dimensions of a single key, # leaving a margin at the bottom so that we can draw the key title # afterwards. @@ -295,12 +299,16 @@ def render_key_image(deck, icon_filename, label_text): draw = ImageDraw.Draw(image) global DEFAULT_FONT if label_text: + if only_uppercase and not label_text.isupper(): + print("WARN: label {} is not upper case only, " + "converting to upper (to disable this check out 'config.yaml'".format(label_text)) + label_text = label_text.upper() draw.text((image.width / 2, image.height - 8), text=label_text, font=DEFAULT_FONT, anchor="ms", fill="white") return PILHelper.to_native_format(deck, image) -def load_images_datarefs(deck, presets_dir): +def load_images_datarefs(deck, presets_dir, only_uppercase): set_images = {} for _, button in enumerate(presets_dir): if button is None: @@ -327,7 +335,7 @@ def load_images_datarefs(deck, presets_dir): for i, state_name in enumerate(button.file_names): if state_name not in set_images: - state_image = render_key_image(deck, state_name, button.label) + state_image = render_key_image(deck, state_name, button.label, only_uppercase) # change file_names in preset according to images_all, allowing same icons with different labels # notice how this is executed in the post-processing stage @@ -341,10 +349,10 @@ def load_images_datarefs(deck, presets_dir): return set_images -def load_images_datarefs_all(deck, presets_all): - set_images_all = {"none.png": render_key_image(deck, get_filename_button_static_png("none"), None)} +def load_images_datarefs_all(deck, presets_all, only_uppercase): + set_images_all = {"none.png": render_key_image(deck, get_filename_button_static_png("none"), None, only_uppercase)} for _, dataref_dir in presets_all.items(): - images_single_dir = load_images_datarefs(deck, dataref_dir) + images_single_dir = load_images_datarefs(deck, dataref_dir, only_uppercase) set_images_all.update(images_single_dir) return set_images_all