@@ -13,9 +13,12 @@ enum states {
13
13
14
14
int state = ZERO_POSITION;
15
15
16
- float values[10000 ];
16
+ static int const MAX_SAMPLES = 6 *1000 *2 ; /* 20 seconds. */
17
+
18
+ float values[MAX_SAMPLES];
17
19
float * idx = values;
18
20
float * final_idx = 0 ;
21
+ int sample_cnt = 0 ;
19
22
float homePos[6 ] = {157.5 , 157.5 , 157.5 , 157.5 , 157.5 , 90.0 };
20
23
21
24
static lv_obj_t * counter;
@@ -42,6 +45,7 @@ static void eventHandlerMenu(lv_event_t * e) {
42
45
}
43
46
44
47
idx = values;
48
+ sample_cnt = 0 ;
45
49
46
50
switch (id) {
47
51
case 0 : // if the button pressed is the first one
@@ -141,25 +145,32 @@ void setup() {
141
145
142
146
void loop () {
143
147
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. */
144
157
Braccio.positions (idx);
145
158
idx += 6 ;
159
+ sample_cnt += 6 ;
146
160
}
147
161
if (state == REPLAY) {
148
162
Braccio.moveTo (idx[0 ], idx[1 ], idx[2 ], idx[3 ], idx[4 ], idx[5 ]);
149
163
idx += 6 ;
164
+ sample_cnt += 6 ;
150
165
if (idx >= final_idx) {
151
166
Serial.println (" REPLAY done" );
152
167
state = ZERO_POSITION;
153
168
btnm_map[2 ] = " REPLAY" ; // reset the label of the first button back to "REPLAY"
154
169
lv_btnmatrix_set_btn_ctrl (btnm, 2 , LV_BTNMATRIX_CTRL_CHECKED);
155
170
}
156
171
}
157
- if (idx - values >= sizeof (values)) {
158
- Serial.println (" ZERO_POSITION" );
159
- state = ZERO_POSITION;
160
- }
161
172
delay (100 );
162
173
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 ) );
164
175
}
165
176
}
0 commit comments