Skip to content

Commit 40056f8

Browse files
authored
Merge pull request #947 from cogliano/master
PyPortal Smart Switch updates
2 parents 51679ea + 89f665b commit 40056f8

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

PyPortal_Smart_Switch/code.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
from adafruit_minimqtt import MQTT
1818

19-
DISPLAY_COLOR = 0x4444FF
19+
DISPLAY_COLOR = 0x006600
20+
SWITCH_COLOR = 0x008800
21+
SWITCH_FILL_COLOR = 0xffffff
2022

2123
# Switch location
2224
SWITCHX = 260
@@ -87,9 +89,10 @@ class Switch(object):
8789
def __init__(self, pin, my_pyportal):
8890
self.switch = digitalio.DigitalInOut(pin)
8991
self.switch.direction = digitalio.Direction.OUTPUT
90-
rect = RoundRect(SWITCHX, SWITCHY, 31, 60, 16, fill=0x0, outline=DISPLAY_COLOR, stroke=3)
92+
rect = RoundRect(SWITCHX, SWITCHY, 31, 60, 16, outline=SWITCH_COLOR,
93+
fill=SWITCH_FILL_COLOR, stroke=3)
9194
my_pyportal.splash.append(rect)
92-
self.circle_on = Circle(SWITCHX + 15, SWITCHY + 16, 10, fill=0x0)
95+
self.circle_on = Circle(SWITCHX + 15, SWITCHY + 16, 10, fill=SWITCH_FILL_COLOR)
9396
my_pyportal.splash.append(self.circle_on)
9497
self.circle_off = Circle(SWITCHX + 15, SWITCHY + 42, 10, fill=DISPLAY_COLOR)
9598
my_pyportal.splash.append(self.circle_off)
@@ -99,10 +102,10 @@ def enable(self, enable):
99102
print("turning switch to ", enable)
100103
self.switch.value = enable
101104
if enable:
102-
self.circle_off.fill = 0x0
105+
self.circle_off.fill = SWITCH_FILL_COLOR
103106
self.circle_on.fill = DISPLAY_COLOR
104107
else:
105-
self.circle_on.fill = 0x0
108+
self.circle_on.fill = SWITCH_FILL_COLOR
106109
self.circle_off.fill = DISPLAY_COLOR
107110

108111
def toggle(self):
@@ -127,11 +130,11 @@ def __init__(self, my_pyportal):
127130
self.pyportal = my_pyportal
128131
self.current_time = 0
129132
self.light = analogio.AnalogIn(board.LIGHT)
130-
text_area_configs = [dict(x=0, y=110, size=10, color=DISPLAY_COLOR, font=time_font),
131-
dict(x=260, y=165, size=3, color=DISPLAY_COLOR, font=ampm_font),
132-
dict(x=10, y=40, size=20, color=DISPLAY_COLOR, font=date_font)]
133+
text_area_configs = [dict(x=0, y=105, size=10, color=DISPLAY_COLOR, font=time_font),
134+
dict(x=260, y=153, size=3, color=DISPLAY_COLOR, font=ampm_font),
135+
dict(x=110, y=40, size=20, color=DISPLAY_COLOR, font=date_font)]
133136
self.text_areas = create_text_areas(text_area_configs)
134-
self.text_areas[2].text = "starting ..."
137+
self.text_areas[2].text = "starting..."
135138
for ta in self.text_areas:
136139
self.pyportal.splash.append(ta)
137140

@@ -229,7 +232,9 @@ def message(client, topic, message):
229232
print("Firmware vers.", esp.firmware_version)
230233
print("MAC addr:", [hex(i) for i in esp.MAC_address])
231234

232-
pyportal = PyPortal(esp=esp, external_spi=spi)
235+
pyportal = PyPortal(esp=esp,
236+
external_spi=spi,
237+
default_bg="/background.bmp")
233238

234239
ampm_font = bitmap_font.load_font("/fonts/RobotoMono-18.bdf")
235240
ampm_font.load_glyphs(b'ampAMP')

PyPortal_Smart_Switch/secrets.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
secrets = {
55
'ssid' : 'CHANGE ME',
66
'password' : 'CHANGE ME',
7-
'timezone' : 'CHANGE ME',
7+
# leave blank or use timezone from # http://worldtimeapi.org/timezones
8+
'timezone' : '',
89
'aio_username' : 'CHANGE ME',
910
'aio_key' : 'CHANGE ME',
1011
}

0 commit comments

Comments
 (0)