Update spiritlevel.js

Now also visible on Bangle.js 2
pull/1310/head
Hilmar Strauch 2022-01-18 13:05:09 +01:00 committed by GitHub
parent e539013c8e
commit 6d5df8019e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 1 deletions

View File

@ -2,6 +2,13 @@ g.clear();
var old = {x:0,y:0};
var W = g.getWidth();
var H = g.getHeight();
// colour definitions for Bangle.js 2
const RED = "#ff0000";
const GRN = "#00ff00";
const BLU = "#0000ff";
const HwVer = process.env.HWVERSION;
Bangle.on('accel',function(v) {
var max = Math.max(Math.abs(v.x),Math.abs(v.y),Math.abs(v.z));
if (Math.abs(v.y)==max) {
@ -12,7 +19,8 @@ Bangle.on('accel',function(v) {
var d = Math.sqrt(v.x*v.x+v.y*v.y);
var ang = Math.atan2(d,Math.abs(v.z))*180/Math.PI;
if (2 == HwVer) g.setColor(RED); else
g.setColor(1,1,1);
g.setFont("6x8",2);
g.setFontAlign(0,-1);
@ -22,11 +30,19 @@ Bangle.on('accel',function(v) {
x:E.clip(W/2+v.x*256,4,W-4),
y:E.clip(H/2+v.y*256,4,H-4)};
g.clearRect(old.x-3,old.y-3,old.x+6,old.y+6);
if (2 == HwVer) g.setColor(GRN); else
g.setColor(1,1,1);
g.fillRect(n.x-3,n.y-3,n.x+6,n.y+6);
if (2 == HwVer) g.setColor(BLU); else
g.setColor(1,0,0);
g.drawCircle(W/2,H/2,W*(1/12));
g.drawCircle(W/2,H/2,W*(1/4));
g.drawCircle(W/2,H/2,W*(5/12));
old = n;
});
setWatch(_=>load(), BTN1);
if (global.BTN2) {
setWatch(_=>load(), BTN2);
setWatch(_=>load(), BTN3);
}