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
1819volatile uint32_t hal_timestamp = 0 ;
1920unsigned 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 ******************************************************************************/
4745void 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