Skip to content

Commit d7cf141

Browse files
add not working
1 parent 188229e commit d7cf141

File tree

12 files changed

+486
-78
lines changed

12 files changed

+486
-78
lines changed

Code PlatformIO/Gesture Control Bare Bone/platformio.ini

+2
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@
1212
platform = ststm32
1313
board = nucleo_f302r8
1414
framework = stm32cube
15+
test_transport = custom
16+
monitor_speed = 115200

Code PlatformIO/Gesture Control Bare Bone/src/main.c

+109-72
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include "stm32f3xx_hal_rcc_ex.h"
3232
#include "vl53lx_api.h"
3333
#include "stdbool.h"
34+
#include <stdio.h>
35+
#include <string.h>
3436
/* USER CODE END Includes */
3537

3638
/* Private typedef -----------------------------------------------------------*/
@@ -50,10 +52,11 @@
5052
/* Private variables ---------------------------------------------------------*/
5153

5254
/* USER CODE BEGIN PV */
53-
VL53L3CX_Object_t sensor;
54-
long distance = 0;
55-
volatile bool isReady = false;
56-
volatile bool hasRead = false;
55+
56+
57+
long distance[5] = {0,0,0,0,0};
58+
volatile bool isReady[5] = {false, false, false, false, false};
59+
volatile bool hasRead[5] = {false, false, false, false, false};
5760
VL53L3CX_Result_t results;
5861
/* USER CODE END PV */
5962

@@ -65,7 +68,7 @@ void SystemClock_Config(void);
6568

6669
/* Private user code ---------------------------------------------------------*/
6770
/* USER CODE BEGIN 0 */
68-
71+
VL53L3CX_Object_t sensor[];
6972
/* USER CODE END 0 */
7073

7174
/**
@@ -75,21 +78,20 @@ void SystemClock_Config(void);
7578
int main(void)
7679
{
7780
/* USER CODE BEGIN 1 */
78-
7981
/* USER CODE END 1 */
8082

8183
/* MCU Configuration--------------------------------------------------------*/
8284

8385
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
8486
HAL_Init();
85-
87+
HAL_Delay(20);
8688
/* USER CODE BEGIN Init */
8789

8890
/* USER CODE END Init */
8991

9092
/* Configure the system clock */
9193
SystemClock_Config();
92-
94+
HAL_Delay(20);
9395
/* USER CODE BEGIN SysInit */
9496

9597
/* USER CODE END SysInit */
@@ -101,27 +103,12 @@ int main(void)
101103
MX_USART1_UART_Init();
102104
/* USER CODE BEGIN 2 */
103105

104-
sensor.IO.DeInit = CUSTOM_VL53L3CX_I2C_DeInit;
105-
sensor.IO.Init = CUSTOM_VL53L3CX_I2C_Init;
106-
sensor.IO.ReadReg = CUSTOM_VL53L3CX_I2C_ReadReg;
107-
sensor.IO.WriteReg = CUSTOM_VL53L3CX_I2C_WriteReg;
108-
sensor.IO.GetTick = CUSTOM_VL53L3CX_I2C_GetTick;
109-
sensor.IO.Address = 0x52;
110-
111-
HAL_GPIO_WritePin(XSHUT_0_GPIO_Port, XSHUT_0_Pin, 0);
112-
HAL_GPIO_WritePin(XSHUT_1_GPIO_Port, XSHUT_1_Pin, 0);
113-
HAL_GPIO_WritePin(XSHUT_2_GPIO_Port, XSHUT_2_Pin, 0);
114-
HAL_GPIO_WritePin(XSHUT_3_GPIO_Port, XSHUT_3_Pin, 0);
115-
HAL_GPIO_WritePin(XSHUT_4_GPIO_Port, XSHUT_4_Pin, 0);
116-
117-
HAL_Delay(20);
118-
sensor.IsInitialized = 0;
119-
120-
HAL_GPIO_WritePin(XSHUT_4_GPIO_Port, XSHUT_4_Pin, 1);
121-
CUSTOM_VL53L3CX_I2C_Init();
122-
VL53L3CX_Init(&sensor);
123-
VL53L3CX_SetAddress(&sensor, 0x53);
124-
sensor.IO.Address = 0x53;
106+
sensor->IO.DeInit = CUSTOM_VL53L3CX_I2C_DeInit;
107+
sensor->IO.Init = CUSTOM_VL53L3CX_I2C_Init;
108+
sensor->IO.ReadReg = CUSTOM_VL53L3CX_I2C_ReadReg;
109+
sensor->IO.WriteReg = CUSTOM_VL53L3CX_I2C_WriteReg;
110+
sensor->IO.GetTick = CUSTOM_VL53L3CX_I2C_GetTick;
111+
sensor->IO.Address = VL53L3CX_DEVICE_ADDRESS; // Default adres
125112

