@@ -78,12 +78,12 @@ def render_display(selected_class, recording : bool):
78
78
'jumpingjack' ,
79
79
'lunge' ,
80
80
'squat' ,
81
- 'pushup ' ,
81
+ 'other ' ,
82
82
]
83
83
84
84
samplerate = 100
85
85
chunk_length = 50
86
- file_duration = 5 .0
86
+ file_duration = 10 .0
87
87
data_dir = 'har_record'
88
88
89
89
@@ -110,6 +110,7 @@ def main():
110
110
def update_display ():
111
111
c = classes [class_selected ]
112
112
render_display (c , recorder ._recording )
113
+ led_pin .value (1 if recorder ._recording else 0 )
113
114
114
115
def on_longpress ():
115
116
# toggle recording state
@@ -136,14 +137,13 @@ def on_doubleclick():
136
137
button .long_func (on_longpress , args = ())
137
138
button .double_func (on_doubleclick , args = ())
138
139
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 )
140
145
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 ():
147
147
148
148
while True :
149
149
@@ -153,18 +153,24 @@ async def read_data():
153
153
start = time .ticks_ms ()
154
154
mpu .read_samples_into (chunk )
155
155
decode_samples (chunk , decoded , mpu .bytes_per_sample )
156
+ #print(decoded)
156
157
157
158
# record data (if enabled)
158
159
recorder .process (decoded )
159
160
160
- # Let LED reflect recording state
161
- led_pin .value (1 if recorder ._recording else 0 )
162
-
163
161
await asyncio .sleep (0.10 )
164
162
163
+ async def run ():
164
+ await asyncio .gather (update_display_loop (), read_data ())
165
+
165
166
with Recorder (samplerate , file_duration , directory = data_dir ) as recorder :
166
167
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 ())
168
174
169
175
if __name__ == '__main__' :
170
176
main ()
0 commit comments