diff --git a/README.md b/README.md index 1cb1a07..0126e10 100644 --- a/README.md +++ b/README.md @@ -26,12 +26,12 @@ Before you build the first time, apply any patches to vendored content: Then to build the images run: - docker run -it --env "TARGET=esp32s3" -v "$(pwd)"/:/firmware matthewwilkes/esp_idf:5.2.1 + docker run -it --rm --env "TARGET=esp32s3" -v "$(pwd)"/:/firmware matthewwilkes/esp_idf:5.2.1 Alternatively, to flash a badge: put the badge into bootloader by disconnecting the usb in, press and hold bat and boop buttons for 20 seconds then reconnect the usb in and run: - docker run -it --device /dev/ttyACM0:/dev/ttyUSB0 --env "TARGET=esp32s3" -v "$(pwd)"/:/firmware matthewwilkes/esp_idf:5.2.1 deploy + docker run -it --rm --device /dev/ttyACM0:/dev/ttyUSB0 --env "TARGET=esp32s3" -v "$(pwd)"/:/firmware matthewwilkes/esp_idf:5.2.1 deploy where /dev/ttyACM0 is the device's endpoint. This value is correct on Linux. diff --git a/modules/lib/simple_tildagon.py b/modules/lib/simple_tildagon.py new file mode 100644 index 0000000..689433c --- /dev/null +++ b/modules/lib/simple_tildagon.py @@ -0,0 +1,119 @@ +# A easy to use module for the basic components of the tildagon badge + +from tildagonos import tildagonos +import imu as tilda_imu +import math +import time + + +class led(): + + @staticmethod + def _setup_leds(): + tildagonos.set_led_power(True) + + @staticmethod + def set(led_number, state): + if not isinstance(led_number, int) or led_number < 1 or led_number > 12: + raise ValueError("led_number must be an integer between 1 and 12") + + # TODO : Ideally shouldn't need to run _setup_leds each use of set_led + led._setup_leds() + + tildagonos.leds[led_number] = state + tildagonos.leds.write() + + +class button(): + + @staticmethod + def get(button_letter): + button_letter = button_letter.lower() + button_letters = { + "a": (0x5A, 0, (1 << 6)), + "b": (0x5A, 0, (1 << 7)), + "c": (0x59, 0, (1 << 0)), + "d": (0x59, 0, (1 << 1)), + "e": (0x59, 0, (1 << 2)), + "f": (0x59, 0, (1 << 3)), + } + if button_letter in button_letters.keys(): + # Note the button must be flipped, as will return True when not pressed + return not tildagonos.check_egpio_state(button_letters[button_letter]) + else: + raise ValueError("button_letter must be a string of a single letter from a to f") + + +class imu(): + class ImuData(): + def __init__(self, x, y, z): + self.x = x + self.y = y + self.z = z + + def __getitem__(self, index): + if index == 0: + return self.x + elif index == 1: + return self.y + elif index == 2: + return self.z + else: + raise IndexError("Index out of range. Valid indices are 0, 1, and 2.") + + def __str__(self): + return f"x: {self.x}, y: {self.y}, z: {self.z}" + + @staticmethod + def _magnitude(acc_read): + return math.sqrt(sum(i ** 2 for i in acc_read)) + + @staticmethod + def is_tilted_forward(): + acc_read = tilda_imu.acc_read() + if acc_read[0] < -4: + return True + return False + + @staticmethod + def is_tilted_back(): + acc_read = tilda_imu.acc_read() + if acc_read[0] > 4: + return True + return False + + @staticmethod + def is_tilted_left(): + acc_read = tilda_imu.acc_read() + if acc_read[1] < -4: + return True + return False + + @staticmethod + def is_tilted_right(): + acc_read = tilda_imu.acc_read() + if acc_read[1] > 4: + return True + return False + + @staticmethod + def is_shaken(): + acc_read1 = tilda_imu.acc_read() + magnitude1 = imu._magnitude(acc_read1) + + # Wait for a short period of time before taking another reading + time.sleep(0.1) + + acc_read2 = tilda_imu.acc_read() + magnitude2 = imu._magnitude(acc_read2) + + # If the change in magnitude is above a certain threshold (4 for now), the IMU is being shaken + if abs(magnitude1 - magnitude2) > 4: + return True + return False + + @staticmethod + def get_acceleration(): + raw_data = tilda_imu.acc_read() + acc_object = imu.ImuData(raw_data[0], raw_data[1], raw_data[2]) + return acc_object diff --git a/modules/system/ota/ota.py b/modules/system/ota/ota.py index 59d49c7..4ecfa98 100644 --- a/modules/system/ota/ota.py +++ b/modules/system/ota/ota.py @@ -161,7 +161,7 @@ async def otaupdate(self, render_update): # window.println("Press [A] to") # window.println("reboot and") # window.println("finish update.") - self.status.value = "Rebooting" + self.status.value = "Rebooping" await render_update() await asyncio.sleep(5) machine.reset() diff --git a/modules/system/patterndisplay/app.py b/modules/system/patterndisplay/app.py index 4133a05..77e624a 100644 --- a/modules/system/patterndisplay/app.py +++ b/modules/system/patterndisplay/app.py @@ -17,7 +17,7 @@ def __init__(self): _pmodule = __import__(_patternpath, globals(), locals(), [_patternclass]) _pclass = getattr(_pmodule, _patternclass) self._p = _pclass() - self.enabled = True + self.enabled = settings.get("pattern_generator_enabled", True) except: raise ImportError(f"Pattern {self.pattern} not found!") diff --git a/tildagon/manifest.py b/tildagon/manifest.py index e940c9d..670cf4b 100644 --- a/tildagon/manifest.py +++ b/tildagon/manifest.py @@ -38,6 +38,7 @@ def freeze_images(path, generated_dir): freeze("$(MPY_DIR)/../modules/lib", "typing.py") freeze("$(MPY_DIR)/../modules/lib", "typing_extensions.py") freeze("$(MPY_DIR)/../modules/lib", "shutil.py") +freeze("$(MPY_DIR)/../modules/lib", "simple_tildagon.py") #freeze("$(MPY_DIR)/../micropython-lib/python-ecosys/urequests", "urequests.py") #freeze("$(MPY_DIR)/../micropython-lib/micropython/upysh", "upysh.py") #freeze("$(MPY_DIR)/../micropython-lib/python-stdlib/functools", "functools.py") @@ -55,4 +56,4 @@ def freeze_images(path, generated_dir): require("aioble") require("aiorepl") require("gzip") -require("tarfile") \ No newline at end of file +require("tarfile")