From 33549fff41e7ca04c1126e0f67d087e894048644 Mon Sep 17 00:00:00 2001 From: Bob Clough Date: Sat, 1 Jun 2024 18:18:50 +0100 Subject: [PATCH 1/8] pattern generator: add secret config option to set pattern generator off by default --- modules/system/patterndisplay/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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!") From 86547c67cc232e2883dd9f5a4561d7c429c36df4 Mon Sep 17 00:00:00 2001 From: Sven Date: Sat, 1 Jun 2024 17:40:42 +0200 Subject: [PATCH 2/8] Update README.md docker instructions Add `--rm` to the docker commandline to not leave old unused containers around. All the state is in the mapped folders, so they only waste disk space (and caused some weird btrfs issues on my system) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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. From 7143b2b13f333a9fd7530b6a47f33cacfd8f9fc8 Mon Sep 17 00:00:00 2001 From: Andrew Mulholland Date: Sat, 1 Jun 2024 20:15:44 +0100 Subject: [PATCH 3/8] Add initial simple_tildagon module --- modules/lib/simple_tildagon.py | 119 +++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 modules/lib/simple_tildagon.py diff --git a/modules/lib/simple_tildagon.py b/modules/lib/simple_tildagon.py new file mode 100644 index 0000000..946683f --- /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 < 0 or led_number > 7: + raise ValueError("led_number must be an integer between 0 and 7") + + # 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[1] > 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[0] < -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 From dbfce9a1cae091234fc9dc946598f76ff237f3f7 Mon Sep 17 00:00:00 2001 From: Andrew Mulholland Date: Sat, 1 Jun 2024 23:18:03 +0100 Subject: [PATCH 4/8] Fix tilt directions --- modules/lib/simple_tildagon.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/lib/simple_tildagon.py b/modules/lib/simple_tildagon.py index 946683f..07ec020 100644 --- a/modules/lib/simple_tildagon.py +++ b/modules/lib/simple_tildagon.py @@ -78,21 +78,21 @@ def is_tilted_forward(): @staticmethod def is_tilted_back(): acc_read = tilda_imu.acc_read() - if acc_read[1] > 4: + 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: + if acc_read[1] < -4: return True return False @staticmethod def is_tilted_right(): acc_read = tilda_imu.acc_read() - if acc_read[0] < -4: + if acc_read[1] > 4: return True return False From 180eb36efe9f2ca2758398f0b2ae576335c52939 Mon Sep 17 00:00:00 2001 From: Andrew Mulholland Date: Sat, 1 Jun 2024 23:22:07 +0100 Subject: [PATCH 5/8] Fix LED ID checks --- modules/lib/simple_tildagon.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/lib/simple_tildagon.py b/modules/lib/simple_tildagon.py index 07ec020..530051e 100644 --- a/modules/lib/simple_tildagon.py +++ b/modules/lib/simple_tildagon.py @@ -14,13 +14,13 @@ def _setup_leds(): @staticmethod def set(led_number, state): - if not isinstance(led_number, int) or led_number < 0 or led_number > 7: - raise ValueError("led_number must be an integer between 0 and 7") + 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[led_number-1] = state tildagonos.leds.write() From 15bf0a86a28ee08af4a87825ffa4c84c84c6b4f5 Mon Sep 17 00:00:00 2001 From: Andrew Mulholland Date: Sat, 1 Jun 2024 23:27:29 +0100 Subject: [PATCH 6/8] Undo LED offset as not needed --- modules/lib/simple_tildagon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/lib/simple_tildagon.py b/modules/lib/simple_tildagon.py index 530051e..689433c 100644 --- a/modules/lib/simple_tildagon.py +++ b/modules/lib/simple_tildagon.py @@ -20,7 +20,7 @@ def set(led_number, state): # TODO : Ideally shouldn't need to run _setup_leds each use of set_led led._setup_leds() - tildagonos.leds[led_number-1] = state + tildagonos.leds[led_number] = state tildagonos.leds.write() From a3ec6e0062b3350f6b87bbb0471cec615bedf7f3 Mon Sep 17 00:00:00 2001 From: Andrew Mulholland <833193+gbaman@users.noreply.github.com> Date: Sun, 2 Jun 2024 10:52:45 +0100 Subject: [PATCH 7/8] Update manifest.py to add simple_tildagon --- tildagon/manifest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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") From 220fd575f638f70be53ca8901cede4152f246af8 Mon Sep 17 00:00:00 2001 From: Mat Booth Date: Sun, 2 Jun 2024 13:20:49 +0100 Subject: [PATCH 8/8] Fix typographical error in "Rebooping" message --- modules/system/ota/ota.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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()