Skip to content

Commit 0fac2d6

Browse files
committed
Extract code for RECORD state into separate function.
1 parent f3635ee commit 0fac2d6

File tree

1 file changed

+34
-20
lines changed

1 file changed

+34
-20
lines changed

examples/Braccio_Learn_and_Repeat/Braccio_Learn_and_Repeat.ino

+34-20
Original file line numberDiff line numberDiff line change
@@ -178,26 +178,7 @@ void loop()
178178

179179
if (state == State::RECORD)
180180
{
181-
/* Check if we still have space for samples. */
182-
if (sample_cnt >= MAX_SAMPLES)
183-
{
184-
state = State::ZERO_POSITION;
185-
replay_cnt = 0;
186-
Braccio.lvgl_lock();
187-
btnm_map[0] = "RECORD"; // reset the label of the first button back to "RECORD"
188-
lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKABLE);
189-
Braccio.lvgl_unlock();
190-
}
191-
else
192-
{
193-
/* Capture those samples. */
194-
Braccio.positions(values + sample_cnt);
195-
sample_cnt += 6;
196-
}
197-
198-
Braccio.lvgl_lock();
199-
lv_label_set_text_fmt(counter, "Counter: %d" , (sample_cnt / 6));
200-
Braccio.lvgl_unlock();
181+
state = handle_RECORD();
201182
}
202183

203184
if (state == State::REPLAY)
@@ -226,3 +207,36 @@ void loop()
226207
}
227208
}
228209
}
210+
211+
/**************************************************************************************
212+
* FUNCTION DEFINITIONS
213+
**************************************************************************************/
214+
215+
State handle_RECORD()
216+
{
217+
/* Check if we still have space for samples. */
218+
if (sample_cnt >= MAX_SAMPLES)
219+
{
220+
replay_cnt = 0;
221+
222+
Braccio.lvgl_lock();
223+
btnm_map[0] = "RECORD"; // reset the label of the first button back to "RECORD"
224+
lv_btnmatrix_set_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKABLE);
225+
Braccio.lvgl_unlock();
226+
227+
return State::ZERO_POSITION;
228+
}
229+
else
230+
{
231+
/* Capture those samples. */
232+
Braccio.positions(values + sample_cnt);
233+
sample_cnt += 6;
234+
235+
/* Update sample counter. */
236+
Braccio.lvgl_lock();
237+
lv_label_set_text_fmt(counter, "Counter: %d" , (sample_cnt / 6));
238+
Braccio.lvgl_unlock();
239+
240+
return State::RECORD;
241+
}
242+
}

0 commit comments

Comments
 (0)