@@ -88,13 +88,20 @@ def check_timeout(self):
8888advertisement .complete_name = "CIRCUITPY"
8989advertisement .solicited_services .append (AppleNotificationCenterService )
9090
91- def wrap_in_tilegrid (open_file ):
92- odb = displayio .OnDiskBitmap (open_file )
93- return displayio .TileGrid (odb , pixel_shader = getattr (odb , 'pixel_shader' , displayio .ColorConverter ()))
91+ def wrap_in_tilegrid (filename :str ):
92+ # CircuitPython 6 & 7 compatible
93+ odb = displayio .OnDiskBitmap (open (filename , "rb" ))
94+ return displayio .TileGrid (
95+ odb , pixel_shader = getattr (odb , 'pixel_shader' , displayio .ColorConverter ())
96+ )
97+
98+ # # CircuitPython 7+ compatible
99+ # odb = displayio.OnDiskBitmap(filename)
100+ # return displayio.TileGrid(odb, pixel_shader=odb.pixel_shader)
94101
95102display = tft_gizmo .TFT_Gizmo ()
96- group = displayio .Group (max_size = 3 )
97- group .append (wrap_in_tilegrid (open ( "/ancs_connect.bmp" , "rb" ) ))
103+ group = displayio .Group ()
104+ group .append (wrap_in_tilegrid ("/ancs_connect.bmp" ))
98105display .show (group )
99106
100107current_notification = None
@@ -116,58 +123,57 @@ def wrap_in_tilegrid(open_file):
116123 dimmer .update ()
117124 play_sound ()
118125
119- with open ("/ancs_none.bmp" , "rb" ) as no_notifications :
120- group .append (wrap_in_tilegrid (no_notifications ))
121- while active_connection .connected :
122- all_ids .clear ()
123- current_notifications = notification_service .active_notifications
124- for notif_id in current_notifications :
125- notification = current_notifications [notif_id ]
126- if notification .app_id not in APP_ICONS or notification .app_id in BLOCKLIST :
127- continue
128- all_ids .append (notif_id )
129-
130- # pylint: disable=protected-access
131- all_ids .sort (key = lambda x : current_notifications [x ]._raw_date )
132- # pylint: enable=protected-access
133-
134- if current_notification and current_notification .removed :
135- # Stop showing the latest and show that there are no new notifications.
136- current_notification = None
137-
138- if not current_notification and not all_ids and not cleared :
139- cleared = True
126+ no_notifications = "/ancs_none.bmp"
127+ group .append (wrap_in_tilegrid (no_notifications ))
128+ while active_connection .connected :
129+ all_ids .clear ()
130+ current_notifications = notification_service .active_notifications
131+ for notif_id in current_notifications :
132+ notification = current_notifications [notif_id ]
133+ if notification .app_id not in APP_ICONS or notification .app_id in BLOCKLIST :
134+ continue
135+ all_ids .append (notif_id )
136+
137+ # pylint: disable=protected-access
138+ all_ids .sort (key = lambda x : current_notifications [x ]._raw_date )
139+ # pylint: enable=protected-access
140+
141+ if current_notification and current_notification .removed :
142+ # Stop showing the latest and show that there are no new notifications.
143+ current_notification = None
144+
145+ if not current_notification and not all_ids and not cleared :
146+ cleared = True
147+ dimmer .update ()
148+ group [1 ] = wrap_in_tilegrid (no_notifications )
149+ elif all_ids :
150+ cleared = False
151+ now = time .monotonic ()
152+ if current_notification and current_notification .id in all_ids and \
153+ now - last_press < DELAY_AFTER_PRESS :
154+ index = all_ids .index (current_notification .id )
155+ else :
156+ index = len (all_ids ) - 1
157+ if now - last_press >= DEBOUNCE :
158+ if b .value and index > 0 :
159+ last_press = now
160+ index += - 1
161+ if a .value and index < len (all_ids ) - 1 :
162+ last_press = now
163+ index += 1
164+ notif_id = all_ids [index ]
165+ if not current_notification or current_notification .id != notif_id :
140166 dimmer .update ()
141- group [1 ] = wrap_in_tilegrid (no_notifications )
142- elif all_ids :
143- cleared = False
144- now = time .monotonic ()
145- if current_notification and current_notification .id in all_ids and \
146- now - last_press < DELAY_AFTER_PRESS :
147- index = all_ids .index (current_notification .id )
148- else :
149- index = len (all_ids ) - 1
150- if now - last_press >= DEBOUNCE :
151- if b .value and index > 0 :
152- last_press = now
153- index += - 1
154- if a .value and index < len (all_ids ) - 1 :
155- last_press = now
156- index += 1
157- notif_id = all_ids [index ]
158- if not current_notification or current_notification .id != notif_id :
159- dimmer .update ()
160- current_notification = current_notifications [notif_id ]
161- # pylint: disable=protected-access
162- print (current_notification ._raw_date , current_notification )
163- # pylint: enable=protected-access
164- app_icon_file = open (APP_ICONS [current_notification .app_id ], "rb" )
165- group [1 ] = wrap_in_tilegrid (app_icon_file )
166-
167- dimmer .check_timeout ()
168-
169- # Bluetooth Disconnected
170- group .pop ()
171- dimmer .update ()
172- active_connection = None
173- notification_service = None
167+ current_notification = current_notifications [notif_id ]
168+ # pylint: disable=protected-access
169+ print (current_notification ._raw_date , current_notification )
170+ # pylint: enable=protected-access
171+ group [1 ] = wrap_in_tilegrid (APP_ICONS [current_notification .app_id ])
172+
173+ dimmer .check_timeout ()
174+
175+ # Bluetooth Disconnected
176+ group .pop ()
177+ dimmer .update ()
178+ active_connection = None
179+ notification_service = None
0 commit comments