Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed nRF51822 MPU6050_lib
Revision 12:dc46aa2edccd, committed 2015-09-22
- Comitter:
- fruediger
- Date:
- Tue Sep 22 10:49:59 2015 +0000
- Parent:
- 11:1412ede83587
- Child:
- 13:496c0f5e8a61
- Commit message:
- last commit before making this a public repository
Changed in this revision
| MPU6050Service.h | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/MPU6050Service.h Tue Sep 08 13:47:25 2015 +0000
+++ b/MPU6050Service.h Tue Sep 22 10:49:59 2015 +0000
@@ -77,18 +77,20 @@
(
BLE &ble,
MPU6050 &mpu6050,
- PinName interruptPin,
+ InterruptIn *interruptIn = NULL,
const SensorData *initialData = NULL,
const MeasuringRange measuringRange = ACCEL_RANGE_2G | GYRO_RANGE_250,
const uint32_t masterClock_us = 0
) :
gattServer(ble.gattServer()),
mpu(mpu6050),
- intIn(interruptPin),
+ intIn(interruptIn),
timer(),
_isRunning(false),
updateSensorDataCharacteristicTrigger(false),
+ updateMotionIndicatorCharacteristicTrigger(false),
+ updateMeasuringRangeTrigger(false),
timerOffset_us(masterClock_us),
@@ -136,7 +138,8 @@
gattServer.onDataSent(this, &MPU6050Service::dataSentCallback);
gattServer.onDataWritten(this, &MPU6050Service::dataWrittenCallback);
- intIn.rise(this, &MPU6050Service::interruptRiseCallback);
+ if (intIn != NULL)
+ intIn->rise(this, &MPU6050Service::interruptRiseCallback);
serviceAdded = true;
}
@@ -186,11 +189,11 @@
}
private:
- static const int MAX_SENSOR_POLLS_PER_UPDATE = 15;
+ static const int MAX_SENSOR_POLLS_PER_UPDATE = 10;
GattServer &gattServer;
MPU6050 &mpu;
- InterruptIn intIn;
+ InterruptIn *intIn;
Timer timer;
volatile bool _isRunning;
--- a/main.cpp Tue Sep 08 13:47:25 2015 +0000
+++ b/main.cpp Tue Sep 22 10:49:59 2015 +0000
@@ -6,7 +6,6 @@
#include "MPU6050Service.h"
#include "PowerService.h"
#include "services/DeviceInformationService.h"
-#include "MPU6050/helpers.h"
/** Constants */
@@ -22,15 +21,25 @@
static const uint16_t maximumConnectionInterval = Gap::MSEC_TO_GAP_DURATION_UNITS(40); // 40ms;
static const uint16_t slaveLatency = 0;
-static const float ledTimeout = 0.05f;
-static const uint8_t connectedBlinkSequ[] = { BYTE(11111111), BYTE(11111111), BYTE(11111111), BYTE(11111111),
- BYTE(11111111), BYTE(11111111), BYTE(11111111), BYTE(11111111),
- BYTE(11111111), BYTE(11111111), BYTE(11111111), BYTE(11000000),
- BYTE(00000000) };
-static const uint8_t disconnectedBlinkSequ[] = { BYTE(11111111), BYTE(11000000), BYTE(00001111), BYTE(11111100),
- BYTE(00000000), BYTE(11111111), BYTE(11000000), BYTE(00001111),
- BYTE(11111100), BYTE(00000000), BYTE(00000000) };
-static const uint8_t batteryCritBlinkSequ[] = { BYTE(11111100), BYTE(00001111), BYTE(11000000) };
+static const float ledTimeout = 0.05f;
+static const float batteryCritBlinkSequ[] = { 0.000f, 0.146f, 0.500f, 0.854f, 1.000f, 0.854f, 0.500f, 0.146f };
+static const float connectedBlinkSequ[] = { 1.000f, 1.000f, 1.000f, 1.000f, 1.000f, 1.000f, 1.000f, 1.000f,
+ 1.000f, 1.000f, 1.000f, 1.000f, 1.000f, 1.000f, 1.000f, 1.000f,
+ 1.000f, 1.000f, 1.000f, 1.000f, 1.000f, 1.000f, 1.000f, 1.000f,
+ 1.000f, 1.000f, 1.000f, 1.000f, 1.000f, 1.000f, 1.000f, 1.000f,
+ 1.000f, 1.000f, 1.000f, 1.000f, 1.000f, 1.000f, 1.000f, 1.000f,
+ 1.000f, 1.000f, 1.000f, 1.000f, 1.000f, 1.000f, 1.000f, 1.000f,
+ 1.000f, 0.962f, 0.854f, 0.691f, 0.500f, 0.309f, 0.146f, 0.038f,
+ 0.000f, 0.038f, 0.146f, 0.309f, 0.500f, 0.691f, 0.854f, 0.962f };
+static const float disconnectedBlinkSequ[] = { 0.000f, 0.038f, 0.146f, 0.309f, 0.500f, 0.691f, 0.854f, 0.962f,
+ 1.000f, 0.962f, 0.854f, 0.691f, 0.500f, 0.309f, 0.146f, 0.038f,
+ 0.000f, 0.038f, 0.146f, 0.309f, 0.500f, 0.691f, 0.854f, 0.962f,
+ 1.000f, 0.962f, 0.854f, 0.691f, 0.500f, 0.309f, 0.146f, 0.038f,
+ 0.000f, 0.038f, 0.146f, 0.309f, 0.500f, 0.691f, 0.854f, 0.962f,
+ 1.000f, 0.962f, 0.854f, 0.691f, 0.500f, 0.309f, 0.146f, 0.038f,
+ 0.000f, 0.000f, 0.000f, 0.000f, 0.000f, 0.000f, 0.000f, 0.000f,
+ 0.000f, 0.000f, 0.000f, 0.000f, 0.000f, 0.000f, 0.000f, 0.000f,
+ 0.000f, 0.000f, 0.000f, 0.000f, 0.000f, 0.000f, 0.000f, 0.000f };
/** Power determination stuff:
*
@@ -89,13 +98,15 @@
MPU6050 mpu(I2C_SDA0, I2C_SCL0, MPU6050::ADDRESS_0);
-DigitalOut btLed(P0_28);
-DigitalOut pwrLed(P0_29);
+PwmOut btLed(P0_28);
+PwmOut pwrLed(P0_29);
DigitalOut aliveLed(LED);
AnalogIn uRef1(P0_4);
AnalogIn uRef2(P0_5);
+InterruptIn intIn(P0_9);
+
Ticker powerAccumulationTicker;
Ticker powerServiceUpdateTicker;
Ticker ledTicker;
@@ -133,8 +144,8 @@
powerServiceUpdateTrigger = false;
powerService->updateVoltage(U0);
- powerService->updateCurrent(I0 * 1000);
- powerService->updateDischarge(Q * 0.277777777f);
+ powerService->updateCurrent(I0 * 1000); // mA
+ powerService->updateDischarge(Q * 0.277777777f); // mAh
}
void powerServiceUpdatePeriodicCallback()
@@ -148,25 +159,28 @@
static bool ledTrigger = false;
static bool batteryCritical = false;
-void ledHandler(Gap &gap, MPU6050Service *mpu)
+void ledHandler(Gap &gap)
{
ledTrigger = false;
- static uint8_t byte = 0;
- static uint8_t bit = 0;
+ static uint32_t cnt = 0;
+ static const int batteryCritBlinkSequSize = sizeof(batteryCritBlinkSequ) / sizeof(float);
+ static const int connectedBlinkSequSize = sizeof(connectedBlinkSequ) / sizeof(float);
+ static const int disconnectedBlinkSequSize = sizeof(disconnectedBlinkSequ) / sizeof(float);
- if (mpu->isRunning())
- aliveLed = !aliveLed;
+ aliveLed = !aliveLed;
if (gap.getState().connected)
- btLed = (connectedBlinkSequ[byte % sizeof(connectedBlinkSequ)] >> bit) & 0x01;
+ btLed = connectedBlinkSequ[cnt % connectedBlinkSequSize];
else
- btLed = (disconnectedBlinkSequ[byte % sizeof(connectedBlinkSequ)] >> bit) & 0x01;
+ btLed = disconnectedBlinkSequ[cnt % disconnectedBlinkSequSize];
if (batteryCritical)
- pwrLed = (batteryCritBlinkSequ[byte % sizeof(batteryCritBlinkSequ)] >> bit) & 0x01;
+ pwrLed = batteryCritBlinkSequ[cnt % batteryCritBlinkSequSize];
else
pwrLed = 1;
+
+ cnt++;
}
void ledPeriodicCallback()
@@ -238,8 +252,8 @@
int main()
{
- btLed = 1;
- pwrLed = 1;
+ btLed = 1.0f;
+ pwrLed = 1.0f;
aliveLed = 0;
ble.init();
@@ -271,9 +285,9 @@
fast.slaveLatency = slaveLatency;
gap.setPreferredConnectionParams(&fast);
- DeviceInformationService deviceInformation(ble, &deviceManufacturers[0], deviceModelNumber, deviceSerialNumber, deviceHardwareRev, deviceFirmwareRev, deviceSoftwareRev);
+ DeviceInformationService deviceInformation(ble, deviceManufacturers, deviceModelNumber, deviceSerialNumber, deviceHardwareRev, deviceFirmwareRev, deviceSoftwareRev);
PowerService powerService(ble);
- MPU6050Service mpu6050(ble, mpu, P0_9);
+ MPU6050Service mpu6050(ble, mpu, &intIn);
gap.startAdvertising();
@@ -285,7 +299,7 @@
powerServiceUpdateHandler(&powerService);
if (ledTrigger)
- ledHandler(gap, &mpu6050);
+ ledHandler(gap);
if (connectionTrigger)
connectionHandler(&mpu6050);
