Skip to content

Commit af07b2a

Browse files
committed
Align identical examples.
1 parent 824bbb2 commit af07b2a

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

examples/Platform_Tutorials/projects/p03-learning-mode/01_Braccio_learning_mode/01_Braccio_learning_mode.ino

+17-6
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ enum states {
1313

1414
int state = ZERO_POSITION;
1515

16-
float values[10000];
16+
static int const MAX_SAMPLES = 6*1000*2; /* 20 seconds. */
17+
18+
float values[MAX_SAMPLES];
1719
float* idx = values;
1820
float* final_idx = 0;
21+
int sample_cnt = 0;
1922
float homePos[6] = {157.5, 157.5, 157.5, 157.5, 157.5, 90.0};
2023

2124
static lv_obj_t * counter;
@@ -42,6 +45,7 @@ static void eventHandlerMenu(lv_event_t * e) {
4245
}
4346

4447
idx = values;
48+
sample_cnt = 0;
4549

4650
switch (id) {
4751
case 0: // if the button pressed is the first one
@@ -141,25 +145,32 @@ void setup() {
141145

142146
void loop() {
143147
if (state == RECORD) {
148+
149+
/* Check if we still have space for samples. */
150+
if (sample_cnt >= MAX_SAMPLES) {
151+
state = ZERO_POSITION;
152+
Serial.println("ZERO_POSITION");
153+
btnm_map[0] = "RECORD"; // reset the label of the first button back to "RECORD"
154+
lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKABLE);
155+
}
156+
/* Capture those samples. */
144157
Braccio.positions(idx);
145158
idx += 6;
159+
sample_cnt += 6;
146160
}
147161
if (state == REPLAY) {
148162
Braccio.moveTo(idx[0], idx[1], idx[2], idx[3], idx[4], idx[5]);
149163
idx += 6;
164+
sample_cnt += 6;
150165
if (idx >= final_idx) {
151166
Serial.println("REPLAY done");
152167
state = ZERO_POSITION;
153168
btnm_map[2] = "REPLAY"; // reset the label of the first button back to "REPLAY"
154169
lv_btnmatrix_set_btn_ctrl(btnm, 2, LV_BTNMATRIX_CTRL_CHECKED);
155170
}
156171
}
157-
if (idx - values >= sizeof(values)) {
158-
Serial.println("ZERO_POSITION");
159-
state = ZERO_POSITION;
160-
}
161172
delay(100);
162173
if (state != ZERO_POSITION) {
163-
lv_label_set_text_fmt(counter, "Counter: %d" , idx - values);
174+
lv_label_set_text_fmt(counter, "Counter: %d" , (sample_cnt / 6));
164175
}
165176
}

0 commit comments

Comments
 (0)