More fixes

pull/339/head
Paul Cockrell 2020-04-20 21:39:30 +01:00
parent 900805e71b
commit 707f4a1ccd
6 changed files with 313 additions and 318 deletions

View File

@ -2,10 +2,8 @@ const STARTED = 1;
const RESTING = 2; const RESTING = 2;
const COMPLETED = 3; const COMPLETED = 3;
const ONE_SECOND = 1000; const ONE_SECOND = 1000;
const INCREMENT = "increment";
const DECREMENT = "decrement";
class Exercise { exports = class Exercise {
constructor(params /*{title, weight, unit, restPeriod}*/) { constructor(params /*{title, weight, unit, restPeriod}*/) {
const DEFAULTS = { const DEFAULTS = {
title: "Unknown", title: "Unknown",

View File

@ -1,4 +1,4 @@
class Program { exports = class Program {
constructor(params) { constructor(params) {
const DEFAULTS = { const DEFAULTS = {
title: "Unknown", title: "Unknown",

View File

@ -1,101 +1 @@
[ [{"title":"Program A","exercises":[{"title":"Squats","weight":40,"unit":"Kg","sets":[5,5,5,5,5]},{"title":"Overhead press","weight":20,"unit":"Kg","sets":[5,5,5,5,5]},{"title":"Deadlift","weight":20,"unit":"Kg","sets":[5]},{"title":"Pullups","weight":0,"unit":"Kg","sets":[10,10,10]}]},{"title":"Program B","exercises":[{"title":"Squats","weight":40,"unit":"Kg","sets":[5,5,5,5,5]},{"title":"Bench press","weight":20,"unit":"Kg","sets":[5,5,5,5,5]},{"title":"Row","weight":20,"unit":"Kg","sets":[5,5,5,5,5]},{"title":"Tricep extension","weight":20,"unit":"Kg","sets":[10,10,10]}]}]
{
title: "Program A",
exercises: [
{
title: "Squats",
weight: 40,
unit: "Kg",
sets: [
5,
5,
5,
5,
5
]
},
{
title: "Overhead press",
weight: 20,
unit: "Kg",
sets: [
5,
5,
5,
5,
5
]
},
{
title: "Deadlift",
weight: 20,
unit: "Kg",
sets: [
5
]
},
{
title: "Pullups",
weight: 0,
unit: "Kg",
sets: [
10,
10,
10
]
}
]
},
{
title: "Program B",
exercises: [
{
title: "Squats",
weight: 40,
unit: "Kg",
sets: [
5,
5,
5,
5,
5
]
},
{
title: "Bench press",
weight: 20,
unit: "Kg",
sets: [
5,
5,
5,
5,
5
]
},
{
title: "Row",
weight: 20,
unit:"Kg",
sets: [
5,
5,
5,
5,
5
]
},
{
title: "Tricep extension",
weight: 20,
unit: "Kg",
sets: [
10,
10,
10
]
}
]
}
]

View File

@ -0,0 +1,101 @@
[
{
"title": "Program A",
"exercises": [
{
"title": "Squats",
"weight": 40,
"unit": "Kg",
"sets": [
5,
5,
5,
5,
5
]
},
{
"title": "Overhead press",
"weight": 20,
"unit": "Kg",
"sets": [
5,
5,
5,
5,
5
]
},
{
"title": "Deadlift",
"weight": 20,
"unit": "Kg",
"sets": [
5
]
},
{
"title": "Pullups",
"weight": 0,
"unit": "Kg",
"sets": [
10,
10,
10
]
}
]
},
{
"title": "Program B",
"exercises": [
{
"title": "Squats",
"weight": 40,
"unit": "Kg",
"sets": [
5,
5,
5,
5,
5
]
},
{
"title": "Bench press",
"weight": 20,
"unit": "Kg",
"sets": [
5,
5,
5,
5,
5
]
},
{
"title": "Row",
"weight": 20,
"unit":"Kg",
"sets": [
5,
5,
5,
5,
5
]
},
{
"title": "Tricep extension",
"weight": 20,
"unit": "Kg",
"sets": [
10,
10,
10
]
}
]
}
]

View File

@ -1,4 +1,4 @@
class Set { exports = class Set {
constructor(maxReps) { constructor(maxReps) {
this._minReps = 0; this._minReps = 0;
this._maxReps = maxReps; this._maxReps = maxReps;

View File

@ -1,36 +1,33 @@
/* global g, setWatch, clearWatch, reset, BTN1, BTN2, BTN3 */ const W = g.getWidth();
const H = g.getHeight();
const RED = "#d32e29";
const PINK = "#f05a56";
const WHITE = "#ffffff";
(() => { const Set = require("buffgym-set.js");
const W = g.getWidth(); const Exercise = require("buffgym-exercise.js");
const H = g.getHeight(); const Program = require("buffgym-program.js");
const RED = "#d32e29";
const PINK = "#f05a56";
const WHITE = "#ffffff";
const Set = require("set.js"); function centerStringX(str) {
const Exercise = require("exercise.js");
const Program = require("program.js");
function centerStringX(str) {
return (W - g.stringWidth(str)) / 2; return (W - g.stringWidth(str)) / 2;
} }
function iconIncrement() { function iconIncrement() {
const img = require("heatshrink").decompress(atob("ikUxH+AA3XAAgNHCJIVMBYXQ5PC4XJ6AUJCIQQBAAoVCCQwjCAA/JCgglHA4IpJBYwTHA4RMJCY5oDJo4THKIQKET5IMGCaY7TMaKLTWajbTFJIlICgoVBFYXJYQYSGCggAGCRAVIBgw")); const img = require("heatshrink").decompress(atob("ikUxH+AA3XAAgNHCJIVMBYXQ5PC4XJ6AUJCIQQBAAoVCCQwjCAA/JCgglHA4IpJBYwTHA4RMJCY5oDJo4THKIQKET5IMGCaY7TMaKLTWajbTFJIlICgoVBFYXJYQYSGCggAGCRAVIBgw"));
return img; return img;
} }
function iconDecrement() { function iconDecrement() {
const img = require("heatshrink").decompress(atob("ikUxH+AA3XAAgNHCJIVMBYXQ5PC4XJ6AUJCIQQBAAoVCCQwjCAA/JCgglKFJADBCRYABCYQmOFAhNMKIw6FTw4LHCaY7TMaKLTWajbTFJglFCgoVBFYXJYQYSGCggAGCRAVIBgw=")); const img = require("heatshrink").decompress(atob("ikUxH+AA3XAAgNHCJIVMBYXQ5PC4XJ6AUJCIQQBAAoVCCQwjCAA/JCgglKFJADBCRYABCYQmOFAhNMKIw6FTw4LHCaY7TMaKLTWajbTFJglFCgoVBFYXJYQYSGCggAGCRAVIBgw="));
return img; return img;
} }
function iconOk() { function iconOk() {
const img = require("heatshrink").decompress(atob("ikUxH+AA3XAAgNHCJIVMBYXQ5PC4XJ6AUJCIQQBAAoVCCQwjCAA/JCgglKFJADBCJQxCCYQmMIwZoDJpQMCKIg6KBYwTGFQgeHHYouCCRI7EMYTXFRhILEK5SfFRgYSIborbSbpglFCgoVBFYXJYQYSGCggAGCRAVIBgwA==")); const img = require("heatshrink").decompress(atob("ikUxH+AA3XAAgNHCJIVMBYXQ5PC4XJ6AUJCIQQBAAoVCCQwjCAA/JCgglKFJADBCJQxCCYQmMIwZoDJpQMCKIg6KBYwTGFQgeHHYouCCRI7EMYTXFRhILEK5SfFRgYSIborbSbpglFCgoVBFYXJYQYSGCggAGCRAVIBgwA=="));
return img; return img;
} }
function drawMenu(params) { function drawMenu(params) {
const DEFAULT_PARAMS = { const DEFAULT_PARAMS = {
showBTN1: false, showBTN1: false,
showBTN2: false, showBTN2: false,
@ -40,22 +37,22 @@
if (p.showBTN1) g.drawImage(iconIncrement(), W - 30, 10); if (p.showBTN1) g.drawImage(iconIncrement(), W - 30, 10);
if (p.showBTN2) g.drawImage(iconOk(), W - 30, 110); if (p.showBTN2) g.drawImage(iconOk(), W - 30, 110);
if (p.showBTN3) g.drawImage(iconDecrement(), W - 30, 210); if (p.showBTN3) g.drawImage(iconDecrement(), W - 30, 210);
} }
function clearScreen() { function clearScreen() {
g.setColor(RED); g.setColor(RED);
g.fillRect(0,0,W,H); g.fillRect(0,0,W,H);
} }
function drawTitle(exercise) { function drawTitle(exercise) {
const title = exercise.humanTitle; const title = exercise.humanTitle;
g.setFont("Vector",20); g.setFont("Vector",20);
g.setColor(WHITE); g.setColor(WHITE);
g.drawString(title, centerStringX(title), 5); g.drawString(title, centerStringX(title), 5);
} }
function drawReps(exercise) { function drawReps(exercise) {
const set = exercise.currentSet; const set = exercise.currentSet;
if (set.isCompleted()) return; if (set.isCompleted()) return;
@ -67,24 +64,24 @@
g.setFont("Vector", 15); g.setFont("Vector", 15);
const note = `of ${set.maxReps}`; const note = `of ${set.maxReps}`;
g.drawString(note, centerStringX(note), (H / 2) + 25); g.drawString(note, centerStringX(note), (H / 2) + 25);
} }
function drawSets(exercise) { function drawSets(exercise) {
const sets = exercise.subTitle; const sets = exercise.subTitle;
g.setColor(WHITE); g.setColor(WHITE);
g.setFont("Vector", 15); g.setFont("Vector", 15);
g.drawString(sets, centerStringX(sets), H - 25); g.drawString(sets, centerStringX(sets), H - 25);
} }
function drawSetProgress(exercise) { function drawSetProgress(exercise) {
drawTitle(exercise); drawTitle(exercise);
drawReps(exercise); drawReps(exercise);
drawSets(exercise); drawSets(exercise);
drawMenu({showBTN1: true, showBTN2: true, showBTN3: true}); drawMenu({showBTN1: true, showBTN2: true, showBTN3: true});
} }
function drawStartNextExercise() { function drawStartNextExercise() {
const title = "Good work"; const title = "Good work";
const msg = "No need to rest\nmove straight on\nto the next exercise"; const msg = "No need to rest\nmove straight on\nto the next exercise";
@ -94,9 +91,9 @@
g.setFont("Vector", 15); g.setFont("Vector", 15);
g.drawString(msg, 30, 150); g.drawString(msg, 30, 150);
drawMenu({showBTN1: false, showBTN2: true, showBTN3: false}); drawMenu({showBTN1: false, showBTN2: true, showBTN3: false});
} }
function drawProgramCompleted() { function drawProgramCompleted() {
const title1 = "You did"; const title1 = "You did";
const title2 = "GREAT!"; const title2 = "GREAT!";
const msg = "That's the program\ncompleted. Now eat\nsome food and\nget plenty of rest."; const msg = "That's the program\ncompleted. Now eat\nsome food and\nget plenty of rest.";
@ -112,10 +109,10 @@
g.setFont("Vector", 15); g.setFont("Vector", 15);
g.drawString(msg, 30, 150); g.drawString(msg, 30, 150);
drawMenu({showBTN1: false, showBTN2: true, showBTN3: false}); drawMenu({showBTN1: false, showBTN2: true, showBTN3: false});
} }
/* /*
function drawExerciseCompleted(program) { function drawExerciseCompleted(program) {
const exercise = program.currentExercise(); const exercise = program.currentExercise();
const title = exercise.canProgress? const title = exercise.canProgress?
"WELL DONE!" : "WELL DONE!" :
@ -138,10 +135,10 @@
setWatch(() => { setWatch(() => {
init(program); init(program);
}, BTN2, {repeat: false}); }, BTN2, {repeat: false});
} }
*/ */
function drawRestTimer(program) { function drawRestTimer(program) {
const exercise = program.currentExercise(); const exercise = program.currentExercise();
const motivation = "Take a breather.."; const motivation = "Take a breather..";
clearScreen(); clearScreen();
@ -160,9 +157,9 @@
exercise.resetRestTimer(); exercise.resetRestTimer();
redraw(program); redraw(program);
} }
} }
function redraw(program) { function redraw(program) {
const exercise = program.currentExercise(); const exercise = program.currentExercise();
clearScreen(); clearScreen();
@ -183,17 +180,17 @@
} }
drawSetProgress(exercise); drawSetProgress(exercise);
} }
function init(program) { function init(program) {
clearWatch(); clearWatch();
program.next(); program.next();
} }
// Setup training program. This should come from file // Setup training program. This should come from file
// Squats // Squats
function buildPrograms() { function buildPrograms() {
const programsJSON = require("Storage").readJSON("buffgym-programs.json", 1); const programsJSON = require("Storage").readJSON("buffgym-programs.json", 1);
if (!programsJSON) throw "No programs JSON found"; if (!programsJSON) throw "No programs JSON found";
@ -221,10 +218,9 @@
}); });
return programs; return programs;
} }
// For this spike, just run the first program, what will // For this spike, just run the first program, what will
// really happen is the user picks a program to do from // really happen is the user picks a program to do from
// some menu on a start page. // some menu on a start page.
init(buildPrograms()[0]); init(buildPrograms()[0]);
})();