From 8550b1a09a077cc6900dedccc28c94223f47da2a Mon Sep 17 00:00:00 2001 From: peeweek <4037271+peeweek@users.noreply.github.com> Date: Wed, 21 Jul 2021 15:27:58 +0200 Subject: [PATCH] Fixed buttons at startup, app visibility, added AM/PM support --- apps.json | 7 +++---- apps/hcclock/hcclock.app.js | 25 ++++++++++++++++++------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/apps.json b/apps.json index 6585a7c89..f879fca22 100644 --- a/apps.json +++ b/apps.json @@ -3318,17 +3318,16 @@ ] }, { "id": "hcclock", - "name": "High Contrast Clock", + "name": "Hi-Contrast Clock", "icon": "hcclock-icon.png", "version":"0.01", - "description": "High Contrast Clock : A simple yet very bold clock that aims to be readable in high luninosity environments. Uses big 10x5 pixel digits. Use BTN 1 to switch background and foreground colors.", + "description": "Hi-Contrast Clock : A simple yet very bold clock that aims to be readable in high luninosity environments. Uses big 10x5 pixel digits. Use BTN 1 to switch background and foreground colors.", "tags": "clock", "type":"clock", "allow_emulator":true, "storage": [ {"name":"hcclock.app.js","url":"hcclock.app.js"}, {"name":"hcclock.img","url":"hcclock-icon.js","evaluate":true} - ], - "sortorder" : -9 + ] } ] diff --git a/apps/hcclock/hcclock.app.js b/apps/hcclock/hcclock.app.js index cfff16c8b..d1866c11b 100644 --- a/apps/hcclock/hcclock.app.js +++ b/apps/hcclock/hcclock.app.js @@ -1,4 +1,4 @@ -{ + ////////////////////////////////////////////////////// // Numbers Rect order (left, top, right, bottom) // Each number defines a set of rects to draw @@ -72,6 +72,8 @@ const months = [ "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", const interval = 1000; // in ms const top = 32; +let ampm = (require("Storage").readJSON("setting.json",1)||{})["12hour"]; + let bg = 255; let fg = 0; @@ -94,7 +96,7 @@ function updateTime() let h = now.getHours(); let mo = now.getMonth(); let y = now.getFullYear(); - let d = now.getDay(); + let d = now.getDate(); if(h != hour) { @@ -102,7 +104,9 @@ function updateTime() g.setColor(bg,bg,bg); g.fillRect(0,60,240,110); g.setColor(fg,fg,fg); - drawDigits(60, hour); + if(ampm) + h = h%12; + drawDigits(60, h); } if(m != mins) { @@ -117,7 +121,7 @@ function updateTime() day = d; g.setFont("6x8", 2); g.setFontAlign(0, -1, 0); - g.drawString(fmtDate(d,mo,y), 120, 120); + g.drawString(fmtDate(d,mo,y,hour), 120, 120); } } @@ -154,9 +158,17 @@ function lerp(a,b,t) return a + t*(b-a); } -function fmtDate(day,month,year) +function fmtDate(day,month,year,hour) { - return months[month] + " " + day + " " + year; + if(ampm) + { + let ap = "(AM)"; + if(hour == 0 || hour > 12) + ap = "(PM)"; + return months[month] + " " + day + " " + year + " "+ ap; + } + else + return months[month] + " " + day + " " + year; } // Handles Flipping colors, then refreshes the UI @@ -188,4 +200,3 @@ setInterval(updateTime, interval); setWatch(flipColors, BTN1, true); setWatch(Bangle.showLauncher, BTN2, false); -}