kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Further linter checks after running pylint in VSCode.
rodzic
658025a99b
commit
9b18ed2594
|
@ -9,13 +9,13 @@ Find out more about the Carbon Intensity API here:
|
||||||
https://carbon-intensity.github.io/api-definitions/#carbon-intensity-api-v2-0-0
|
https://carbon-intensity.github.io/api-definitions/#carbon-intensity-api-v2-0-0
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from gfx_pack import GfxPack, SWITCH_E
|
|
||||||
from network_manager import NetworkManager
|
|
||||||
|
|
||||||
import WIFI_CONFIG
|
import WIFI_CONFIG
|
||||||
import time
|
import time
|
||||||
import uasyncio
|
import uasyncio
|
||||||
import urequests
|
import urequests
|
||||||
|
from gfx_pack import GfxPack, SWITCH_E
|
||||||
|
from network_manager import NetworkManager
|
||||||
|
|
||||||
|
|
||||||
gp = GfxPack()
|
gp = GfxPack()
|
||||||
display = gp.display
|
display = gp.display
|
||||||
|
@ -143,7 +143,6 @@ def refresh_intensity_display():
|
||||||
|
|
||||||
# Utility function used when connecting to wifi.
|
# Utility function used when connecting to wifi.
|
||||||
def display_status():
|
def display_status():
|
||||||
global sys_status
|
|
||||||
display.set_pen(0) # Set pen to white
|
display.set_pen(0) # Set pen to white
|
||||||
display.clear()
|
display.clear()
|
||||||
display.set_pen(15)
|
display.set_pen(15)
|
||||||
|
@ -169,7 +168,11 @@ def status_handler(mode, status, ip):
|
||||||
try:
|
try:
|
||||||
# Attempt to connect to the wifi.
|
# Attempt to connect to the wifi.
|
||||||
network_manager = NetworkManager(WIFI_CONFIG.COUNTRY, status_handler=status_handler)
|
network_manager = NetworkManager(WIFI_CONFIG.COUNTRY, status_handler=status_handler)
|
||||||
uasyncio.get_event_loop().run_until_complete(network_manager.client(WIFI_CONFIG.SSID, WIFI_CONFIG.PSK))
|
uasyncio.get_event_loop().run_until_complete(
|
||||||
|
network_manager.client(WIFI_CONFIG.SSID,
|
||||||
|
WIFI_CONFIG.PSK
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
# Update the display, then count down to the next update drawing a
|
# Update the display, then count down to the next update drawing a
|
||||||
# countdown bar periodically. Update immediately if button E pressed.
|
# countdown bar periodically. Update immediately if button E pressed.
|
||||||
|
@ -179,7 +182,7 @@ try:
|
||||||
ticks_before = last_updated
|
ticks_before = last_updated
|
||||||
bar_width = DISPLAY_WIDTH
|
bar_width = DISPLAY_WIDTH
|
||||||
BAR_UPDATE_FREQUENCY = 1000
|
BAR_UPDATE_FREQUENCY = 1000
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
|
@ -190,7 +193,7 @@ try:
|
||||||
bar_width = DISPLAY_WIDTH
|
bar_width = DISPLAY_WIDTH
|
||||||
|
|
||||||
ticks_now = time.ticks_ms()
|
ticks_now = time.ticks_ms()
|
||||||
|
|
||||||
if time.ticks_diff(ticks_now, ticks_before) > BAR_UPDATE_FREQUENCY:
|
if time.ticks_diff(ticks_now, ticks_before) > BAR_UPDATE_FREQUENCY:
|
||||||
bar_width = bar_width - (DISPLAY_WIDTH // CARBON_INTENSITY_UPDATE_FREQUENCY)
|
bar_width = bar_width - (DISPLAY_WIDTH // CARBON_INTENSITY_UPDATE_FREQUENCY)
|
||||||
ticks_before = time.ticks_ms()
|
ticks_before = time.ticks_ms()
|
||||||
|
@ -209,4 +212,4 @@ try:
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Failed to connect to wifi - check credentials in WIFI_CONFIG.py
|
# Failed to connect to wifi - check credentials in WIFI_CONFIG.py
|
||||||
print(f'Wifi connection failed! {e}')
|
print(f'Wifi connection failed! {e}')
|
||||||
|
|
Ładowanie…
Reference in New Issue