Badger2040W: Fix linting, use micropython-lib urllib.

pull/633/head
Phil Howard 2023-01-16 11:23:45 +00:00 zatwierdzone przez Phil Howard
rodzic 2b3b1e4676
commit e859b39e11
5 zmienionych plików z 13 dodań i 74 usunięć

Wyświetl plik

@ -0,0 +1,7 @@
include("../manifest.py")
require("mip")
require("ntptime")
require("urequests")
require("urllib.urequest")
require("umqtt.simple")

Wyświetl plik

@ -1,4 +1,5 @@
import machine
import micropython
from picographics import PicoGraphics, DISPLAY_INKY_PACK
from network_manager import NetworkManager
import WIFI_CONFIG
@ -86,10 +87,10 @@ class Badger2040W():
def thickness(self, thickness):
print("Thickness!")
def halt(self):
pass
def pressed(self, button):
return BUTTONS[button].value() == 1
@ -97,14 +98,14 @@ class Badger2040W():
def icon(self, data, index, data_w, icon_size, x, y):
s_x = (index * icon_size) % data_w
s_y = int((index * icon_size) / data_w)
for o_y in range(icon_size):
for o_x in range(icon_size):
o = ((o_y + s_y) * data_w) + (o_x + s_x)
bm = 0b10000000 >> (o & 0b111)
if data[o >> 3] & bm:
self.display.pixel(x + o_x, y + o_y)
def image(self, data, w, h, x, y):
for oy in range(h):
row = data[oy]
@ -112,7 +113,6 @@ class Badger2040W():
if row & 0b1 == 0:
self.display.pixel(x + ox, y + oy)
row >>= 1
def status_handler(self, mode, status, ip):
print(mode, status, ip)

Wyświetl plik

@ -127,7 +127,7 @@ def launch(file):
button_c.irq(trigger=machine.Pin.IRQ_RISING, handler=quit_to_launcher)
try:
__import__(file)
__import__(file)
except ImportError:
# If the app doesn't exist, notify the user

Wyświetl plik

@ -1,67 +0,0 @@
import usocket
def urlopen(url, data=None, method="GET"):
if data is not None and method == "GET":
method = "POST"
try:
proto, dummy, host, path = url.split("/", 3)
except ValueError:
proto, dummy, host = url.split("/", 2)
path = ""
if proto == "http:":
port = 80
elif proto == "https:":
import ussl
port = 443
else:
raise ValueError("Unsupported protocol: " + proto)
if ":" in host:
host, port = host.split(":", 1)
port = int(port)
ai = usocket.getaddrinfo(host, port, 0, usocket.SOCK_STREAM)
ai = ai[0]
s = usocket.socket(ai[0], ai[1], ai[2])
try:
s.connect(ai[-1])
if proto == "https:":
s = ussl.wrap_socket(s, server_hostname=host)
s.write(method)
s.write(b" /")
s.write(path)
s.write(b" HTTP/1.0\r\nHost: ")
s.write(host)
s.write(b"\r\n")
if data:
s.write(b"Content-Length: ")
s.write(str(len(data)))
s.write(b"\r\n")
s.write(b"\r\n")
if data:
s.write(data)
l = s.readline()
l = l.split(None, 2)
# print(l)
status = int(l[1])
while True:
l = s.readline()
if not l or l == b"\r\n":
break
# print(l)
if l.startswith(b"Transfer-Encoding:"):
if b"chunked" in l:
raise ValueError("Unsupported " + l)
elif l.startswith(b"Location:"):
raise NotImplementedError("Redirects not yet supported")
except OSError:
s.close()
raise
return s

Wyświetl plik

@ -1,5 +1,4 @@
*.py
lib/*.py
lib/urllib/*.py
examples/*.jpg
examples/*.py