mirror of https://github.com/espruino/BangleApps
Update app.js
parent
fef0fc0743
commit
b673038680
|
@ -1,7 +1,11 @@
|
|||
setupcomplete_colour = "#ff3329";
|
||||
default_colour = "#ffffff";
|
||||
calc_display_colour = "#00FFFF";
|
||||
display_colour = default_colour;
|
||||
|
||||
require("Font8x12").add(Graphics);
|
||||
require("Font7x11Numeric7Seg").add(Graphics);
|
||||
|
||||
var setupcomplete_colour = "#ff3329";
|
||||
var default_colour = "#ffffff";
|
||||
var calc_display_colour = "#00FFFF";
|
||||
var display_colour = default_colour;
|
||||
|
||||
var processing = false;
|
||||
var all_extras_array = [];
|
||||
|
@ -10,11 +14,19 @@ var mode = "planetary";
|
|||
var modeswitch = false;
|
||||
|
||||
var colours_switched = false;
|
||||
var sensorsOn = false;
|
||||
|
||||
// Load fonts
|
||||
require("Font7x11Numeric7Seg").add(Graphics);
|
||||
|
||||
// position on screen
|
||||
const Xaxis = 150, Yaxis = 55;
|
||||
var screenSize = g.getHeight();
|
||||
console.log(screenSize);
|
||||
var Xaxis = 150, Yaxis = 55;
|
||||
if (screenSize <= 176) {
|
||||
setupcomplete_colour = "#00FFFF";
|
||||
Xaxis = 110;
|
||||
Yaxis = 40;
|
||||
}
|
||||
|
||||
//lat lon settings loading
|
||||
var astral_settings;
|
||||
|
@ -443,7 +455,8 @@ function dec2str(x) {
|
|||
var sgn = (x < 0) ? "-" : " ";
|
||||
var d = Math.floor(dec);
|
||||
var m = 60 * (dec - d);
|
||||
return sgn + cintstr(d, 2) + "° " + frealstr(m, 4, 1) + "'";
|
||||
//return sgn + cintstr(d, 2) + "° " + frealstr(m, 4, 1) + "'";
|
||||
return sgn + cintstr(d, 2) + "° ";
|
||||
}
|
||||
|
||||
// return the integer part of a number
|
||||
|
@ -534,7 +547,7 @@ function mean_sidereal_time(lon) {
|
|||
var mst = 280.46061837 + 360.98564736629 * jd
|
||||
+ 0.000387933 * jt * jt - jt * jt * jt / 38710000 + lon;
|
||||
|
||||
mst %=360;
|
||||
mst = mst % 360;
|
||||
return mst;
|
||||
}
|
||||
|
||||
|
@ -552,7 +565,8 @@ function degr2str(x) {
|
|||
var sgn = (x < 0) ? "-" : " ";
|
||||
var d = Math.floor(dec);
|
||||
var m = 60 * (dec - d);
|
||||
return sgn + cintstr(d, 3) + "° " + frealstr(m, 4, 1) + "'";
|
||||
//return sgn + cintstr(d, 3) + "° " + frealstr(m, 4, 1) + "'";
|
||||
return sgn + cintstr(d, 3) + "° ";
|
||||
}
|
||||
|
||||
// converts latitude in signed degrees into string
|
||||
|
@ -561,7 +575,8 @@ function lat2str(x) {
|
|||
var sgn = (x < 0) ? " S" : " N";
|
||||
var d = Math.floor(dec);
|
||||
var m = 60 * (dec - d);
|
||||
return cintstr(d, 3) + "° " + frealstr(m, 4, 1) + "'" + sgn;
|
||||
//return cintstr(d, 3) + "° " + frealstr(m, 4, 1) + "'" + sgn;
|
||||
return cintstr(d, 3) + "° ";
|
||||
}
|
||||
|
||||
// converts longitude in signed degrees into string
|
||||
|
@ -570,7 +585,8 @@ function lon2str(x) {
|
|||
var sgn = (x < 0) ? " W" : " E";
|
||||
var d = Math.floor(dec);
|
||||
var m = 60 * (dec - d);
|
||||
return cintstr(d, 3) + "° " + frealstr(m, 4, 1) + "'" + sgn;
|
||||
//return cintstr(d, 3) + "° " + frealstr(m, 4, 1) + "'" + sgn;
|
||||
return cintstr(d, 3) + "° ";
|
||||
}
|
||||
|
||||
// format two digits with leading zero if needed
|
||||
|
@ -642,9 +658,9 @@ function write_refresh_note(colour) {
|
|||
if (!ready_to_compute) {
|
||||
g.drawString("mode change:", Xaxis + 50, cursor, false);
|
||||
cursor += 15;
|
||||
g.drawString("BTN1 to refresh", Xaxis + 50, cursor, true /*clear background*/);
|
||||
g.drawString("swipe up to refresh", Xaxis + 50, cursor, true /*clear background*/);
|
||||
cursor += 15;
|
||||
g.drawString("BTN3 to cancel", Xaxis + 50, cursor, true /*clear background*/);
|
||||
g.drawString("swipe left/right to cancel", Xaxis + 50, cursor, true /*clear background*/);
|
||||
}
|
||||
else
|
||||
g.drawString("updating, please wait", Xaxis + 50, cursor, false);
|
||||
|
@ -652,42 +668,92 @@ function write_refresh_note(colour) {
|
|||
|
||||
function draw_moon(phase) {
|
||||
g.setColor(display_colour);
|
||||
var moonOffset = 12;
|
||||
var mooonRadius = 25;
|
||||
if (screenSize > 176) {
|
||||
if (phase == 5) {
|
||||
g.fillCircle(200, Yaxis, 30);
|
||||
g.fillCircle(200, Yaxis + moonOffset, mooonRadius);
|
||||
g.setColor("#000000");
|
||||
g.fillRect(220, 25, 240, 90);
|
||||
}
|
||||
else if (phase == 6) {
|
||||
g.fillCircle(200, Yaxis, 30);
|
||||
g.fillCircle(200, Yaxis + moonOffset, mooonRadius);
|
||||
g.setColor("#000000");
|
||||
g.fillRect(200, 25, 240, 90);
|
||||
}
|
||||
else if (phase == 1) {
|
||||
g.fillCircle(200, Yaxis, 30);
|
||||
g.fillCircle(200, Yaxis + moonOffset, mooonRadius);
|
||||
g.setColor("#000000");
|
||||
g.fillCircle(180, Yaxis, 30);
|
||||
g.fillCircle(180, Yaxis + moonOffset, mooonRadius);
|
||||
}
|
||||
else if (phase == 4)
|
||||
g.fillCircle(200, Yaxis, 30);
|
||||
g.fillCircle(200, Yaxis + moonOffset, mooonRadius);
|
||||
else if (phase == 3) {
|
||||
g.fillCircle(200, Yaxis, 30);
|
||||
g.fillCircle(200, Yaxis + moonOffset, mooonRadius);
|
||||
g.setColor("#000000");
|
||||
g.fillRect(160, 25, 180, 90);
|
||||
}
|
||||
else if (phase == 2) {
|
||||
g.fillCircle(200, Yaxis, 30);
|
||||
g.fillCircle(200, Yaxis + moonOffset, mooonRadius);
|
||||
g.setColor("#000000");
|
||||
g.fillRect(160, 25, 200, 90);
|
||||
}
|
||||
else if (phase == 7) {
|
||||
g.fillCircle(200, Yaxis, 30);
|
||||
g.fillCircle(200, Yaxis + moonOffset, mooonRadius);
|
||||
g.setColor("#000000");
|
||||
g.fillCircle(220, Yaxis, 30);
|
||||
g.fillCircle(220, Yaxis, 25);
|
||||
}
|
||||
}
|
||||
else {
|
||||
moonOffset = 12;
|
||||
//var moonOffsetX = 150;
|
||||
mooonRadius = 17;
|
||||
g.setColor(display_colour);
|
||||
if (phase != 0)
|
||||
g.fillCircle(150, Yaxis + moonOffset, mooonRadius);
|
||||
if (phase == 5) {
|
||||
g.setColor("#000000");
|
||||
g.fillRect(165, 25, 180, 90);
|
||||
}
|
||||
else if (phase == 6) {
|
||||
g.setColor("#000000");
|
||||
g.fillRect(150, 25, 240, 90);
|
||||
}
|
||||
else if (phase == 1) {
|
||||
g.setColor("#000000");
|
||||
g.fillCircle(140, Yaxis + moonOffset, mooonRadius);
|
||||
}
|
||||
else if (phase == 4)
|
||||
g.fillCircle(150, Yaxis + moonOffset, mooonRadius);
|
||||
else if (phase == 3) {
|
||||
g.setColor("#000000");
|
||||
g.fillRect(125, 25, 135, 90);
|
||||
}
|
||||
else if (phase == 2) {
|
||||
g.setColor("#000000");
|
||||
g.fillRect(125, 25, 150, 90);
|
||||
}
|
||||
else if (phase == 7) {
|
||||
g.setColor("#000000");
|
||||
g.fillCircle(160, Yaxis + moonOffset, mooonRadius);
|
||||
}
|
||||
}
|
||||
g.setColor(display_colour);
|
||||
}
|
||||
|
||||
function autoUpdate() {
|
||||
ready_to_compute = true;
|
||||
g.setColor(display_colour);
|
||||
g.fillCircle(15, 160, 5);
|
||||
setTimeout(function () {
|
||||
print("ready");
|
||||
draw();
|
||||
secondInterval = setInterval(draw, 1000);
|
||||
}, 100);
|
||||
}
|
||||
|
||||
function draw() {
|
||||
//print("drawing");
|
||||
if (astral_settings.astral_default)
|
||||
display_colour = default_colour;
|
||||
else if (!colours_switched)
|
||||
|
@ -701,19 +767,26 @@ function draw() {
|
|||
g.reset();
|
||||
g.setColor(display_colour);
|
||||
// draw the current time (4x size 7 segment)
|
||||
g.setFont("7x11Numeric7Seg", 5);
|
||||
g.setFont("7x11Numeric7Seg", 4);
|
||||
g.setFontAlign(1, 1); // align right bottom
|
||||
g.drawString(time, Xaxis + 20, Yaxis + 30, true /*clear background*/);
|
||||
g.drawString(time, Xaxis + 23, Yaxis + 34, true /*clear background*/);
|
||||
|
||||
g.setFont("6x8");
|
||||
g.setFontAlign(1, 1); // align center bottom
|
||||
// pad the date - this clears the background if the date were to change length
|
||||
var dateStr = " " + require("locale").date(d) + " ";
|
||||
g.drawString(dateStr, Xaxis - 40, Yaxis - 40, true /*clear background*/);
|
||||
|
||||
if (screenSize < 177) {
|
||||
g.drawString(dateStr, 100, 20, true /*clear background*/);
|
||||
}
|
||||
else {
|
||||
//bangle 1
|
||||
g.drawString(dateStr, 150, 40, true /*clear background*/);
|
||||
}
|
||||
|
||||
//compute location of objects
|
||||
g.setFontAlign(1, 1);
|
||||
g.setFont("6x8");
|
||||
g.setFont("6x8", 1);
|
||||
|
||||
if (ready_to_compute)
|
||||
g.setColor(calc_display_colour);
|
||||
|
@ -722,25 +795,15 @@ function draw() {
|
|||
g.setColor("#000000");
|
||||
|
||||
cursor = Yaxis + 50;
|
||||
if (pstrings.length == 0) {
|
||||
if (ready_to_compute)
|
||||
g.drawString("updating, please wait", Xaxis + 50, cursor, true);
|
||||
else
|
||||
g.drawString("press BTN1 to update", Xaxis + 50, cursor, true /*clear background*/);
|
||||
}
|
||||
else {
|
||||
if (pstrings.length != 0) {
|
||||
|
||||
for (let i = 0; i < pstrings.length; i++) {
|
||||
g.drawString(pstrings[i], Xaxis + 50, cursor, true /*clear background*/);
|
||||
cursor += 15;
|
||||
g.drawString(pstrings[i], Xaxis + 40, cursor, true /*clear background*/);
|
||||
cursor += 10;
|
||||
}
|
||||
if (secondInterval) clearInterval(secondInterval);
|
||||
secondInterval = undefined;
|
||||
}
|
||||
|
||||
if (modeswitch)
|
||||
if (ready_to_compute)
|
||||
write_refresh_note(calc_display_colour);
|
||||
else
|
||||
write_refresh_note(display_colour);
|
||||
|
||||
if (ready_to_compute) {
|
||||
processing = true;
|
||||
ready_to_compute = false;
|
||||
|
@ -750,34 +813,43 @@ function draw() {
|
|||
g.fillRect(Xaxis - 150, Yaxis + 40, Xaxis + 200, Yaxis + 200);
|
||||
modeswitch = false;
|
||||
processing = false;
|
||||
Bangle.buzz();
|
||||
//Bangle.buzz();
|
||||
}
|
||||
|
||||
current_moonphase = getMoonPhase();
|
||||
all_extras_array = [];
|
||||
if (sensorsOn) {
|
||||
g.setColor(display_colour);
|
||||
g.fillCircle(160, 160, 5);
|
||||
}
|
||||
}
|
||||
|
||||
function SwitchSensorState() {
|
||||
if (sensorsOn) {
|
||||
print("turning sensors off");
|
||||
Bangle.setCompassPower(0);
|
||||
Bangle.setGPSPower(0);
|
||||
sensorsOn = 0;
|
||||
g.setColor("#000000");
|
||||
g.fillCircle(screenSize - 15, screenSize - 15, 7);
|
||||
//g.drawString(compass_heading, 30, 115, true /*clear background*/);
|
||||
g.fillRect(0, 100, 30, 120);
|
||||
}
|
||||
else {
|
||||
Bangle.setCompassPower(1);
|
||||
Bangle.setGPSPower(1);
|
||||
sensorsOn = 1;
|
||||
g.setColor(display_colour);
|
||||
g.fillCircle(screenSize - 15, screenSize - 15, 5);
|
||||
}
|
||||
}
|
||||
|
||||
g.clear();
|
||||
g.setColor("#000000");
|
||||
g.setBgColor(0, 0, 0);
|
||||
g.fillRect(0, 0, 175, 175);
|
||||
current_moonphase = getMoonPhase();
|
||||
|
||||
Bangle.setUI("clockupdown", btn => {
|
||||
if (btn==0) {
|
||||
if (!processing) {
|
||||
if (!modeswitch) {
|
||||
modeswitch = true;
|
||||
if (mode == "planetary") mode = "extras";
|
||||
else mode = "planetary";
|
||||
}
|
||||
else
|
||||
modeswitch = false;
|
||||
}
|
||||
} else {
|
||||
if (!processing)
|
||||
ready_to_compute = true;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Load widgets
|
||||
Bangle.loadWidgets();
|
||||
Bangle.drawWidgets();
|
||||
|
@ -785,59 +857,70 @@ Bangle.drawWidgets();
|
|||
draw_moon(current_moonphase);
|
||||
draw();
|
||||
|
||||
var secondInterval = setInterval(draw, 1000);
|
||||
// Stop updates when LCD is off, restart when on
|
||||
Bangle.on('lcdPower', on => {
|
||||
if (secondInterval) clearInterval(secondInterval);
|
||||
secondInterval = undefined;
|
||||
Bangle.setCompassPower(0);
|
||||
if (!astral_settings.astral_default)
|
||||
Bangle.setGPSPower(0);
|
||||
if (on) {
|
||||
Bangle.setCompassPower(1);
|
||||
Bangle.setGPSPower(1);
|
||||
if (current_moonphase !== undefined) {
|
||||
draw_moon(current_moonphase);
|
||||
}
|
||||
secondInterval = setInterval(draw, 1000);
|
||||
draw(); // draw immediately
|
||||
}
|
||||
});
|
||||
var updateInterval = setInterval(autoUpdate, 120000);
|
||||
//var magInterval = setInterval(updateMag, 50);
|
||||
|
||||
Bangle.setCompassPower(1);
|
||||
Bangle.setGPSPower(1);
|
||||
|
||||
var secondInterval;
|
||||
|
||||
Bangle.setUI("clock");
|
||||
|
||||
autoUpdate();
|
||||
|
||||
setWatch(SwitchSensorState, BTN1, { repeat: true });
|
||||
|
||||
// Show launcher when button pressed
|
||||
Bangle.setClockMode();
|
||||
//Bangle.setClockMode();
|
||||
|
||||
setWatch(function () {
|
||||
if (!astral_settings.astral_default) {
|
||||
colours_switched = true;
|
||||
if (display_colour == setupcomplete_colour)
|
||||
display_colour = default_colour;
|
||||
else
|
||||
display_colour = setupcomplete_colour;
|
||||
draw_moon(current_moonphase);
|
||||
Bangle.on("swipe", function (directionLR, directionUD) {
|
||||
if (!processing) {
|
||||
if (-1 == directionUD) {
|
||||
g.setColor(display_colour);
|
||||
g.fillCircle(15, 160, 5);
|
||||
ready_to_compute = true;
|
||||
}
|
||||
else if (-1 == directionLR || directionLR == 1) {
|
||||
print("attempting mode switch");
|
||||
if (mode == "planetary") mode = "extras";
|
||||
else mode = "planetary";
|
||||
g.setColor(display_colour);
|
||||
g.fillCircle(15, 160, 5);
|
||||
ready_to_compute = true;
|
||||
}
|
||||
else if (directionUD == 1) {
|
||||
SwitchSensorState();
|
||||
}
|
||||
}, BTN4, { repeat: true });
|
||||
|
||||
setTimeout(function () {
|
||||
print("ready");
|
||||
draw();
|
||||
secondInterval = setInterval(draw, 1000);
|
||||
}, 100);
|
||||
}
|
||||
});
|
||||
//events
|
||||
Bangle.on('mag', function (m) {
|
||||
g.setFont("6x8",2);
|
||||
if (isNaN(m.heading))
|
||||
compass_heading = "---";
|
||||
else
|
||||
if (!isNaN(m.heading)) {
|
||||
compass_heading = Math.round(m.heading);
|
||||
// g.setColor("#000000");
|
||||
// g.fillRect(160, 10, 160, 20);
|
||||
g.setColor(display_colour);
|
||||
if(compass_heading<100)
|
||||
if (compass_heading < 100)
|
||||
compass_heading = " " + compass_heading;
|
||||
g.drawString(compass_heading, 150, 20, true /*clear background*/);
|
||||
if (sensorsOn) {
|
||||
g.setFont("8x12");
|
||||
g.setFontAlign(1, 1);
|
||||
g.drawString(compass_heading, 25, 112, true /*clear background*/);
|
||||
}
|
||||
}
|
||||
//var n = magArray.length;
|
||||
//var mean = Math.round( magArray.reduce((a, b) => a + b) / n);
|
||||
//compass_heading = mean;
|
||||
});
|
||||
|
||||
Bangle.on('GPS', function (g) {
|
||||
if (g.fix) {
|
||||
display_colour = setupcomplete_colour;
|
||||
astral_settings.lat = g.lat;
|
||||
astral_settings.lon = g.lon;
|
||||
astral_settings.astral_default = false;
|
||||
|
|
Loading…
Reference in New Issue