Skip to content

Commit 012d82c

Browse files
author
Kevin J Walters
committed
Adding feature to ComboBlock to allow syncing of clocks to be disabled in time set mode.
Removing 9:30pm time setting, using what is left in RTC now. Switching to ticks_ms() for ZIP flashing in time set mode.
1 parent 5495668 commit 012d82c

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

zhhclock/zc_comboclock.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ def __init__(self, rtc, *,
2525
self._rtc.time = current_time
2626

2727
self._rtc.start()
28-
if not self.sync_clocks():
29-
raise RuntimeError("Cannot synchronise RTC with MP MB clock")
30-
3128
self._mp_clock_drift_ppm = mp_clock_drift_ppm
3229
self._conv_ticks_ms = 1.0 - mp_clock_drift_ppm / 1e6 if mp_clock_drift_ppm else 1
3330
self._last_frac_ms = None
3431
self._lost_sync = 0
32+
self.resync_enabled = True
33+
if not self.sync_clocks():
34+
raise RuntimeError("Cannot synchronise RTC with MP MB clock")
3535

3636
self.stopwatch_running = False
3737
self._stopwatch_start = self._stopwatch_stop = self._stopwatch_last = utime.ticks_ms()
@@ -58,14 +58,16 @@ def sync_clocks(self, attempts=10_000, current_time=None):
5858

5959
@property
6060
def time_with_ms_and_ticks(self):
61-
if self._lost_sync != 0:
62-
#print("RESYNC ATTEMPT")
61+
if self.resync_enabled and self._lost_sync != 0:
6362
if self.sync_clocks(20, self._rtc.time):
6463
pass
65-
#print("RESYNCED!")
6664

6765
rtc_time = self._rtc.time
6866
now_t_ms = utime.ticks_ms()
67+
if not self.resync_enabled:
68+
self._last_frac_ms = 0
69+
return (rtc_time, self._last_frac_ms, now_t_ms)
70+
6971
since_ms = utime.ticks_diff(now_t_ms, self._sync_time_tms)
7072
cor_since_ms = round(since_ms * self._conv_ticks_ms)
7173

zhhclock/zhhclock.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ def writeto_mem(self, addr, memaddr, buf, *, addrsize=8):
118118
zip_px.fill(BLACK)
119119
zip_px.show()
120120

121-
122121
display_image = [0] * (5 * 5)
123122

124123
microbit_bri_conv = 9.0 / 255.0
@@ -134,12 +133,10 @@ def show_display_image():
134133
show_display_image()
135134
gc.collect()
136135

137-
### Remove the current_time setting
138136
clock = ComboClock(mcp,
139137
rtc_clock_drift_ppm=THIS_ZHH_RTC_PPM,
140138
rtc_trim_conv=PPM_TO_TRIM_CONV,
141-
mp_clock_drift_ppm=THIS_MICROBIT_CLOCK_PPM,
142-
current_time=(2025, 2, 26, 9, 30, 0, 2, 57))
139+
mp_clock_drift_ppm=THIS_MICROBIT_CLOCK_PPM)
143140

144141
stopwatch_hmsms = [0, 0, 0, 0.0]
145142

@@ -204,7 +201,7 @@ def show_display_image():
204201
if not (bg_displayed & (1 << SECOND)):
205202
s_idx = rtc_time[SECOND] * ZIPCOUNT // 60
206203
elif mode_idx == MODE_TIME_SET:
207-
flash_on = ss_ms > 500.0
204+
flash_on = (utime.ticks_ms() % 1000) > 300.0
208205
if time_set_change != HOUR or flash_on:
209206
h_idx = rtc_time[HOUR] * ZIPCOUNT // 12 % ZIPCOUNT
210207
display_char = ("p" if rtc_time[HOUR] >= 12 else "a")
@@ -291,6 +288,8 @@ def show_display_image():
291288
threshold = threshold * 0.9 + 0.1 * int(pin_logo.is_touched())
292289

293290
if mode_idx == MODE_TIME_SET:
291+
### Exit time set mode
292+
clock.resync_enabled = True
294293
clock.sync_clocks()
295294
mode_idx = MODE_CLOCK
296295
elif utime.ticks_diff(t2_ms, t1_ms) < LONG_PRESS_DURATION_MS:
@@ -306,3 +305,4 @@ def show_display_image():
306305
else:
307306
mode_idx = MODE_TIME_SET
308307
time_set_change = HOUR
308+
clock.resync_enabled = False

0 commit comments

Comments
 (0)