@@ -12,7 +12,7 @@ variable: timezone
12
12
13
13
: age ( -- ms ) ms@ last-sync @ - ;
14
14
: expired? ( -- bool ) age 60000 15 * > ;
15
- : stale? ( -- bool ) age 60000 60 * > ;
15
+ : stale? ( -- bool ) age 60000 60 * > clock @ 0= or ;
16
16
: fetch ( -- ts ) 123 "time.google.com" network-time ;
17
17
: sync ( -- ) { fetch clock ! ms@ last-sync ! } catch ?dup if print: 'sync error:' ex-type cr then ;
18
18
: time ( -- ts ) clock @ offset @ 60 * + age 1000 / + ;
@@ -117,24 +117,27 @@ EDT US1 .summer !
117
117
: current-zone ( -- rule ) daylight-saving? if timezone @ .summer @ else timezone @ .standard @ then ;
118
118
: apply-zone ( -- ) current-zone .offset @ offset ! ;
119
119
120
- : format
120
+ : format ( -- )
121
121
time hour 10 < if $0 hh c! 1 else 0 then ]hh time hour >str
122
122
time mins 10 < if $0 mm c! 1 else 0 then ]mm time mins >str ;
123
123
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
131
133
current-zone .name @ draw-str ;
132
134
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 ;
135
138
136
139
0 task: time-task
137
- : main
140
+ : main ( -- )
138
141
US3 timezone !
139
142
display-init font5x7 font !
140
143
sync multi time-task start ;
0 commit comments