126113
// Config profile
127114
VL53L3CX_ProfileConfig_t Profile;
@@ -132,57 +119,101 @@ int main(void)
132119
Profile.EnableAmbient = 1; /* Enable: 1, Disable: 0 */
133120
Profile.EnableSignal = 1; /* Enable: 1, Disable: 0 */
134121

135-
VL53L3CX_ConfigProfile(&sensor, &Profile);
122+
HAL_GPIO_WritePin(XSHUT_0_GPIO_Port, XSHUT_0_Pin, 0);
123+
HAL_GPIO_WritePin(XSHUT_1_GPIO_Port, XSHUT_1_Pin, 0);
124+
HAL_GPIO_WritePin(XSHUT_2_GPIO_Port, XSHUT_2_Pin, 0);
125+
HAL_GPIO_WritePin(XSHUT_3_GPIO_Port, XSHUT_3_Pin, 0);
126+
HAL_GPIO_WritePin(XSHUT_4_GPIO_Port, XSHUT_4_Pin, 0);
136127

137-
// Starten
138-
VL53L3CX_Start(&sensor, VL53L3CX_MODE_ASYNC_CONTINUOUS);
128+
CUSTOM_VL53L3CX_I2C_Init();
139129

140-
VL53L3CX_GetDistance(&sensor, &results);
141-
// HAL_Delay(1000);
142-
// VL53L3CX_GetDistance(&sensor, &results);
130+
HAL_Delay(20);
131+
HAL_GPIO_WritePin(XSHUT_0_GPIO_Port, XSHUT_0_Pin, 1);
132+
HAL_Delay(20);
133+
VL53L3CX_Init(&sensor[0]);
134+
HAL_Delay(20);
135+
VL53L3CX_SetAddress(&sensor[0], 0x53);
136+
VL53L3CX_ConfigProfile(&sensor[0], &Profile);
143137

144-
/* USER CODE END 2 */
138+
// Starten sensor 0
139+
VL53L3CX_Start(&sensor[0], VL53L3CX_MODE_ASYNC_CONTINUOUS);
140+
HAL_Delay(20);
141+
VL53L3CX_GetDistance(&sensor[0], &results);
142+
HAL_Delay(20);
145143

