Skip to content

Commit

Permalink
Include ADC2 in module detection
Browse files Browse the repository at this point in the history
  • Loading branch information
ZodiusInfuser committed Oct 14, 2023
1 parent 82f56df commit 682edf6
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 84 deletions.
44 changes: 28 additions & 16 deletions lib/pimoroni_yukon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()

Expand Down
10 changes: 5 additions & 5 deletions lib/pimoroni_yukon/modules/audio_amp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()
Expand Down
10 changes: 5 additions & 5 deletions lib/pimoroni_yukon/modules/bench_power.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()
Expand Down
12 changes: 6 additions & 6 deletions lib/pimoroni_yukon/modules/big_motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()
Expand Down
10 changes: 5 additions & 5 deletions lib/pimoroni_yukon/modules/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/pimoroni_yukon/modules/dual_motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()
Expand Down
10 changes: 5 additions & 5 deletions lib/pimoroni_yukon/modules/dual_switched.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()
Expand Down
10 changes: 5 additions & 5 deletions lib/pimoroni_yukon/modules/led_strip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()
Expand Down
30 changes: 15 additions & 15 deletions lib/pimoroni_yukon/modules/proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()
Expand All @@ -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
Expand Down
19 changes: 12 additions & 7 deletions lib/pimoroni_yukon/modules/quad_servo_direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 5 additions & 5 deletions lib/pimoroni_yukon/modules/quad_servo_reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()
Expand Down
10 changes: 5 additions & 5 deletions lib/pimoroni_yukon/modules/serial_servo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()
Expand Down

0 comments on commit 682edf6

Please sign in to comment.