6
6
******************************************************************************/
7
7
#include "main.h"
8
8
#include "imu.h"
9
- #include <mpu_configuration.h>
9
+ #include "mpu_configuration.h"
10
+ #include "data_builder.h"
10
11
11
12
/*******************************************************************************
12
13
* Definitions
18
19
volatile uint32_t hal_timestamp = 0 ;
19
20
unsigned char * mpl_key = (unsigned char * )"eMPL 5.1" ;
20
21
21
- service_t * service_pointer ;
22
- volatile msg_t pub_msg ;
23
- volatile int pub = LUOS_LAST_STD_CMD ;
24
-
25
22
/*******************************************************************************
26
23
* Function
27
24
******************************************************************************/
@@ -36,6 +33,7 @@ void Imu_Init(void)
36
33
{
37
34
revision_t revision = {.major = 1 , .minor = 0 , .build = 0 };
38
35
mpu_setup ();
36
+ HAL_GPIO_WritePin (GPIOA , LED_Pin , GPIO_PIN_RESET );
39
37
hal .report .quat = 1 ;
40
38
Luos_CreateService (Imu_MsgHandler , IMU_TYPE , "Imu" , revision );
41
39
}
@@ -46,11 +44,15 @@ void Imu_Init(void)
46
44
******************************************************************************/
47
45
void Imu_Loop (void )
48
46
{
47
+ if (!Luos_IsDetected ())
48
+ {
49
+ return ;
50
+ }
51
+
49
52
// *********************IMU management*******************************
50
53
unsigned long sensor_timestamp ;
51
- unsigned long timestamp ;
54
+ unsigned long timestamp = Luos_GetSystick () ;
52
55
int new_data = 0 ;
53
- timestamp = HAL_GetTick ();
54
56
static unsigned char new_temp = 0 ;
55
57
#ifdef COMPASS_ENABLED
56
58
static unsigned char new_compass = 0 ;
@@ -226,11 +228,6 @@ void Imu_Loop(void)
226
228
* rate requested by the host.
227
229
*/
228
230
}
229
- if (hal .update_request == 1 )
230
- {
231
- read_from_mpl (service_pointer );
232
- hal .update_request = 0 ;
233
- }
234
231
}
235
232
/******************************************************************************
236
233
* @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)
242
239
{
243
240
if (msg -> header .cmd == GET_CMD )
244
241
{
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 );
250
245
return ;
251
246
}
252
247
if (msg -> header .cmd == PARAMETERS )
253
248
{
254
- service_pointer = service ;
255
- // fill the message infos
249
+ // Get the message infos
256
250
memcpy (& hal .report , msg -> data , sizeof (short ));
257
- pub = LUOS_LAST_STD_CMD ;
258
251
return ;
259
252
}
260
253
}
@@ -266,12 +259,3 @@ void gyro_data_ready_cb(void)
266
259
{
267
260
hal .new_gyro = 1 ;
268
261
}
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