@@ -4,7 +4,8 @@ import { units } from "user-settings";
44import * as util from "../common/utils" ;
55import { gettext } from "i18n" ;
66import { getDate } from "./date" ;
7- import { getTime } from './time' ;
7+ import { getTimeHM } from './time' ;
8+ import { getTimeMS } from './time' ;
89import { today } from 'user-activity'
910import { HeartRateSensor } from 'heart-rate' ;
1011import { display } from "display" ;
@@ -15,7 +16,6 @@ import { me as device } from "device";
1516import * as messaging from "messaging" ;
1617import * as fs from "fs" ;
1718
18-
1919// Update the clock every minute
2020clock . granularity = "minutes" ;
2121
@@ -40,6 +40,7 @@ let currentAct = 0;
4040let latitude = 0 ;
4141let longitude = 0 ;
4242let lastfetch = 0 ;
43+ let secDisplay = 0 ;
4344
4445
4546// load weather
@@ -72,7 +73,7 @@ hrm.addEventListener("reading", () => {
7273 if ( currentAct == 1 )
7374 display . on ? hrm . start ( ) : hrm . stop ( ) ;
7475 } ) ;
75- actText . text = hrm . heartRate ;
76+ actText . text = hrm . heartRate ;
7677} ) ;
7778
7879
@@ -168,7 +169,10 @@ clock.ontick = (evt) => {
168169 actText . text = today . adjusted . calories || 0 ;
169170 else if ( currentAct == 3 ) //elevation
170171 actText . text = today . adjusted . elevationGain || 0 ;
171- timeText . text = getTime ( currentDate ) ;
172+ if ( secDisplay == 0 )
173+ timeText . text = getTimeHM ( currentDate ) ;
174+ else
175+ timeText . text = getTimeMS ( currentDate ) ;
172176 //try to get location and weather
173177 setTimeout ( function ( ) {
174178 if ( ( currentDate . getTime ( ) - lastfetch ) > 1800000 ) { //every 30 min
@@ -191,28 +195,49 @@ clock.ontick = (evt) => {
191195
192196
193197//onclick
194- main . onclick = ( ) => {
198+ main . onclick = ( evt ) => {
195199 vibration . start ( 'bump' ) ;
196- if ( currentAct == 0 ) { //steps
197- hrm . start ( ) ;
198- actIcon . href = "icons/heart.png"
199- actText . text = hrm . heartRate ;
200- currentAct = 1 ;
201- }
202- else if ( currentAct == 1 ) { //HR
203- hrm . stop ( ) ;
204- actIcon . href = "icons/flame.png"
205- actText . text = today . adjusted . calories || 0 ;
206- currentAct = 2 ;
207- }
208- else if ( currentAct == 2 ) { // calo
209- actIcon . href = "icons/stairs.png"
210- actText . text = today . adjusted . elevationGain || 0 ;
211- currentAct = 3 ;
200+ if ( ( evt . screenX ) > 150 && ( evt . screenY ) < 150 ) {
201+ if ( secDisplay == 0 ) {
202+ clock . granularity = "seconds" ;
203+ secDisplay = 1 ;
204+ }
205+ else {
206+ secDisplay = 0 ;
207+ setTimeout ( function ( ) {
208+ clock . granularity = "minutes" ;
209+ } , 1500 ) ;
210+ }
212211 }
213- else if ( currentAct == 3 ) { // elevation
214- actIcon . href = "icons/step.png"
215- actText . text = today . adjusted . steps || 0 ;
216- currentAct = 0 ;
212+ else {
213+ if ( currentAct == 0 ) { //steps
214+ hrm . start ( ) ;
215+ actIcon . href = "icons/heart.png"
216+ actText . text = hrm . heartRate ;
217+ currentAct = 1 ;
218+ }
219+ else if ( currentAct == 1 ) { //HR
220+ hrm . stop ( ) ;
221+ actIcon . href = "icons/flame.png"
222+ actText . text = today . adjusted . calories || 0 ;
223+ currentAct = 2 ;
224+ }
225+ else if ( currentAct == 2 ) { // calo
226+ actIcon . href = "icons/stairs.png"
227+ actText . text = today . adjusted . elevationGain || 0 ;
228+ currentAct = 3 ;
229+ }
230+ else if ( currentAct == 3 ) { // elevation
231+ actIcon . href = "icons/step.png"
232+ actText . text = today . adjusted . steps || 0 ;
233+ currentAct = 0 ;
234+ }
217235 }
218- }
236+ }
237+
238+ display . addEventListener ( "change" , ( ) => {
239+ if ( ! display . on ) {
240+ secDisplay = 0 ;
241+ clock . granularity = "minutes" ;
242+ }
243+ } ) ;
0 commit comments