@@ -13,9 +13,12 @@ enum states {
1313
1414int 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];
1719float * idx = values;
1820float * final_idx = 0 ;
21+ int sample_cnt = 0 ;
1922float homePos[6 ] = {157.5 , 157.5 , 157.5 , 157.5 , 157.5 , 90.0 };
2023
2124static 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
142146void 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