pull/1282/head
Andreas Rozek 2022-01-12 09:43:42 +01:00
commit 63d1fbd827
3 changed files with 62 additions and 62 deletions

View File

@ -7,4 +7,5 @@
0.07: Added settings to adjust data that is shown for each row.
0.08: Support for multiple screens. 24h graph for steps + HRM. Fullscreen Mode.
0.09: Tab anywhere to open the launcher.
0.10: Fix - Clock is unresponsive, if gadgetbridge connects.
0.11: Added getting the gadgetbridge weather

View File

@ -33,8 +33,8 @@ let cGrey = "#9E9E9E";
let lcarsViewPos = 0;
let drag;
let hrmValue = 0;
var connected = NRF.getSecurityStatus().connected;
var plotWeek = false;
var disableInfoUpdate = true; // When gadgetbridge connects, step infos cannot be loaded
/*
* Requirements and globals
@ -157,10 +157,10 @@ function printData(key, y, c){
}
g.setColor(c);
g.fillRect(79, y-2, 87 ,y+18);
g.fillRect(79, y-2, 85 ,y+18);
g.setFontAlign(1,-1,0);
g.drawString(value, 131, y);
g.setFontAlign(0,-1,0);
g.drawString(value, 110, y);
g.setColor(c);
g.setFontAlign(-1,-1,0);
@ -179,7 +179,7 @@ function drawHorizontalBgLine(color, x1, x2, y, h){
}
function drawLock(){
function drawInfo(){
if(lcarsViewPos != 0){
return;
}
@ -188,7 +188,8 @@ function drawLock(){
g.setColor(cOrange);
g.clearRect(120, 10, g.getWidth(), 75);
g.drawString("LCARS", 128, 13);
if(connected){
if(NRF.getSecurityStatus().connected){
g.drawString("CONN", 128, 33);
} else {
g.drawString("NOCON", 128, 33);
@ -249,11 +250,11 @@ function drawPosition0(){
// The last line is a battery indicator too
var bat = E.getBattery() / 100.0;
var batX2 = parseInt((172 - 35) * bat + 35);
drawHorizontalBgLine(cOrange, 35, batX2, 171, 5);
drawHorizontalBgLine(cGrey, batX2+10, 172, 171, 5);
drawHorizontalBgLine(cOrange, 35, batX2-5, 171, 5);
drawHorizontalBgLine(cGrey, batX2+5, 172, 171, 5);
// Draw logo
drawLock();
// Draw Infos
drawInfo();
// Write time
g.setFontAlign(-1, -1, 0);
@ -261,15 +262,15 @@ function drawPosition0(){
var currentDate = new Date();
var timeStr = locale.time(currentDate,1);
g.setFontAntonioLarge();
g.drawString(timeStr, 29, 10);
g.drawString(timeStr, 27, 10);
// Write date
g.setColor(cWhite);
g.setFontAntonioMedium();
var dayStr = locale.dow(currentDate, true).toUpperCase();
dayStr += " " + currentDate.getDate();
dayStr += " " + currentDate.getFullYear();
g.drawString(dayStr, 32, 56);
dayStr += " " + locale.month(currentDate, 1).toUpperCase();
g.drawString(dayStr, 30, 56);
// Draw data
g.setFontAlign(-1, -1, 0);
@ -416,6 +417,7 @@ function draw(){
*/
function getSteps() {
var steps = 0;
let health;
try {
health = require("health");
} catch(ex) {
@ -476,24 +478,17 @@ function handleAlarm(){
Bangle.on('lcdPower',on=>{
if (on) {
// Whenever we connect to Gadgetbridge, reading data from
// health failed. Therefore, we update and read data from
// health iff the connection state did not change.
if(connected == NRF.getSecurityStatus().connected) {
draw();
} else {
connected = NRF.getSecurityStatus().connected
drawLock();
}
// health failed. Therefore, we update only partially...
drawInfo();
drawState();
} else { // stop draw timer
if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = undefined;
}
connected = NRF.getSecurityStatus().connected
});
Bangle.on('lock', function(isLocked) {
drawLock();
drawInfo();
});
Bangle.on('charging',function(charging) {
@ -526,49 +521,53 @@ function decreaseAlarm(){
Storage.writeJSON(SETTINGS_FILE, settings);
}
function feedback(){
Bangle.buzz(40, 0.3);
}
// Thanks to the app "gbmusic" for this code to detect swipes in all 4 directions.
Bangle.on("drag", e => {
if (!drag) { // start dragging
drag = {x: e.x, y: e.y};
} else if (!e.b) { // released
const dx = e.x-drag.x, dy = e.y-drag.y;
drag = null;
// Touch gestures to control clock. We don't use swipe to be compatible with the bangle ecosystem
Bangle.on('touch', function(btn, e){
var left = parseInt(g.getWidth() * 0.2);
var right = g.getWidth() - left;
var upper = parseInt(g.getHeight() * 0.2);
var lower = g.getHeight() - upper;
// Horizontal swipe
if (Math.abs(dx)>Math.abs(dy)+10) {
if(dx > 0){
lcarsViewPos = 0;
} else {
lcarsViewPos = 1;
}
// Vertical swipe
} else if (Math.abs(dy)>Math.abs(dx)+10) {
if(lcarsViewPos == 0){
if(dy > 0){
decreaseAlarm();
} else {
increaseAlarm();
}
// Only update the state and return to
// avoid a full draw as this is much faster.
drawState();
return;
}
if(lcarsViewPos == 1){
plotWeek = dy < 0 ? true : false;
}
}
var is_left = e.x < left;
var is_right = e.x > right;
var is_upper = e.y < upper;
var is_lower = e.y > lower;
if(is_left && lcarsViewPos == 1){
feedback();
lcarsViewPos = 0;
draw();
}
});
return;
Bangle.on("touch", e => {
Bangle.showLauncher();
} else if(is_right && lcarsViewPos == 0){
feedback();
lcarsViewPos = 1;
draw();
return;
}
if(lcarsViewPos == 0){
if(is_upper){
feedback();
increaseAlarm();
drawState();
return;
} if(is_lower){
feedback();
decreaseAlarm();
drawState();
return;
}
} else if (lcarsViewPos == 1 && (is_upper || is_lower) && plotWeek != is_lower){
feedback();
plotWeek = is_lower;
draw();
return;
}
});

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB