Skip to content

Commit 1d73b6a

Browse files
committed
har_trees: Fix screen not updating in recorder
1 parent a6358e2 commit 1d73b6a

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

examples/har_trees/har_record.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ def render_display(selected_class, recording : bool):
7878
'jumpingjack',
7979
'lunge',
8080
'squat',
81-
'pushup',
81+
'other',
8282
]
8383

8484
samplerate = 100
8585
chunk_length = 50
86-
file_duration = 5.0
86+
file_duration = 10.0
8787
data_dir = 'har_record'
8888

8989

@@ -110,6 +110,7 @@ def main():
110110
def update_display():
111111
c = classes[class_selected]
112112
render_display(c, recorder._recording)
113+
led_pin.value(1 if recorder._recording else 0)
113114

114115
def on_longpress():
115116
# toggle recording state
@@ -136,14 +137,13 @@ def on_doubleclick():
136137
button.long_func(on_longpress, args=())
137138
button.double_func(on_doubleclick, args=())
138139

139-
async def read_data():
140+
async def update_display_loop():
141+
# workaround for display not always updating on boot
142+
while True:
143+
update_display()
144+
await asyncio.sleep(1.0)
140145

141-
# UNCOMMENT to clean up data_dir
142-
recorder.delete()
143-
144-
# FIXME: text does not show on boot
145-
update_display()
146-
print('har-record-ready')
146+
async def read_data():
147147

148148
while True:
149149

@@ -153,18 +153,24 @@ async def read_data():
153153
start = time.ticks_ms()
154154
mpu.read_samples_into(chunk)
155155
decode_samples(chunk, decoded, mpu.bytes_per_sample)
156+
#print(decoded)
156157

157158
# record data (if enabled)
158159
recorder.process(decoded)
159160

160-
# Let LED reflect recording state
161-
led_pin.value(1 if recorder._recording else 0)
162-
163161
await asyncio.sleep(0.10)
164162

163+
async def run():
164+
await asyncio.gather(update_display_loop(), read_data())
165+
165166
with Recorder(samplerate, file_duration, directory=data_dir) as recorder:
166167

167-
asyncio.run(read_data())
168+
# UNCOMMENT to clean up data_dir
169+
#recorder.delete()
170+
171+
print('har-record-ready')
172+
173+
asyncio.run(run())
168174

169175
if __name__ == '__main__':
170176
main()

0 commit comments

Comments
 (0)