@@ -37,7 +37,7 @@ def _init_resources(self):
37
37
socket .SOCK_DGRAM )
38
38
39
39
def _init_state (self ):
40
- self .start_time = None
40
+ self .project_start_time = None
41
41
self .need_wifi_count = 0
42
42
self .sntp_setup = False
43
43
self .bacotto_ping_counter = 0
@@ -47,6 +47,9 @@ def _init_state(self):
47
47
self .project_list = ['Otto' , 'Fuffa' , 'Foobar' , 'Gah' ]
48
48
self .project_idx = 0
49
49
50
+ # hours to send to bacotto
51
+ self .projects_hours = []
52
+
50
53
def welcome (self ):
51
54
self .display .blit (icons .logo , 0 , 0 )
52
55
self .display .show ()
@@ -67,7 +70,7 @@ def display_project_list(self):
67
70
self .display .text (p , 5 , 15 + i * 10 )
68
71
69
72
def display_project_time (self ):
70
- delta = utime .time () - self .start_time
73
+ delta = utime .time () - self .project_start_time
71
74
hours = int (delta / 3600 )
72
75
mins = int ((delta % 3600 ) / 60 )
73
76
project = self .current_project
@@ -77,7 +80,7 @@ def display_project_time(self):
77
80
10 , 30 )
78
81
79
82
def display_body (self ):
80
- if not self .start_time :
83
+ if not self .sntp_setup :
81
84
self .display_initializing ()
82
85
return
83
86
@@ -93,7 +96,12 @@ def run(self):
93
96
self .display .fill (0 )
94
97
95
98
if self .current_project is None and self .button .value ():
99
+ self .project_start_time = utime .time ()
96
100
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
97
105
98
106
old_need_wifi_count = self .need_wifi_count
99
107
if self .need_wifi_count > 0 :
@@ -106,6 +114,8 @@ def run(self):
106
114
except Exception as exc :
107
115
print ('Error debug:' , exc )
108
116
117
+ self .send_hours ()
118
+
109
119
# try:
110
120
# self.ping_bacotto()
111
121
# except Exception as exc:
@@ -139,6 +149,21 @@ def debug(self):
139
149
self .debug_sock .sendto (display .buffer , (settings .DEBUG_HOST , 9999 ))
140
150
utime .sleep_ms (1000 )
141
151
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
+
142
167
def ping_bacotto (self ):
143
168
if self .bacotto_ping_counter == 9 :
144
169
if self .wlan .is_connected ():
0 commit comments