12
12
import timebased
13
13
import emlearn_trees
14
14
15
+ # for display
16
+ # mpremote mip install "github:peterhinch/micropython-nano-gui"
17
+ from color_setup import ssd
18
+ from gui .core .writer import Writer
19
+ from gui .core .nanogui import refresh
20
+ from gui .widgets .meter import Meter
21
+ from gui .widgets .label import Label , ALIGN_RIGHT
22
+ import gui .fonts .courier20 as fixed_font
23
+
24
+ # Cleanup after import frees considerable memory
25
+ gc .collect ()
26
+
15
27
def mean (arr ):
16
28
m = sum (arr ) / float (len (arr ))
17
29
return m
@@ -105,6 +117,34 @@ def send_bluetooth_le(sequence, probabilities,
105
117
# Turn of BLE
106
118
ble .active (False )
107
119
120
+
121
+ def render_display (durations ):
122
+ start_time = time .ticks_ms ()
123
+
124
+ ssd .fill (0 )
125
+
126
+ Writer .set_textpos (ssd , 0 , 0 ) # In case previous tests have altered it
127
+ wri = Writer (ssd , fixed_font , verbose = False )
128
+ wri .set_clip (False , False , False )
129
+
130
+ y = 5
131
+ for classname , stats in durations .items ():
132
+
133
+ key_text = classname
134
+ text1 = Label (wri , y , 10 , wri .stringlen (key_text ))
135
+ text1 .value (key_text )
136
+
137
+ value_text = f'{ stats :.0f} s'
138
+ text2 = Label (wri , y , 140 , 50 , align = ALIGN_RIGHT )
139
+ text2 .value (value_text )
140
+ y += 22
141
+
142
+ refresh (ssd )
143
+
144
+ duration = time .ticks_ms () - start_time
145
+ print ('render-display' , duration , 'ms' )
146
+
147
+
108
148
def main ():
109
149
110
150
dataset = 'har_exercise_1'
@@ -113,7 +153,7 @@ def main():
113
153
classname_index = {"LAYING" : 0 , "SITTING" : 1 , "STANDING" : 2 , "WALKING" : 3 , "WALKING_DOWNSTAIRS" : 4 , "WALKING_UPSTAIRS" : 5 }
114
154
window_length = 128
115
155
elif dataset == 'har_exercise_1' :
116
- classname_index = {"jumpingjack " : 0 , "lunge" : 1 , "other" : 2 , "squat" : 3 }
156
+ classname_index = {"jacks " : 0 , "lunge" : 1 , "other" : 2 , "squat" : 3 }
117
157
window_length = 256
118
158
else :
119
159
raise ValueError ('Unknown dataset' )
@@ -186,12 +226,18 @@ def main():
186
226
187
227
durations [activity ] += (hop_length / SAMPLERATE )
188
228
229
+ # Print status
189
230
d = time .ticks_diff (time .ticks_ms (), start )
190
231
print ('classify' , activity , list (out ), d , 'ms' )
191
232
for classname , duration in durations .items ():
192
233
print (f'{ classname } :\t \t \t { duration :.0f} seconds' )
193
234
235
+ # Send predictions over BLE
194
236
send_bluetooth_le (prediction_no , out )
237
+
238
+ # Update display
239
+ render_display (durations )
240
+
195
241
prediction_no += 1
196
242
197
243
time .sleep_ms (100 )
0 commit comments