v2 with altmodes
parent
d14c4675ab
commit
3d02e82644
|
|
@ -49,9 +49,9 @@ var layout = new Layout(
|
||||||
{type:"txt", font:DataFont, col:"#0F0", bgCol:"#000", label:"00", id:"NOUN", fillx:1, height:EL7_height},
|
{type:"txt", font:DataFont, col:"#0F0", bgCol:"#000", label:"00", id:"NOUN", fillx:1, height:EL7_height},
|
||||||
]},
|
]},
|
||||||
{ type:"",bgCol:'#070', width:80, height:2 },
|
{ type:"",bgCol:'#070', width:80, height:2 },
|
||||||
{type:"txt", font:DataFont, col:"#0F0", bgCol:"#000", label:"00000", id:"R1", fillx:1, height:EL7_height},
|
{type:"txt", font:DataFont, col:"#0F0", bgCol:"#000", label:"00000", id:"R1", halign:1, fillx:1, height:EL7_height},
|
||||||
{type:"txt", font:DataFont, col:"#0F0", bgCol:"#000", label:"00000", id:"R2", fillx:1, height:EL7_height},
|
{type:"txt", font:DataFont, col:"#0F0", bgCol:"#000", label:"00000", id:"R2", halign:1, fillx:1, height:EL7_height},
|
||||||
{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", halign:1, fillx:1, height:EL7_height},
|
||||||
]},
|
]},
|
||||||
{type:"",width:5},
|
{type:"",width:5},
|
||||||
],
|
],
|
||||||
|
|
@ -61,25 +61,7 @@ layout.update();
|
||||||
//support functions
|
//support functions
|
||||||
|
|
||||||
function getWeather() {
|
function getWeather() {
|
||||||
try {
|
weather = require("Storage").readJSON('weather.json', 1).weather;
|
||||||
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;
|
return weather;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -173,13 +155,20 @@ function setLight(id,label,check,onColour,offColour){
|
||||||
layout.render(layout[id]);
|
layout.render(layout[id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setDATA(id,label){
|
function setDATA(id,label) {
|
||||||
layout.clear(layout[id]);
|
layout.clear(layout[id]);
|
||||||
try {
|
try {
|
||||||
if (isNaN(label)) {
|
if (isNaN(label)) {
|
||||||
data='-----';
|
data='-----';
|
||||||
} else {
|
} else {
|
||||||
|
if (label < 0) {
|
||||||
|
label=Math.abs(label);
|
||||||
|
sign='-';
|
||||||
|
} else {
|
||||||
|
sign='';
|
||||||
|
}
|
||||||
data=String(String(label).toString(16)).toUpperCase().padStart(5,'0').substring(0,5);
|
data=String(String(label).toString(16)).toUpperCase().padStart(5,'0').substring(0,5);
|
||||||
|
data=sign+data;
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
data='-----';
|
data='-----';
|
||||||
|
|
@ -215,7 +204,6 @@ function draw_bg(){
|
||||||
|
|
||||||
// actual display
|
// actual display
|
||||||
function drawMain(){
|
function drawMain(){
|
||||||
remove_alt_events();
|
|
||||||
datetime=getdatetime();
|
datetime=getdatetime();
|
||||||
|
|
||||||
setDATA('R1',datetime.localtime);
|
setDATA('R1',datetime.localtime);
|
||||||
|
|
@ -236,24 +224,15 @@ function drawMain(){
|
||||||
|
|
||||||
// layout.forgetLazyState();
|
// layout.forgetLazyState();
|
||||||
layout.render();
|
layout.render();
|
||||||
}
|
queueDraw();
|
||||||
|
|
||||||
var drawTimeout;
|
|
||||||
// schedule a draw for the next minute
|
|
||||||
function queueDraw() {
|
|
||||||
if (drawTimeout) clearTimeout(drawTimeout);
|
|
||||||
drawTimeout = setTimeout(function() {
|
|
||||||
drawTimeout = undefined;
|
|
||||||
let mode = 0;
|
|
||||||
remove_alt_events();
|
|
||||||
drawMain();
|
|
||||||
}, 60000 - (Date.now() % 60000));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////// ALT modes /////
|
////// ALT modes /////
|
||||||
|
var AltDrawTimer;
|
||||||
function drawAlt(mode) {
|
function drawAlt(mode) {
|
||||||
remove_alt_events();
|
if (AltDrawTimer) clearTimeout(AltDrawTimer);
|
||||||
mode = typeof mode !== 'undefined' ? mode:0;
|
mode = typeof mode !== 'undefined' ? mode:0;
|
||||||
|
mode=Math.abs(mode);
|
||||||
// print('drawAlt: ', mode); // debug
|
// print('drawAlt: ', mode); // debug
|
||||||
// Show mode in PROG
|
// Show mode in PROG
|
||||||
setWORD('PROG',mode);
|
setWORD('PROG',mode);
|
||||||
|
|
@ -261,6 +240,9 @@ function drawAlt(mode) {
|
||||||
setWORD('VERB','');
|
setWORD('VERB','');
|
||||||
// Disable Battery warning light in to show PROG no longer shows battery level
|
// Disable Battery warning light in to show PROG no longer shows battery level
|
||||||
setLight('L4','BATT',false);
|
setLight('L4','BATT',false);
|
||||||
|
setDATA('R1');
|
||||||
|
setDATA('R2');
|
||||||
|
setDATA('R3');
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 1:
|
case 1:
|
||||||
setLight('L6','HRM',true);
|
setLight('L6','HRM',true);
|
||||||
|
|
@ -288,78 +270,82 @@ function drawAlt(mode) {
|
||||||
layout.render();
|
layout.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mode_HRM() {
|
||||||
|
setLight('COMPACTY','',true,Light_COMPACTY);
|
||||||
|
AltDrawTimer = setTimeout( function() {
|
||||||
|
Bangle.setHRMPower(true, 'dsky_clock');
|
||||||
|
hrm=getHRM();
|
||||||
|
setDATA('R1',hrm.bpm);
|
||||||
|
setDATA('R2',hrm.bpmConfidence);
|
||||||
|
setDATA('R3',getSteps());
|
||||||
|
mode_HRM();
|
||||||
|
}, 5000);
|
||||||
|
Bangle.setHRMPower(false);
|
||||||
|
}
|
||||||
|
|
||||||
function mode_weather() {
|
function mode_weather() {
|
||||||
weather=getWeather();
|
weather=getWeather();
|
||||||
|
weather.temp = Math.round(weather.temp-273.15);
|
||||||
setDATA('R1',weather.temp);
|
setDATA('R1',weather.temp);
|
||||||
setDATA('R2',weather.hum);
|
setDATA('R2',weather.hum);
|
||||||
setDATA('R3',weather.wind);
|
setDATA('R3',weather.code);
|
||||||
|
setWORD('NOUN',weather.hum);
|
||||||
|
setWORD('VERB',weather.rain);
|
||||||
}
|
}
|
||||||
|
|
||||||
function mode_compass() {
|
function mode_compass() {
|
||||||
Bangle.setCompassPower(1);
|
AltDrawTimer = setTimeout ( function() {
|
||||||
Bangle.on('mag', show_compass);
|
setLight('COMPACTY','',true,Light_COMPACTY); //isCompassOn seems to be incorrect?
|
||||||
}
|
Bangle.setCompassPower(1);
|
||||||
function mode_accel() {
|
compass=Bangle.getCompass();
|
||||||
Bangle.on('accel', show_accel);
|
setDATA('R1',compass.heading);
|
||||||
}
|
setDATA('R2');
|
||||||
function mode_GPS() {
|
setDATA('R3');
|
||||||
Bangle.setGPSPower(1,'dsky_clock');
|
mode_compass();
|
||||||
Bangle.on('GPS', show_GPS);
|
}, 200);
|
||||||
}
|
|
||||||
|
|
||||||
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.setCompassPower(0);
|
||||||
Bangle.removeListener('GPS', show_GPS);
|
}
|
||||||
|
|
||||||
|
function mode_GPS() {
|
||||||
|
setLight('COMPACTY','',true,Light_COMPACTY);
|
||||||
|
AltDrawTimer = setTimeout( function() {
|
||||||
|
Bangle.setGPSPower(1,'dsky_clock');
|
||||||
|
gps=Bangle.getGPSFix();
|
||||||
|
setWORD('NOUN',gps.fix);
|
||||||
|
setWORD('VERB',gps.satellites);
|
||||||
|
setDATA('R1',gps.lat);
|
||||||
|
setDATA('R2',gps.lon);
|
||||||
|
setDATA('R3',gps.speed);
|
||||||
|
mode_GPS();
|
||||||
|
}, 5000);
|
||||||
Bangle.setGPSPower(0);
|
Bangle.setGPSPower(0);
|
||||||
Bangle.removeListener('HRM', show_HRM);
|
}
|
||||||
Bangle.setHRMPower(0);
|
|
||||||
setLight('COMPACTY','',isActive(),Light_COMPACTY);
|
function mode_accel() {
|
||||||
|
AltDrawTimer = setTimeout( function() {
|
||||||
|
setLight('COMPACTY','',isActive(),Light_COMPACTY);
|
||||||
|
accel=Bangle.getAccel();
|
||||||
|
setDATA('R1',accel.x);
|
||||||
|
setDATA('R2',accel.y);
|
||||||
|
setDATA('R3',accel.z);
|
||||||
|
mode_accel();
|
||||||
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////// Main
|
//////////// Main
|
||||||
|
|
||||||
|
var drawTimeout;
|
||||||
|
// schedule a draw for the next minute
|
||||||
|
function queueDraw() {
|
||||||
|
if (drawTimeout) clearTimeout(drawTimeout);
|
||||||
|
drawTimeout = setTimeout(function() {
|
||||||
|
drawTimeout = undefined;
|
||||||
|
mode = 0;
|
||||||
|
if (AltDrawTimer) clearTimeout(AltDrawTimer);
|
||||||
|
drawMain();
|
||||||
|
}, 60000 - (Date.now() % 60000));
|
||||||
|
}
|
||||||
|
|
||||||
// Show launcher when middle button pressed
|
// Show launcher when middle button pressed
|
||||||
Bangle.setUI({
|
Bangle.setUI({
|
||||||
mode : "clock",
|
mode : "clock",
|
||||||
|
|
@ -373,26 +359,26 @@ require("widget_utils").swipeOn(); // hide widgets, make them visible with a swi
|
||||||
|
|
||||||
Bangle.on('lock',on=>{
|
Bangle.on('lock',on=>{
|
||||||
mode = 0;
|
mode = 0;
|
||||||
remove_alt_events();
|
|
||||||
drawMain(); // draw immediately
|
drawMain(); // draw immediately
|
||||||
});
|
});
|
||||||
Bangle.on('HRM',function() { setLight('COMPACTY','',isActive(),Light_COMPACTY);});
|
//Bangle.on('HRM',function() { setLight('COMPACTY','',isActive(),Light_COMPACTY);});
|
||||||
Bangle.on("message",function() { setLight('COMPACTY','',isActive(),Light_COMPACTY);});
|
Bangle.on("message",function() { setLight('COMPACTY','',isActive(),Light_COMPACTY);});
|
||||||
Bangle.on('charging',drawMain);
|
Bangle.on('charging',drawMain);
|
||||||
NRF.on('connect',function() { setLight('L3','BT',!isBTConnected(),Light_warn); });
|
NRF.on('connect',function() { setLight('L3','BT',!isBTConnected(),Light_warn); });
|
||||||
NRF.on('disconnect',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) {
|
Bangle.on('swipe', function(directionLR) {
|
||||||
if (mode > 5 ) {
|
if (directionLR == 1) {
|
||||||
mode = 0;
|
mode=mode+1;
|
||||||
} else {
|
|
||||||
mode=mode+1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (directionLR == -1) {
|
||||||
|
mode=mode-1;
|
||||||
|
}
|
||||||
|
if (mode < 0 ) { mode=5; }
|
||||||
|
mode=(mode % 6);
|
||||||
drawAlt(mode);
|
drawAlt(mode);
|
||||||
});
|
});
|
||||||
|
|
||||||
g.clear();
|
g.clear();
|
||||||
draw_bg();
|
draw_bg();
|
||||||
drawMain();
|
drawMain();
|
||||||
queueDraw();
|
|
||||||
Loading…
Reference in New Issue