13
13
import adafruit_touchscreen
14
14
import adafruit_imageload
15
15
16
- PURPLE = 0x64337E
17
-
16
+ # Set up the touchscreen
18
17
ts = adafruit_touchscreen .Touchscreen (
19
18
board .TOUCH_XL ,
20
19
board .TOUCH_XR ,
43
42
44
43
wifi = adafruit_esp32spi_wifimanager .ESPSPI_WiFiManager (esp , secrets , status_light )
45
44
46
- keys = [
47
- "Home" ,
48
- "Rev" ,
49
- "Fwd" ,
50
- "Play" ,
51
- "Select" ,
52
- "Left" ,
53
- "Right" ,
54
- "Down" ,
55
- "Up" ,
56
- "Back" ,
57
- "InstantReplay" ,
58
- "Info" ,
59
- "Backspace" ,
60
- "Search" ,
61
- "Enter" ,
62
- "FindRemote" ,
63
- ]
64
-
65
- # Keys that only work on smart TVs with built-in Rokus
66
- rokutvkeys = [
67
- "VolumeDown" ,
68
- "VolumeMute" ,
69
- "VolumeUp" ,
70
- "PowerOff" ,
71
- "ChannelUp" ,
72
- "ChannelDown" ,
73
- ]
45
+ # Set the ip of your Roku here
46
+ ip = "192.168.1.3"
47
+
48
+ """
49
+ Possible keypress key values to send the Roku
50
+ Home
51
+ Rev
52
+ Fwd
53
+ Play
54
+ Select
55
+ Left
56
+ Right
57
+ Down
58
+ Up
59
+ Back
60
+ InstantReplay
61
+ Info
62
+ Backspace
63
+ Search
64
+ Enter
65
+ FindRemote
66
+
67
+ Keypress key values that only work on smart TVs with built-in Rokus
68
+ VolumeDown
69
+ VolumeMute
70
+ VolumeUp
71
+ PowerOff
72
+ ChannelUp
73
+ ChannelDown
74
+ """
74
75
75
76
76
77
def getchannels ():
78
+ """ Gets the channels installed on the device. Also useful because it
79
+ verifies that the PyPortal can see the Roku"""
77
80
try :
78
81
print ("Getting channels. Usually takes around 10 seconds..." , end = "" )
79
- response = wifi .get ("http://192.168.1.3 :8060/query/apps" )
82
+ response = wifi .get ("http://{} :8060/query/apps" . format ( ip ) )
80
83
channel_dict = {}
81
84
for i in response .text .split ("<app" )[2 :]:
82
85
a = i .split ("=" )
@@ -94,9 +97,10 @@ def getchannels():
94
97
95
98
96
99
def sendkey (key ):
100
+ """ Sends a key to the Roku """
97
101
try :
98
102
print ("Sending key: {}..." .format (key ), end = "" )
99
- response = wifi .post ("http://192.168.1.3 :8060/keypress/{}" .format (key ))
103
+ response = wifi .post ("http://{} :8060/keypress/{}" .format (ip , key ))
100
104
if response :
101
105
response .close ()
102
106
print ("OK" )
@@ -108,9 +112,10 @@ def sendkey(key):
108
112
109
113
110
114
def sendletter (letter ):
115
+ """ Sends a letter to the Roku, not used in this guide """
111
116
try :
112
117
print ("Sending letter: {}..." .format (letter ), end = "" )
113
- response = wifi .post ("http://192.168.1.3 :8060/keypress/lit_{}" .format (letter ))
118
+ response = wifi .post ("http://{} :8060/keypress/lit_{}" .format (ip , letter ))
114
119
if response :
115
120
response .close ()
116
121
print ("OK" )
@@ -122,9 +127,10 @@ def sendletter(letter):
122
127
123
128
124
129
def openchannel (channel ):
130
+ """ Tells the Roku to open the channel with the corresponding channel id """
125
131
try :
126
132
print ("Opening channel: {}..." .format (channel ), end = "" )
127
- response = wifi .post ("http://192.168.1.3 :8060/launch/{}" .format (channel ))
133
+ response = wifi .post ("http://{} :8060/launch/{}" .format (ip , channel ))
128
134
if response :
129
135
response .close ()
130
136
print ("OK" )
@@ -136,6 +142,7 @@ def openchannel(channel):
136
142
137
143
138
144
def switchpage (tup ):
145
+ """ Used to switch to a different page """
139
146
p_num = tup [0 ]
140
147
tile_grid = tup [1 ]
141
148
new_page = pages [p_num - 1 ]
@@ -144,9 +151,9 @@ def switchpage(tup):
144
151
return new_page , new_page_vals
145
152
146
153
154
+ # Verifies the Roku and Pyportal are connected and visible
147
155
channels = getchannels ()
148
156
149
-
150
157
my_display_group = displayio .Group (max_size = 25 )
151
158
152
159
image_1 , palette_1 = adafruit_imageload .load (
@@ -216,9 +223,13 @@ def switchpage(tup):
216
223
x = math .floor (p [0 ] / 80 )
217
224
y = abs (math .floor (p [1 ] / 80 ) - 2 )
218
225
index = 3 * x + y
219
- if last_index == index :
226
+ if (
227
+ last_index == index
228
+ ): # Used to prevent the touchscreen sending incorrect results
220
229
if page [index ]:
221
- if page [index ] == switchpage : # pylint: disable=comparison-with-callable
230
+ if (
231
+ page [index ] == switchpage
232
+ ): # pylint: disable=comparison-with-callable
222
233
page , page_vals = switchpage (page_vals [index ])
223
234
else :
224
235
page [index ](page_vals [index ])
0 commit comments