Skip to content

Commit

Permalink
Future module ideas
Browse files Browse the repository at this point in the history
  • Loading branch information
ZodiusInfuser committed Dec 12, 2024
1 parent 869b4c0 commit 0f308fd
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/pimoroni_yukon/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
from .quad_servo_direct import QuadServoDirectModule
from .quad_servo_reg import QuadServoRegModule
from .serial_servo import SerialServoModule
from .micro_sd import MicroSDModule
from .mech_key import MechKeyModule
from .potentiometer import PotModule


KNOWN_MODULES = (
Expand All @@ -24,4 +27,7 @@
ProtoPotModule,
QuadServoDirectModule,
QuadServoRegModule,
SerialServoModule)
SerialServoModule,
MicroSDModule,
MechKeyModule,
PotModule)
45 changes: 45 additions & 0 deletions lib/pimoroni_yukon/modules/mech_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# SPDX-FileCopyrightText: 2025 Christopher Parrott for Pimoroni Ltd
#
# SPDX-License-Identifier: MIT

from .common import YukonModule, ADC_FLOAT, ADC_HIGH, IO_HIGH, IO_LOW
from machine import Pin
from pimoroni import RGBLED


class MechKeyModule(YukonModule):
NAME = "Mechanical Key + RGB"

# | ADC1 | ADC2 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) |
# |-------|-------|-------|-------|-------|----------------------|-----------------------------|
# | HIGH | FLOAT | 1 | 0 | 0 | Mechanical Key | |
@staticmethod
def is_module(adc1_level, adc2_level, slow1, slow2, slow3):
return adc1_level is ADC_HIGH and adc2_level is ADC_FLOAT and slow1 is IO_HIGH and slow2 is IO_LOW and slow3 is IO_LOW

def __init__(self):
super().__init__()

def initialise(self, slot, adc1_func, adc2_func):

# Create the key pin object
self.__key = slot.FAST4
self.__key.init(Pin.IN, Pin.PULL_UP)

# Create the RGB LED object
self.__led = RGBLED(slot.FAST1, slot.FAST2, slot.FAST3, invert=True)

# Pass the slot and adc functions up to the parent now that module specific initialisation has finished
super().initialise(slot, adc1_func, adc2_func)

def reset(self):
self.__led.set_rgb(0, 0, 0)

def set_rgb(self, r, g, b):
self.__led.set_rgb(r, g, b)

def set_hsv(self, h, s, v):
self.__led.set_hsv(h, s, v)

def is_pressed(self):
return self.__key.value() != 1
64 changes: 64 additions & 0 deletions lib/pimoroni_yukon/modules/micro_sd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# SPDX-FileCopyrightText: 2025 Christopher Parrott for Pimoroni Ltd
#
# SPDX-License-Identifier: MIT

import vfs
from machine import SPI
from sdcard import SDCard
from .common import YukonModule, ADC_LOW, ADC_FLOAT, IO_LOW, IO_HIGH


class MicroSDModule(YukonModule):
NAME = "Micro SD Card"

CARD_DETECT_LEVEL = 1.65

# | ADC1 | ADC2 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) |
# |-------|-------|-------|-------|-------|----------------------|-----------------------------|
# | LOW | LOW | 1 | 0 | 1 | Micro SD Card | Card Inserted |
# | LOW | HIGH | 1 | 0 | 1 | Micro SD Card | No Card |
@staticmethod
def is_module(adc1_level, adc2_level, slow1, slow2, slow3):
return adc1_level == ADC_LOW and adc2_level != ADC_FLOAT and slow1 is IO_HIGH and slow2 is IO_LOW and slow3 is IO_HIGH

def __init__(self):
super().__init__()

try:
import sdcard
except ImportError:
raise RuntimeError("This build does not contain sd card support. Please flash your Yukon with a build that supports sd cards in order to use this module.")

def initialise(self, slot, adc1_func, adc2_func):
try:
# Create the SPI object
spi_id = (((slot.ID - 1) * 4) // 8) % 2
self.__spi = SPI(spi_id, sck=slot.FAST3, mosi=slot.FAST4, miso=slot.FAST1)

except ValueError as e:
raise type(e)("SPI perhiperal already in use. Check that a module in another slot does not share the same SPI perhiperal") from None

self.__card_cs = slot.FAST2
self.__sd = None
self.__path = None

# Pass the slot and adc functions up to the parent now that module specific initialisation has finished
super().initialise(slot, adc1_func, adc2_func)

def reset(self):
self.umount()

def mount(self, path="/sd", baudrate=26400000):
if self.__sd is None:
self.__sd = SDCard(self.__spi, self.__card_cs, baudrate=baudrate)
self.__path = path
vfs.mount(self.__sd, self.__path)

def umount(self):
if self.__sd is not None:
vfs.umount(self.__path)
self.__sd = None
self.__path = None

def card_present(self):
return self.__read_adc2() >= self.CARD_DETECT_LEVEL
47 changes: 47 additions & 0 deletions lib/pimoroni_yukon/modules/potentiometer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# SPDX-FileCopyrightText: 2023 Christopher Parrott for Pimoroni Ltd
#
# SPDX-License-Identifier: MIT

from .common import YukonModule, ADC_HIGH, ADC_LOW, IO_HIGH, IO_LOW
from machine import Pin
from pimoroni import RGBLED


class PotModule(YukonModule):
NAME = "Potentiometer + RGB"

# | ADC1 | ADC2 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) |
# |-------|-------|-------|-------|-------|----------------------|-----------------------------|
# | HIGH | LOW | 1 | 1 | 0 | Potentiometer + RGB | |
@staticmethod
def is_module(adc1_level, adc2_level, slow1, slow2, slow3):
return adc1_level is ADC_HIGH and adc2_level is ADC_LOW and slow1 is IO_HIGH and slow2 is IO_HIGH and slow3 is IO_LOW

def __init__(self):
super().__init__()

def initialise(self, slot, adc1_func, adc2_func):

# Create the potentiometer end pin object
self.__pot_a = slot.SLOW1
self.__pot_b = slot.SLOW2
self.__pot_a.init(Pin.OUT, value=False)
self.__pot_b.init(Pin.OUT, value=True)

# Create the RGB LED object
self.__led = RGBLED(slot.FAST1, slot.FAST2, slot.FAST3, invert=True)

# Pass the slot and adc functions up to the parent now that module specific initialisation has finished
super().initialise(slot, adc1_func, adc2_func)

def reset(self):
self.__led.set_rgb(0, 0, 0)

def set_rgb(self, r, g, b):
self.__led.set_rgb(r, g, b)

def set_hsv(self, h, s, v):
self.__led.set_hsv(h, s, v)

def read(self, samples=1):
return self.__read_adc1(samples) / 3.3

0 comments on commit 0f308fd

Please sign in to comment.