146-
/* Infinite loop */
147-
/* USER CODE BEGIN WHILE */
148-
// VL53LX_ClearInterruptAndStartMeasurement(&sensor);
149-
while (1)
144+
// HAL_GPIO_WritePin(XSHUT_1_GPIO_Port, XSHUT_1_Pin, 1);
145+
// HAL_Delay(20);
146+
// VL53L3CX_Init(&sensor[1]);
147+
// HAL_Delay(20);
148+
// VL53L3CX_SetAddress(&sensor[1], 0x54);
149+
150+
// HAL_Delay(20);
151+
152+
// sensor.IO.Address = address[1];
153+
// VL53L3CX_ConfigProfile(&sensor, &Profile);
154+
155+
// // Starten sensor 1
156+
// sensor.IO.Address = address[1];
157+
// sensor.IsRanging = (uint8_t)isRanging[1];
158+
// VL53L3CX_Start(&sensor, VL53L3CX_MODE_ASYNC_CONTINUOUS);
159+
// isRanging[1] = true;
160+
// HAL_Delay(20);
161+
// VL53L3CX_GetDistance(&sensor, &results);
162+
// HAL_Delay(1000);
163+
// VL53L3CX_GetDistance(&sensor, &results);
164+
165+
/* USER CODE END 2 */
166+
167+
/* Infinite loop */
168+
/* USER CODE BEGIN WHILE */
169+
// VL53LX_ClearInterruptAndStartMeasurement(&sensor);
170+
while (1)
150171
{
151172
/* USER CODE END WHILE */
152173
// VL53L3CX_GetDistance(&sensor, &results);
153-
// printf("distance: %4d\r\n", (long)results.ZoneResult[0].Distance[0]);
154-
if (isReady || (!isReady && !HAL_GPIO_ReadPin(GPIOI_4_Pin, GPIOI_4_GPIO_Port)))
174+
HAL_Delay(5);
175+
if (isReady[0] || (!isReady[0] && !HAL_GPIO_ReadPin(GPIOI_0_GPIO_Port, GPIOI_0_Pin)))
155176
{
156-
isReady = false;
157-
VL53L3CX_GetDistance(&sensor, &results);
158177
HAL_Delay(1);
159-
distance = (long)results.ZoneResult[0].Distance[0];
178+
isReady[0] = false;
179+
180+
VL53L3CX_GetDistance(&sensor[0], &results);
181+
HAL_Delay(1);
182+
distance[0] = (long)results.ZoneResult[0].Distance[0];
183+
}
184+
if (isReady[1] || (!isReady[1] && !HAL_GPIO_ReadPin(GPIOI_1_GPIO_Port, GPIOI_1_Pin)))
185+
{
186+
HAL_Delay(1);
187+
isReady[1] = false;
188+
VL53L3CX_GetDistance(&sensor[1], &results);
189+
HAL_Delay(1);
190+
distance[1] = (long)results.ZoneResult[0].Distance[0];
160191
}
161192

162-
if (distance >= 50 && distance <= 300)
193+
if (distance[0] >= 50 && distance[0] <= 300)
163194
{
164195
HAL_GPIO_WritePin(LED_0_GPIO_Port, LED_0_Pin, 1);
165196
HAL_Delay(200);
166197
}
167198

168-
if (distance > 300 && distance <= 600)
199+
if (distance[0] > 300 && distance[0] <= 600)
169200
{
170201
HAL_GPIO_WritePin(LED_1_GPIO_Port, LED_1_Pin, 1);
171202
HAL_Delay(200);
172203
}
173204

174-
if (distance > 600 && distance <= 800)
205+
if (distance[0] > 600 && distance[0] <= 800)
175206
{
176207
HAL_GPIO_WritePin(LED_2_GPIO_Port, LED_2_Pin, 1);
177208
HAL_Delay(200);
178209
}
179210

180-
if (distance > 800 && distance <= 1200)
211+
if (distance[0] > 800 && distance[0] <= 1200)
181212
{
182213
HAL_GPIO_WritePin(LED_3_GPIO_Port, LED_3_Pin, 1);
183214
HAL_Delay(200);
184215
}
185-
if (distance > 1200)
216+
if (distance[0] > 1200)
186217
{
187218
HAL_GPIO_WritePin(LED_4_GPIO_Port, LED_4_Pin, 1);
188219
HAL_Delay(200);
@@ -194,6 +225,8 @@ int main(void)
194225
HAL_GPIO_WritePin(LED_2_GPIO_Port, LED_2_Pin, 0);
195226
HAL_GPIO_WritePin(LED_3_GPIO_Port, LED_3_Pin, 0);
196227
HAL_GPIO_WritePin(LED_4_GPIO_Port, LED_4_Pin, 0);
228+
229+
printf("distance 0: %4d\tdistance 1: %4d\r\n", distance[0], distance[1]);
197230
/* USER CODE BEGIN 3 */
198231
}
199232
/* USER CODE END 3 */
@@ -254,8 +287,7 @@ int _write(int file, char *data, int len)
254287
}
255288

