replaced app-icon.js
parent
7c06bf454f
commit
a1bcd0dbad
|
|
@ -13,6 +13,7 @@ Light_height=25;
|
||||||
EL7_height=30;
|
EL7_height=30;
|
||||||
LightFont='Teletext5x9Ascii';
|
LightFont='Teletext5x9Ascii';
|
||||||
DataFont='7x11Numeric7Seg:2';
|
DataFont='7x11Numeric7Seg:2';
|
||||||
|
mode = 0;
|
||||||
|
|
||||||
var layout = new Layout(
|
var layout = new Layout(
|
||||||
{type:"h", c:[
|
{type:"h", c:[
|
||||||
|
|
@ -53,12 +54,35 @@ var layout = new Layout(
|
||||||
{type:"txt", font:DataFont, col:"#0F0", bgCol:"#000", label:"00000", id:"R3", fillx:1, height:EL7_height},
|
{type:"txt", font:DataFont, col:"#0F0", bgCol:"#000", label:"00000", id:"R3", fillx:1, height:EL7_height},
|
||||||
]},
|
]},
|
||||||
{type:"",width:5},
|
{type:"",width:5},
|
||||||
]},
|
],
|
||||||
{lazy:true});
|
lazy:true});
|
||||||
layout.update();
|
layout.update();
|
||||||
|
|
||||||
//support functions
|
//support functions
|
||||||
|
|
||||||
|
function getWeather() {
|
||||||
|
try {
|
||||||
|
var weatherLib = require("weather");
|
||||||
|
weather = weatherLib.get();
|
||||||
|
} catch(e) {
|
||||||
|
console.log("Weather lib not found." );
|
||||||
|
}
|
||||||
|
if (weather) {
|
||||||
|
weather.temp = Math.round(require("locale").temp(weather.temp-273.15));
|
||||||
|
weather.hum = weather.hum;
|
||||||
|
weather.wind = Math.round(require("locale").speed(weather.wind).match(/^(\D*\d*)(.*)$/));
|
||||||
|
weather.wind = Math.round(weather.wind[1]);
|
||||||
|
} else {
|
||||||
|
weather = {
|
||||||
|
temp: "-----",
|
||||||
|
hum: "-----",
|
||||||
|
wind: "-----",
|
||||||
|
txt: "-----",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return weather;
|
||||||
|
}
|
||||||
|
|
||||||
function getdatetime(){
|
function getdatetime(){
|
||||||
var datetime = [];
|
var datetime = [];
|
||||||
var d = new Date();
|
var d = new Date();
|
||||||
|
|
@ -67,9 +91,9 @@ function getdatetime(){
|
||||||
datetime.clock = require("locale").time(d, 1);
|
datetime.clock = require("locale").time(d, 1);
|
||||||
datetime.month = d.getMonth()+1;
|
datetime.month = d.getMonth()+1;
|
||||||
datetime.day = d.getDate();
|
datetime.day = d.getDate();
|
||||||
datetime.localtime=String(String(d.getHours()).padStart(2,'0')+String(d.getMinutes()).padStart(2,'0')).padStart(5,'0');
|
datetime.localtime=String(d.getHours()).padStart(2,'0')+String(d.getMinutes()).padStart(2,'0');
|
||||||
utchour=((d.getHours()+(Math.round(d.getTimezoneOffset()/60))) % 24);
|
utchour=((d.getHours()+(Math.round(d.getTimezoneOffset()/60))) % 24);
|
||||||
datetime.utctime=String(String(utchour).padStart(2,'0')+String(d.getMinutes()).padStart(2,'0')).padStart(5,'0');
|
datetime.utctime=String(utchour).padStart(2,'0')+String(d.getMinutes()).padStart(2,'0');
|
||||||
return datetime;
|
return datetime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,23 +122,17 @@ function isMessagesNotify(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//function getTemperature(){
|
function getTemperature(){
|
||||||
// var temperature = E.getTemperature();
|
var temperature = E.getTemperature();
|
||||||
// temperature = typeof temperature !== 'undefined' ? temperature:99999;
|
temperature = typeof temperature !== 'undefined' ? temperature:99999;
|
||||||
// return Math.round(temperature);
|
return Math.round(temperature);
|
||||||
//}
|
}
|
||||||
|
|
||||||
//function getHRM(){
|
function getHRM(){
|
||||||
// hrm=Bangle.getHealthStatus('10min').bpm;
|
hrm=Bangle.getHealthStatus('last');
|
||||||
// hrm = typeof hrm !== 'undefined' ? hrm:0;
|
hrm = typeof hrm !== 'undefined' ? hrm:0;
|
||||||
// return hrm;
|
return hrm;
|
||||||
//}
|
}
|
||||||
|
|
||||||
//function getGPS(){
|
|
||||||
// GPS=Bangle.getPressure();
|
|
||||||
// GPS = typeof GPS !== 'undefined' ? GPS:{temperature:0,pressure:0,altitude:0};
|
|
||||||
// return GPS;
|
|
||||||
//}
|
|
||||||
|
|
||||||
function isBTConnected(){
|
function isBTConnected(){
|
||||||
return NRF.getSecurityStatus().connected;
|
return NRF.getSecurityStatus().connected;
|
||||||
|
|
@ -127,7 +145,7 @@ function getBattery(){
|
||||||
} else if (battlevel >= 100) {
|
} else if (battlevel >= 100) {
|
||||||
battlevel = 99;
|
battlevel = 99;
|
||||||
}
|
}
|
||||||
battlevel=String(battlevel).padStart(2,'0');
|
battlevel=String(battlevel);
|
||||||
return battlevel;
|
return battlevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -140,6 +158,8 @@ function isActive(){
|
||||||
}
|
}
|
||||||
|
|
||||||
function setLight(id,label,check,onColour,offColour){
|
function setLight(id,label,check,onColour,offColour){
|
||||||
|
// print('setlight:',id); //debug
|
||||||
|
layout.clear(layout[id]);
|
||||||
onColour = typeof onColour !== 'undefined' ? onColour:Light_on;
|
onColour = typeof onColour !== 'undefined' ? onColour:Light_on;
|
||||||
offColour = typeof offColour !== 'undefined' ? offColour:Light_off;
|
offColour = typeof offColour !== 'undefined' ? offColour:Light_off;
|
||||||
if (label !== '') {
|
if (label !== '') {
|
||||||
|
|
@ -150,6 +170,38 @@ function setLight(id,label,check,onColour,offColour){
|
||||||
} else {
|
} else {
|
||||||
layout[id].bgCol=offColour;
|
layout[id].bgCol=offColour;
|
||||||
}
|
}
|
||||||
|
layout.render(layout[id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setDATA(id,label){
|
||||||
|
layout.clear(layout[id]);
|
||||||
|
try {
|
||||||
|
if (isNaN(label)) {
|
||||||
|
data='-----';
|
||||||
|
} else {
|
||||||
|
data=String(String(label).toString(16)).toUpperCase().padStart(5,'0').substring(0,5);
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
data='-----';
|
||||||
|
}
|
||||||
|
layout[id].label=data;
|
||||||
|
layout.render(layout[id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setWORD(id,label){
|
||||||
|
layout.clear(layout[id]);
|
||||||
|
try {
|
||||||
|
if (isNaN(label)) {
|
||||||
|
data='--';
|
||||||
|
} else {
|
||||||
|
data=String(String(label).toString(16)).toUpperCase().padStart(2,'0').substring(0,2);
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
data='--';
|
||||||
|
}
|
||||||
|
// print(id, data); //debug
|
||||||
|
layout[id].label=data;
|
||||||
|
layout.render(layout[id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function draw_bg(){
|
function draw_bg(){
|
||||||
|
|
@ -162,16 +214,17 @@ function draw_bg(){
|
||||||
}
|
}
|
||||||
|
|
||||||
// actual display
|
// actual display
|
||||||
function draw(){
|
function drawMain(){
|
||||||
|
remove_alt_events();
|
||||||
datetime=getdatetime();
|
datetime=getdatetime();
|
||||||
|
|
||||||
layout.R1.label=datetime.localtime;
|
setDATA('R1',datetime.localtime);
|
||||||
layout.R2.label=datetime.utctime;
|
setDATA('R2',datetime.utctime);
|
||||||
layout.R3.label=String(getSteps()).padStart(5,'0');
|
setDATA('R3',getSteps());
|
||||||
|
|
||||||
layout.PROG.label=String(getBattery()).padStart(2,'0');
|
setWORD('PROG',getBattery());
|
||||||
layout.VERB.label=String(datetime.month).padStart(2,'0');
|
setWORD('VERB',datetime.month);
|
||||||
layout.NOUN.label=String(datetime.day).padStart(2,'0');
|
setWORD('NOUN',datetime.day);
|
||||||
|
|
||||||
setLight('COMPACTY','',isActive(),Light_COMPACTY);
|
setLight('COMPACTY','',isActive(),Light_COMPACTY);
|
||||||
setLight('L1','MSG',isMessagesNotify());
|
setLight('L1','MSG',isMessagesNotify());
|
||||||
|
|
@ -181,8 +234,8 @@ function draw(){
|
||||||
setLight('L5','ALARM',isAlarmSet(),Light_warn);
|
setLight('L5','ALARM',isAlarmSet(),Light_warn);
|
||||||
setLight('L6','STEP',(getSteps()>=getStepGoal()),'#0a0');
|
setLight('L6','STEP',(getSteps()>=getStepGoal()),'#0a0');
|
||||||
|
|
||||||
|
// layout.forgetLazyState();
|
||||||
layout.render();
|
layout.render();
|
||||||
// layout.debug();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var drawTimeout;
|
var drawTimeout;
|
||||||
|
|
@ -191,10 +244,120 @@ function queueDraw() {
|
||||||
if (drawTimeout) clearTimeout(drawTimeout);
|
if (drawTimeout) clearTimeout(drawTimeout);
|
||||||
drawTimeout = setTimeout(function() {
|
drawTimeout = setTimeout(function() {
|
||||||
drawTimeout = undefined;
|
drawTimeout = undefined;
|
||||||
draw();
|
let mode = 0;
|
||||||
|
remove_alt_events();
|
||||||
|
drawMain();
|
||||||
}, 60000 - (Date.now() % 60000));
|
}, 60000 - (Date.now() % 60000));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////// ALT modes /////
|
||||||
|
function drawAlt(mode) {
|
||||||
|
remove_alt_events();
|
||||||
|
mode = typeof mode !== 'undefined' ? mode:0;
|
||||||
|
// print('drawAlt: ', mode); // debug
|
||||||
|
// Show mode in PROG
|
||||||
|
setWORD('PROG',mode);
|
||||||
|
setWORD('NOUN','');
|
||||||
|
setWORD('VERB','');
|
||||||
|
// Disable Battery warning light in to show PROG no longer shows battery level
|
||||||
|
setLight('L4','BATT',false);
|
||||||
|
switch (mode) {
|
||||||
|
case 1:
|
||||||
|
setLight('L6','HRM',true);
|
||||||
|
mode_HRM();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
setLight('L6','GPS',true);
|
||||||
|
mode_GPS();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
setLight('L6','TEMP',true);
|
||||||
|
mode_weather();
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
setLight('L6','ACCEL',true);
|
||||||
|
mode_accel();
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
setLight('L6','HDG',true);
|
||||||
|
mode_compass();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
drawMain();
|
||||||
|
}
|
||||||
|
layout.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function mode_weather() {
|
||||||
|
weather=getWeather();
|
||||||
|
setDATA('R1',weather.temp);
|
||||||
|
setDATA('R2',weather.hum);
|
||||||
|
setDATA('R3',weather.wind);
|
||||||
|
}
|
||||||
|
|
||||||
|
function mode_compass() {
|
||||||
|
Bangle.setCompassPower(1);
|
||||||
|
Bangle.on('mag', show_compass);
|
||||||
|
}
|
||||||
|
function mode_accel() {
|
||||||
|
Bangle.on('accel', show_accel);
|
||||||
|
}
|
||||||
|
function mode_GPS() {
|
||||||
|
Bangle.setGPSPower(1,'dsky_clock');
|
||||||
|
Bangle.on('GPS', show_GPS);
|
||||||
|
}
|
||||||
|
|
||||||
|
function mode_HRM() {
|
||||||
|
Bangle.setHRMPower(true, 'dsky_clock');
|
||||||
|
Bangle.on('HRM', show_HRM);
|
||||||
|
}
|
||||||
|
function show_HRM() {
|
||||||
|
setLight('COMPACTY','',isActive(),Light_COMPACTY);
|
||||||
|
hrm=getHRM();
|
||||||
|
setDATA('R1',hrm.bpm);
|
||||||
|
setDATA('R2',hrm.bpmConfidence);
|
||||||
|
// setDATA('R3',hrm.steps);
|
||||||
|
}
|
||||||
|
|
||||||
|
function show_GPS() {
|
||||||
|
setLight('COMPACTY','',isActive(),Light_COMPACTY);
|
||||||
|
gps=Bangle.getGPSFix();
|
||||||
|
setWORD('NOUN',gps.fix);
|
||||||
|
setWORD('VERB',gps.satellites);
|
||||||
|
setDATA('R1',gps.lat);
|
||||||
|
setDATA('R2',gps.lon);
|
||||||
|
setDATA('R3',gps.speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
function show_compass() {
|
||||||
|
setLight('COMPACTY','',isActive(),Light_COMPACTY);
|
||||||
|
compass=Bangle.getCompass();
|
||||||
|
setDATA('R1',compass.heading);
|
||||||
|
setDATA('R2');
|
||||||
|
setDATA('R3');
|
||||||
|
}
|
||||||
|
|
||||||
|
function show_accel() {
|
||||||
|
setLight('COMPACTY','',isActive(),Light_COMPACTY);
|
||||||
|
accel=Bangle.getAccel();
|
||||||
|
setDATA('R1',accel.x);
|
||||||
|
setDATA('R2',accel.y);
|
||||||
|
setDATA('R3',accel.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function remove_alt_events() {
|
||||||
|
Bangle.removeListener('accel', show_accel);
|
||||||
|
Bangle.removeListener('mag', show_compass);
|
||||||
|
Bangle.setCompassPower(0);
|
||||||
|
Bangle.removeListener('GPS', show_GPS);
|
||||||
|
Bangle.setGPSPower(0);
|
||||||
|
Bangle.removeListener('HRM', show_HRM);
|
||||||
|
Bangle.setHRMPower(0);
|
||||||
|
setLight('COMPACTY','',isActive(),Light_COMPACTY);
|
||||||
|
}
|
||||||
|
|
||||||
//////////// Main
|
//////////// Main
|
||||||
|
|
||||||
// Show launcher when middle button pressed
|
// Show launcher when middle button pressed
|
||||||
|
|
@ -209,17 +372,27 @@ Bangle.loadWidgets();
|
||||||
require("widget_utils").swipeOn(); // hide widgets, make them visible with a swipe
|
require("widget_utils").swipeOn(); // hide widgets, make them visible with a swipe
|
||||||
|
|
||||||
Bangle.on('lock',on=>{
|
Bangle.on('lock',on=>{
|
||||||
draw(); // draw immediately
|
mode = 0;
|
||||||
|
remove_alt_events();
|
||||||
|
drawMain(); // draw immediately
|
||||||
|
});
|
||||||
|
Bangle.on('HRM',function() { setLight('COMPACTY','',isActive(),Light_COMPACTY);});
|
||||||
|
Bangle.on("message",function() { setLight('COMPACTY','',isActive(),Light_COMPACTY);});
|
||||||
|
Bangle.on('charging',drawMain);
|
||||||
|
NRF.on('connect',function() { setLight('L3','BT',!isBTConnected(),Light_warn); });
|
||||||
|
NRF.on('disconnect',function() { setLight('L3','BT',!isBTConnected(),Light_warn); });
|
||||||
|
Bangle.on('tap', function(data) {
|
||||||
|
if (!Bangle.isLocked() && data.double) {
|
||||||
|
if (mode > 5 ) {
|
||||||
|
mode = 0;
|
||||||
|
} else {
|
||||||
|
mode=mode+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
drawAlt(mode);
|
||||||
});
|
});
|
||||||
|
|
||||||
Bangle.on('GPS',draw);
|
|
||||||
Bangle.on('HRM',draw);
|
|
||||||
Bangle.on("message",draw);
|
|
||||||
Bangle.on('charging',draw);
|
|
||||||
NRF.on('connect',draw);
|
|
||||||
NRF.on('disconnect',draw);
|
|
||||||
|
|
||||||
g.clear();
|
g.clear();
|
||||||
draw_bg();
|
draw_bg();
|
||||||
draw();
|
drawMain();
|
||||||
queueDraw();
|
queueDraw();
|
||||||
Loading…
Reference in New Issue