Skip to content

Commit

Permalink
Merge branch 'main' of github.com:emfcamp/badge-2024-software into main
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewWilkes committed Jun 2, 2024
2 parents 7ca1186 + 06b1606 commit 8ee0030
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
119 changes: 119 additions & 0 deletions modules/lib/simple_tildagon.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion modules/system/ota/ota.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion modules/system/patterndisplay/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!")

Expand Down
3 changes: 2 additions & 1 deletion tildagon/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -55,4 +56,4 @@ def freeze_images(path, generated_dir):
require("aioble")
require("aiorepl")
require("gzip")
require("tarfile")
require("tarfile")

0 comments on commit 8ee0030

Please sign in to comment.