2020-04-21 18:38:02 +00:00
|
|
|
Bangle.setLCDMode("120x120");
|
|
|
|
|
2020-04-20 20:39:30 +00:00
|
|
|
const W = g.getWidth();
|
|
|
|
const H = g.getHeight();
|
|
|
|
const RED = "#d32e29";
|
|
|
|
const PINK = "#f05a56";
|
|
|
|
const WHITE = "#ffffff";
|
|
|
|
|
|
|
|
function drawMenu(params) {
|
2020-04-21 18:38:02 +00:00
|
|
|
const hs = require("heatshrink");
|
|
|
|
const incImg = hs.decompress(atob("gsFwMAkM+oUA"));
|
|
|
|
const decImg = hs.decompress(atob("gsFwIEBnwCBA"));
|
|
|
|
const okImg = hs.decompress(atob("gsFwMAhGFo0A"));
|
2020-04-20 20:39:30 +00:00
|
|
|
const DEFAULT_PARAMS = {
|
|
|
|
showBTN1: false,
|
|
|
|
showBTN2: false,
|
|
|
|
showBTN3: false,
|
|
|
|
};
|
|
|
|
const p = Object.assign({}, DEFAULT_PARAMS, params);
|
2020-04-21 18:38:02 +00:00
|
|
|
if (p.showBTN1) g.drawImage(incImg, W - 10, 10);
|
|
|
|
if (p.showBTN2) g.drawImage(okImg, W - 10, 60);
|
|
|
|
if (p.showBTN3) g.drawImage(decImg, W - 10, 110);
|
2020-04-20 20:39:30 +00:00
|
|
|
}
|
|
|
|
|
2020-04-21 18:38:02 +00:00
|
|
|
function drawSet(exercise) {
|
|
|
|
const set = exercise.currentSet();
|
2020-04-20 20:39:30 +00:00
|
|
|
if (set.isCompleted()) return;
|
|
|
|
|
2020-04-21 18:38:02 +00:00
|
|
|
g.clear();
|
|
|
|
|
|
|
|
// Draw exercise title
|
2020-04-20 20:39:30 +00:00
|
|
|
g.setColor(PINK);
|
2020-04-21 18:38:02 +00:00
|
|
|
g.fillRect(15, 0, W - 15, 18);
|
|
|
|
g.setFontAlign(0, -1);
|
|
|
|
g.setFont("6x8", 1);
|
2020-04-20 20:39:30 +00:00
|
|
|
g.setColor(WHITE);
|
2020-04-21 18:38:02 +00:00
|
|
|
g.drawString(exercise.title, W / 2, 5);
|
|
|
|
g.setFont("6x8", 1);
|
|
|
|
g.drawString(exercise.weight + " " + exercise.unit, W / 2, 27);
|
|
|
|
// Draw completed reps counter
|
|
|
|
g.setFontAlign(0, 0);
|
|
|
|
g.setColor(PINK);
|
|
|
|
g.fillRect(15, 42, W - 15, 80);
|
2020-04-20 20:39:30 +00:00
|
|
|
g.setColor(WHITE);
|
2020-04-21 18:38:02 +00:00
|
|
|
g.setFont("6x8", 5);
|
|
|
|
g.drawString(set.reps, (W / 2) + 2, (H / 2) + 1);
|
|
|
|
g.setFont("6x8", 1);
|
|
|
|
const note = `Target reps: ${set.maxReps}`;
|
|
|
|
g.drawString(note, W / 2, H - 24);
|
|
|
|
// Draw sets monitor
|
|
|
|
g.drawString(exercise.subTitle, W / 2, H - 12);
|
2020-04-20 20:39:30 +00:00
|
|
|
|
|
|
|
drawMenu({showBTN1: true, showBTN2: true, showBTN3: true});
|
|
|
|
|
2020-04-21 18:38:02 +00:00
|
|
|
g.flip();
|
2020-04-20 20:39:30 +00:00
|
|
|
}
|
|
|
|
|
2020-04-21 18:38:02 +00:00
|
|
|
function drawProgDone() {
|
2020-04-20 20:39:30 +00:00
|
|
|
const title1 = "You did";
|
|
|
|
const title2 = "GREAT!";
|
|
|
|
const msg = "That's the program\ncompleted. Now eat\nsome food and\nget plenty of rest.";
|
|
|
|
|
|
|
|
clearWatch();
|
2020-04-20 21:02:55 +00:00
|
|
|
setWatch(Bangle.showLauncher, BTN2, {repeat: false});
|
2020-04-21 18:38:02 +00:00
|
|
|
drawMenu({showBTN2: true});
|
2020-04-20 20:39:30 +00:00
|
|
|
|
2020-04-21 18:38:02 +00:00
|
|
|
g.setFontAlign(0, -1);
|
2020-04-20 20:39:30 +00:00
|
|
|
g.setColor(WHITE);
|
2020-04-21 18:38:02 +00:00
|
|
|
g.setFont("6x8", 2);
|
|
|
|
g.drawString(title1, W / 2, 10);
|
|
|
|
g.drawString(title2, W / 2, 30);
|
|
|
|
g.setFont("6x8", 1);
|
|
|
|
g.drawString(msg, (W / 2) + 3, 70);
|
|
|
|
g.flip();
|
2020-04-20 20:39:30 +00:00
|
|
|
}
|
|
|
|
|
2020-04-21 18:38:02 +00:00
|
|
|
function drawSetComp() {
|
|
|
|
const title = "Good work";
|
|
|
|
const msg = "No need to rest\nmove straight on\nto the next\nexercise.Your\nweight has been\nincreased for\nnext time!";
|
|
|
|
|
|
|
|
g.clear();
|
2020-04-20 20:39:30 +00:00
|
|
|
drawMenu({showBTN2: true});
|
|
|
|
|
2020-04-21 18:38:02 +00:00
|
|
|
g.setFontAlign(0, -1);
|
|
|
|
g.setColor(WHITE);
|
|
|
|
g.setFont("6x8", 2);
|
|
|
|
g.drawString(title, W / 2, 10);
|
|
|
|
g.setFont("6x8", 1);
|
|
|
|
g.drawString(msg, (W / 2) - 2, 45);
|
|
|
|
|
|
|
|
g.flip();
|
2020-04-20 20:39:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function drawRestTimer(program) {
|
|
|
|
const exercise = program.currentExercise();
|
|
|
|
const motivation = "Take a breather..";
|
|
|
|
|
|
|
|
if (exercise.restPeriod <= 0) {
|
|
|
|
exercise.resetRestTimer();
|
2020-04-21 18:38:02 +00:00
|
|
|
program.next();
|
|
|
|
|
|
|
|
return;
|
2020-04-20 20:39:30 +00:00
|
|
|
}
|
2020-04-21 18:38:02 +00:00
|
|
|
|
|
|
|
g.clear();
|
|
|
|
drawMenu({showBTN2: true});
|
|
|
|
g.setFontAlign(0, -1);
|
|
|
|
g.setColor(PINK);
|
|
|
|
g.fillRect(15, 42, W - 15, 80);
|
|
|
|
g.setColor(WHITE);
|
|
|
|
g.setFont("6x8", 1);
|
|
|
|
g.drawString("Have a short\nrest period.", W / 2, 10);
|
|
|
|
g.setFont("6x8", 5);
|
|
|
|
g.drawString(exercise.restPeriod, (W / 2) + 2, (H / 2) - 19);
|
|
|
|
g.flip();
|
|
|
|
|
|
|
|
exercise.decRestPeriod();
|
2020-04-20 20:39:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function redraw(program) {
|
|
|
|
const exercise = program.currentExercise();
|
2020-04-21 18:38:02 +00:00
|
|
|
g.clear();
|
2020-04-20 20:39:30 +00:00
|
|
|
|
|
|
|
if (program.isCompleted()) {
|
2020-04-21 18:38:02 +00:00
|
|
|
saveProg(program);
|
|
|
|
drawProgDone(program);
|
2020-04-20 20:39:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exercise.isRestTimerRunning()) {
|
|
|
|
if (exercise.isLastSet()) {
|
2020-04-21 18:38:02 +00:00
|
|
|
drawSetComp(program);
|
2020-04-20 20:39:30 +00:00
|
|
|
} else {
|
|
|
|
drawRestTimer(program);
|
2020-04-20 14:00:06 +00:00
|
|
|
}
|
|
|
|
|
2020-04-20 20:39:30 +00:00
|
|
|
return;
|
2020-04-20 14:00:06 +00:00
|
|
|
}
|
|
|
|
|
2020-04-21 18:38:02 +00:00
|
|
|
drawSet(exercise);
|
2020-04-20 20:39:30 +00:00
|
|
|
}
|
|
|
|
|
2020-04-21 18:38:02 +00:00
|
|
|
function drawProgMenu(programs, selProgIdx) {
|
|
|
|
g.clear();
|
|
|
|
g.setFontAlign(0, -1);
|
|
|
|
g.setColor(WHITE);
|
|
|
|
g.setFont("6x8", 2);
|
|
|
|
g.drawString("BuffGym", W / 2, 10);
|
|
|
|
|
|
|
|
g.setFont("6x8", 1);
|
|
|
|
g.setFontAlign(-1, -1);
|
|
|
|
let selectedProgram = programs[selProgIdx].title;
|
|
|
|
let yPos = 50;
|
|
|
|
programs.forEach(program => {
|
|
|
|
g.setColor("#f05a56");
|
|
|
|
g.fillRect(0, yPos, W, yPos + 11);
|
|
|
|
g.setColor("#ffffff");
|
|
|
|
if (selectedProgram === program.title) {
|
|
|
|
g.drawRect(0, yPos, W - 1, yPos + 11);
|
|
|
|
}
|
|
|
|
g.drawString(program.title, 10, yPos + 2);
|
|
|
|
yPos += 15;
|
|
|
|
});
|
|
|
|
g.flip();
|
2020-04-20 20:39:30 +00:00
|
|
|
}
|
2020-04-20 14:00:06 +00:00
|
|
|
|
2020-04-21 18:38:02 +00:00
|
|
|
function setupMenu() {
|
|
|
|
clearWatch();
|
|
|
|
const progs = getProgIndex();
|
|
|
|
let selProgIdx = 0;
|
|
|
|
drawProgMenu(progs, selProgIdx);
|
|
|
|
|
|
|
|
setWatch(()=>{
|
|
|
|
selProgIdx--;
|
|
|
|
if (selProgIdx< 0) selProgIdx = 0;
|
|
|
|
drawProgMenu(progs, selProgIdx);
|
|
|
|
}, BTN1, {repeat: true});
|
|
|
|
|
|
|
|
setWatch(()=>{
|
|
|
|
const prog = buildProg(progs[selProgIdx].file);
|
|
|
|
prog.next();
|
|
|
|
}, BTN2, {repeat: false});
|
|
|
|
|
|
|
|
setWatch(()=>{
|
|
|
|
selProgIdx++;
|
|
|
|
if (selProgIdx > progs.length - 1) selProgIdx = progs.length - 1;
|
|
|
|
drawProgMenu(progs, selProgIdx);
|
|
|
|
}, BTN3, {repeat: true});
|
|
|
|
}
|
2020-04-20 14:00:06 +00:00
|
|
|
|
2020-04-21 18:38:02 +00:00
|
|
|
function drawSplash() {
|
|
|
|
g.reset();
|
|
|
|
g.setBgColor(RED);
|
|
|
|
g.clear();
|
|
|
|
g.setColor(WHITE);
|
|
|
|
g.setFontAlign(0,-1);
|
|
|
|
g.setFont("6x8", 2);
|
|
|
|
g.drawString("BuffGym", W / 2, 10);
|
|
|
|
g.setFont("6x8", 1);
|
|
|
|
g.drawString("5x5", W / 2, 42);
|
|
|
|
g.drawString("training app", W / 2, 55);
|
|
|
|
g.drawRect(19, 38, 100, 99);
|
|
|
|
const img = require("heatshrink").decompress(atob("lkdxH+AB/I5ASQACwpB5vNFkwpBAIfNFdZZkFYwskFZAsiFZBZiVYawEFf6ETFUwsIFUYmB54ADAwIskFYoRKBoIroB4grV58kkgCDFRotWFZwqHFiwYMFZIsTC5wLDFjGlCoWlkgJDRQIABCRAsLCwodCFAIABCwIOCFQYABr4RCCQIrMC4gqEAAwpFFZosFC5ArHFQ4rFNYQrGEgosMBxIrFLQwrLAB4sFSw4rFFjYrQFi4rNbASeEFjIoJFQYsGMAgAPEQgAIGwosCRoorbA="));
|
|
|
|
g.drawImage(img, 40, 70);
|
|
|
|
g.flip();
|
|
|
|
|
|
|
|
let flasher = false;
|
|
|
|
let bgCol, txtCol;
|
|
|
|
const i = setInterval(() => {
|
|
|
|
if (flasher) {
|
|
|
|
bgCol = WHITE;
|
|
|
|
txtCol = RED;
|
|
|
|
} else {
|
|
|
|
bgCol = RED;
|
|
|
|
txtCol = WHITE;
|
|
|
|
}
|
|
|
|
flasher = !flasher;
|
|
|
|
g.setColor(bgCol);
|
|
|
|
g.fillRect(0, 108, W, 120);
|
|
|
|
g.setColor(txtCol);
|
|
|
|
g.drawString("Press btn to begin", W / 2, 110);
|
|
|
|
g.flip();
|
|
|
|
}, 250);
|
|
|
|
|
|
|
|
setWatch(()=>{
|
|
|
|
clearInterval(i);
|
|
|
|
setupMenu();
|
|
|
|
}, BTN1, {repeat: false});
|
|
|
|
|
|
|
|
setWatch(()=>{
|
|
|
|
clearInterval(i);
|
|
|
|
setupMenu();
|
|
|
|
}, BTN2, {repeat: false});
|
2020-04-20 14:27:21 +00:00
|
|
|
|
2020-04-21 18:38:02 +00:00
|
|
|
setWatch(()=>{
|
|
|
|
clearInterval(i);
|
|
|
|
setupMenu();
|
|
|
|
}, BTN3, {repeat: false});
|
|
|
|
}
|
2020-04-20 14:27:21 +00:00
|
|
|
|
2020-04-21 18:38:02 +00:00
|
|
|
function getProgIndex() {
|
|
|
|
const progIdx = require("Storage").readJSON("buffgym-program-index.json");
|
|
|
|
return progIdx;
|
|
|
|
}
|
2020-04-20 14:27:21 +00:00
|
|
|
|
2020-04-21 18:38:02 +00:00
|
|
|
function buildProg(fName) {
|
|
|
|
const Set = require("buffgym-set.js");
|
|
|
|
const Exercise = require("buffgym-exercise.js");
|
|
|
|
const Program = require("buffgym-program.js");
|
|
|
|
const progJSON = require("Storage").readJSON(fName);
|
|
|
|
const prog = new Program({
|
|
|
|
title: progJSON.title,
|
|
|
|
});
|
|
|
|
const exercises = progJSON.exercises.map(exerciseJSON => {
|
|
|
|
const exercise = new Exercise({
|
|
|
|
title: exerciseJSON.title,
|
|
|
|
weight: exerciseJSON.weight,
|
|
|
|
unit: exerciseJSON.unit,
|
|
|
|
restPeriod: exerciseJSON.restPeriod,
|
2020-04-20 20:39:30 +00:00
|
|
|
});
|
2020-04-21 18:38:02 +00:00
|
|
|
exerciseJSON.sets.forEach(setJSON => {
|
|
|
|
exercise.addSet(new Set(setJSON));
|
2020-04-20 14:00:06 +00:00
|
|
|
});
|
2020-04-21 18:38:02 +00:00
|
|
|
|
|
|
|
return exercise;
|
2020-04-20 20:39:30 +00:00
|
|
|
});
|
2020-04-21 18:38:02 +00:00
|
|
|
prog.addExercises(exercises);
|
|
|
|
|
|
|
|
return prog;
|
|
|
|
}
|
2020-04-20 14:27:21 +00:00
|
|
|
|
2020-04-21 18:38:02 +00:00
|
|
|
function saveProg(program) {
|
|
|
|
const fName = getProgIndex().find(prog => prog.title === program.title).file;
|
|
|
|
require("Storage").writeJSON(fName, program.toJSON());
|
2020-04-20 20:39:30 +00:00
|
|
|
}
|
2020-04-20 14:00:06 +00:00
|
|
|
|
2020-04-21 18:38:02 +00:00
|
|
|
drawSplash();
|