Wrote basic code for a modular app design

This commit is contained in:
Blue Fox 2022-06-05 09:51:20 +02:00
parent 220fd9ee42
commit 4300a4bfe8

View File

@ -0,0 +1,26 @@
// Some initialization
Bangle.setGPSPower(true);
g.clear();
// variables
var firstRun = true;
const text_y = 80;
const font = "Vector";
var STOR = require("Storage");
var FACES = [];
STOR.list(/\.trailsense\.js$/).forEach(face=>FACES.push(eval(require("Storage").read(face))));
var currentFace = 0;
FACES[currentFace].drawFace();
Bangle.setUI("updown", (upOrDown) => {
if(!firstRun) FACES[currentFace].stop();
firstRun = false; // loop ran once; firstRun has to be false
if(isNaN(upOrDown)) upOrDown = 0;
currentFace += upOrDown;
if(currentFace > FACES.length-1) { currentFace = 0; }
if(currentFace < 0) { currentFace = FACES.length-1; }
FACES[currentFace].drawFace();
});