Skip to content

Commit 7236b1a

Browse files
Merge pull request #498 from Luos-io/fix/imu_cleanup
Clean The IMU code example to fit new Luos implementation.
2 parents 4d20ba7 + ab2e55d commit 7236b1a

File tree

14 files changed

+1351
-1449
lines changed

14 files changed

+1351
-1449
lines changed

examples/projects/l0/gate_serialcom/node_config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
* INIT_TIME | 150 | Wait init time before first detection
108108
******************************************************************************/
109109
#define GATE_BUFF_SIZE 1024
110-
#define PIPE_TX_BUFFER_SIZE 1024
110+
#define PIPE_TX_BUFFER_SIZE 2048
111111
#define PIPE_RX_BUFFER_SIZE 2048
112112

113113
/*******************************************************************************

examples/projects/l0/imu/include/main.h

-18
Original file line numberDiff line numberDiff line change
@@ -93,30 +93,12 @@ void Error_Handler(void);
9393
#define INVEN_INT_EXTI_IRQn EXTI0_1_IRQn
9494
#define CS_Pin GPIO_PIN_1
9595
#define CS_GPIO_Port GPIOA
96-
#define POWER_SENSOR_Pin GPIO_PIN_2
97-
#define POWER_SENSOR_GPIO_Port GPIOA
9896
#define LED_Pin GPIO_PIN_3
9997
#define LED_GPIO_Port GPIOA
100-
#define COM_LVL_DOWN_Pin GPIO_PIN_5
101-
#define COM_LVL_DOWN_GPIO_Port GPIOA
102-
#define COM_LVL_UP_Pin GPIO_PIN_6
103-
#define COM_LVL_UP_GPIO_Port GPIOA
10498
#define SCL_Pin GPIO_PIN_10
10599
#define SCL_GPIO_Port GPIOB
106100
#define SDA_Pin GPIO_PIN_11
107101
#define SDA_GPIO_Port GPIOB
108-
#define PTPB_Pin GPIO_PIN_13
109-
#define PTPB_GPIO_Port GPIOB
110-
#define RX_EN_Pin GPIO_PIN_14
111-
#define RX_EN_GPIO_Port GPIOB
112-
#define TX_EN_Pin GPIO_PIN_15
113-
#define TX_EN_GPIO_Port GPIOB
114-
#define PTPA_Pin GPIO_PIN_8
115-
#define PTPA_GPIO_Port GPIOA
116-
#define COM_TX_Pin GPIO_PIN_9
117-
#define COM_TX_GPIO_Port GPIOA
118-
#define COM_RX_Pin GPIO_PIN_10
119-
#define COM_RX_GPIO_Port GPIOA
120102
/* USER CODE BEGIN Private defines */
121103
#define FIRM_REV "0.5.1"
122104
void gyro_data_ready_cb(void);

examples/projects/l0/imu/lib/Imu/imu.c

+13-29
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
******************************************************************************/
77
#include "main.h"
88
#include "imu.h"
9-
#include <mpu_configuration.h>
9+
#include "mpu_configuration.h"
10+
#include "data_builder.h"
1011

1112
/*******************************************************************************
1213
* Definitions
@@ -18,10 +19,6 @@
1819
volatile uint32_t hal_timestamp = 0;
1920
unsigned char *mpl_key = (unsigned char *)"eMPL 5.1";
2021

21-
service_t *service_pointer;
22-
volatile msg_t pub_msg;
23-
volatile int pub = LUOS_LAST_STD_CMD;
24-
2522
/*******************************************************************************
2623
* Function
2724
******************************************************************************/
@@ -36,6 +33,7 @@ void Imu_Init(void)
3633
{
3734
revision_t revision = {.major = 1, .minor = 0, .build = 0};
3835
mpu_setup();
36+
HAL_GPIO_WritePin(GPIOA, LED_Pin, GPIO_PIN_RESET);
3937
hal.report.quat = 1;
4038
Luos_CreateService(Imu_MsgHandler, IMU_TYPE, "Imu", revision);
4139
}
@@ -46,11 +44,15 @@ void Imu_Init(void)
4644
******************************************************************************/
4745
void Imu_Loop(void)
4846
{
47+
if (!Luos_IsDetected())
48+
{
49+
return;
50+
}
51+
4952
// *********************IMU management*******************************
5053
unsigned long sensor_timestamp;
51-
unsigned long timestamp;
54+
unsigned long timestamp = Luos_GetSystick();
5255
int new_data = 0;
53-
timestamp = HAL_GetTick();
5456
static unsigned char new_temp = 0;
5557
#ifdef COMPASS_ENABLED
5658
static unsigned char new_compass = 0;
@@ -226,11 +228,6 @@ void Imu_Loop(void)
226228
* rate requested by the host.
227229
*/
228230
}
229-
if (hal.update_request == 1)
230-
{
231-
read_from_mpl(service_pointer);
232-
hal.update_request = 0;
233-
}
234231
}
235232
/******************************************************************************
236233
* @brief Msg Handler call back when a msg receive for this service
@@ -242,19 +239,15 @@ static void Imu_MsgHandler(service_t *service, const msg_t *msg)
242239
{
243240
if (msg->header.cmd == GET_CMD)
244241
{
245-
// fill the message infos
246-
hal.update_request = 1;
247-
service_pointer = service;
248-
hal.source_id = msg->header.source;
249-
pub = LUOS_LAST_STD_CMD;
242+
// Fill the message infos
243+
hal.source_id = msg->header.source;
244+
read_from_mpl(service);
250245
return;
251246
}
252247
if (msg->header.cmd == PARAMETERS)
253248
{
254-
service_pointer = service;
255-
// fill the message infos
249+
// Get the message infos
256250
memcpy(&hal.report, msg->data, sizeof(short));
257-
pub = LUOS_LAST_STD_CMD;
258251
return;
259252
}
260253
}
@@ -266,12 +259,3 @@ void gyro_data_ready_cb(void)
266259
{
267260
hal.new_gyro = 1;
268261
}
269-
270-
void HAL_SYSTICK_Callback(void)
271-
{
272-
if (pub != LUOS_LAST_STD_CMD)
273-
{
274-
Luos_SendMsg(service_pointer, (msg_t *)&pub_msg);
275-
pub = LUOS_LAST_STD_CMD;
276-
}
277-
}

0 commit comments

Comments
 (0)