Skip to content

Commit 9426bc8

Browse files
committed
Added some docs and removed unused code
1 parent 6ebb3e2 commit 9426bc8

File tree

1 file changed

+48
-37
lines changed

1 file changed

+48
-37
lines changed

PyPortal_Remote/code.py

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
import adafruit_touchscreen
1414
import adafruit_imageload
1515

16-
PURPLE = 0x64337E
17-
16+
# Set up the touchscreen
1817
ts = adafruit_touchscreen.Touchscreen(
1918
board.TOUCH_XL,
2019
board.TOUCH_XR,
@@ -43,40 +42,44 @@
4342

4443
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
4544

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+
"""
7475

7576

7677
def getchannels():
78+
""" Gets the channels installed on the device. Also useful because it
79+
verifies that the PyPortal can see the Roku"""
7780
try:
7881
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))
8083
channel_dict = {}
8184
for i in response.text.split("<app")[2:]:
8285
a = i.split("=")
@@ -94,9 +97,10 @@ def getchannels():
9497

9598

9699
def sendkey(key):
100+
""" Sends a key to the Roku """
97101
try:
98102
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))
100104
if response:
101105
response.close()
102106
print("OK")
@@ -108,9 +112,10 @@ def sendkey(key):
108112

109113

110114
def sendletter(letter):
115+
""" Sends a letter to the Roku, not used in this guide """
111116
try:
112117
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))
114119
if response:
115120
response.close()
116121
print("OK")
@@ -122,9 +127,10 @@ def sendletter(letter):
122127

123128

124129
def openchannel(channel):
130+
""" Tells the Roku to open the channel with the corresponding channel id """
125131
try:
126132
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))
128134
if response:
129135
response.close()
130136
print("OK")
@@ -136,6 +142,7 @@ def openchannel(channel):
136142

137143

138144
def switchpage(tup):
145+
""" Used to switch to a different page """
139146
p_num = tup[0]
140147
tile_grid = tup[1]
141148
new_page = pages[p_num - 1]
@@ -144,9 +151,9 @@ def switchpage(tup):
144151
return new_page, new_page_vals
145152

146153

154+
# Verifies the Roku and Pyportal are connected and visible
147155
channels = getchannels()
148156

149-
150157
my_display_group = displayio.Group(max_size=25)
151158

152159
image_1, palette_1 = adafruit_imageload.load(
@@ -216,9 +223,13 @@ def switchpage(tup):
216223
x = math.floor(p[0] / 80)
217224
y = abs(math.floor(p[1] / 80) - 2)
218225
index = 3 * x + y
219-
if last_index == index:
226+
if (
227+
last_index == index
228+
): # Used to prevent the touchscreen sending incorrect results
220229
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
222233
page, page_vals = switchpage(page_vals[index])
223234
else:
224235
page[index](page_vals[index])

0 commit comments

Comments
 (0)