Remove old grid code
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
{ // must be inside our own scope here so that when we are unloaded everything disappears
|
||||
// we also define functions using 'let fn = function() {..}' for the same reason. function decls are global
|
||||
const STATE_IDLE = 0;
|
||||
const STATE_GRID_OPEN_WAIT = 1;
|
||||
const STATE_GRID_OPEN = 2;
|
||||
const STATE_MENU_OPEN = 3;
|
||||
|
||||
let apiKey = require("Storage").readJSON("apikey.json", null);
|
||||
@@ -17,15 +15,8 @@
|
||||
let temperature = "";
|
||||
|
||||
let drawTimer = null;
|
||||
let gridTimer = null;
|
||||
let lockTimer = null;
|
||||
let swipeLockout = false;
|
||||
|
||||
let grid = require("Storage").readJSON("grid.json", true);
|
||||
let prevNum = require("Storage").readJSON("prevNum.json", true) || -1;
|
||||
let gridNum = -1;
|
||||
let gridDir = -1;
|
||||
|
||||
let menu = require("Storage").readJSON("menu.json", true);
|
||||
let subMenu = null;
|
||||
let menuCommand = "";
|
||||
@@ -116,128 +107,6 @@
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
let drawGrid = function(touchX, touchY) {
|
||||
let x = g.getWidth() / 2;
|
||||
let y = g.getHeight() / 2;
|
||||
let text = "";
|
||||
let rank = "";
|
||||
|
||||
g.reset().clearRect(Bangle.appRect);
|
||||
|
||||
truncX = Math.floor(touchX/15);
|
||||
truncY = Math.floor(touchY/15);
|
||||
|
||||
gridNum = -1;
|
||||
gridDir = -1;
|
||||
|
||||
if (!grid) {
|
||||
text = "Grid missing";
|
||||
} else if (truncX < 2) {
|
||||
text = "left";
|
||||
gridDir = "left";
|
||||
} else if (truncX > 10) {
|
||||
text = "right";
|
||||
gridDir = "right";
|
||||
} else if (truncY < 2) {
|
||||
text = "Repeat";
|
||||
gridDir = "top";
|
||||
} else if (truncY > 10) {
|
||||
text = "Cancel";
|
||||
gridDir = "bottom";
|
||||
} else {
|
||||
const gridX = truncX - 2;
|
||||
const gridY = truncY - 2;
|
||||
|
||||
gridNum = gridY * 9 + gridX;
|
||||
rank = "ABCDEFGHI"[gridY];
|
||||
text = grid[gridNum] || gridNum;
|
||||
}
|
||||
|
||||
g.setFontAlign(0, 0).setFont("Vector", 26).drawString(text, x, y-45);
|
||||
g.setFontAlign(0, 0).setFont("Vector", 26).drawString(text, x, y+70);
|
||||
g.setFontAlign(0, 0).setFont("Vector", 26).drawString(rank, x-65, y+15);
|
||||
g.setFontAlign(0, 0).setFont("Vector", 26).drawString(rank, x+65, y+15);
|
||||
};
|
||||
|
||||
let handleDrag = function(e) {
|
||||
//console.log(e);
|
||||
// { "x": 96, "y": 147, "b": 1, "dx": 0, "dy": 1 }
|
||||
|
||||
const touchX = e.x;
|
||||
const touchY = e.y;
|
||||
const pressed = Boolean(e.b);
|
||||
|
||||
if (watchState == STATE_IDLE && pressed) {
|
||||
watchState = STATE_GRID_OPEN_WAIT;
|
||||
gridTimer = setTimeout(function() {
|
||||
watchState = STATE_GRID_OPEN;
|
||||
drawGrid(touchX, touchY);
|
||||
swipeLockout = true;
|
||||
}, 500);
|
||||
} else if (watchState == STATE_GRID_OPEN_WAIT && !pressed) {
|
||||
watchState = STATE_IDLE;
|
||||
if (gridTimer) clearTimeout(gridTimer);
|
||||
} else if (watchState == STATE_GRID_OPEN && !pressed) {
|
||||
watchState = STATE_IDLE;
|
||||
|
||||
if (lockTimer) clearTimeout(lockTimer);
|
||||
lockTimer = setTimeout(function() {
|
||||
swipeLockout = false;
|
||||
}, 2000);
|
||||
|
||||
if (gridNum == 72) {
|
||||
myMessage = "Refresh Grid";
|
||||
require("Storage").writeJSON("grid.json", false);
|
||||
grid = false;
|
||||
gridNum = -1;
|
||||
load();
|
||||
} else if (gridNum >= 0 && grid[gridNum]) {
|
||||
myMessage = grid[gridNum];
|
||||
prevNum = gridNum;
|
||||
require("Storage").writeJSON("prevNum.json", prevNum);
|
||||
|
||||
if (Bangle.http){
|
||||
const headers = {"Authorization": "Bearer " + apiKey};
|
||||
const options = {timeout:3000, method: "post", body: gridNum, headers: headers};
|
||||
Bangle.http("https://api.home.dns.t0.vc/grid", options).then(event => {
|
||||
myMessage = "ok";
|
||||
if (paintFace) paintFace();
|
||||
}).catch((e)=>{
|
||||
myMessage = "POST error";
|
||||
if (paintFace) paintFace();
|
||||
});
|
||||
}
|
||||
gridNum = -1;
|
||||
} else if (gridDir == "top") {
|
||||
if (prevNum >= 0) {
|
||||
myMessage = grid[prevNum];
|
||||
|
||||
if (Bangle.http){
|
||||
const headers = {"Authorization": "Bearer " + apiKey};
|
||||
const options = {timeout:3000, method: "post", body: prevNum, headers: headers};
|
||||
Bangle.http("https://api.home.dns.t0.vc/grid", options).then(event => {
|
||||
myMessage = "ok";
|
||||
if (paintFace) paintFace();
|
||||
}).catch((e)=>{
|
||||
myMessage = "POST error";
|
||||
if (paintFace) paintFace();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
myMessage = "No repeat";
|
||||
}
|
||||
} else if (gridDir == "bottom") {
|
||||
myMessage = "Cancelled";
|
||||
Bangle.setLocked(true);
|
||||
}
|
||||
|
||||
if (paintFace) paintFace();
|
||||
} else if (watchState == STATE_GRID_OPEN && pressed) {
|
||||
drawGrid(touchX, touchY);
|
||||
}
|
||||
};
|
||||
|
||||
let drawMenu = function(menu) {
|
||||
const keys = Object.keys(menu);
|
||||
|
||||
@@ -339,20 +208,10 @@
|
||||
}
|
||||
};
|
||||
|
||||
if (Bangle.http && (!grid || !menu)){
|
||||
Bangle.http("https://api.home.dns.t0.vc/grid", {timeout:3000}).then(event => {
|
||||
grid = JSON.parse(event.resp);
|
||||
require("Storage").writeJSON("grid.json", grid);
|
||||
//console.log(grid);
|
||||
}).catch((e)=>{
|
||||
myMessage = "Grid error";
|
||||
if (paintFace) paintFace();
|
||||
});
|
||||
|
||||
if (Bangle.http && !menu){
|
||||
Bangle.http("https://api.home.dns.t0.vc/menu", {timeout:3000}).then(event => {
|
||||
menu = JSON.parse(event.resp);
|
||||
require("Storage").writeJSON("menu.json", menu);
|
||||
//console.log(grid);
|
||||
}).catch((e)=>{
|
||||
myMessage = "Menu error";
|
||||
if (paintFace) paintFace();
|
||||
@@ -360,7 +219,7 @@
|
||||
}
|
||||
|
||||
Bangle.on('swipe', handleSwipe);
|
||||
Bangle.on('drag', handleDrag);
|
||||
//Bangle.on('drag', handleDrag);
|
||||
Bangle.on('touch', handleTouch);
|
||||
Bangle.on('twist', handleTwist);
|
||||
|
||||
@@ -370,17 +229,12 @@
|
||||
remove : function() {
|
||||
// Called to unload all of the clock app
|
||||
Bangle.removeListener('swipe', handleSwipe);
|
||||
Bangle.removeListener('drag', handleDrag);
|
||||
//Bangle.removeListener('drag', handleDrag);
|
||||
Bangle.removeListener('touch', handleTouch);
|
||||
Bangle.removeListener('twist', handleTwist);
|
||||
if (drawTimer) clearTimeout(drawTimer);
|
||||
drawTimer = undefined;
|
||||
if (gridTimer) clearTimeout(gridTimer);
|
||||
gridTimer = undefined;
|
||||
if (lockTimer) clearTimeout(lockTimer);
|
||||
lockTimer = undefined;
|
||||
|
||||
delete Graphics.prototype.setFontAnton;
|
||||
paintFace = undefined; // http request may resolve after font's been unloaded, so unset
|
||||
}});
|
||||
// Load widgets
|
||||
|
||||
Reference in New Issue
Block a user