From a11f10d855c96b8fdd8cf12b71037310fa5844ee Mon Sep 17 00:00:00 2001 From: Klaus-Peter Bernschneider Date: Tue, 15 Mar 2022 09:19:14 +0100 Subject: [PATCH] Add files via upload --- apps/sunclock/app.js | 79 ++++++++++++++++++++++++++++++++++++++++++ apps/sunclock/app.png | Bin 0 -> 776 bytes 2 files changed, 79 insertions(+) create mode 100644 apps/sunclock/app.js create mode 100644 apps/sunclock/app.png diff --git a/apps/sunclock/app.js b/apps/sunclock/app.js new file mode 100644 index 000000000..1401c2a98 --- /dev/null +++ b/apps/sunclock/app.js @@ -0,0 +1,79 @@ +/* sclock.app.js for Bangle2 +Peter Bernschneider 30.12.2021 +Update current latitude and longitude in My Location app +Update current Timezone in Settings app, menu item "System" +Update for summer time by incrementing Timezone += 1 */ +setting = require("Storage").readJSON("setting.json",1); +E.setTimeZone(setting.timezone); // timezone = 1 for MEZ, = 2 for MESZ +SunCalc = require("suncalc.js"); +loc = require('locale'); +const LOCATION_FILE = "mylocation.json"; +const xyCenter = g.getWidth() / 2 + 3; +const yposTime = 60; +const yposDate = 100; +const yposRS = 135; +const yposPos = 160; +var rise = "07:00"; +var set = "20:00"; +var pos = {altitude: 20, azimuth: 135}; +var noonpos = {altitude: 37, azimuth: 180}; +let idTimeout = null; + +function updatePos() { + coord = require("Storage").readJSON(LOCATION_FILE,1)|| {"lat":53.3,"lon":10.1,"location":"Pattensen"}; + pos = SunCalc.getPosition(Date.now(), coord.lat, coord.lon); + times = SunCalc.getTimes(Date.now(), coord.lat, coord.lon); + rise = times.sunrise.toString().split(" ")[4].substr(0,5); + set = times.sunset.toString().split(" ")[4].substr(0,5); + noonpos = SunCalc.getPosition(times.solarNoon, coord.lat, coord.lon); +} + +function drawSimpleClock() { + var d = new Date(); // get date + var da = d.toString().split(" "); + g.clear(); + Bangle.drawWidgets(); + g.reset(); // default draw styles + g.setFontAlign(0, 0); // drawSting centered + + var time = da[4].substr(0, 5); // draw time + + g.setFont("Vector",60); + g.drawString(time, xyCenter, yposTime, true); + + var date = [loc.dow(new Date(),1), loc.date(d,1)].join(" "); // draw Day, name of month, Date + g.setFont("Vector",24); + g.drawString(date, xyCenter, yposDate, true); + + g.setFont("Vector",25); + g.drawString(`${rise} ${set}`, xyCenter, yposRS, true); // draw riseset + g.drawImage(require("Storage").read("sunrise.img"), xyCenter-16, yposRS-16); + + g.setFont("Vector",21); + g.drawString(`H${pos.altitude}/${noonpos.altitude} Az${pos.azimuth}`, xyCenter, yposPos, true); // draw sun pos + + let t = d.getSeconds()*1000 + d.getMilliseconds(); + idTimeout = setTimeout(drawSimpleClock, 60000 - t); // time till next minute +} + +// special function to handle display switch on +Bangle.on('lcdPower', function(on){ + if (on) { + drawSimpleClock(); + } else { + if(idTimeout) { + clearTimeout(idTimeout); + } + } +}); + +g.clear(); // clean app screen +Bangle.loadWidgets(); +Bangle.drawWidgets(); + +setInterval(updatePos, 60*15E3); // refesh every 15 mins + +updatePos(); +drawSimpleClock(); // draw now + +setWatch(Bangle.showLauncher, BTN1, { repeat: false, edge: "falling" }); // Show launcher when button pressed \ No newline at end of file diff --git a/apps/sunclock/app.png b/apps/sunclock/app.png new file mode 100644 index 0000000000000000000000000000000000000000..72c5b10d53f98912d0bcea5c7eec61ee215bcbee GIT binary patch literal 776 zcmV+j1NZ!iP)Qc8qH1%iQMDNbXAnjaZ{>(!al!i$Z0Z&w|m zf_dPs-t+$6-+9lu@4XNu%KuELTx}1PtL>3!*duZvDT*i`uth2mDeF2AIz3AwuK zLuTT(Mt^~YL3E8=pj#-ES{rEak4m34Ff$0o}k4v ziR07X!_p>!PN8tZ=tzat4gh2aPG+6gfEvJMv3v%&LHyipahN$PZA%04RopHR%|QM} z%!bhk@{A~+|GH%Zdhz%CYV~Fr0$KPc6Q*-OcHq=^zSZIYX&{a39_XSfxu;#SA-c@{ksuJP9`+tOMJlo9bGI+ z2mOngJesKB=~NlgWPl1J-h?JDB-WGR=mR7HO{HbZ%fpFFK}|Yh!d4Fis$8B`rSv;f zNs5geDMXcka!h7~KvEe0`b(Ch_g38U%yWQwyQ`#kF{}FBY|(Bra{xl{Qiix26QXB1 z-sK;-C>9J?dmGvh>}2HLXDuV|TQJq3utZwy;7qE0@N=f)V|C5B>o1J*YMW|H`e(9k z4lk$g9a>6vElE4c_OS)GZEEaCDCx?Z%IwFc?xIBbTl@s$D(DmEAVu;30000