@@ -155,12 +155,12 @@ int main(void)
155
155
156
156
CUSTOM_VL53L3CX_I2C_Init ();
157
157
158
- //De sensoren initialiseren
158
+ // De sensoren initialiseren
159
159
Init_Sensor (& sensor [center .id ], center .gpioPin );
160
160
Init_Sensor (& sensor [left .id ], left .gpioPin );
161
161
Init_Sensor (& sensor [right .id ], right .gpioPin );
162
162
163
- //Als de drukknop SW_1 actief is, wordt er gekalibreerd
163
+ // Als de drukknop SW_1 actief is, wordt er gekalibreerd
164
164
if (HAL_GPIO_ReadPin (SW_1_GPIO_Port , SW_1_Pin ))
165
165
{
166
166
getCalibrate (& sensor [center .id ], center .id );
@@ -209,14 +209,14 @@ int main(void)
209
209
}
210
210
else
211
211
{
212
- setCalibrate (& sensor [center .id ], center .id );;
213
- setCalibrate (& sensor [left .id ], left .id );
214
- setCalibrate (& sensor [right .id ], right .id );
212
+ // setCalibrate(&sensor[center.id], center.id);;
213
+ // setCalibrate(&sensor[left.id], left.id);
214
+ // setCalibrate(&sensor[right.id], right.id);
215
215
}
216
216
217
+ Start_Sensor (& sensor [center .id ], center .gpioPin );
217
218
Start_Sensor (& sensor [left .id ], left .gpioPin );
218
- // Start_Sensor(&sensor[left.id], left.gpioPin);
219
- // Start_Sensor(&sensor[right.id], right.gpioPin);
219
+ Start_Sensor (& sensor [right .id ], right .gpioPin );
220
220
221
221
/* USER CODE END 2 */
222
222
@@ -225,118 +225,31 @@ int main(void)
225
225
226
226
initObjectPresent (-1 , -1 , -1 );
227
227
228
+ int leftDistance = 0 ;
229
+ int centerDistance = 0 ;
230
+ int rightDistance = 0 ;
231
+
228
232
while (1 )
229
233
{
230
234
isReady [left .id ] = getData (& sensor [left .id ], & left , & resultaat [left .id ], (uint8_t * )isReady );
231
235
setMeanVal (left .id , resultaat [left .id ].distance );
232
236
233
- if (objectPresent )
234
- {
235
- isReady [center .id ] = getData (& sensor [center .id ], & center , & resultaat [center .id ], (uint8_t * )isReady );
236
- setMeanVal (center .id , resultaat [center .id ].distance );
237
+ isReady [center .id ] = getData (& sensor [center .id ], & center , & resultaat [center .id ], (uint8_t * )isReady );
238
+ setMeanVal (center .id , resultaat [center .id ].distance );
237
239
238
- isReady [right .id ] = getData (& sensor [right .id ], & right , & resultaat [right .id ], (uint8_t * )isReady );
239
- setMeanVal (right .id , resultaat [right .id ].distance );
240
- }
240
+ isReady [right .id ] = getData (& sensor [right .id ], & right , & resultaat [right .id ], (uint8_t * )isReady );
241
+ setMeanVal (right .id , resultaat [right .id ].distance );
241
242
242
- objectPresent = ckeckObjectPresent (& resultaat [left .id ], & objectPresent , & resultaat [left .id ].distance );
243
- int leftDistance = 0 ;
244
- int centerDistance = 0 ;
245
- int rightDistance = 0 ;
246
- // Wanneer er geen commando aanwezig is, kijken ofdat er een gesture is
247
- if (commando == NONE )
248
- {
249
- leftDistance = getMean (left .id );
250
- centerDistance = getMean (center .id );
251
- rightDistance = getMean (right .id );
252
- int8_t val = detectgesture (leftDistance , resultaat [left .id ].status , centerDistance , resultaat [center .id ].status , rightDistance , resultaat [right .id ].status );
253
- if (val != -1 )
254
- commando = val ;
255
-
256
- //printf("leftDistance: %5d,centerDistance: %5d,rightDistance: %5d \r\n", leftDistance, centerDistance, rightDistance);
257
- }
243
+ leftDistance = getMean (left .id );
244
+ centerDistance = getMean (center .id );
245
+ rightDistance = getMean (right .id );
258
246
259
- checkResetTimer ();
260
247
261
248
HAL_GPIO_WritePin (LED_3_GPIO_Port , LED_3_Pin , objectPresent );
262
249
/* USER CODE END WHILE */
263
250
264
251
/* USER CODE BEGIN 3 */
265
252
266
- if (objectPresent && !prevObjectPresent )
267
- {
268
- // Opstarten van sensoren
269
- Start_Sensor (& sensor [center .id ], center .gpioPin );
270
- Start_Sensor (& sensor [right .id ], right .gpioPin );
271
- // printf("Start\r\n");
272
- }
273
-
274
- if (!objectPresent && prevObjectPresent )
275
- {
276
- Stop_Sensor (& sensor [center .id ]);
277
- Stop_Sensor (& sensor [right .id ]);
278
- // printf("Stop\r\n");
279
- }
280
-
281
- prevObjectPresent = objectPresent ;
282
-
283
- /* Timer om leds even aan te laten
284
- Er wordt gekeken wanneer commando veranderd wordt naar alles behalve NONE.
285
- Dan zetten we een timer
286
- Wanneer de timer afloopt wordt het commando gereset
287
- */
288
- if (!timerCommandSet && commando != NONE )
289
- {
290
- timerCommandSet = true;
291
- timerCommand = HAL_GetTick ();
292
- // printf("command: %2d\r\n", commando);
293
- }
294
- if ((HAL_GetTick () - timerCommand ) >= timerCommandTimeout )
295
- {
296
- timerCommandSet = false;
297
- commando = NONE ;
298
- }
299
- // Commando's uitsturen
300
- switch (commando )
301
- {
302
- case NONE :
303
- HAL_GPIO_WritePin (LED_0_GPIO_Port , LED_0_Pin , GPIO_PIN_RESET );
304
- HAL_GPIO_WritePin (LED_1_GPIO_Port , LED_1_Pin , GPIO_PIN_RESET );
305
- HAL_GPIO_WritePin (LED_2_GPIO_Port , LED_2_Pin , GPIO_PIN_RESET );
306
- break ;
307
- case RL :
308
- HAL_GPIO_WritePin (LED_0_GPIO_Port , LED_0_Pin , GPIO_PIN_SET );
309
- HAL_GPIO_WritePin (LED_1_GPIO_Port , LED_1_Pin , GPIO_PIN_RESET );
310
- HAL_GPIO_WritePin (LED_2_GPIO_Port , LED_2_Pin , GPIO_PIN_RESET );
311
- break ;
312
- case LR :
313
- HAL_GPIO_WritePin (LED_0_GPIO_Port , LED_0_Pin , GPIO_PIN_RESET );
314
- HAL_GPIO_WritePin (LED_1_GPIO_Port , LED_1_Pin , GPIO_PIN_SET );
315
- HAL_GPIO_WritePin (LED_2_GPIO_Port , LED_2_Pin , GPIO_PIN_RESET );
316
- break ;
317
- case UD :
318
- HAL_GPIO_WritePin (LED_0_GPIO_Port , LED_0_Pin , GPIO_PIN_SET );
319
- HAL_GPIO_WritePin (LED_1_GPIO_Port , LED_1_Pin , GPIO_PIN_SET );
320
- HAL_GPIO_WritePin (LED_2_GPIO_Port , LED_2_Pin , GPIO_PIN_RESET );
321
- break ;
322
- case DU :
323
- HAL_GPIO_WritePin (LED_0_GPIO_Port , LED_0_Pin , GPIO_PIN_RESET );
324
- HAL_GPIO_WritePin (LED_1_GPIO_Port , LED_1_Pin , GPIO_PIN_RESET );
325
- HAL_GPIO_WritePin (LED_2_GPIO_Port , LED_2_Pin , GPIO_PIN_SET );
326
- break ;
327
- case DIM :
328
- HAL_GPIO_WritePin (LED_0_GPIO_Port , LED_0_Pin , GPIO_PIN_SET );
329
- HAL_GPIO_WritePin (LED_1_GPIO_Port , LED_1_Pin , GPIO_PIN_RESET );
330
- HAL_GPIO_WritePin (LED_2_GPIO_Port , LED_2_Pin , GPIO_PIN_SET );
331
- break ;
332
-
333
- default :
334
- HAL_GPIO_WritePin (LED_0_GPIO_Port , LED_0_Pin , GPIO_PIN_RESET );
335
- HAL_GPIO_WritePin (LED_1_GPIO_Port , LED_1_Pin , GPIO_PIN_RESET );
336
- HAL_GPIO_WritePin (LED_2_GPIO_Port , LED_2_Pin , GPIO_PIN_RESET );
337
- break ;
338
- }
339
-
340
253
HAL_GPIO_TogglePin (LED_4_GPIO_Port , LED_4_Pin );
341
254
342
255
#ifdef DATACOLLECTION
@@ -350,8 +263,8 @@ int main(void)
350
263
// printf("%d,%d\r\n", leftDistance, resultaat[left.id].status);
351
264
// printf("L%d, C%d, R%d\r\n", leftDistance, centerDistance, rightDistance);
352
265
int8_t buf ;
353
- HAL_I2C_Slave_Receive_IT (& hi2c2 , & buf , sizeof (buf ));
354
- HAL_Delay (20 );
266
+ // HAL_I2C_Slave_Receive_IT(&hi2c2, &buf, sizeof(buf));
267
+ HAL_Delay (1 );
355
268
}
356
269
/* USER CODE END 3 */
357
270
}
0 commit comments