From 5c8ba46ea96159da3e8fc23daf5f7845f4698435 Mon Sep 17 00:00:00 2001 From: David Peer Date: Sat, 11 Jun 2022 17:49:47 +0200 Subject: [PATCH] Version 0.10 - Show daily step count, temperature as well as heartrate. --- apps/cassioWatch/ChangeLog | 3 +- apps/cassioWatch/README.md | 3 +- apps/cassioWatch/app.js | 61 ++++++++++++++++++++++++++++++++++---- 3 files changed, 60 insertions(+), 7 deletions(-) diff --git a/apps/cassioWatch/ChangeLog b/apps/cassioWatch/ChangeLog index f00b3fa0a..419810021 100644 --- a/apps/cassioWatch/ChangeLog +++ b/apps/cassioWatch/ChangeLog @@ -7,4 +7,5 @@ 0.6: Add Settings Page 0.7: Update Rocket Sequences Scope to not use memory all time 0.8: Update Some Variable Scopes to not use memory until need -0.9: Remove ESLint spaces \ No newline at end of file +0.9: Remove ESLint spaces +0.10: Show daily steps, heartrate and the temperature if weather information is available. \ No newline at end of file diff --git a/apps/cassioWatch/README.md b/apps/cassioWatch/README.md index 1342af8e6..aaeb3f122 100644 --- a/apps/cassioWatch/README.md +++ b/apps/cassioWatch/README.md @@ -6,5 +6,6 @@ Clock with Space Cassio Watch Style. It displays current temperature,day,steps,battery.heartbeat and weather. + **To-do**: -Integrate heartbeat and Weather, Align and change size of some elements. +Align and change size of some elements. diff --git a/apps/cassioWatch/app.js b/apps/cassioWatch/app.js index 93538ec50..49e23c2eb 100644 --- a/apps/cassioWatch/app.js +++ b/apps/cassioWatch/app.js @@ -1,7 +1,11 @@ +const storage = require('Storage'); +const locale = require('locale'); + require("Font6x12").add(Graphics); require("Font8x12").add(Graphics); require("Font7x11Numeric7Seg").add(Graphics); + let ClockInterval; let RocketInterval; let BatteryInterval; @@ -43,7 +47,7 @@ function getRocketSequences() { let rocket_sequence = 1; -let settings = require('Storage').readJSON("cassioWatch.settings.json", true) || {}; +let settings = storage.readJSON("cassioWatch.settings.json", true) || {}; let rocketSpeed = settings.rocketSpeed || 700; delete settings; @@ -82,6 +86,43 @@ function DrawRocket() { if (rocket_sequence > 8) rocket_sequence = 1; } +function getTemperature(){ + try { + var weatherJson = storage.readJSON('weather.json'); + var weather = weatherJson.weather; + return Math.round(weather.temp-273.15); + + } catch(ex) { + print(ex) + return "?" + } +} + +function getSteps() { + var steps = 0; + try{ + if (WIDGETS.wpedom !== undefined) { + steps = WIDGETS.wpedom.getSteps(); + } else if (WIDGETS.activepedom !== undefined) { + steps = WIDGETS.activepedom.getSteps(); + } else { + steps = Bangle.getHealthStatus("day").steps; + } + } catch(ex) { + // In case we failed, we can only show 0 steps. + return "? k"; + } + + // Show always 2 digits. E.g. 1.5k if < 10000 otherwise 12k + if(steps > 10000){ + steps = Math.round(steps/1000); + } else { + steps = Math.round(steps/100) / 10; + } + return steps + "k"; +} + + function DrawScene() { g.reset(); g.clear(); @@ -94,17 +135,22 @@ function DrawScene() { g.drawString("Launching Process", 30, 20); g.setFont("8x12"); g.drawString("ACTIVATE", 40, 35); + + g.setFontAlign(0,-1); g.setFont("8x12", 2); - g.drawString("30", 142, 132); - g.drawString("55", 95, 98); - g.setFont("8x12", 1); - g.drawString(Bangle.getStepCount(), 143, 104); + g.drawString(getTemperature(), 155, 132); + g.drawString(Math.round(Bangle.getHealthStatus("last").bpm), 109, 98); + g.drawString(getSteps(), 158, 98); + + g.setFontAlign(-1,-1); ClockInterval = setInterval(DrawClock, 30000); DrawClock(); RocketInterval = setInterval(DrawRocket, rocketSpeed); DrawRocket(); BatteryInterval = setInterval(DrawBattery, 5 * 60000); DrawBattery(); + + for (let wd of WIDGETS) {wd.draw=()=>{};wd.area="";} } Bangle.on("lcdPower", (on) => { @@ -123,6 +169,11 @@ Bangle.on("lock", (locked) => { } }); + +// Load widgets, but don't show them +Bangle.loadWidgets(); + + g.reset(); g.clear(); Bangle.setUI("clock");