22# SPDX-License-Identifier: MIT
33
44import time
5+ import math
56import board
67import busio
78from digitalio import DigitalInOut
89import neopixel
910from adafruit_esp32spi import adafruit_esp32spi
1011from adafruit_esp32spi import adafruit_esp32spi_wifimanager
1112import displayio
12- import math
1313import adafruit_touchscreen
1414import adafruit_imageload
1515
16- #board.DISPLAY.rotation=0
1716PURPLE = 0x64337E
1817
1918ts = adafruit_touchscreen .Touchscreen (
@@ -78,19 +77,20 @@ def getchannels():
7877 try :
7978 print ("Getting channels. Usually takes around 10 seconds..." , end = "" )
8079 response = wifi .get ("http://192.168.1.3:8060/query/apps" )
81- channels = {}
80+ channel_dict = {}
8281 for i in response .text .split ("<app" )[2 :]:
8382 a = i .split ("=" )
8483 chan_id = a [1 ].split ('"' )[1 ]
8584 name = a [- 1 ].split (">" )[1 ].split ("<" )[0 ]
86- channels [name ] = chan_id
85+ channel_dict [name ] = chan_id
8786 response .close ()
88- return channels
87+ return channel_dict
8988 except (ValueError , RuntimeError ) as e :
9089 print ("Failed to get data\n " , e )
9190 wifi .reset ()
92- return
91+ return None
9392 response = None
93+ return None
9494
9595
9696def sendkey (key ):
@@ -134,13 +134,15 @@ def openchannel(channel):
134134 wifi .reset ()
135135 response = None
136136
137+
137138def switchpage (tup ):
138139 p_num = tup [0 ]
139140 tile_grid = tup [1 ]
140- page = pages [p_num - 1 ]
141- page_vals = pages_vals [p_num - 1 ]
141+ new_page = pages [p_num - 1 ]
142+ new_page_vals = pages_vals [p_num - 1 ]
142143 my_display_group [- 1 ] = tile_grid
143- return page , page_vals
144+ return new_page , new_page_vals
145+
144146
145147channels = getchannels ()
146148
@@ -163,6 +165,7 @@ def switchpage(tup):
163165)
164166tile_grid_3 = displayio .TileGrid (image_3 , pixel_shader = palette_3 )
165167
168+ # fmt: off
166169# Page 1
167170page_1 = [sendkey , sendkey , sendkey ,
168171 sendkey , sendkey , sendkey ,
@@ -194,6 +197,7 @@ def switchpage(tup):
194197 "Search" , None , "Info" ,
195198 "Rev" , "Play" , "Fwd" ,
196199 (2 , tile_grid_2 ), "Back" , "Home" ]
200+ # fmt: on
197201
198202pages = [page_1 , page_2 , page_3 ]
199203pages_vals = [page_1_vals , page_2_vals , page_3_vals ]
@@ -209,12 +213,12 @@ def switchpage(tup):
209213while True :
210214 p = ts .touch_point
211215 if p :
212- x = math .floor (p [0 ]/ 80 )
213- y = abs (math .floor (p [1 ]/ 80 ) - 2 )
214- index = 3 * x + y
216+ x = math .floor (p [0 ] / 80 )
217+ y = abs (math .floor (p [1 ] / 80 ) - 2 )
218+ index = 3 * x + y
215219 if last_index == index :
216220 if page [index ]:
217- if page [index ] == switchpage :
221+ if page [index ] == switchpage : # pylint: disable=comparison-with-callable
218222 page , page_vals = switchpage (page_vals [index ])
219223 else :
220224 page [index ](page_vals [index ])
0 commit comments