Petr Manas / Mbed OS pdiot-f-mbed

Dependencies:   MPU9250

Files at this revision

API Documentation at this revision

Comitter:
brano2
Date:
Tue Nov 05 13:54:48 2019 +0000
Parent:
7:db23f12fcd02
Commit message:
Print acceleration at slow rate

Changed in this revision

source/main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/source/main.cpp	Tue Nov 05 13:36:16 2019 +0000
+++ b/source/main.cpp	Tue Nov 05 13:54:48 2019 +0000
@@ -58,6 +58,7 @@
         
 
         _event_queue.call_every(50, this, &BatteryDemo::send_acceleration);
+        _event_queue.call_every(2000, this, &BatteryDemo::print_last_acceleration);
         _event_queue.call_every(500, this, &BatteryDemo::blink);
         _event_queue.call_every(1000, this, &BatteryDemo::update_sensor_value);
 
@@ -137,16 +138,15 @@
     }
     
     void send_acceleration() {
-//        printf("Hello world!\n");
-        int16_t acc[3] = {0,0,0};
-        _mpu.readAccelData(acc);
+        _mpu.readAccelData(_acc);
+        _imu_service->updateImuState(_acc);
+//        _event_queue.call(Callback<void(int16_t*)>(_imu_service, &ImuService::updateImuState), acc);
+    }
+    
+    void print_last_acceleration() {
         float scale = _mpu.aRes;
-//        printf("acc: %f, %f, %f\r\n",
-//               acc[0]*scale, acc[1]*scale, acc[2]*scale);
-//        printf("acc: %d, %d, %d\r\n",
-//               acc[0], acc[1], acc[2]);
-        _imu_service->updateImuState(acc);
-//        _event_queue.call(Callback<void(int16_t*)>(_imu_service, &ImuService::updateImuState), acc);
+        printf("acc: %f, %f, %f\r\n",
+               _acc[0]*scale, _acc[1]*scale, _acc[2]*scale);
     }
 
     void blink(void) {
@@ -174,6 +174,7 @@
     
     MPU9250 _mpu;
     ImuService* _imu_service;
+    int16_t _acc[3] = {0,0,0};
 };
 
 /** Schedule processing of events from the BLE middleware in the event queue. */