added timeout

This commit is contained in:
Nicholas Dyer 2023-08-19 19:08:19 -04:00
parent 3fe978b00a
commit 2794172a98
Signed by: ndyer
GPG Key ID: 1118528038C53648
2 changed files with 11 additions and 6 deletions

View File

@ -4,7 +4,7 @@ import thermostat.surfaces as surfaces
# Global variables # Global variables
SCREEN_SIZE = (720, 720) SCREEN_SIZE = (720, 720)
FPS = 60 FPS = 15
VALID_SURFACES = [ VALID_SURFACES = [
'button_pad', 'button_pad',
'screensaver' 'screensaver'

View File

@ -93,11 +93,13 @@ class Surface(pygame.Surface):
self.big_font = pygame.font.Font(SCRIPT_DIR + '/resources/tuffy.ttf', 96) self.big_font = pygame.font.Font(SCRIPT_DIR + '/resources/tuffy.ttf', 96)
self.set_temp = 74 self.set_temp = 74
self.frame_counter = 300 self.mouse_frame_counter = 75
self.timeout_frame_counter = 0
self.current_temp = 0 self.current_temp = 0
def update(self): def update(self):
self.frame_counter += 1 self.mouse_frame_counter += 1
self.timeout_frame_counter += 1
self.fill((16, 16, 16)) self.fill((16, 16, 16))
self.mouse_handler.update() self.mouse_handler.update()
for event in pygame.event.get(): for event in pygame.event.get():
@ -117,7 +119,7 @@ class Surface(pygame.Surface):
self.mouse_handler.click = False self.mouse_handler.click = False
if self.mouse_handler.click: if self.mouse_handler.click:
self.timeout_frame_counter = 0
if self.mouse_handler.mouse_pos[0] <= QUIT_BUTTON_SIZE and \ if self.mouse_handler.mouse_pos[0] <= QUIT_BUTTON_SIZE and \
self.mouse_handler.mouse_pos[1] <= QUIT_BUTTON_SIZE: self.mouse_handler.mouse_pos[1] <= QUIT_BUTTON_SIZE:
self.running = False self.running = False
@ -143,13 +145,13 @@ class Surface(pygame.Surface):
print(send_data(f'SET;{self.set_temp}')) print(send_data(f'SET;{self.set_temp}'))
button.update() button.update()
self.blit(button, button.rect) self.blit(button, button.rect)
if self.frame_counter > 300: if self.mouse_frame_counter > 75:
request_data = send_data(f'REQ') request_data = send_data(f'REQ')
split_data = request_data.decode('utf-8').split(';') split_data = request_data.decode('utf-8').split(';')
if split_data[0] == 'SDATA': if split_data[0] == 'SDATA':
self.current_temp = int(round(float(split_data[1]))) self.current_temp = int(round(float(split_data[1])))
self.set_temp = float(split_data[2]) self.set_temp = float(split_data[2])
self.frame_counter = 0 self.mouse_frame_counter = 0
text = self.small_font.render(f'Set to {self.set_temp}°F', True, (255, 255, 255)) text = self.small_font.render(f'Set to {self.set_temp}°F', True, (255, 255, 255))
text_rect = text.get_rect() text_rect = text.get_rect()
@ -159,3 +161,6 @@ class Surface(pygame.Surface):
text_rect = text.get_rect() text_rect = text.get_rect()
text_rect.center = (360, 360) text_rect.center = (360, 360)
self.blit(text, text_rect) self.blit(text, text_rect)
if self.timeout_frame_counter >= 15*30:
self.timeout_frame_counter = 15*30
self.fill((0, 0, 0))