-
Notifications
You must be signed in to change notification settings - Fork 0
/
Training.cpp
179 lines (152 loc) · 5.82 KB
/
Training.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//
// Created by Richard on 23.04.2020.
//
#include "Training.h"
/**
* e.value is the no of lines sent via uart ble
* == no of exercises in Training
* @param e
*/
void Training::onExercisesChanged(MicroBitEvent e) {
//e.value == no of lines == no of new exercises
Exercise exercise = Exercise();
exercises.clear();
for (int i = 0; i < e.value; ++i) {
exercise.fromString(uart->readUntil("\n"));
exercises.push_back(exercise);
// MicroBitEvent evt(TrainingID,rcvd);
}
}
void Training::onRemoveExercise(MicroBitEvent e) {
//// e.value == index of deleted exercise 0..n
//if(exercises.size()>e.value){
// exercises.erase(exercises.begin()+e.value);
//}
}
/**
* set name of Training via uart ble
* @param e
*/
void Training::onSetName(MicroBitEvent e) {
name = uart->readUntil("\n");
}
/**
* set Date of Training via Uart. format int == day since 1970 etc.
* @param e
*/
void Training::onSetDate(MicroBitEvent e) {
customDate = atoi(uart->readUntil("\n").toCharArray());
}
void Training::inputLoopOverExercises() {
myInput in;
int loop_case = 0;
for (std::vector<Exercise>::size_type e = 0; e != exercises.size(); ) {
Exercise &exercise = exercises.at(e);
for (std::vector<ExerciseSet>::size_type s = 0; s != exercise.sets.size(); s++) {
ExerciseSet &eSet = exercise.sets.at(s);
loop_case = 0;
uint16_t oldID;
uint16_t newID;
while(loop_case<3) {
switch (loop_case) {
case 0:
uBit.display.scroll("ID");
uBit.display.clear();
oldID = exercise.custom_id;
newID = in.input(WAITFORINPUTTIME, oldID);
uBit.sleep(500);
if(terminator){
terminator=false;
exercises.erase(exercises.begin()+e);
goto nextExercise;
}
//TODO scroll Name of Exercise, from Flash DB?
// // exercise.name=read_to_string(ManagedString(exercise.custom_id))
uBit.sleep(500);
if (newID != oldID && oldID !=0) {
auto it=std::find_if(exercises.begin(),exercises.end(),[newID](const Exercise& ex){
return ex.custom_id == newID;
});
if(it!=exercises.end()) {
std::iter_swap(exercises.begin()+e, it);
//TODO MicrobitEvent evt(EXERCISES_SWAPED_ID,byte[from,to])
} else {
Exercise newEx;
newEx.custom_id = newID;
newEx.sets.reserve(10);
exercises.insert(exercises.begin() + e, newEx);
//TODO MicrobitEvent evt(EXERCISE_ADDED_ID,byte[UUID,customID])
}
goto nextExercise;
}
else{
exercise.custom_id=newID;
}
uBit.sleep(500);
loop_case++;
break;
case 1:
uBit.display.scroll("Kg", LONGTEXTDELAY);
uBit.sleep(300);
if (goback != 0) {
break;
}
eSet.weight=in.input(WAITFORINPUTTIME, eSet.weight);
//TODO MicrobitEvent evt(SET_WEIGHT_CHANGED_ID,byte[UUID,weight])
uBit.sleep(500);
loop_case += 1 - goback;
break;
case 2:
uBit.display.scroll("RPS", LONGTEXTDELAY);
if (goback != 0) {
break;
}
eSet.cntReps(in);
uBit.sleep(500);
uBit.display.clear();
if(s==exercise.sets.size()-1){
uBit.display.scroll("+ Set?",LONGTEXTDELAY);
displayLeftArrow();
while(inputBuff==0){
uBit.sleep(100);
}
if(inputBuff==INCREMENT_A){
exercise.sets.push_back(eSet);
uBit.display.scrollAsync("+",LONGTEXTDELAY);
inputBuff=0;
}
eSet.isDone=true;
//TODO MicrobitEvent evt(SET_REPS_CHANGED_ID,byte[UUID,reps])
inputBuff=0;
}
loop_case += 1 - goback;
break;
default:
break;
}
goback = 0;
if (terminator == 1) {
terminator = false;
goto nextExercise;
}
}
}
if(e==exercises.size()-1){
uBit.display.scroll("+ Ex? -",FASTSCROLLTIME);
displayLeftArrow();
while(inputBuff==0){
uBit.sleep(100);
}
if(inputBuff==INCREMENT_A){
exercises.emplace_back();
uBit.display.scrollAsync("+",FASTSCROLLTIME);
}
inputBuff=0;
}
displayTick();
e++;
// prüfe ob Set Loop verlassen werden soll.
nextExercise:;
}
uBit.sleep(500);
}