Skip to content

Commit 22bcf87

Browse files
committed
color status codes
1 parent 5ae80ff commit 22bcf87

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

code.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def handle_quiet_mode(new_voltage):
5555
f.close()
5656
print('QUIET MODE DATA - new voltage:{}, last_voltage:{}'.format(new_voltage, last_voltage))
5757
if(new_voltage > float(last_voltage) + VOLT_DIFF_FOR_CHARGE):
58-
fade_up_status(50, 0, 128, 3, 2)
58+
fade_up_status(128, 128, 128, 4, 1)
5959
print("QUIET MODE ENDED - battery is charging. Unit must be plugged in")
6060
print("Clearing battery.txt and quiet.txt")
6161
# Higher voltage even with some offset! We're plugged in
@@ -71,14 +71,14 @@ def handle_quiet_mode(new_voltage):
7171
print("QUIET MODE: overwriting battery.txt low water mark")
7272
with open('battery.txt', "w") as bf:
7373
bf.write('{}\n'.format(new_voltage))
74-
fade_status(50, 0, 128, 3, 2)
74+
flash_status(80, 0, 128, 2, 1)
7575
print("QUIET MODE: Sleeping for "+ str(QUIET_MODE_SLEEP_LENGTH / 60) + " min")
7676
deep_sleep(QUIET_MODE_SLEEP_LENGTH)
7777
else:
7878
print("QUIET MODE: writing new battery.txt")
7979
with open('battery.txt', "w") as bf:
8080
bf.write('{}\n'.format(new_voltage))
81-
fade_status(50, 0, 128, 3, 2)
81+
flash_status(80, 0, 128, 2, 1)
8282
print("QUIET MODE: Sleeping for "+ str(QUIET_MODE_SLEEP_LENGTH / 60) + " min")
8383
deep_sleep(QUIET_MODE_SLEEP_LENGTH)
8484

@@ -141,18 +141,19 @@ def flash_warning(red=128, green=0, blue=0, red2=128, green2=128, blue2=0,flash_
141141
time.sleep(flash_length)
142142
pixels.fill((0, 0, 0))
143143

144-
def fade_status(red=0, green=0, blue=128, fade_length=3, repeat=1):
144+
145+
def fade_status(red=0, green=0, blue=128, fade_length=2, repeat=1):
145146
for x in range(0, repeat):
146-
for y in range(1, fade_length * 100):
147-
pixels.fill((int(red / y), int(green / y), int(blue / y)))
147+
for y in range(100, 1, -1):
148+
pixels.fill((int(pow(red, y/100)), int(pow(green, y/100)), int(pow(blue, y/100))))
148149
time.sleep(fade_length / 100)
149150
pixels.fill((0, 0, 0))
150151

151152

152-
def fade_up_status(red=128, green=128, blue=128, fade_length=3, repeat=1):
153+
def fade_up_status(red=128, green=128, blue=128, fade_length=2, repeat=1):
153154
for x in range(0, repeat):
154-
for y in range(fade_length * 100, 1):
155-
pixels.fill((int(red / y), int(green / y), int(blue / y)))
155+
for y in range(1, 100):
156+
pixels.fill((int(pow(red, y/100)), int(pow(green, y/100)), int(pow(blue, y/100))))
156157
time.sleep(fade_length / 100)
157158
pixels.fill((0, 0, 0))
158159

@@ -197,11 +198,11 @@ def fade_up_status(red=128, green=128, blue=128, fade_length=3, repeat=1):
197198
sensor = adafruit_ahtx0.AHTx0(i2c)
198199
# If the sensor is connected, go to read only mode so we can write temperatures
199200
print("\nSENSOR DETECTED, attempting to writing to temperatures.txt, CIRCUITPY is read-only by computer")
200-
flash_status(0,128,0,0.5,1)
201+
flash_status(0,128,0,1,1)
201202
# storage.remount("", switch.value)
202203
except ValueError:
203204
print("\nNO SENSOR, not writing to temperatures.txt CIRCUITPY is writeable by computer")
204-
flash_status(0,0,128,0.5,1)
205+
flash_status(0,0,128,1,1)
205206

206207
reading_interval = int(secrets["reading_interval"])
207208
net_connected = False
@@ -220,7 +221,7 @@ def fade_up_status(red=128, green=128, blue=128, fade_length=3, repeat=1):
220221
pool = socketpool.SocketPool(wifi.radio)
221222
requests = adafruit_requests.Session(pool, ssl.create_default_context())
222223
net_connected = True
223-
flash_status(0,128,0,1,2)
224+
flash_status(0,128,0,0.5,2)
224225
except:
225226
print("Connecting to fallback network %s"%secrets["heatseek_wifi_ssid"])
226227
wifi.radio.connect(secrets["heatseek_wifi_ssid"], secrets["heatseek_wifi_password"])
@@ -230,12 +231,12 @@ def fade_up_status(red=128, green=128, blue=128, fade_length=3, repeat=1):
230231
pool = socketpool.SocketPool(wifi.radio)
231232
requests = adafruit_requests.Session(pool, ssl.create_default_context())
232233
net_connected = True
233-
flash_status(0,128,0,1,2)
234+
flash_status(0,128,0,0.5,2)
234235

235236
## Set the time if this is a cold boot
236237
if not alarm.wake_alarm:
237238
print("Cold boot. Fetching updated time and setting realtime clock")
238-
239+
fade_up_status(0,128,0,3,1)
239240
response = requests.get("http://worldtimeapi.org/api/timezone/America/New_York")
240241
if response.status_code == 200:
241242
r.datetime = time.localtime(response.json()['unixtime'])

0 commit comments

Comments
 (0)