Update main.py

Update screensaver
This commit is contained in:
jeanGaston 2024-06-09 17:19:57 +02:00
parent 9cf4d017c7
commit 2703494296

View File

@ -1,3 +1,4 @@
import math
import network import network
import urequests as requests import urequests as requests
import ujson as json import ujson as json
@ -89,9 +90,31 @@ def display_message(message, ip_address):
print("display error:", e) print("display error:", e)
init_oled() init_oled()
# Function to draw a circle
def draw_circle(oled, x0, y0, radius, color):
x = radius
y = 0
err = 0
while x >= y:
oled.pixel(x0 + x, y0 + y, color)
oled.pixel(x0 + y, y0 + x, color)
oled.pixel(x0 - y, y0 + x, color)
oled.pixel(x0 - x, y0 + y, color)
oled.pixel(x0 - x, y0 - y, color)
oled.pixel(x0 - y, y0 - x, color)
oled.pixel(x0 + y, y0 - x, color)
oled.pixel(x0 + x, y0 - y, color)
y += 1
err += 1 + 2*y
if 2*(err - x) + 1 > 0:
x -= 1
err += 1 - 2*x
# Screensaver function with circular wave animation
def screensaver(): def screensaver():
""" """
<<<<<<< Updated upstream
Activate the screensaver with RF-AD animation. Activate the screensaver with RF-AD animation.
This function activates the screensaver by displaying an RF-AD animation moving across the screen. This function activates the screensaver by displaying an RF-AD animation moving across the screen.
@ -101,23 +124,30 @@ def screensaver():
- screensaver_thread_running (bool): Flag indicating if the screensaver thread is running. - screensaver_thread_running (bool): Flag indicating if the screensaver thread is running.
- last_activity_time (float): Timestamp of the last activity. - last_activity_time (float): Timestamp of the last activity.
=======
Screensaver function with circular wave animation
>>>>>>> Stashed changes
""" """
global screensaver_active, screensaver_thread_running global screensaver_active, screensaver_thread_running
x, y = 0, 0 text = "RF-AD"
direction_x, direction_y = 1, 1 center_x = 64 # Center horizontally
center_y = 32 # Center vertically
radius = 36
max_radius = 64 # Maximum radius for the animation
while screensaver_active: while screensaver_active:
oled.fill(0) oled.fill(0)
oled.text("RF-AD", x, y) oled.text(text, 44, 28)
# Draw expanding circles
for r in range(radius, max_radius, 5):
draw_circle(oled, center_x, center_y, r, 1)
oled.show() oled.show()
time.sleep(0.05) radius += 1
if radius > max_radius:
radius = 36
x += direction_x time.sleep(0.01)
y += direction_y
if x <= 0 or x >= 128 - 36: # 36 is the length of "RF-AD"
direction_x *= -1
if y <= 0 or y >= 64 - 10: # 10 is the height of text
direction_y *= -1
# Check for activity # Check for activity
if time.time() - last_activity_time <= 60: if time.time() - last_activity_time <= 60: