Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INPUT LED lookup #44

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions domehunter/dome_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ def __init__(self,
# need something to let us know when dome is calibrating so home sensor
# activation doesnt zero encoder counts
self.calibrating = False

# Pin mappings, see https://pinout.xyz/pinout/automation_hat
# Used to look up which LED to flash for each input
self._input_lookup = {
26: LED_Lights.INPUT_1,
20: LED_Lights.INPUT_2,
21: LED_Lights.INPUT_3,
}

# NOTE: this led setup needs to be done before setting any callback
# functions
Expand Down Expand Up @@ -208,7 +216,7 @@ def __init__(self,
encoder_pin_number, bounce_time=bounce_time)
# _increment_count function to run when encoder is triggered
self._encoder.when_activated = self._increment_count
self._encoder.when_deactivated = self._turn_off_input_1_led
self._encoder.when_deactivated = self._turn_off_encoder_led

self._home_sensor = DigitalInputDevice(
home_sensor_pin_number, bounce_time=bounce_time)
Expand Down Expand Up @@ -411,7 +419,7 @@ def _set_at_home(self):
"""
Update home status to at home and debug LEDs (if enabled).
"""
self._change_led_state(1, leds=[LED_Lights.INPUT_2])
self._change_led_state(1, leds=[self._input_lookup[self._home_sensor.pin.number]])
# don't want to zero encoder while calibrating
# note: because Direction.CW is +1 and Direction.CCW is -1, need to
# add 1 to self.current_direction, to get CCW to evaluate to False
Expand All @@ -422,7 +430,7 @@ def _set_not_home(self):
"""
Update home status to not at home and debug LEDs (if enabled).
"""
self._change_led_state(0, leds=[LED_Lights.INPUT_2])
self._change_led_state(0, leds=[self._input_lookup[self._home_sensor.pin.number]])

def _increment_count(self):
"""
Expand All @@ -436,8 +444,8 @@ def _increment_count(self):
direction is adopted.
"""
print(f"Encoder activated _increment_count")
self._change_led_state(1, leds=[LED_Lights.INPUT_1])

self._change_led_state(1, leds=[self._input_lookup[self._encoder.pin.number]])
if self.current_direction != Direction.NONE:
self._encoder_count += self.current_direction
elif self.last_direction != Direction.NONE:
Expand Down Expand Up @@ -573,9 +581,10 @@ def _change_led_state(self, desired_state, leds=[]): # pragma: no cover
# pass the new binary int to LED controller
sn3218.enable_leds(self.led_status.value)

def _turn_off_input_1_led(self):
def _turn_off_encoder_led(self):
"""
Call back function for encoder pin, turns the status led off when
encoder pin is deactivated.
"""
self._change_led_state(0, leds=[LED_Lights.INPUT_1])
self._change_led_state(1, leds=[self._input_lookup[self._encoder.pin.number]])