Skip to content

Commit 8ee0030

Browse files
committed
Merge branch 'main' of github.com:emfcamp/badge-2024-software into main
2 parents 7ca1186 + 06b1606 commit 8ee0030

File tree

5 files changed

+125
-5
lines changed

5 files changed

+125
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ Before you build the first time, apply any patches to vendored content:
2626

2727
Then to build the images run:
2828

29-
docker run -it --env "TARGET=esp32s3" -v "$(pwd)"/:/firmware matthewwilkes/esp_idf:5.2.1
29+
docker run -it --rm --env "TARGET=esp32s3" -v "$(pwd)"/:/firmware matthewwilkes/esp_idf:5.2.1
3030

3131
Alternatively, to flash a badge:
3232
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:
3333

34-
docker run -it --device /dev/ttyACM0:/dev/ttyUSB0 --env "TARGET=esp32s3" -v "$(pwd)"/:/firmware matthewwilkes/esp_idf:5.2.1 deploy
34+
docker run -it --rm --device /dev/ttyACM0:/dev/ttyUSB0 --env "TARGET=esp32s3" -v "$(pwd)"/:/firmware matthewwilkes/esp_idf:5.2.1 deploy
3535

3636
where /dev/ttyACM0 is the device's endpoint. This value is correct on Linux.
3737

modules/lib/simple_tildagon.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# A easy to use module for the basic components of the tildagon badge
2+
3+
from tildagonos import tildagonos
4+
import imu as tilda_imu
5+
import math
6+
import time
7+
8+
9+
class led():
10+
11+
@staticmethod
12+
def _setup_leds():
13+
tildagonos.set_led_power(True)
14+
15+
@staticmethod
16+
def set(led_number, state):
17+
if not isinstance(led_number, int) or led_number < 1 or led_number > 12:
18+
raise ValueError("led_number must be an integer between 1 and 12")
19+
20+
# TODO : Ideally shouldn't need to run _setup_leds each use of set_led
21+
led._setup_leds()
22+
23+
tildagonos.leds[led_number] = state
24+
tildagonos.leds.write()
25+
26+
27+
class button():
28+
29+
@staticmethod
30+
def get(button_letter):
31+
button_letter = button_letter.lower()
32+
button_letters = {
33+
"a": (0x5A, 0, (1 << 6)),
34+
"b": (0x5A, 0, (1 << 7)),
35+
"c": (0x59, 0, (1 << 0)),
36+
"d": (0x59, 0, (1 << 1)),
37+
"e": (0x59, 0, (1 << 2)),
38+
"f": (0x59, 0, (1 << 3)),
39+
}
40+
if button_letter in button_letters.keys():
41+
# Note the button must be flipped, as will return True when not pressed
42+
return not tildagonos.check_egpio_state(button_letters[button_letter])
43+
else:
44+
raise ValueError("button_letter must be a string of a single letter from a to f")
45+
46+
47+
class imu():
48+
class ImuData():
49+
def __init__(self, x, y, z):
50+
self.x = x
51+
self.y = y
52+
self.z = z
53+
54+
def __getitem__(self, index):
55+
if index == 0:
56+
return self.x
57+
elif index == 1:
58+
return self.y
59+
elif index == 2:
60+
return self.z
61+
else:
62+
raise IndexError("Index out of range. Valid indices are 0, 1, and 2.")
63+
64+
def __str__(self):
65+
return f"x: {self.x}, y: {self.y}, z: {self.z}"
66+
67+
@staticmethod
68+
def _magnitude(acc_read):
69+
return math.sqrt(sum(i ** 2 for i in acc_read))
70+
71+
@staticmethod
72+
def is_tilted_forward():
73+
acc_read = tilda_imu.acc_read()
74+
if acc_read[0] < -4:
75+
return True
76+
return False
77+
78+
@staticmethod
79+
def is_tilted_back():
80+
acc_read = tilda_imu.acc_read()
81+
if acc_read[0] > 4:
82+
return True
83+
return False
84+
85+
@staticmethod
86+
def is_tilted_left():
87+
acc_read = tilda_imu.acc_read()
88+
if acc_read[1] < -4:
89+
return True
90+
return False
91+
92+
@staticmethod
93+
def is_tilted_right():
94+
acc_read = tilda_imu.acc_read()
95+
if acc_read[1] > 4:
96+
return True
97+
return False
98+
99+
@staticmethod
100+
def is_shaken():
101+
acc_read1 = tilda_imu.acc_read()
102+
magnitude1 = imu._magnitude(acc_read1)
103+
104+
# Wait for a short period of time before taking another reading
105+
time.sleep(0.1)
106+
107+
acc_read2 = tilda_imu.acc_read()
108+
magnitude2 = imu._magnitude(acc_read2)
109+
110+
# If the change in magnitude is above a certain threshold (4 for now), the IMU is being shaken
111+
if abs(magnitude1 - magnitude2) > 4:
112+
return True
113+
return False
114+
115+
@staticmethod
116+
def get_acceleration():
117+
raw_data = tilda_imu.acc_read()
118+
acc_object = imu.ImuData(raw_data[0], raw_data[1], raw_data[2])
119+
return acc_object

modules/system/ota/ota.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ async def otaupdate(self, render_update):
161161
# window.println("Press [A] to")
162162
# window.println("reboot and")
163163
# window.println("finish update.")
164-
self.status.value = "Rebooting"
164+
self.status.value = "Rebooping"
165165
await render_update()
166166
await asyncio.sleep(5)
167167
machine.reset()

modules/system/patterndisplay/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __init__(self):
1717
_pmodule = __import__(_patternpath, globals(), locals(), [_patternclass])
1818
_pclass = getattr(_pmodule, _patternclass)
1919
self._p = _pclass()
20-
self.enabled = True
20+
self.enabled = settings.get("pattern_generator_enabled", True)
2121
except:
2222
raise ImportError(f"Pattern {self.pattern} not found!")
2323

tildagon/manifest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def freeze_images(path, generated_dir):
3838
freeze("$(MPY_DIR)/../modules/lib", "typing.py")
3939
freeze("$(MPY_DIR)/../modules/lib", "typing_extensions.py")
4040
freeze("$(MPY_DIR)/../modules/lib", "shutil.py")
41+
freeze("$(MPY_DIR)/../modules/lib", "simple_tildagon.py")
4142
#freeze("$(MPY_DIR)/../micropython-lib/python-ecosys/urequests", "urequests.py")
4243
#freeze("$(MPY_DIR)/../micropython-lib/micropython/upysh", "upysh.py")
4344
#freeze("$(MPY_DIR)/../micropython-lib/python-stdlib/functools", "functools.py")
@@ -55,4 +56,4 @@ def freeze_images(path, generated_dir):
5556
require("aioble")
5657
require("aiorepl")
5758
require("gzip")
58-
require("tarfile")
59+
require("tarfile")

0 commit comments

Comments
 (0)