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