Skip to content

Commit b38c8d1

Browse files
committed
ports: esp32: go back to list of projects on click
1 parent 0ba3920 commit b38c8d1

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

ports/esp32/modules/otto.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _init_resources(self):
3737
socket.SOCK_DGRAM)
3838

3939
def _init_state(self):
40-
self.start_time = None
40+
self.project_start_time = None
4141
self.need_wifi_count = 0
4242
self.sntp_setup = False
4343
self.bacotto_ping_counter = 0
@@ -47,6 +47,9 @@ def _init_state(self):
4747
self.project_list = ['Otto', 'Fuffa', 'Foobar', 'Gah']
4848
self.project_idx = 0
4949

50+
# hours to send to bacotto
51+
self.projects_hours = []
52+
5053
def welcome(self):
5154
self.display.blit(icons.logo, 0, 0)
5255
self.display.show()
@@ -67,7 +70,7 @@ def display_project_list(self):
6770
self.display.text(p, 5, 15 + i * 10)
6871

6972
def display_project_time(self):
70-
delta = utime.time() - self.start_time
73+
delta = utime.time() - self.project_start_time
7174
hours = int(delta / 3600)
7275
mins = int((delta % 3600) / 60)
7376
project = self.current_project
@@ -77,7 +80,7 @@ def display_project_time(self):
7780
10, 30)
7881

7982
def display_body(self):
80-
if not self.start_time:
83+
if not self.sntp_setup:
8184
self.display_initializing()
8285
return
8386

@@ -93,7 +96,12 @@ def run(self):
9396
self.display.fill(0)
9497

9598
if self.current_project is None and self.button.value():
99+
self.project_start_time = utime.time()
96100
self.current_project = self.project_list[self.project_idx]
101+
elif self.current_project is not None and self.button.value():
102+
self.register_current_project()
103+
self.current_project = None
104+
self.project_start_time = None
97105

98106
old_need_wifi_count = self.need_wifi_count
99107
if self.need_wifi_count > 0:
@@ -106,6 +114,8 @@ def run(self):
106114
except Exception as exc:
107115
print('Error debug:', exc)
108116

117+
self.send_hours()
118+
109119
# try:
110120
# self.ping_bacotto()
111121
# except Exception as exc:
@@ -139,6 +149,21 @@ def debug(self):
139149
self.debug_sock.sendto(display.buffer, (settings.DEBUG_HOST, 9999))
140150
utime.sleep_ms(1000)
141151

152+
def register_current_project(self):
153+
project_delta = utime.time() - self.project_start_time
154+
self.projects_hours.append((self.current_project, project_delta))
155+
156+
def send_hours(self):
157+
if not self.projects_hours:
158+
return
159+
160+
if self.wlan.is_connected():
161+
print('sending hours to bacotto')
162+
self.projects_hours = []
163+
self.need_wifi_count -= 1
164+
else:
165+
self.need_wifi_count += 1
166+
142167
def ping_bacotto(self):
143168
if self.bacotto_ping_counter == 9:
144169
if self.wlan.is_connected():

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy