@@ -29,10 +29,8 @@ class Clue:
29
29
"""
30
30
def __init__ (self ):
31
31
self ._i2c = board .I2C ()
32
-
33
32
self ._touches = [board .D0 , board .D1 , board .D2 ]
34
33
self ._touch_threshold_adjustment = 0
35
-
36
34
self ._a = digitalio .DigitalInOut (board .BUTTON_A )
37
35
self ._a .switch_to_input (pull = digitalio .Pull .UP )
38
36
self ._b = digitalio .DigitalInOut (board .BUTTON_B )
@@ -79,7 +77,6 @@ def touch_2(self):
79
77
return self ._touch (2 )
80
78
81
79
82
-
83
80
class Pyloton :
84
81
"""
85
82
Contains the various functions necessary for doing the Pyloton learn guide.
@@ -94,18 +91,14 @@ class Pyloton:
94
91
95
92
def __init__ (self , ble , display , circ , heart = True , speed = True , cad = True , ams = True , debug = False ): #pylint: disable=too-many-arguments
96
93
self .debug = debug
97
-
98
94
self .ble = ble
99
-
100
95
self .display = display
101
-
102
96
self .circumference = circ
103
97
104
98
self .heart_enabled = heart
105
99
self .speed_enabled = speed
106
100
self .cadence_enabled = cad
107
101
self .ams_enabled = ams
108
-
109
102
self .hr_connection = None
110
103
111
104
self .num_enabled = heart + speed + cad + ams
@@ -129,13 +122,12 @@ def __init__(self, ble, display, circ, heart=True, speed=True, cad=True, ams=Tru
129
122
self ._speed_y = None
130
123
self ._cadence_y = None
131
124
self ._ams_y = None
132
-
133
125
self .ams = None
134
126
self .cyc_connections = None
135
127
self .cyc_services = None
128
+ self .track_artist = True
136
129
137
130
self .start = time .time ()
138
- self .track_artist = True
139
131
140
132
self .splash = displayio .Group (max_size = 25 )
141
133
self .loading_group = displayio .Group ()
@@ -164,25 +156,15 @@ def show_splash(self):
164
156
return
165
157
with open ('blinka-pyloton.bmp' , 'rb' ) as bitmap_file :
166
158
bitmap1 = displayio .OnDiskBitmap (bitmap_file )
167
-
168
159
tile_grid = displayio .TileGrid (bitmap1 , pixel_shader = displayio .ColorConverter ())
169
-
170
-
171
160
self .loading_group .append (tile_grid )
172
-
173
161
self .display .show (self .loading_group )
174
-
175
162
status_heading = label .Label (font = self .arial16 , x = 80 , y = 175 ,
176
163
text = "Status" , color = self .YELLOW )
177
-
178
164
rect = Rect (0 , 165 , 240 , 75 , fill = self .PURPLE )
179
-
180
165
self .loading_group .append (rect )
181
166
self .loading_group .append (status_heading )
182
167
183
- self .display .show (self .loading_group )
184
- time .sleep (.01 )
185
-
186
168
187
169
def _load_fonts (self ):
188
170
"""
@@ -191,6 +173,7 @@ def _load_fonts(self):
191
173
self .arial12 = bitmap_font .load_font ("/fonts/Arial-12.bdf" )
192
174
self .arial16 = bitmap_font .load_font ("/fonts/Arial-16.bdf" )
193
175
self .arial24 = bitmap_font .load_font ("/fonts/Arial-Bold-24.bdf" )
176
+
194
177
glyphs = b'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-!,. "\' ?!'
195
178
self .arial12 .load_glyphs (glyphs )
196
179
self .arial16 .load_glyphs (glyphs )
@@ -204,20 +187,15 @@ def _status_update(self, message):
204
187
if self .debug :
205
188
print (message )
206
189
return
207
-
208
190
if self .text_group not in self .loading_group :
209
191
self .loading_group .append (self .text_group )
210
-
211
192
if len (message ) > 25 :
212
193
self .status .text = message [:25 ]
213
194
self .status1 .text = message [25 :50 ]
214
-
215
195
else :
216
196
self .status .text = message
217
197
self .status1 .text = ''
218
198
219
- #self.display.show(self.loading_group)
220
-
221
199
222
200
def timeout (self ):
223
201
"""
@@ -243,6 +221,7 @@ def heart_connect(self):
243
221
self ._hr_service = self .hr_connection [HeartRateService ]
244
222
return self .hr_connection
245
223
224
+
246
225
@staticmethod
247
226
def _has_timed_out (start , timeout ):
248
227
if time .time () - start >= timeout :
@@ -263,14 +242,10 @@ def ams_connect(self, start=time.time(), timeout=30):
263
242
pass
264
243
265
244
self ._status_update ("AppleMediaService: Connected" )
266
-
267
- #known_notifications = set()
268
-
269
245
for connection in radio .connections :
270
246
if not connection .paired :
271
247
connection .pair ()
272
248
self ._status_update ("AppleMediaService: Paired" )
273
-
274
249
self .ams = connection [AppleMediaService ]
275
250
276
251
return radio
@@ -301,19 +276,17 @@ def speed_cadence_connect(self):
301
276
self .cyc_connections .append (self .ble .connect (adv ))
302
277
self ._status_update ("Speed and Cadence: Connected {}" .format (len (self .cyc_connections )))
303
278
304
-
305
279
self .cyc_services = []
306
280
for conn in self .cyc_connections :
307
-
308
281
self .cyc_services .append (conn [CyclingSpeedAndCadenceService ])
309
282
self ._status_update ("Pyloton: Finishing up..." )
283
+
310
284
return self .cyc_connections
311
285
312
286
313
287
def _compute_speed (self , values , speed ):
314
288
wheel_diff = values .last_wheel_event_time - self ._previous_wheel
315
289
rev_diff = values .cumulative_wheel_revolutions - self ._previous_revolutions
316
-
317
290
if wheel_diff :
318
291
# Rotations per minute is 60 times the amount of revolutions since
319
292
# the last update over the time since the last update
@@ -330,6 +303,7 @@ def _compute_speed(self, values, speed):
330
303
if self ._speed_failed >= 3 :
331
304
speed = 0
332
305
self ._previous_wheel = values .last_wheel_event_time
306
+
333
307
return speed
334
308
335
309
@@ -351,6 +325,7 @@ def _compute_cadence(self, values, cadence):
351
325
if self ._cadence_failed >= 3 :
352
326
cadence = 0
353
327
self ._previous_crank = values .last_crank_event_time
328
+
354
329
return cadence
355
330
356
331
@@ -364,32 +339,26 @@ def read_s_and_c(self):
364
339
if not conn .connected :
365
340
speed = cadence = 0
366
341
continue
367
-
368
342
values = svc .measurement_values
369
-
370
343
if not values :
371
344
if self ._cadence_failed >= 3 or self ._speed_failed >= 3 :
372
345
if self ._cadence_failed > 3 :
373
346
cadence = 0
374
347
if self ._speed_failed > 3 :
375
348
speed = 0
376
349
continue
377
-
378
350
if not values .last_wheel_event_time :
379
351
continue
380
-
381
352
speed = self ._compute_speed (values , speed )
382
-
383
-
384
353
if not values .last_crank_event_time :
385
354
continue
386
-
387
355
cadence = self ._compute_cadence (values , cadence )
388
356
389
357
if speed :
390
358
speed = str (speed )[:8 ]
391
359
if cadence :
392
360
cadence = str (cadence )[:8 ]
361
+
393
362
return speed , cadence
394
363
395
364
@@ -403,8 +372,10 @@ def read_heart(self):
403
372
else :
404
373
heart = measurement .heart_rate
405
374
self ._previous_heart = measurement .heart_rate
375
+
406
376
if heart :
407
377
heart = str (heart )[:4 ]
378
+
408
379
return heart
409
380
410
381
@@ -417,7 +388,6 @@ def read_ams(self):
417
388
if current - self .start > 3 :
418
389
self .track_artist = not self .track_artist
419
390
self .start = time .time ()
420
-
421
391
if self .track_artist :
422
392
data = self .ams .artist
423
393
if not self .track_artist :
@@ -427,6 +397,7 @@ def read_ams(self):
427
397
428
398
if data :
429
399
data = data [:16 ] + (data [16 :] and '..' )
400
+
430
401
return data
431
402
432
403
@@ -458,15 +429,12 @@ def _get_y(self):
458
429
if self .heart_enabled :
459
430
self ._heart_y = 45 * (self .num_enabled - enabled ) + 75
460
431
enabled -= 1
461
-
462
432
if self .speed_enabled :
463
433
self ._speed_y = 45 * (self .num_enabled - enabled ) + 75
464
434
enabled -= 1
465
-
466
435
if self .cadence_enabled :
467
436
self ._cadence_y = 45 * (self .num_enabled - enabled ) + 75
468
437
enabled -= 1
469
-
470
438
if self .ams_enabled :
471
439
self ._ams_y = 45 * (self .num_enabled - enabled ) + 75
472
440
enabled -= 1
@@ -508,7 +476,6 @@ def setup_display(self):
508
476
self .loading_group .pop ()
509
477
510
478
511
-
512
479
def update_display (self ): #pylint: disable=too-many-branches
513
480
"""
514
481
Updates the display to display the most recent values
0 commit comments