Skip to content

Commit 2cc2776

Browse files
committed
stale warning
1 parent c4767fa commit 2cc2776

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

arch/esp8266/forth/examples/example-clock.forth

+15-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ variable: timezone
1212

1313
: age ( -- ms ) ms@ last-sync @ - ;
1414
: expired? ( -- bool ) age 60000 15 * > ;
15-
: stale? ( -- bool ) age 60000 60 * > ;
15+
: stale? ( -- bool ) age 60000 60 * > clock @ 0= or ;
1616
: fetch ( -- ts ) 123 "time.google.com" network-time ;
1717
: sync ( -- ) { fetch clock ! ms@ last-sync ! } catch ?dup if print: 'sync error:' ex-type cr then ;
1818
: time ( -- ts ) clock @ offset @ 60 * + age 1000 / + ;
@@ -117,24 +117,27 @@ EDT US1 .summer !
117117
: current-zone ( -- rule ) daylight-saving? if timezone @ .summer @ else timezone @ .standard @ then ;
118118
: apply-zone ( -- ) current-zone .offset @ offset ! ;
119119

120-
: format
120+
: format ( -- )
121121
time hour 10 < if $0 hh c! 1 else 0 then ]hh time hour >str
122122
time mins 10 < if $0 mm c! 1 else 0 then ]mm time mins >str ;
123123

124-
: centery HEIGHT 2 / 8 font-size @ * 2 / - text-top ! ;
125-
: colon tick @ if ":" else " " then draw-str tick @ invert tick ! ;
126-
: draw-time
127-
0 fill-buffer
128-
font-medium
129-
0 text-left ! centery
130-
hh draw-str colon mm draw-str " " draw-str
124+
: center ( -- )
125+
WIDTH 2 / "00:00 PDT" str-width 2 / - text-left !
126+
HEIGHT 2 / 8 font-size @ * 2 / - text-top ! ;
127+
: colon ( -- ) tick @ if ":" else " " then draw-str tick @ invert tick ! ;
128+
: clean ( -- ) 0 fill-buffer ;
129+
: draw-time ( -- )
130+
format
131+
WIDTH 128 >= if font-medium else font-small then
132+
center hh draw-str colon mm draw-str " " draw-str
131133
current-zone .name @ draw-str ;
132134

133-
: draw format draw-time display ;
134-
: start ( task -- ) activate begin expired? if sync then apply-zone draw 1000 ms pause again ;
135+
: stale-warning ( -- ) font-small 0 text-top ! 0 text-left ! "Stale" draw-str ;
136+
: draw ( -- ) clean stale? if stale-warning else apply-zone draw-time then display ;
137+
: start ( task -- ) activate begin expired? if sync then draw 1000 ms pause again ;
135138

136139
0 task: time-task
137-
: main
140+
: main ( -- )
138141
US3 timezone !
139142
display-init font5x7 font !
140143
sync multi time-task start ;

arch/esp8266/forth/ssd1306-i2c.forth

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ GPIO load
1313
\ change width/height
1414
64 constant: WIDTH
1515
48 constant: HEIGHT
16+
\ 128 constant: WIDTH
17+
\ 32 constant: HEIGHT
1618

1719
5 ( D1 SCL ) constant: SCL
1820
4 ( D2 SDA ) constant: SDA
@@ -167,7 +169,7 @@ create: buf 16r80 c, 0 c,
167169
loop
168170
drop ;
169171

170-
: str-width ( str -- ) strlen 8 * font-size @ * ;
172+
: str-width ( str -- ) strlen 6 * font-size @ * ;
171173

172174
/end
173175

arch/esp8266/forth/ssd1306-spi.forth

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ screen1 init-variable: actual
226226
loop
227227
drop ;
228228

229-
: str-width ( str -- ) strlen 8 * font-size @ * ;
229+
: str-width ( str -- ) strlen 6 * font-size @ * ;
230230

231231
/end
232232

0 commit comments

Comments
 (0)