Rename program to workout
parent
bf5bf91967
commit
9e8dea08e4
|
|
@ -1,16 +1,16 @@
|
||||||
exports = class Exercise {
|
exports = class Exercise {
|
||||||
constructor(params) {
|
constructor(params) {
|
||||||
|
this.completed = false;
|
||||||
|
this.sets = [];
|
||||||
this.title = params.title;
|
this.title = params.title;
|
||||||
this.weight = params.weight;
|
this.weight = params.weight;
|
||||||
this.unit = params.unit;
|
this.unit = params.unit;
|
||||||
this.restPeriod = params.restPeriod;
|
this.restPeriod = params.restPeriod;
|
||||||
this.completed = false;
|
this._originalRestPeriod = params.restPeriod;
|
||||||
this.sets = [];
|
this._weightIncrement = params.weightIncrement;
|
||||||
this._restTimeout = null;
|
this._restTimeout = null;
|
||||||
this._restInterval = null;
|
this._restInterval = null;
|
||||||
this._state = null;
|
this._state = null;
|
||||||
this._originalRestPeriod = params.restPeriod;
|
|
||||||
this._weightIncrement = params.weightIncrement || 2.5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get humanTitle() {
|
get humanTitle() {
|
||||||
|
|
@ -63,13 +63,13 @@ exports = class Exercise {
|
||||||
return (targetRepsTotalSum - completedRepsTotalSum) === 0;
|
return (targetRepsTotalSum - completedRepsTotalSum) === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
startRestTimer(program) {
|
startRestTimer(workout) {
|
||||||
this._restTimeout = setTimeout(() => {
|
this._restTimeout = setTimeout(() => {
|
||||||
this.next(program);
|
this.next(workout);
|
||||||
}, 1000 * this.restPeriod);
|
}, 1000 * this.restPeriod);
|
||||||
|
|
||||||
this._restInterval = setInterval(() => {
|
this._restInterval = setInterval(() => {
|
||||||
program.emit("redraw");
|
workout.emit("redraw");
|
||||||
}, 1000 );
|
}, 1000 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,28 +85,28 @@ exports = class Exercise {
|
||||||
return this._restTimeout != null;
|
return this._restTimeout != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
setupStartedButtons(program) {
|
setupStartedButtons(workout) {
|
||||||
clearWatch();
|
clearWatch();
|
||||||
|
|
||||||
setWatch(() => {
|
setWatch(() => {
|
||||||
this.currentSet().incReps();
|
this.currentSet().incReps();
|
||||||
program.emit("redraw");
|
workout.emit("redraw");
|
||||||
}, BTN1, {repeat: true});
|
}, BTN1, {repeat: true});
|
||||||
|
|
||||||
setWatch(program.next.bind(program), BTN2, {repeat: false});
|
setWatch(workout.next.bind(workout), BTN2, {repeat: false});
|
||||||
|
|
||||||
setWatch(() => {
|
setWatch(() => {
|
||||||
this.currentSet().decReps();
|
this.currentSet().decReps();
|
||||||
program.emit("redraw");
|
workout.emit("redraw");
|
||||||
}, BTN3, {repeat: true});
|
}, BTN3, {repeat: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
setupRestingButtons(program) {
|
setupRestingButtons(workout) {
|
||||||
clearWatch();
|
clearWatch();
|
||||||
setWatch(program.next.bind(program), BTN2, {repeat: false});
|
setWatch(workout.next.bind(workout), BTN2, {repeat: false});
|
||||||
}
|
}
|
||||||
|
|
||||||
next(program) {
|
next(workout) {
|
||||||
const STARTED = 1;
|
const STARTED = 1;
|
||||||
const RESTING = 2;
|
const RESTING = 2;
|
||||||
const COMPLETED = 3;
|
const COMPLETED = 3;
|
||||||
|
|
@ -114,12 +114,12 @@ exports = class Exercise {
|
||||||
switch(this._state) {
|
switch(this._state) {
|
||||||
case null:
|
case null:
|
||||||
this._state = STARTED;
|
this._state = STARTED;
|
||||||
this.setupStartedButtons(program);
|
this.setupStartedButtons(workout);
|
||||||
break;
|
break;
|
||||||
case STARTED:
|
case STARTED:
|
||||||
this._state = RESTING;
|
this._state = RESTING;
|
||||||
this.startRestTimer(program);
|
this.startRestTimer(workout);
|
||||||
this.setupRestingButtons(program);
|
this.setupRestingButtons(workout);
|
||||||
break;
|
break;
|
||||||
case RESTING:
|
case RESTING:
|
||||||
this.resetRestTimer();
|
this.resetRestTimer();
|
||||||
|
|
@ -132,13 +132,13 @@ exports = class Exercise {
|
||||||
this._state = null;
|
this._state = null;
|
||||||
}
|
}
|
||||||
// As we are changing state and require it to be reprocessed
|
// As we are changing state and require it to be reprocessed
|
||||||
// invoke the next step of program
|
// invoke the next step of workout
|
||||||
program.next();
|
workout.next();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw "Exercise: Attempting to move to an unknown state";
|
throw "Exercise: Attempting to move to an unknown state";
|
||||||
}
|
}
|
||||||
|
|
||||||
program.emit("redraw");
|
workout.emit("redraw");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
[
|
|
||||||
{
|
|
||||||
"title": "Program A",
|
|
||||||
"file": "buffgym-program-a.json"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Program B",
|
|
||||||
"file": "buffgym-program-b.json"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
exports = class Set {
|
exports = class Set {
|
||||||
constructor(maxReps) {
|
constructor(maxReps) {
|
||||||
this.minReps = 0;
|
|
||||||
this.maxReps = maxReps;
|
|
||||||
this.reps = 0;
|
|
||||||
this.completed = false;
|
this.completed = false;
|
||||||
|
this.minReps = 0;
|
||||||
|
this.reps = 0;
|
||||||
|
this.maxReps = maxReps;
|
||||||
}
|
}
|
||||||
|
|
||||||
isCompleted() {
|
isCompleted() {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"title": "Program A",
|
"title": "Workout A",
|
||||||
"exercises": [
|
"exercises": [
|
||||||
{
|
{
|
||||||
"title": "Squats",
|
"title": "Squats",
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"title": "Program B",
|
"title": "Workout B",
|
||||||
"exercises": [
|
"exercises": [
|
||||||
{
|
{
|
||||||
"title": "Squats",
|
"title": "Squats",
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"title": "Workout A",
|
||||||
|
"file": "buffgym-workout-a.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Workout B",
|
||||||
|
"file": "buffgym-workout-b.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
exports = class Program {
|
exports = class Workout {
|
||||||
constructor(params) {
|
constructor(params) {
|
||||||
this.title = params.title;
|
this.title = params.title;
|
||||||
this.exercises = [];
|
this.exercises = [];
|
||||||
|
|
@ -27,6 +27,10 @@ exports = class Program {
|
||||||
return !!this.completed;
|
return !!this.completed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static fromJSON(workout) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
toJSON() {
|
toJSON() {
|
||||||
return {
|
return {
|
||||||
title: this.title,
|
title: this.title,
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
* Created: April 2020
|
* Created: April 2020
|
||||||
*
|
*
|
||||||
* Inspired by:
|
* Inspired by:
|
||||||
* - Stronglifts 5x5 training program https://stronglifts.com/5x5/
|
* - Stronglifts 5x5 training workout https://stronglifts.com/5x5/
|
||||||
* - Stronglifts smart watch app
|
* - Stronglifts smart watch app
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -66,10 +66,10 @@ function drawSet(exercise) {
|
||||||
g.flip();
|
g.flip();
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawProgDone() {
|
function drawWorkoutDone() {
|
||||||
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 workout\ncompleted. Now eat\nsome food and\nget plenty of rest.";
|
||||||
|
|
||||||
clearWatch();
|
clearWatch();
|
||||||
setWatch(Bangle.showLauncher, BTN2, {repeat: false});
|
setWatch(Bangle.showLauncher, BTN2, {repeat: false});
|
||||||
|
|
@ -102,13 +102,13 @@ function drawSetComp() {
|
||||||
g.flip();
|
g.flip();
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawRestTimer(program) {
|
function drawRestTimer(workout) {
|
||||||
const exercise = program.currentExercise();
|
const exercise = workout.currentExercise();
|
||||||
const motivation = "Take a breather..";
|
const motivation = "Take a breather..";
|
||||||
|
|
||||||
if (exercise.restPeriod <= 0) {
|
if (exercise.restPeriod <= 0) {
|
||||||
exercise.resetRestTimer();
|
exercise.resetRestTimer();
|
||||||
program.next();
|
workout.next();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -128,21 +128,21 @@ function drawRestTimer(program) {
|
||||||
exercise.decRestPeriod();
|
exercise.decRestPeriod();
|
||||||
}
|
}
|
||||||
|
|
||||||
function redraw(program) {
|
function redraw(workout) {
|
||||||
const exercise = program.currentExercise();
|
const exercise = workout.currentExercise();
|
||||||
g.clear();
|
g.clear();
|
||||||
|
|
||||||
if (program.isCompleted()) {
|
if (workout.isCompleted()) {
|
||||||
saveProg(program);
|
saveWorkout(workout);
|
||||||
drawProgDone(program);
|
drawWorkoutDone(workout);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exercise.isRestTimerRunning()) {
|
if (exercise.isRestTimerRunning()) {
|
||||||
if (exercise.isLastSet()) {
|
if (exercise.isLastSet()) {
|
||||||
drawSetComp(program);
|
drawSetComp(workout);
|
||||||
} else {
|
} else {
|
||||||
drawRestTimer(program);
|
drawRestTimer(workout);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
@ -151,7 +151,7 @@ function redraw(program) {
|
||||||
drawSet(exercise);
|
drawSet(exercise);
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawProgMenu(programs, selProgIdx) {
|
function drawWorkoutMenu(workouts, selWorkoutIdx) {
|
||||||
g.clear();
|
g.clear();
|
||||||
g.setFontAlign(0, -1);
|
g.setFontAlign(0, -1);
|
||||||
g.setColor(WHITE);
|
g.setColor(WHITE);
|
||||||
|
|
@ -160,16 +160,16 @@ function drawProgMenu(programs, selProgIdx) {
|
||||||
|
|
||||||
g.setFont("6x8", 1);
|
g.setFont("6x8", 1);
|
||||||
g.setFontAlign(-1, -1);
|
g.setFontAlign(-1, -1);
|
||||||
let selectedProgram = programs[selProgIdx].title;
|
let selectedWorkout = workouts[selWorkoutIdx].title;
|
||||||
let yPos = 50;
|
let yPos = 50;
|
||||||
programs.forEach(program => {
|
workouts.forEach(workout => {
|
||||||
g.setColor("#f05a56");
|
g.setColor("#f05a56");
|
||||||
g.fillRect(0, yPos, W, yPos + 11);
|
g.fillRect(0, yPos, W, yPos + 11);
|
||||||
g.setColor("#ffffff");
|
g.setColor("#ffffff");
|
||||||
if (selectedProgram === program.title) {
|
if (selectedWorkout === workout.title) {
|
||||||
g.drawRect(0, yPos, W - 1, yPos + 11);
|
g.drawRect(0, yPos, W - 1, yPos + 11);
|
||||||
}
|
}
|
||||||
g.drawString(program.title, 10, yPos + 2);
|
g.drawString(workout.title, 10, yPos + 2);
|
||||||
yPos += 15;
|
yPos += 15;
|
||||||
});
|
});
|
||||||
g.flip();
|
g.flip();
|
||||||
|
|
@ -177,25 +177,25 @@ function drawProgMenu(programs, selProgIdx) {
|
||||||
|
|
||||||
function setupMenu() {
|
function setupMenu() {
|
||||||
clearWatch();
|
clearWatch();
|
||||||
const progs = getProgIndex();
|
const workouts = getWorkoutIndex();
|
||||||
let selProgIdx = 0;
|
let selWorkoutIdx = 0;
|
||||||
drawProgMenu(progs, selProgIdx);
|
drawWorkoutMenu(workouts, selWorkoutIdx);
|
||||||
|
|
||||||
setWatch(()=>{
|
setWatch(()=>{
|
||||||
selProgIdx--;
|
selWorkoutIdx--;
|
||||||
if (selProgIdx< 0) selProgIdx = 0;
|
if (selWorkoutIdx< 0) selWorkoutIdx = 0;
|
||||||
drawProgMenu(progs, selProgIdx);
|
drawWorkoutMenu(workouts, selWorkoutIdx);
|
||||||
}, BTN1, {repeat: true});
|
}, BTN1, {repeat: true});
|
||||||
|
|
||||||
setWatch(()=>{
|
setWatch(()=>{
|
||||||
const prog = buildProg(progs[selProgIdx].file);
|
const workout = buildWorkout(workouts[selWorkoutIdx].file);
|
||||||
prog.next();
|
workout.next();
|
||||||
}, BTN2, {repeat: false});
|
}, BTN2, {repeat: false});
|
||||||
|
|
||||||
setWatch(()=>{
|
setWatch(()=>{
|
||||||
selProgIdx++;
|
selWorkoutIdx++;
|
||||||
if (selProgIdx > progs.length - 1) selProgIdx = progs.length - 1;
|
if (selWorkoutIdx > workouts.length - 1) selWorkoutIdx = workouts.length - 1;
|
||||||
drawProgMenu(progs, selProgIdx);
|
drawWorkoutMenu(workouts, selWorkoutIdx);
|
||||||
}, BTN3, {repeat: true});
|
}, BTN3, {repeat: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -249,23 +249,24 @@ function drawSplash() {
|
||||||
}, BTN3, {repeat: false});
|
}, BTN3, {repeat: false});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getProgIndex() {
|
function getWorkoutIndex() {
|
||||||
const progIdx = require("Storage").readJSON("buffgym-program-index.json");
|
const workoutIdx = require("Storage").readJSON("buffgym-workout-index.json");
|
||||||
return progIdx;
|
return workoutIdx;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildProg(fName) {
|
function buildWorkout(fName) {
|
||||||
const Set = require("buffgym-set.js");
|
const Set = require("buffgym-set.js");
|
||||||
const Exercise = require("buffgym-exercise.js");
|
const Exercise = require("buffgym-exercise.js");
|
||||||
const Program = require("buffgym-program.js");
|
const Workout = require("buffgym-workout.js");
|
||||||
const progJSON = require("Storage").readJSON(fName);
|
const workoutJSON = require("Storage").readJSON(fName);
|
||||||
const prog = new Program({
|
const workout = new Workout({
|
||||||
title: progJSON.title,
|
title: workoutJSON.title,
|
||||||
});
|
});
|
||||||
const exercises = progJSON.exercises.map(exerciseJSON => {
|
const exercises = workoutJSON.exercises.map(exerciseJSON => {
|
||||||
const exercise = new Exercise({
|
const exercise = new Exercise({
|
||||||
title: exerciseJSON.title,
|
title: exerciseJSON.title,
|
||||||
weight: exerciseJSON.weight,
|
weight: exerciseJSON.weight,
|
||||||
|
weightIncrement: exerciseJSON.weightIncrement,
|
||||||
unit: exerciseJSON.unit,
|
unit: exerciseJSON.unit,
|
||||||
restPeriod: exerciseJSON.restPeriod,
|
restPeriod: exerciseJSON.restPeriod,
|
||||||
});
|
});
|
||||||
|
|
@ -275,14 +276,14 @@ function buildProg(fName) {
|
||||||
|
|
||||||
return exercise;
|
return exercise;
|
||||||
});
|
});
|
||||||
prog.addExercises(exercises);
|
workout.addExercises(exercises);
|
||||||
|
|
||||||
return prog;
|
return workout;
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveProg(program) {
|
function saveWorkout(workout) {
|
||||||
const fName = getProgIndex().find(prog => prog.title === program.title).file;
|
const fName = getWorkoutIndex().find(workout => workout.title === workout.title).file;
|
||||||
require("Storage").writeJSON(fName, program.toJSON());
|
require("Storage").writeJSON(fName, workout.toJSON());
|
||||||
}
|
}
|
||||||
|
|
||||||
drawSplash();
|
drawSplash();
|
||||||
Loading…
Reference in New Issue