diff --git a/lib/pimoroni_yukon/__init__.py b/lib/pimoroni_yukon/__init__.py index d812c4c..601be3e 100644 --- a/lib/pimoroni_yukon/__init__.py +++ b/lib/pimoroni_yukon/__init__.py @@ -317,11 +317,11 @@ def deregister_slot(self, slot): module.deregister() self.__slot_assignments[slot] = None - def __match_module(self, adc_level, slow1, slow2, slow3): + def __match_module(self, adc1_level, adc2_level, slow1, slow2, slow3): for m in KNOWN_MODULES: - if m.is_module(adc_level, slow1, slow2, slow3): + if m.is_module(adc1_level, adc2_level, slow1, slow2, slow3): return m - if YukonModule.is_module(adc_level, slow1, slow2, slow3): + if YukonModule.is_module(adc1_level, adc2_level, slow1, slow2, slow3): return YukonModule return None @@ -336,20 +336,32 @@ def __detect_module(self, slot): slow3.init(Pin.IN) self.__select_address(slot.ADC1_ADDR) - adc_val = 0 - for i in range(self.DETECTION_SAMPLES): - adc_val += self.__shared_adc_voltage() - adc_val /= self.DETECTION_SAMPLES + adc1_val = 0 + for _ in range(self.DETECTION_SAMPLES): + adc1_val += self.__shared_adc_voltage() + adc1_val /= self.DETECTION_SAMPLES - logging.debug(f"ADC1 = {adc_val}, SLOW1 = {slow1.value()}, SLOW2 = {slow2.value()}, SLOW3 = {slow3.value()}", end=", ") - - adc_level = ADC_FLOAT - if adc_val <= self.DETECTION_ADC_LOW: - adc_level = ADC_LOW - elif adc_val >= self.DETECTION_ADC_HIGH: - adc_level = ADC_HIGH - - detected = self.__match_module(adc_level, slow1.value() == 1, slow2.value() == 1, slow3.value() == 1) + self.__select_address(slot.ADC2_THERM_ADDR) + adc2_val = 0 + for _ in range(self.DETECTION_SAMPLES): + adc2_val += self.__shared_adc_voltage() + adc2_val /= self.DETECTION_SAMPLES + + logging.debug(f"ADC1 = {adc1_val}, ADC2 = {adc2_val}, SLOW1 = {slow1.value()}, SLOW2 = {slow2.value()}, SLOW3 = {slow3.value()}", end=", ") + + adc1_level = ADC_FLOAT + if adc1_val <= self.DETECTION_ADC_LOW: + adc1_level = ADC_LOW + elif adc1_val >= self.DETECTION_ADC_HIGH: + adc1_level = ADC_HIGH + + adc2_level = ADC_FLOAT + if adc2_val <= self.DETECTION_ADC_LOW: + adc2_level = ADC_LOW + elif adc2_val >= self.DETECTION_ADC_HIGH: + adc2_level = ADC_HIGH + + detected = self.__match_module(adc1_level, adc2_level, slow1.value() == 1, slow2.value() == 1, slow3.value() == 1) self.__deselect_address() diff --git a/lib/pimoroni_yukon/modules/audio_amp.py b/lib/pimoroni_yukon/modules/audio_amp.py index 2be6df5..5b418e5 100644 --- a/lib/pimoroni_yukon/modules/audio_amp.py +++ b/lib/pimoroni_yukon/modules/audio_amp.py @@ -128,12 +128,12 @@ class AudioAmpModule(YukonModule): AMP_I2C_ADDRESS = 0x38 TEMPERATURE_THRESHOLD = 50.0 - # | ADC1 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | - # |-------|-------|-------|-------|----------------------|-----------------------------| - # | FLOAT | 0 | 1 | 1 | Audio Amp | | + # | ADC1 | ADC2 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | + # |-------|-------|-------|-------|-------|----------------------|-----------------------------| + # | FLOAT | ALL | 0 | 1 | 1 | Audio Amp | | @staticmethod - def is_module(adc_level, slow1, slow2, slow3): - return adc_level == ADC_FLOAT and slow1 is LOW and slow2 is HIGH and slow3 is HIGH + def is_module(adc1_level, adc2_level, slow1, slow2, slow3): + return adc1_level == ADC_FLOAT and slow1 is LOW and slow2 is HIGH and slow3 is HIGH def __init__(self): super().__init__() diff --git a/lib/pimoroni_yukon/modules/bench_power.py b/lib/pimoroni_yukon/modules/bench_power.py index c82ea2b..03be8e6 100644 --- a/lib/pimoroni_yukon/modules/bench_power.py +++ b/lib/pimoroni_yukon/modules/bench_power.py @@ -23,12 +23,12 @@ class BenchPowerModule(YukonModule): TEMPERATURE_THRESHOLD = 70.0 - # | ADC1 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | - # |-------|-------|-------|-------|----------------------|-----------------------------| - # | LOW | 1 | 0 | 0 | Bench Power | | + # | ADC1 | ADC2 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | + # |-------|-------|-------|-------|-------|----------------------|-----------------------------| + # | LOW | ALL | 1 | 0 | 0 | Bench Power | | @staticmethod - def is_module(adc_level, slow1, slow2, slow3): - return adc_level is ADC_LOW and slow1 is HIGH and slow2 is LOW and slow3 is LOW + def is_module(adc1_level, adc2_level, slow1, slow2, slow3): + return adc1_level is ADC_LOW and slow1 is HIGH and slow2 is LOW and slow3 is LOW def __init__(self, halt_on_not_pgood=False): super().__init__() diff --git a/lib/pimoroni_yukon/modules/big_motor.py b/lib/pimoroni_yukon/modules/big_motor.py index ceec9c1..fdd3b44 100644 --- a/lib/pimoroni_yukon/modules/big_motor.py +++ b/lib/pimoroni_yukon/modules/big_motor.py @@ -20,13 +20,13 @@ class BigMotorModule(YukonModule): SHUNT_RESISTOR = 0.001 GAIN = 80 - # | ADC1 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | - # |-------|-------|-------|-------|----------------------|-----------------------------| - # | LOW | 0 | 0 | 1 | Big Motor | Not in fault | - # | LOW | 0 | 1 | 1 | Big Motor | In fault | + # | ADC1 | ADC2 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | + # |-------|-------|-------|-------|-------|----------------------|-----------------------------| + # | LOW | ALL | 0 | 0 | 1 | Big Motor | Not in fault | + # | LOW | ALL | 0 | 1 | 1 | Big Motor | In fault | @staticmethod - def is_module(adc_level, slow1, slow2, slow3): - return adc_level == ADC_LOW and slow1 is LOW and slow3 is HIGH + def is_module(adc1_level, adc2_level, slow1, slow2, slow3): + return adc1_level == ADC_LOW and slow1 is LOW and slow3 is HIGH def __init__(self, frequency=DEFAULT_FREQUENCY, counts_per_rev=None): super().__init__() diff --git a/lib/pimoroni_yukon/modules/common.py b/lib/pimoroni_yukon/modules/common.py index e668ddc..2032df7 100644 --- a/lib/pimoroni_yukon/modules/common.py +++ b/lib/pimoroni_yukon/modules/common.py @@ -15,13 +15,13 @@ class YukonModule: NAME = "Unknown" - # | ADC1 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | - # |-------|-------|-------|-------|----------------------|-----------------------------| - # | FLOAT | 1 | 1 | 1 | Empty | | + # | ADC1 | ADC2 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | + # |-------|-------|-------|-------|-------|----------------------|-----------------------------| + # | FLOAT | HIGH | 1 | 1 | 1 | Empty | | @staticmethod - def is_module(adc_level, slow1, slow2, slow3): + def is_module(adc1_level, adc2_level, slow1, slow2, slow3): # This will return true if a slot is detected as not being empty, so as to give useful error information - return adc_level is not ADC_FLOAT or slow1 is not HIGH or slow2 is not HIGH or slow3 is not HIGH + return adc1_level is not ADC_FLOAT or adc2_level is not ADC_HIGH or slow1 is not HIGH or slow2 is not HIGH or slow3 is not HIGH def __init__(self): self.slot = None diff --git a/lib/pimoroni_yukon/modules/dual_motor.py b/lib/pimoroni_yukon/modules/dual_motor.py index 9f1aba4..562bdde 100644 --- a/lib/pimoroni_yukon/modules/dual_motor.py +++ b/lib/pimoroni_yukon/modules/dual_motor.py @@ -31,12 +31,12 @@ class DualMotorModule(YukonModule): DEFAULT_CURRENT_LIMIT = CURRENT_LIMIT_3 TEMPERATURE_THRESHOLD = 50.0 - # | ADC1 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | - # |-------|-------|-------|-------|----------------------|-----------------------------| - # | HIGH | 0 | 0 | 1 | Dual Motor | | + # | ADC1 | ADC2 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | + # |-------|-------|-------|-------|-------|----------------------|-----------------------------| + # | HIGH | ALL | 0 | 0 | 1 | Dual Motor | | @staticmethod - def is_module(adc_level, slow1, slow2, slow3): - return adc_level == ADC_HIGH and slow1 is LOW and slow2 is LOW and slow3 is HIGH + def is_module(adc1_level, adc2_level, slow1, slow2, slow3): + return adc1_level == ADC_HIGH and slow1 is LOW and slow2 is LOW and slow3 is HIGH def __init__(self, motor_type=DUAL, frequency=DEFAULT_FREQUENCY, current_limit=DEFAULT_CURRENT_LIMIT, init_motors=True): super().__init__() diff --git a/lib/pimoroni_yukon/modules/dual_switched.py b/lib/pimoroni_yukon/modules/dual_switched.py index 0547883..d6a1854 100644 --- a/lib/pimoroni_yukon/modules/dual_switched.py +++ b/lib/pimoroni_yukon/modules/dual_switched.py @@ -14,12 +14,12 @@ class DualSwitchedModule(YukonModule): NUM_SWITCHES = 2 TEMPERATURE_THRESHOLD = 50.0 - # | ADC1 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | - # |-------|-------|-------|-------|----------------------|-----------------------------| - # | FLOAT | 1 | 0 | 1 | Dual Switched Output | | + # | ADC1 | ADC2 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | + # |-------|-------|-------|-------|-------|----------------------|-----------------------------| + # | FLOAT | ALL | 1 | 0 | 1 | Dual Switched Output | | @staticmethod - def is_module(adc_level, slow1, slow2, slow3): - return adc_level == ADC_FLOAT and slow1 is HIGH and slow2 is LOW and slow3 is HIGH + def is_module(adc1_level, adc2_level, slow1, slow2, slow3): + return adc1_level == ADC_FLOAT and slow1 is HIGH and slow2 is LOW and slow3 is HIGH def __init__(self, halt_on_not_pgood=False): super().__init__() diff --git a/lib/pimoroni_yukon/modules/led_strip.py b/lib/pimoroni_yukon/modules/led_strip.py index 8e0ab0e..0746b89 100644 --- a/lib/pimoroni_yukon/modules/led_strip.py +++ b/lib/pimoroni_yukon/modules/led_strip.py @@ -16,12 +16,12 @@ class LEDStripModule(YukonModule): DOTSTAR = 2 TEMPERATURE_THRESHOLD = 70.0 - # | ADC1 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | - # |-------|-------|-------|-------|----------------------|-----------------------------| - # | LOW | 1 | 1 | 1 | LED Strip | | + # | ADC1 | ADC2 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | + # |-------|-------|-------|-------|-------|----------------------|-----------------------------| + # | LOW | ALL | 1 | 1 | 1 | LED Strip | | @staticmethod - def is_module(adc_level, slow1, slow2, slow3): - return adc_level == ADC_LOW and slow1 is HIGH and slow2 is HIGH and slow3 is HIGH + def is_module(adc1_level, adc2_level, slow1, slow2, slow3): + return adc1_level == ADC_LOW and slow1 is HIGH and slow2 is HIGH and slow3 is HIGH def __init__(self, strip_type, pio, sm, num_leds, brightness=1.0, halt_on_not_pgood=False): super().__init__() diff --git a/lib/pimoroni_yukon/modules/proto.py b/lib/pimoroni_yukon/modules/proto.py index 7ab7af6..ca7ca92 100644 --- a/lib/pimoroni_yukon/modules/proto.py +++ b/lib/pimoroni_yukon/modules/proto.py @@ -2,20 +2,20 @@ # # SPDX-License-Identifier: MIT -from .common import YukonModule, LOW, HIGH +from .common import YukonModule, ADC_FLOAT, ADC_HIGH, LOW, HIGH class ProtoPotModule(YukonModule): NAME = "Proto Potentiometer" - # | ADC1 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | - # |-------|-------|-------|-------|----------------------|-----------------------------| - # | LOW | 1 | 1 | 0 | Proto Potentiometer | Pot in low position | - # | FLOAT | 1 | 1 | 0 | Proto Potentiometer | Pot in middle position | - # | HIGH | 1 | 1 | 0 | Proto Potentiometer | Pot in high position | + # | ADC1 | ADC2 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | + # |-------|-------|-------|-------|-------|----------------------|-----------------------------| + # | LOW | HIGH | 1 | 1 | 0 | Proto Potentiometer | Pot in low position | + # | FLOAT | HIGH | 1 | 1 | 0 | Proto Potentiometer | Pot in middle position | + # | HIGH | HIGH | 1 | 1 | 0 | Proto Potentiometer | Pot in high position | @staticmethod - def is_module(adc_level, slow1, slow2, slow3): - return slow1 is HIGH and slow2 is HIGH and slow3 is LOW + def is_module(adc1_level, adc2_level, slow1, slow2, slow3): + return adc2_level is ADC_HIGH and slow1 is HIGH and slow2 is HIGH and slow3 is LOW def __init__(self): super().__init__() @@ -29,14 +29,14 @@ class ProtoPotModule2(YukonModule): NAME = "Proto Potentiometer 2" PULLUP = 5100 - # | ADC1 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | - # |-------|-------|-------|-------|----------------------|-----------------------------| - # | LOW | 1 | 1 | 0 | Proto Potentiometer | Pot in low position | - # | FLOAT | 1 | 1 | 0 | Proto Potentiometer | Pot in middle position | - # | HIGH | 1 | 1 | 0 | Proto Potentiometer | Pot in high position | + # | ADC1 | ADC2 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | + # |-------|-------|-------|-------|-------|----------------------|-----------------------------| + # | FLOAT | LOW | 1 | 1 | 0 | Proto Potentiometer | Pot in low position | + # | FLOAT | FLOAT | 1 | 1 | 0 | Proto Potentiometer | Pot in middle position | + # | FLOAT | HIGH | 1 | 1 | 0 | Proto Potentiometer | Pot in high position | @staticmethod - def is_module(adc_level, slow1, slow2, slow3): - return slow1 is HIGH and slow2 is HIGH and slow3 is LOW + def is_module(adc1_level, adc2_level, slow1, slow2, slow3): + return adc1_level is ADC_FLOAT and slow1 is HIGH and slow2 is HIGH and slow3 is LOW # ADC2 has a pull-up connected to simplify its use with modules that feature an onboard thermistor. # Unfortunately, when connecting up a potentiometer, creating the below circuit, this has the diff --git a/lib/pimoroni_yukon/modules/quad_servo_direct.py b/lib/pimoroni_yukon/modules/quad_servo_direct.py index d009f4e..c7e0fb6 100644 --- a/lib/pimoroni_yukon/modules/quad_servo_direct.py +++ b/lib/pimoroni_yukon/modules/quad_servo_direct.py @@ -10,14 +10,19 @@ class QuadServoDirectModule(YukonModule): NAME = "Quad Servo Direct" NUM_SERVOS = 4 - # | ADC1 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | - # |-------|-------|-------|-------|----------------------|-----------------------------| - # | LOW | 0 | 0 | 0 | Quad Servo Direct | A1 input near 0V | - # | FLOAT | 0 | 0 | 0 | Quad Servo Direct | A1 input between 0 and 3.3V | - # | HIGH | 0 | 0 | 0 | Quad Servo Direct | A1 input near 3.3V | + # | ADC1 | ADC2 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | + # |-------|-------|-------|-------|-------|----------------------|-----------------------------| + # | LOW | LOW | 0 | 0 | 0 | Quad Servo Direct | A1 near 0V. A2 near 0V | + # | FLOAT | LOW | 0 | 0 | 0 | Quad Servo Direct | A1 between. A2 near 0V | + # | HIGH | LOW | 0 | 0 | 0 | Quad Servo Direct | A1 near 3.3V. A2 near 0V | + # | LOW | FLOAT | 0 | 0 | 0 | Quad Servo Direct | A1 near 0V. A2 between | + # | FLOAT | FLOAT | 0 | 0 | 0 | Quad Servo Direct | A1 between. A2 between | + # | HIGH | FLOAT | 0 | 0 | 0 | Quad Servo Direct | A1 near 3.3V. A2 between | + # | LOW | HIGH | 0 | 0 | 0 | Quad Servo Direct | A1 near 0V. A2 near 3.3V | + # | FLOAT | HIGH | 0 | 0 | 0 | Quad Servo Direct | A1 between. A2 near 3.3V | + # | HIGH | HIGH | 0 | 0 | 0 | Quad Servo Direct | A1 near 3.3V. A2 near 3.3V | @staticmethod - def is_module(adc_level, slow1, slow2, slow3): - # Current protos need Slow3 jumpered to GND + def is_module(adc1_level, adc2_level, slow1, slow2, slow3): return slow1 is LOW and slow2 is LOW and slow3 is LOW def __init__(self, init_servos=True): diff --git a/lib/pimoroni_yukon/modules/quad_servo_reg.py b/lib/pimoroni_yukon/modules/quad_servo_reg.py index e390f60..a3d6726 100644 --- a/lib/pimoroni_yukon/modules/quad_servo_reg.py +++ b/lib/pimoroni_yukon/modules/quad_servo_reg.py @@ -15,12 +15,12 @@ class QuadServoRegModule(YukonModule): NUM_SERVOS = 4 TEMPERATURE_THRESHOLD = 70.0 - # | ADC1 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | - # |-------|-------|-------|-------|----------------------|-----------------------------| - # | FLOAT | 0 | 1 | 0 | Quad Servo Regulated | | + # | ADC1 | ADC2 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | + # |-------|-------|-------|-------|-------|----------------------|-----------------------------| + # | FLOAT | ALL | 0 | 1 | 0 | Quad Servo Regulated | | @staticmethod - def is_module(adc_level, slow1, slow2, slow3): - return adc_level == ADC_FLOAT and slow1 is LOW and slow2 is HIGH and slow3 is LOW + def is_module(adc1_level, adc2_level, slow1, slow2, slow3): + return adc1_level == ADC_FLOAT and slow1 is LOW and slow2 is HIGH and slow3 is LOW def __init__(self, init_servos=True, halt_on_not_pgood=False): super().__init__() diff --git a/lib/pimoroni_yukon/modules/serial_servo.py b/lib/pimoroni_yukon/modules/serial_servo.py index dafe2e5..d67ea2a 100644 --- a/lib/pimoroni_yukon/modules/serial_servo.py +++ b/lib/pimoroni_yukon/modules/serial_servo.py @@ -13,12 +13,12 @@ class SerialServoModule(YukonModule): DEFAULT_BAUDRATE = 115200 TEMPERATURE_THRESHOLD = 50.0 - # | ADC1 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | - # |-------|-------|-------|-------|----------------------|-----------------------------| - # | FLOAT | 1 | 0 | 0 | Serial Servo | | + # | ADC1 | ADC2 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | + # |-------|-------|-------|-------|-------|----------------------|-----------------------------| + # | FLOAT | ALL | 1 | 0 | 0 | Serial Servo | | @staticmethod - def is_module(adc_level, slow1, slow2, slow3): - return adc_level is ADC_FLOAT and slow1 is HIGH and slow2 is LOW and slow3 is LOW + def is_module(adc1_level, adc2_level, slow1, slow2, slow3): + return adc1_level is ADC_FLOAT and slow1 is HIGH and slow2 is LOW and slow3 is LOW def __init__(self, baudrate=DEFAULT_BAUDRATE): super().__init__()