aconno acnsensa project for iOS devices with iBeacon packets support.
Dependencies: LSM9DS1 Si7006A20 aconno_SEGGER_RTT aconno_bsp adc52832_common
Diff: main.cpp
- Revision:
- 6:51745805d8b0
- Parent:
- 4:634796e5b8c3
- Child:
- 7:7fa0da697c8d
diff -r 4807f549aada -r 51745805d8b0 main.cpp --- a/main.cpp Mon Mar 05 09:40:34 2018 +0000 +++ b/main.cpp Tue Mar 20 08:40:21 2018 +0000 @@ -2,6 +2,7 @@ * aconno.de * Made by Jurica Resetar * Edited by Karlo Milicevic + * Edited by Dominik Bartolovic * All right reserved * */ @@ -34,7 +35,8 @@ #define SPI_MOSI (p3) #define SPI_SCLK (p4) -#define DEBUG_PRINT (0) +#define DEBUG (0) +#define DEBUG_PRINT (1) #define SLEEP_TIME (0.150) /* Sleep time in seconds */ #define WAKE_UP_TIME (0.150) /* Awake time in ms */ #define ADV_INTERVAL (100) /* Advertising interval in ms */ @@ -81,6 +83,7 @@ int16_t gyroscope[3]; int16_t accelerometer[3]; int16_t magnetometer[3]; + uint16_t acc_lsb_value; }; struct{ float temperature; @@ -144,7 +147,7 @@ } uint8_t getBattery(){ - uint16_t batteryVoltage = analogIn.getData()[2]; + uint16_t batteryVoltage = analogIn.getData()[0]; if(batteryVoltage >= 810) return 100; if(batteryVoltage >= 796) return 85; if(batteryVoltage >= 782) return 75; @@ -210,8 +213,12 @@ readGyroscope((vector3_s *)advertisementPacket.gyroscope); readAccelerometer((vector3_s *)advertisementPacket.accelerometer); readMagnetometer((vector3_s *)advertisementPacket.magnetometer); + advertisementPacket.acc_lsb_value = (0xF9E);//(0x3D80); + // ^--- That's in ug cuz MSB is 1 } else{ + analogIn.updateData(); + advertisementPacket.type = 0x01; advertisementPacket.temperature = getTemperature(); advertisementPacket.light = getLight(); @@ -219,13 +226,31 @@ advertisementPacket.pressure = mpl115a1->getPressure(); advertisementPacket.battery = getBattery(); } +#if DEBUG == 0 if(++advertisementType > 2) advertisementType = 0; +#endif adv_data = ble.getAdvertisingData(); adv_data.updateData(adv_data.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(advertisementPacket)); ble.setAdvertisingData(adv_data); } +#if DEBUG +void do_per() +{ + /* + SEND("T: %f\r\nL: %f\r\nH: %f\r\nP: %f\r\nB: %d\r\n", advertisementPacket.temperature, + advertisementPacket.light, + advertisementPacket.humidity, + advertisementPacket.pressure, + advertisementPacket.battery); + */ + + SEND("G: %6d %6d %6d\r\nA: %6d %6d %6d\r\nM: %6d %6d %6d\r\n", advertisementPacket.gyroscope[0], advertisementPacket.gyroscope[1], advertisementPacket.gyroscope[2], + advertisementPacket.accelerometer[0], advertisementPacket.accelerometer[1], advertisementPacket.accelerometer[2], + advertisementPacket.magnetometer[0], advertisementPacket.magnetometer[1], advertisementPacket.magnetometer[2]); +} +#endif int main(){ power = 1; @@ -257,6 +282,11 @@ Ticker ticker; ticker.attach(wakeMeUp, SLEEP_TIME); // Wake the device up +#if DEBUG + Ticker per; + per.attach(do_per, 1); +#endif + while(ble.hasInitialized() == false){ /* spin loop */ }