added id, fw ver, batt %, mem % on BTN1 press in cliock

master
hughbarney 2021-01-28 13:17:41 +00:00
parent b8c181209c
commit 2e520a6d75
7 changed files with 83 additions and 3 deletions

View File

@ -1,2 +1,3 @@
0.07: Submitted to App Loader
0.08: Fixes issue where face would redraw on wake leading to all memory being used and watch crashing.
0.09: Add BTN1 status line with ID,Fw ver, mem %, battery %

14
apps/cliock/README.md Normal file
View File

@ -0,0 +1,14 @@
# Cli Clock
A retro VT100 command line style clock
## Screenshots
### Normall face
![](cli_clock.jpg)
### With BTN1 pressed
* Successive presses of BTN1 will show id, FW version, battery %, memory %
![](cli_clock_with_id.jpg)

View File

@ -4,6 +4,14 @@ var marginTop = 40;
var flag = false;
var WeekDays = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
const NONE_MODE = "none";
const ID_MODE = "id";
const VER_MODE = "ver";
const BATT_MODE = "batt";
const MEM_MODE = "mem";
let infoMode = NONE_MODE;
function drawAll(){
updateTime();
updateRest(new Date());
@ -13,6 +21,7 @@ function updateRest(now){
let date = locale.date(now,false);
writeLine(WeekDays[now.getDay()],1);
writeLine(date,2);
drawInfo(5);
}
function updateTime(){
if (!Bangle.isLCDOn()) return;
@ -32,13 +41,67 @@ function writeLineStart(line){
}
function writeLine(str,line){
g.setFont("6x8",fontsize);
g.setColor(0,1,0);
//g.setColor(0,1,0);
g.setColor(0,0x07E0,0);
g.setFontAlign(-1,-1);
g.clearRect(0,marginTop+line*30,((str.length+1)*20),marginTop+25+line*30);
writeLineStart(line);
g.drawString(str,25,marginTop+line*30);
}
function drawInfo(line) {
let val;
let str = "";
let col = 0x07E0; // green
switch(infoMode) {
case NONE_MODE:
col = 0x0000;
str = "";
break;
case ID_MODE:
val = NRF.getAddress().split(":");
str = "Id: " + val[4] + val[5];
break;
case VER_MODE:
str = "Fw: " + process.env.VERSION;
break;
case MEM_MODE:
val = process.memory();
str = "Memory: " + Math.round(val.usage*100/val.total) + "%";
break;
case BATT_MODE:
default:
str = "Battery: " + E.getBattery() + "%";
}
g.setColor(col);
g.fillRect(0, marginTop-3+line*30, 239, marginTop+25+line*30);
g.setColor(0,0,0);
g.setFontAlign(0, -1);
g.drawString(str, g.getWidth()/2, marginTop+line*30);
}
function changeInfoMode() {
switch(infoMode) {
case NONE_MODE:
infoMode = ID_MODE;
break;
case ID_MODE:
infoMode = VER_MODE;
break;
case VER_MODE:
infoMode = BATT_MODE;
break;
case BATT_MODE:
infoMode = MEM_MODE;
break;
case MEM_MODE:
default:
infoMode = NONE_MODE;
}
}
g.clear();
Bangle.loadWidgets();
Bangle.drawWidgets();
@ -49,3 +112,4 @@ Bangle.on('lcdPower',function(on) {
});
var click = setInterval(updateTime, 1000);
setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"});
setWatch(() => { changeInfoMode(); drawAll(); }, BTN1, {repeat: true});

BIN
apps/cliock/cli_clock.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

View File

@ -1,2 +1,3 @@
0.01: New App
0.02: Restore to SuperE mode on power off.
0.03: dont reset to SuperE mode on power, as it prevents its general use

View File

@ -16,7 +16,7 @@
function gps_get_fix() { return last_fix; }
function gps_get_status() { return WIDGETS.gpsservice.width === 24 ? true : false;}
function gps_get_version() { return "0.2"; }
function gps_get_version() { return "0.03"; }
function log_debug(o) {
if (debug) console.log(o);
@ -67,7 +67,7 @@
}
function gps_power_off() {
setupSuperE(); // return to expected setup for other apps
//setupSuperE(); // return to expected setup for other apps
Bangle.setGPSPower(0);
have_fix = false;
fixToggle = false;