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
SCREEN_SIZE = (720, 720)
FPS = 60
FPS = 15
VALID_SURFACES = [
'button_pad',
'screensaver'

View File

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