learning how to declar variables in js

master
Carl Chan 2024-12-25 17:02:01 -05:00
parent a5c6c6d1e3
commit ae23db5136
1 changed files with 19 additions and 20 deletions

View File

@ -3,17 +3,17 @@ var Layout = require("Layout");
require("Font7x11Numeric7Seg").add(Graphics); require("Font7x11Numeric7Seg").add(Graphics);
require("FontTeletext5x9Ascii").add(Graphics); require("FontTeletext5x9Ascii").add(Graphics);
borders = 1; const borders = 1;
Light_on='#fff'; const Light_on='#fff';
Light_off='#554'; const Light_off='#554';
Light_warn='#f90'; const Light_warn='#f90';
Light_COMPACTY='#0F0'; const Light_COMPACTY='#0F0';
Light_width=43; const Light_width=43;
Light_height=25; const Light_height=25;
EL7_height=30; const EL7_height=30;
LightFont='Teletext5x9Ascii'; const LightFont='Teletext5x9Ascii';
DataFont='7x11Numeric7Seg:2'; const DataFont='7x11Numeric7Seg:2';
mode = 0; var mode = 0;
var layout = new Layout( var layout = new Layout(
{type:"h", c:[ {type:"h", c:[
@ -61,7 +61,7 @@ layout.update();
//support functions //support functions
function getWeather() { function getWeather() {
weather = require("Storage").readJSON('weather.json', 1).weather; var weather = require("Storage").readJSON('weather.json', 1).weather;
return weather; return weather;
} }
@ -80,7 +80,7 @@ function getdatetime(){
} }
function getSteps(){ function getSteps(){
steps=Bangle.getHealthStatus("day").steps; let steps=Bangle.getHealthStatus("day").steps;
steps = typeof steps !== 'undefined' ? steps:0; steps = typeof steps !== 'undefined' ? steps:0;
return steps; return steps;
} }
@ -111,7 +111,7 @@ function getTemperature(){
} }
function getHRM(){ function getHRM(){
hrm=Bangle.getHealthStatus('last'); let hrm=Bangle.getHealthStatus('last');
hrm = typeof hrm !== 'undefined' ? hrm:0; hrm = typeof hrm !== 'undefined' ? hrm:0;
return hrm; return hrm;
} }
@ -121,7 +121,7 @@ function isBTConnected(){
} }
function getBattery(){ function getBattery(){
battlevel = E.getBattery(); let battlevel = E.getBattery();
if (Bangle.isCharging()) { if (Bangle.isCharging()) {
battlevel = -1; battlevel = -1;
} else if (battlevel >= 100) { } else if (battlevel >= 100) {
@ -157,10 +157,9 @@ function setLight(id,label,check,onColour,offColour){
function setDATA(id,label) { function setDATA(id,label) {
layout.clear(layout[id]); layout.clear(layout[id]);
let data='-----';
try { try {
if (isNaN(label)) { if (!isNaN(label)) {
data='-----';
} else {
if (label < 0) { if (label < 0) {
label=Math.abs(label); label=Math.abs(label);
sign='-'; sign='-';
@ -204,7 +203,7 @@ function draw_bg(){
// actual display // actual display
function drawMain(){ function drawMain(){
datetime=getdatetime(); let datetime=getdatetime();
setDATA('R1',datetime.localtime); setDATA('R1',datetime.localtime);
setDATA('R2',datetime.utctime); setDATA('R2',datetime.utctime);
@ -285,7 +284,7 @@ function mode_HRM() {
} }
function mode_weather() { function mode_weather() {
weather=getWeather(); let weather=getWeather();
weather.temp = Math.round(weather.temp-273.15); weather.temp = Math.round(weather.temp-273.15);
setDATA('R1',weather.temp); setDATA('R1',weather.temp);
setDATA('R2',weather.hum); setDATA('R2',weather.hum);