Allow multiple coloured screens

master
Paul Cockrell 2020-05-15 09:33:25 +01:00
parent 2101a28557
commit 7488970e74
1 changed files with 34 additions and 13 deletions

View File

@ -61,11 +61,20 @@ const font5x5 = {
// Char renderer // Char renderer
const COLORS = { const COLORS = {
BG: "#0297fe", blue: {
DARK: "#3b3ce8", BG: "#0297fe",
LIGHT: "#E9ffff", DARK: "#3b3ce8",
LIGHT: "#E9ffff",
},
orange: {
BG: "#f7b336",
DARK: "#ac721e",
LIGHT: "#f6fc0f",
}
}; };
let selectedColor = "blue";
// Example // Example
// binToHex(["0111110", "1000000", "1000000", "1111110", "1000001", "1000001", "0111110"]) // binToHex(["0111110", "1000000", "1000000", "1111110", "1000001", "1000001", "0111110"])
function binToHex(bins /* array of binary strings */) { function binToHex(bins /* array of binary strings */) {
@ -95,8 +104,8 @@ function drawGrid(pos /* {x:int, y:int} */, dims /* {rows:int, cols:int} */, cha
pxlW: 5, pxlW: 5,
pxlH: 5, pxlH: 5,
gap: 1, gap: 1,
offColor: COLORS.DARK, offColor: COLORS[selectedColor].DARK,
onColor: COLORS.LIGHT onColor: COLORS[selectedColor].LIGHT
}; };
const pxl = Object.assign({}, defaultOpts, opts); const pxl = Object.assign({}, defaultOpts, opts);
@ -202,7 +211,7 @@ function drawTime(lastHrs, lastMns, toggle) {
drawFont(mns, "7x7", 124, 109); drawFont(mns, "7x7", 124, 109);
} }
const color = toggle? COLORS.LIGHT : COLORS.DARK; const color = toggle? COLORS[selectedColor].LIGHT : COLORS[selectedColor].DARK;
// This should toggle on/off per second // This should toggle on/off per second
drawPixel({ drawPixel({
@ -240,26 +249,38 @@ function setSensors(state) {
Bangle.setCompassPower(state); Bangle.setCompassPower(state);
} }
function drawScreen() {
g.setBgColor(COLORS[selectedColor].BG);
g.clearRect(0, 24, g.getWidth(), g.getHeight());
// Draw components
drawTitles();
drawCompass();
drawHeart();
drawTime();
drawDate();
}
// Turn sensors on // Turn sensors on
setSensors(1); setSensors(1);
// Reset screen // Reset screen
g.clear(); g.clear();
g.setBgColor(COLORS.BG);
g.clearRect(0, 24, g.getWidth(), g.getHeight());
// Load and draw widgets // Load and draw widgets
Bangle.loadWidgets(); Bangle.loadWidgets();
Bangle.drawWidgets(); Bangle.drawWidgets();
// Draw screen // Draw screen
drawTitles(); drawScreen();
drawCompass();
drawHeart();
drawTime();
drawDate();
// Setup callbacks // Setup callbacks
Bangle.on('swipe', (sDir) => {
selectedColor = selectedColor === "blue" ? "orange" : "blue";
clearTimeout();
drawScreen();
});
Bangle.on('HRM', drawHeart); Bangle.on('HRM', drawHeart);
setWatch(() => { setWatch(() => {