@@ -15,6 +15,7 @@ const S = require("Storage");
1515
1616let drawTimeout : TimeoutId | undefined ;
1717let menuShown = false ;
18+ let latestGps : GPSFix | undefined ;
1819
1920type Dist = number & { brand : 'dist' } ;
2021type Time = number & { brand : 'time' } ;
@@ -24,41 +25,76 @@ type Split = {
2425 time : Time ,
2526} ;
2627
27- const splits : Split [ ] = [ ] ; // times
28+ const splits : Split [ ] = ( S . readJSON ( "pace.json" , 1 ) as Split [ ] ) || [ ] ; // times
2829let splitOffset = 0 , splitOffsetPx = 0 ;
2930
3031const GPS_TIMEOUT_MS = 30000 ;
3132
33+ const drawGpsLvl = ( l : Layout . RenderedHierarchy ) => {
34+ const gps = latestGps ;
35+ const nsats = gps ?. satellites ?? 0 ;
36+
37+ if ( ! gps || ! gps . fix )
38+ g . setColor ( "#FF0000" ) ;
39+ else if ( gps . satellites < 4 )
40+ g . setColor ( "#FF5500" ) ;
41+ else if ( gps . satellites < 6 )
42+ g . setColor ( "#FF8800" ) ;
43+ else if ( gps . satellites < 8 )
44+ g . setColor ( "#FFCC00" ) ;
45+ else
46+ g . setColor ( "#00FF00" ) ;
47+
48+ g . fillRect (
49+ l . x ,
50+ l . y + l . h - 10 - ( l . h - 10 ) * ( ( nsats > 12 ? 12 : nsats ) / 12 ) ,
51+ l . x + l . w ,
52+ l . y + l . h
53+ ) ;
54+ } ;
55+
3256const layout = new Layout ( {
33- type : "v " ,
57+ type : "h " ,
3458 c : [
3559 {
36- type : "txt" ,
37- font : "6x8:2" ,
38- label : "Pace" ,
39- id : "paceLabel" ,
40- pad : 4
41- } ,
42- {
43- type : "txt" ,
44- font : "Vector:40" ,
45- label : "" ,
46- id : "pace" ,
47- halign : 0
48- } ,
49- {
50- type : "txt" ,
51- font : "6x8:2" ,
52- label : "Time" ,
53- id : "timeLabel" ,
54- pad : 4
60+ type : "custom" ,
61+ render : drawGpsLvl ,
62+ filly : 1 ,
63+ width : 10 ,
64+ bgCol : g . theme . bg , // automatically clears before render()
5565 } ,
5666 {
57- type : "txt" ,
58- font : "Vector:40" ,
59- label : "" ,
60- id : "time" ,
61- halign : 0
67+ type : "v" ,
68+ c : [
69+ {
70+ type : "txt" ,
71+ font : "6x8:2" ,
72+ label : "Pace" ,
73+ id : "paceLabel" ,
74+ pad : 4
75+ } ,
76+ {
77+ type : "txt" ,
78+ font : "Vector:40" ,
79+ label : "" ,
80+ id : "pace" ,
81+ halign : 0
82+ } ,
83+ {
84+ type : "txt" ,
85+ font : "6x8:2" ,
86+ label : "Time" ,
87+ id : "timeLabel" ,
88+ pad : 4
89+ } ,
90+ {
91+ type : "txt" ,
92+ font : "Vector:40" ,
93+ label : "" ,
94+ id : "time" ,
95+ halign : 0
96+ } ,
97+ ]
6298 } ,
6399 ]
64100} , {
@@ -262,6 +298,7 @@ Bangle.on('tap', e => {
262298Bangle . loadWidgets ( ) ;
263299Bangle . drawWidgets ( ) ;
264300Bangle . setGPSPower ( 1 , "pace" ) ;
301+ Bangle . on ( "GPS" , gps => latestGps = gps ) ;
265302
266303g . clearRect ( Bangle . appRect ) ;
267304draw ( ) ;
0 commit comments