2020-01-17 11:43:26 +00:00
|
|
|
const canvasWidth = 290;
|
|
|
|
const numberOfColumns = 6;
|
|
|
|
const drawFullGrid = false;
|
2019-11-12 22:16:03 +00:00
|
|
|
|
2020-01-17 11:43:26 +00:00
|
|
|
const colpos = canvasWidth / numberOfColumns - 10;
|
|
|
|
const binSize = (canvasWidth / numberOfColumns) / 3;
|
2019-11-12 22:16:03 +00:00
|
|
|
|
2020-01-17 11:43:26 +00:00
|
|
|
const findBinary = target => {
|
2020-05-23 21:32:33 +00:00
|
|
|
return [
|
|
|
|
[0, 0, 0, 0], // 0
|
|
|
|
[1, 0, 0, 0], // 1
|
|
|
|
[0, 1, 0, 0], // 2
|
|
|
|
[1, 1, 0, 0], // 3
|
|
|
|
[0, 0, 1, 0], // 4
|
|
|
|
[1, 0, 1, 0], // 5
|
|
|
|
[0, 1, 1, 0], // 6
|
|
|
|
[1, 1, 1, 0], // 7
|
|
|
|
[0, 0, 0, 1], // 8
|
|
|
|
[1, 0, 0, 1], // 9
|
|
|
|
][target];
|
2020-01-17 11:43:26 +00:00
|
|
|
};
|
2019-11-12 22:16:03 +00:00
|
|
|
|
2020-01-17 11:43:26 +00:00
|
|
|
const getCurrentTime = () => {
|
2020-05-23 21:32:33 +00:00
|
|
|
const flattenArray = (array = []) => [].concat.apply([], array);
|
|
|
|
const format = number => {
|
|
|
|
const numberStr = number.toString();
|
|
|
|
return numberStr.length === 1 ? ["0", numberStr] : numberStr.split("");
|
|
|
|
};
|
|
|
|
const now = new Date();
|
|
|
|
return flattenArray([now.getHours(), now.getMinutes(), now.getSeconds()].map(format));
|
2020-01-17 11:43:26 +00:00
|
|
|
};
|
2019-11-12 22:16:03 +00:00
|
|
|
|
2020-01-17 11:43:26 +00:00
|
|
|
let prevFrame = [];
|
|
|
|
const drawColumn = (position = 0, column = [0, 0, 0, 0]) => {
|
2020-05-23 21:32:33 +00:00
|
|
|
const maxDotsPerColumn = [2, 4, 3, 4, 3, 4];
|
2019-11-12 22:16:03 +00:00
|
|
|
|
2020-05-23 21:32:33 +00:00
|
|
|
const columnPos = position * colpos;
|
|
|
|
let pos = colpos / 2 + 45;
|
|
|
|
const frame = column.reverse();
|
|
|
|
const drawDot = fn => g[fn]((columnPos + colpos / 2), pos, binSize);
|
2019-11-12 22:16:03 +00:00
|
|
|
|
2020-05-23 21:32:33 +00:00
|
|
|
for (let i = 0; i < frame.length; i += 1) {
|
|
|
|
if (i + maxDotsPerColumn[position] >= 4 || drawFullGrid) {
|
|
|
|
if (prevFrame && prevFrame[position] && prevFrame[position][i]) {
|
|
|
|
if (frame[i] !== prevFrame[position][i]) {
|
|
|
|
// subsequent draw
|
|
|
|
g.clearRect((columnPos + colpos / 2) - 15, pos - 15, (columnPos + colpos / 2) + 20, pos + 20);
|
|
|
|
if (frame[i]) {
|
|
|
|
drawDot('fillCircle');
|
|
|
|
} else {
|
|
|
|
drawDot('drawCircle');
|
|
|
|
}
|
2019-11-12 22:16:03 +00:00
|
|
|
}
|
2020-05-23 21:32:33 +00:00
|
|
|
} else {
|
|
|
|
// First draw
|
|
|
|
if (frame[i]) {
|
|
|
|
drawDot('fillCircle');
|
|
|
|
} else {
|
|
|
|
drawDot('drawCircle');
|
|
|
|
}
|
|
|
|
}
|
2020-01-17 11:43:26 +00:00
|
|
|
}
|
2020-05-23 21:32:33 +00:00
|
|
|
pos += colpos;
|
|
|
|
}
|
2020-01-17 11:43:26 +00:00
|
|
|
};
|
2019-11-12 22:16:03 +00:00
|
|
|
|
2020-01-17 11:43:26 +00:00
|
|
|
const drawClock = () => {
|
2020-05-23 21:32:33 +00:00
|
|
|
const data = getCurrentTime().map(findBinary);
|
|
|
|
for (let i = 0; i < data.length; i += 1) {
|
|
|
|
drawColumn(i, data[i]);
|
|
|
|
}
|
|
|
|
prevFrame = data;
|
2020-01-17 11:43:26 +00:00
|
|
|
};
|
2019-11-12 22:16:03 +00:00
|
|
|
|
2020-01-17 11:43:26 +00:00
|
|
|
// Themes
|
|
|
|
const drawTheme = (idx) => () => {
|
2020-05-23 21:32:33 +00:00
|
|
|
idx += 1;
|
|
|
|
const themes = [
|
|
|
|
[[0, 0, 0], [1, 1, 1]],
|
|
|
|
[[1, 1, 1], [0, 0, 0]],
|
|
|
|
[[0, 0, 0], [1, 0, 0]],
|
|
|
|
[[0, 0, 0], [0, 1, 0]],
|
|
|
|
[[0, 0, 0], [0, 0, 1]],
|
|
|
|
];
|
|
|
|
if (idx >= themes.length) idx = 0;
|
|
|
|
const color = themes[idx];
|
|
|
|
g.setBgColor.apply(g, color[0]);
|
|
|
|
g.setColor.apply(g, color[1]);
|
|
|
|
g.clear();
|
2020-01-17 11:43:26 +00:00
|
|
|
};
|
2019-11-12 22:16:03 +00:00
|
|
|
|
2020-01-17 11:43:26 +00:00
|
|
|
const nextTheme = drawTheme(0);
|
|
|
|
setWatch(() => {
|
2020-05-23 21:32:33 +00:00
|
|
|
prevFrame = [];
|
|
|
|
Bangle.beep();
|
|
|
|
nextTheme();
|
2020-01-17 11:43:26 +00:00
|
|
|
}, BTN1, { repeat: true });
|
2019-11-12 22:16:03 +00:00
|
|
|
|
2020-01-17 11:43:26 +00:00
|
|
|
Bangle.on('lcdPower', on => {
|
2020-05-23 21:32:33 +00:00
|
|
|
if (on) drawClock();
|
2020-01-17 11:43:26 +00:00
|
|
|
});
|
2019-11-12 22:16:03 +00:00
|
|
|
|
2020-01-17 11:43:26 +00:00
|
|
|
g.clear();
|
|
|
|
Bangle.loadWidgets();
|
|
|
|
Bangle.drawWidgets();
|
|
|
|
setInterval(() => { drawClock(); }, 1000);
|
|
|
|
drawClock();
|
2021-06-24 12:12:59 +00:00
|
|
|
// Show launcher when button pressed
|
|
|
|
Bangle.setUI("clock");
|