256289
// arbitrary timeout 1000
257-
HAL_StatusTypeDef status =
258-
HAL_UART_Transmit(&huart2, (uint8_t *)data, len, 1000);
290+
HAL_StatusTypeDef status = HAL_UART_Transmit(&huart1, (uint8_t *)data, len, 1000);
259291

260292
// return # of bytes written - as best we can tell
261293
return (status == HAL_OK ? len : 0);
@@ -266,53 +298,58 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
266298
switch (GPIO_Pin)
267299
{
268300
case GPIOI_0_Pin:
269-
if (!hasRead)
301+
if (!hasRead[0])
270302
{
271-
hasRead = true;
272-
VL53L3CX_GetDistance(&sensor, &results);
303+
hasRead[0] = true;
304+
// sensor.IO.Address = address[0];
305+
// VL53L3CX_GetDistance(&sensor, &results);
273306
}
274307
else
275-
isReady = true;
308+
isReady[0] = true;
276309
break;
277310

278311
case GPIOI_1_Pin:
279-
if (!hasRead)
312+
if (!hasRead[1])
280313
{
281-
hasRead = true;
282-
VL53L3CX_GetDistance(&sensor, &results);
314+
hasRead[1] = true;
315+
// sensor.IO.Address = address[1];
316+
// VL53L3CX_GetDistance(&sensor, &results);
283317
}
284318
else
285-
isReady = true;
319+
isReady[1] = true;
286320
break;
287321

288322
case GPIOI_2_Pin:
289-
if (!hasRead)
323+
if (!hasRead[2])
290324
{
291-
hasRead = true;
292-
VL53L3CX_GetDistance(&sensor, &results);
325+
hasRead[2] = true;
326+
// sensor.IO.Address = address[2];
327+
// VL53L3CX_GetDistance(&sensor, &results);
293328
}
294329
else
295-
isReady = true;
330+
isReady[2] = true;
296331
break;
297332

298333
case GPIOI_3_Pin:
299-
if (!hasRead)
334+
if (!hasRead[3])
300335
{
301-
hasRead = true;
302-
VL53L3CX_GetDistance(&sensor, &results);
336+
hasRead[3] = true;
337+
// sensor.IO.Address = address[3];
338+
// VL53L3CX_GetDistance(&sensor, &results);
303339
}
304340
else
305-
isReady = true;
341+
isReady[3] = true;
306342
break;
307343

308344
case GPIOI_4_Pin:
309-
if (!hasRead)
345+
if (!hasRead[4])
310346
{
311-
hasRead = true;
312-
VL53L3CX_GetDistance(&sensor, &results);
347+
hasRead[4] = true;
348+
// sensor.IO.Address = address[4];
349+
// VL53L3CX_GetDistance(&sensor, &results);
313350
}
314351
else
315-
isReady = true;
352+
isReady[4] = true;
316353
break;
317354
default:
318355
break;

Code PlatformIO/Gesture Control Bare Bone/src/usart.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,17 @@ void MX_USART1_UART_Init(void)
4040

4141
/* USER CODE END USART1_Init 1 */
4242
huart1.Instance = USART1;
43-
huart1.Init.BaudRate = 38400;
43+
huart1.Init.BaudRate = 115200;
4444
huart1.Init.WordLength = UART_WORDLENGTH_8B;
4545
huart1.Init.StopBits = UART_STOPBITS_1;
4646
huart1.Init.Parity = UART_PARITY_NONE;
4747
huart1.Init.Mode = UART_MODE_TX_RX;
48-
huart1.Init.HwFlowCtl = UART_HWCONTROL_RTS_CTS;
48+
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
4949
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
5050
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
51-
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
51+
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_SWAP_INIT;
52+
huart1.AdvancedInit.Swap = UART_ADVFEATURE_SWAP_ENABLE;
53+
5254
if (HAL_UART_Init(&huart1) != HAL_OK)
5355
{
5456
Error_Handler();

0 commit comments

Comments
 (0)