133 lines
6.0 KiB
Python
133 lines
6.0 KiB
Python
import time
|
|
from shared.cookingState import CookingState, CookingStates
|
|
from shared import config
|
|
import framebuf
|
|
|
|
# Icon and bitmaps
|
|
image_weather_frost_bits = bytearray(b'\x01\x00\x13\x901\x18s\x9c\x09 \x05@S\x94\xfe\xfeS\x94\x05@\x09 s\x9c1\x18\x13\x90\x01\x00\x00\x00')
|
|
image_Alert_bits = bytearray(b'\xf7\x80\xe3\x80\xeb\x80\xc9\x80\xc9\x80\x80\x80\x88\x80\x00\x00')
|
|
image_CoolHiSmall_bits = bytearray(b'\x1f\xff\xc0?\xff\xe0\x7f\xff\xf0\xff\xdf\xf8\xffW\xf8\xfd\x8d\xf8\xf9\xdc\xf8\xfe\xdb\xf8\xf7Wx\xfb\x8e\xf8\xe0\x008\xfb\x8e\xf8\xf7Wx\xfe\xdb\xf8\xf9\xdc\xf8\xfd\x8d\xf8\xffW\xf8\xff\xdf\xf8\x7f\xff\xf0?\xff\xe0\x1f\xff\xc0')
|
|
image_CoolLoSmall_bits = bytearray(b'\x1f\xff\xc0 \x00 @\x00\x10\x80 \x08\x80\xa8\x08\x82r\x08\x86#\x08\x81$\x08\x88\xa8\x88\x84q\x08\x9f\xff\xc8\x84q\x08\x88\xa8\x88\x81$\x08\x86#\x08\x82r\x08\x80\xa8\x08\x80 \x08@\x00\x10 \x00 \x1f\xff\xc0')
|
|
image_music_sound_wave_bits = bytearray(b'\x00\x00\x00\x02\x00\x00\x02 \x00\x02 \x00\x02 \x00\x0a(\x00\x0a\xa8\x00*\xa8\x00\xaa\xaa\x80\x0a\xaa\x00\x0a\xa8\x00\x0a \x00\x02 \x00\x02 \x00\x02\x00\x00\x00\x00\x00')
|
|
image_weather_temperature_bits = bytearray(b'\x1c\x00\x22\x00+\x00*\x00+\x00*\x00+\x00*\x00*\x00I\x00\x9c\x80\xae\x80\xbe\x80\x9c\x80A\x00>\x00')
|
|
fb_image_weather_frost_bits = framebuf.FrameBuffer(image_weather_frost_bits, 15, 16, framebuf.MONO_HLSB)
|
|
fb_image_CoolHiSmall_bits = framebuf.FrameBuffer(image_CoolHiSmall_bits, 21, 21, framebuf.MONO_HLSB)
|
|
fb_image_weather_temperature_bits = framebuf.FrameBuffer(image_weather_temperature_bits, 9, 16, framebuf.MONO_HLSB)
|
|
fb_image_Alert_bits = framebuf.FrameBuffer(image_Alert_bits, 9, 8, framebuf.MONO_HLSB)
|
|
fb_image_music_sound_wave_bits = framebuf.FrameBuffer(image_music_sound_wave_bits, 17, 16, framebuf.MONO_HLSB)
|
|
fb_image_CoolLoSmall_bits = framebuf.FrameBuffer(image_CoolLoSmall_bits, 21, 21, framebuf.MONO_HLSB)
|
|
|
|
# Constants
|
|
CHARACTER_WIDTH = 6
|
|
CHARACTER_GAP = 2
|
|
CHARACTER_FULL_WIDTH = CHARACTER_WIDTH + CHARACTER_GAP
|
|
CHARACTER_HEIGHT = 7
|
|
|
|
|
|
class MicrowaveScreen:
|
|
# Used for animation
|
|
# lastUpdateTime = 0 # Not used right now
|
|
|
|
def __init__(self, display):
|
|
self.display = display
|
|
self.width = display.width
|
|
self.height = display.height
|
|
|
|
def h_centered_text(self, text, y, color=1):
|
|
"""Centers text horizontally
|
|
|
|
Args:
|
|
text (str): _description_
|
|
y (int): _description_
|
|
color (int, optional): _description_. Defaults to 1.
|
|
"""
|
|
text = str(text)
|
|
text_width = len(text) * CHARACTER_FULL_WIDTH
|
|
|
|
if config.DEBUG:
|
|
if text_width > self.width:
|
|
print(f"[MicrowaveScreen] Warning: Text '{text}' is too long to fit on the screen.")
|
|
|
|
x = (self.width - text_width) // 2
|
|
self.display.text(text, x, y, color)
|
|
|
|
def flick(self):
|
|
self.display.fill(0)
|
|
|
|
def show(self):
|
|
self.display.show()
|
|
|
|
def bootScreen(self):
|
|
self.display.text("SmartWave", 28, 28, 1)
|
|
self.show()
|
|
|
|
def _progressBar(self, progress, x, y, width=87, height=13, color=1):
|
|
# Box outline
|
|
self.display.rect(x, y, width, height, color)
|
|
|
|
# Fill the progress bar based on the progress value (0.0 to 1.0)
|
|
fill_width = int(progress * (width)) # Subtract 2
|
|
|
|
self.display.fill_rect(x, y, fill_width, height, color)
|
|
|
|
def update(self, cooking_state: CookingState | None, defrost_mode: bool = False):
|
|
self.flick()
|
|
|
|
# self.lastUpdateTime = time.time() # Not Used right now
|
|
|
|
if not cooking_state or cooking_state.state == CookingStates.IDLE: # Is not currently cooking
|
|
self.h_centered_text("Ready !", 28, 1)
|
|
else:
|
|
# Screen center
|
|
if cooking_state.state == CookingStates.STIRRING_REQUIRED:
|
|
self._message("Pls Stir", True)
|
|
elif cooking_state.state == CookingStates.ALERT:
|
|
self._message("Alert !", True)
|
|
elif cooking_state.state == CookingStates.DONE:
|
|
self._message("Done !", False)
|
|
else: # Progress bar
|
|
elapsed_time = cooking_state.get_elapsed_time()
|
|
estimated_progress = elapsed_time / (elapsed_time + cooking_state.estimated_remaining_time)
|
|
self._progressBar(estimated_progress, 21, 25)
|
|
|
|
# Estimated remaining time
|
|
if cooking_state.paused:
|
|
self.h_centered_text("Paused", 40, 1)
|
|
elif cooking_state.state != CookingStates.DONE:
|
|
remaining_time = int(cooking_state.estimated_remaining_time)
|
|
minutes = remaining_time // 60
|
|
seconds = remaining_time % 60
|
|
self.h_centered_text(f"{minutes:02}:{seconds:02}", 40, 1)
|
|
|
|
# Current dish temperature
|
|
if cooking_state.current_dish_temp is not None and cooking_state.current_dish_temp is not 0.0:
|
|
self.display.blit(fb_image_weather_temperature_bits, 27, 2)
|
|
self.display.text(str(int(cooking_state.current_dish_temp)), 37, 6, 1)
|
|
self.display.ellipse(54, 6, 1, 1, 1, False)
|
|
self.display.text("C", 56, 6, 1)
|
|
|
|
# Power level
|
|
if cooking_state.power_level is not None:
|
|
self.display.blit(fb_image_music_sound_wave_bits, 74, 2)
|
|
self.display.text(f"{cooking_state.power_level}W", 92, 6, 1)
|
|
if defrost_mode:
|
|
self.display.blit(fb_image_CoolHiSmall_bits, 2, 2)
|
|
else:
|
|
self.display.blit(fb_image_CoolLoSmall_bits, 2, 2)
|
|
|
|
self.show()
|
|
pass
|
|
|
|
def _message(self, text, alert):
|
|
self.display.fill_rect(0, 27, self.width, CHARACTER_HEIGHT + 4, 1)
|
|
if alert:
|
|
self.display.blit(fb_image_Alert_bits, 10, 29)
|
|
self.display.blit(fb_image_Alert_bits, self.width - 10, 29)
|
|
self.h_centered_text(text, 29, 0)
|
|
|
|
def message(self, text, alert):
|
|
self.flick()
|
|
self._message(text, alert)
|
|
self.show()
|
|
pass
|