@@ -94,11 +94,12 @@ def send_bluetooth_le(sequence, probabilities,
94
94
95
95
payload = manufacturer_specific_advertisement (data )
96
96
97
- print ('ble-advertise' , mac [1 ], data )
97
+ print ('ble-advertise' , ' mac=' + mac [1 ]. hex (), ' data=' + data . hex () )
98
98
99
99
# send and wait until N advertisements are sent
100
100
advertise_us = int (1000 * advertise_interval_ms )
101
101
ble .gap_advertise (advertise_us , adv_data = payload , connectable = False )
102
+ # XXX: blocking wait
102
103
time .sleep_ms (advertisements * advertise_interval_ms )
103
104
104
105
# Turn of BLE
@@ -129,8 +130,9 @@ def main():
129
130
mpu = MPU6886 (I2C (0 , sda = 21 , scl = 22 , freq = 100000 ))
130
131
131
132
# Enable FIFO at a fixed samplerate
133
+ SAMPLERATE = 100
132
134
mpu .fifo_enable (True )
133
- mpu .set_odr (100 )
135
+ mpu .set_odr (SAMPLERATE )
134
136
135
137
hop_length = 64
136
138
chunk = bytearray (mpu .bytes_per_sample * hop_length )
@@ -150,6 +152,8 @@ def main():
150
152
out = array .array ('f' , range (model .outputs ()))
151
153
152
154
prediction_no = 0
155
+ durations = { classname : 0.0 for classname in classname_index .keys () } # how long each class has been active
156
+ MIN_PROBABILITY = 0.5 # if no class has higher, consider as "other"
153
157
154
158
while True :
155
159
@@ -177,9 +181,15 @@ def main():
177
181
model .predict (features , out )
178
182
result = argmax (out )
179
183
activity = class_index_to_name [result ]
184
+ if max (out ) < MIN_PROBABILITY :
185
+ activity = 'other'
186
+
187
+ durations [activity ] += (hop_length / SAMPLERATE )
180
188
181
189
d = time .ticks_diff (time .ticks_ms (), start )
182
- print ('classify' , d , activity , out )
190
+ print ('classify' , activity , list (out ), d , 'ms' )
191
+ for classname , duration in durations .items ():
192
+ print (f'{ classname } :\t \t \t { duration :.0f} seconds' )
183
193
184
194
send_bluetooth_le (prediction_no , out )
185
195
prediction_no += 1
0 commit comments