kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Linter issues.
rodzic
14eabf360f
commit
658025a99b
|
@ -13,7 +13,6 @@ from gfx_pack import GfxPack, SWITCH_E
|
||||||
from network_manager import NetworkManager
|
from network_manager import NetworkManager
|
||||||
|
|
||||||
import WIFI_CONFIG
|
import WIFI_CONFIG
|
||||||
import json
|
|
||||||
import time
|
import time
|
||||||
import uasyncio
|
import uasyncio
|
||||||
import urequests
|
import urequests
|
||||||
|
@ -29,12 +28,14 @@ CARBON_INTENSITY_UPDATE_FREQUENCY = 60
|
||||||
DISPLAY_WIDTH, DISPLAY_HEIGHT = display.get_bounds()
|
DISPLAY_WIDTH, DISPLAY_HEIGHT = display.get_bounds()
|
||||||
sys_status = "STATUS"
|
sys_status = "STATUS"
|
||||||
|
|
||||||
|
|
||||||
# Utility function to clear the screen.
|
# Utility function to clear the screen.
|
||||||
def clear_screen():
|
def clear_screen():
|
||||||
display.set_pen(0)
|
display.set_pen(0)
|
||||||
display.clear()
|
display.clear()
|
||||||
display.set_pen(15)
|
display.set_pen(15)
|
||||||
|
|
||||||
|
|
||||||
# Utility function to clear a rectangular area of the screen.
|
# Utility function to clear a rectangular area of the screen.
|
||||||
# Used to update the progress bar.
|
# Used to update the progress bar.
|
||||||
def clear_rect(start_x, start_y, end_x, end_y, height):
|
def clear_rect(start_x, start_y, end_x, end_y, height):
|
||||||
|
@ -43,10 +44,12 @@ def clear_rect(start_x, start_y, end_x, end_y, height):
|
||||||
display.set_pen(15)
|
display.set_pen(15)
|
||||||
display.update()
|
display.update()
|
||||||
|
|
||||||
|
|
||||||
# Utility function to set the backlight to a given rgbw colour.
|
# Utility function to set the backlight to a given rgbw colour.
|
||||||
def set_backlight(r, g, b, w):
|
def set_backlight(r, g, b, w):
|
||||||
gp.set_backlight(r, g, b, w)
|
gp.set_backlight(r, g, b, w)
|
||||||
|
|
||||||
|
|
||||||
# Utility function to display text centred on the screen.
|
# Utility function to display text centred on the screen.
|
||||||
def display_centered(text_to_display, y_pos, scale):
|
def display_centered(text_to_display, y_pos, scale):
|
||||||
width = display.measure_text(text_to_display, scale)
|
width = display.measure_text(text_to_display, scale)
|
||||||
|
@ -54,6 +57,7 @@ def display_centered(text_to_display, y_pos, scale):
|
||||||
display.text(text_to_display, x_pos, y_pos, DISPLAY_WIDTH, scale)
|
display.text(text_to_display, x_pos, y_pos, DISPLAY_WIDTH, scale)
|
||||||
return x_pos
|
return x_pos
|
||||||
|
|
||||||
|
|
||||||
# Read values from the API and update the display.
|
# Read values from the API and update the display.
|
||||||
def refresh_intensity_display():
|
def refresh_intensity_display():
|
||||||
BAR_MIN_X = 50
|
BAR_MIN_X = 50
|
||||||
|
@ -109,7 +113,7 @@ def refresh_intensity_display():
|
||||||
(nuclear_width, "NUCLEAR"),
|
(nuclear_width, "NUCLEAR"),
|
||||||
(gas_width, "GAS"),
|
(gas_width, "GAS"),
|
||||||
(others_width, "OTHERS")
|
(others_width, "OTHERS")
|
||||||
], reverse = True)
|
], reverse=True)
|
||||||
|
|
||||||
clear_screen()
|
clear_screen()
|
||||||
|
|
||||||
|
@ -136,6 +140,7 @@ def refresh_intensity_display():
|
||||||
display.text("E: Update", 80, 50, DISPLAY_WIDTH, 1)
|
display.text("E: Update", 80, 50, DISPLAY_WIDTH, 1)
|
||||||
display.update()
|
display.update()
|
||||||
|
|
||||||
|
|
||||||
# Utility function used when connecting to wifi.
|
# Utility function used when connecting to wifi.
|
||||||
def display_status():
|
def display_status():
|
||||||
global sys_status
|
global sys_status
|
||||||
|
@ -145,6 +150,7 @@ def display_status():
|
||||||
display.text(sys_status, 0, 0, DISPLAY_WIDTH, 1)
|
display.text(sys_status, 0, 0, DISPLAY_WIDTH, 1)
|
||||||
display.update()
|
display.update()
|
||||||
|
|
||||||
|
|
||||||
# Utility function used when connecting to wifi.
|
# Utility function used when connecting to wifi.
|
||||||
def status_handler(mode, status, ip):
|
def status_handler(mode, status, ip):
|
||||||
global sys_status
|
global sys_status
|
||||||
|
@ -159,6 +165,7 @@ def status_handler(mode, status, ip):
|
||||||
else:
|
else:
|
||||||
print('Wifi connection failed!')
|
print('Wifi connection failed!')
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
|
@ -203,4 +210,3 @@ 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