Skip to content

Commit

Permalink
Redraw the pixels after brightness changes
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscareycode committed May 15, 2023
1 parent 7545e42 commit 5f34c2b
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions cosmic-emoji-react/pico/emoji_paint.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@

ip = connect_to_wifi(SSID, PSK)

print(f"Start painting at: http://{ip}")
print(f"Connected to wifi [{SSID}] ip [{ip}]")

last_pixels = ""

# start web server
server = Microdot()

print(f"Start painting at: http://{ip}")

@server.route("/", methods=["GET"])
def route_index(request):
return send_file("emoji_paint/index.html")
Expand All @@ -41,18 +44,10 @@ def route_get_pixels(req):
res.headers["Access-Control-Allow-Origin"] = '*'
res.body = last_pixels
return res


@server.post('/set_pixels')
def set_pixels(req):
def draw_pixels():
global last_pixels
#print("got data")

data = req.body

# save for later
last_pixels = data

data = last_pixels
arr = list(data)

for j in range(HEIGHT):
Expand All @@ -73,6 +68,15 @@ def set_pixels(req):
graphics.set_pen(graphics.create_pen(r, g, b))
graphics.pixel(i, j)
cu.update(graphics)

@server.post('/set_pixels')
def set_pixels(req):
global last_pixels

# save for later
last_pixels = req.body

draw_pixels()

res = Response()
res.headers["Access-Control-Allow-Origin"] = '*'
Expand All @@ -98,6 +102,9 @@ def set_brightness(req):
if brightnessFloat >= 0 and brightnessFloat <= 10:
cu.set_brightness(brightnessFloat)
res.body = "success"
# after changing brightness you have to draw the pixels again
# to see the brightness change
draw_pixels()
return res

# start the web server on all ips, port 80
Expand Down

0 comments on commit 5f34c2b

Please sign in to comment.