Skip to content

Commit

Permalink
Merge pull request #99 from Koseng/rotaryLed
Browse files Browse the repository at this point in the history
Allow simvar_led configuration for encoders
  • Loading branch information
maartentamboer authored Apr 24, 2022
2 parents 65b8a2d + d7394f9 commit 9cf00c3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
6 changes: 6 additions & 0 deletions configfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def _configure_encoders(self, data):
event_press = elem.get('event_press')
event_short_press = elem.get('event_short_press')
event_long_press = elem.get('event_long_press')
simvar_led = elem.get('simvar_led')
mobiflightsimvar_led = elem.get('mobiflightsimvar_led')
encoder = self._encoders[index - 1]

if event_up and event_down:
Expand All @@ -107,6 +109,10 @@ def _configure_encoders(self, data):
encoder.bind_short_press(self._create_binding(encoder, event_short_press))
if event_long_press:
encoder.bind_long_press(self._create_binding(encoder, event_long_press))
if simvar_led:
encoder.bind_led_to_simvar(simvar_led)
if mobiflightsimvar_led:
encoder.bind_led_to_mobiflightsimvar(mobiflightsimvar_led)

def _configure_buttons(self, data):
for btn in self._buttons:
Expand Down
26 changes: 24 additions & 2 deletions rotaryencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def __init__(self, encoder_index, outport: mido.ports.BaseOutput):
self._receive_data_note = self._encoder_index - 1
self._led_ring_value_cc = self._encoder_index + 8
self._on_layer = ActiveLayerIdentifier.A
self._simvar = None
self._mobiflightsimvar = None
self._event_up = None
self._event_down = None
self._alternate_event_up = None
Expand Down Expand Up @@ -49,6 +51,12 @@ def set_led_ring_on_off(self, on: bool, blink=False):
self._current_led_ring_value = value
self._update_led_ring()

def bind_led_to_simvar(self, simvar: str):
self._simvar = simvar

def bind_led_to_mobiflightsimvar(self, simvar: str):
self._mobiflightsimvar = simvar

def bind_to_event(self, event_up, event_down):
self._event_up = event_up
self._event_down = event_down
Expand All @@ -67,6 +75,8 @@ def bind_long_press(self, event):
self._event_press_long = event

def reset_configuration(self):
self._simvar = None
self._mobiflightsimvar = None
self._event_up = None
self._event_down = None
self._alternate_event_up = None
Expand All @@ -87,11 +97,11 @@ def button_note(self):

@property
def bound_simvar(self):
return None
return self._simvar

@property
def bound_mobiflightsimvar(self):
return None
return self._mobiflightsimvar


def on_cc_data(self, value):
Expand Down Expand Up @@ -134,6 +144,18 @@ def on_alternate(self, enable: bool):
def on_alternate_toggle(self, _):
self._alternate_active = not self._alternate_active

def on_simvar_data(self, data):
if data == 1.0:
self.set_led_ring_on_off(True)
else:
self.set_led_ring_on_off(False)

def on_mobiflightsimvar_data(self, data):
if data == 1.0:
self.set_led_ring_on_off(True)
else:
self.set_led_ring_on_off(False)

def _update_active_layer(self):
ActiveLayer().active_layer = self._on_layer

Expand Down

0 comments on commit 9cf00c3

Please sign in to comment.