Degree Computation

Dependencies:   aconno_SEGGER_RTT LSM9DS1 Si7006A20 adc52832_common aconnoMPL115A1 aconno_bsp

Committer:
jurica238814
Date:
Fri Dec 14 13:33:03 2018 +0100
Revision:
3:b62a73dc76b7
Parent:
0:442d98af8cc7
Child:
4:cb3513aa9814
All sensors. Cleaner code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jurica238814 0:442d98af8cc7 1 /*
jurica238814 0:442d98af8cc7 2 * aconno.de
jurica238814 0:442d98af8cc7 3 * Made by Jurica Resetar
jurica238814 0:442d98af8cc7 4 * Edited by Karlo Milicevic
jurica238814 0:442d98af8cc7 5 * Edited by Dominik Bartolovic
jurica238814 0:442d98af8cc7 6 * All right reserved
jurica238814 0:442d98af8cc7 7 *
jurica238814 0:442d98af8cc7 8 */
jurica238814 0:442d98af8cc7 9
jurica238814 0:442d98af8cc7 10 #include "mbed.h"
jurica238814 0:442d98af8cc7 11 #include "ble/BLE.h"
jurica238814 0:442d98af8cc7 12 #include "acd52832_bsp.h"
jurica238814 0:442d98af8cc7 13 #include "GapAdvertisingData.h"
jurica238814 0:442d98af8cc7 14 #include "aconnoConfig.h"
jurica238814 0:442d98af8cc7 15 #include "Si7006A20.h"
jurica238814 0:442d98af8cc7 16 #include "LSM9DS1.h"
jurica238814 0:442d98af8cc7 17 #include "adc52832_common/utilities.h"
jurica238814 0:442d98af8cc7 18 #include "acd_nrf52_saadc.h"
jurica238814 0:442d98af8cc7 19 #include "tasks.h"
jurica238814 0:442d98af8cc7 20 #include <events/mbed_events.h>
jurica238814 0:442d98af8cc7 21 #include "aconnoHelpers.h"
jurica238814 0:442d98af8cc7 22
jurica238814 0:442d98af8cc7 23 GapAdvertisingData adv_data = GapAdvertisingData();
jurica238814 0:442d98af8cc7 24 advertising_packet advertisementPacket;
jurica238814 0:442d98af8cc7 25 DigitalOut lightPower(p28);
jurica238814 0:442d98af8cc7 26 DigitalOut temperaturePower(p31);
jurica238814 0:442d98af8cc7 27 DigitalOut shdn(p6);
jurica238814 0:442d98af8cc7 28 DigitalOut power(p2);
jurica238814 0:442d98af8cc7 29
jurica238814 0:442d98af8cc7 30 Thread updateDataThread;
jurica238814 0:442d98af8cc7 31 Thread sendDataThread;
jurica238814 0:442d98af8cc7 32
jurica238814 0:442d98af8cc7 33 EventQueue eventQueue;
jurica238814 0:442d98af8cc7 34
jurica238814 0:442d98af8cc7 35 /**
jurica238814 0:442d98af8cc7 36 * Callback triggered when the ble initialization process has finished
jurica238814 0:442d98af8cc7 37 */
jurica238814 0:442d98af8cc7 38 void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
jurica238814 0:442d98af8cc7 39 {
jurica238814 0:442d98af8cc7 40 BLE &ble = BLE::Instance();
jurica238814 0:442d98af8cc7 41
jurica238814 0:442d98af8cc7 42 advertisementPacket.header = APPLICATION_ID;
jurica238814 0:442d98af8cc7 43 /* setup advertising */
jurica238814 0:442d98af8cc7 44 ble.gap().accumulateAdvertisingPayload(
jurica238814 0:442d98af8cc7 45 GapAdvertisingData::BREDR_NOT_SUPPORTED);
jurica238814 0:442d98af8cc7 46 ble.gap().accumulateAdvertisingPayload(
jurica238814 0:442d98af8cc7 47 GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA,
jurica238814 0:442d98af8cc7 48 (uint8_t *)&advertisementPacket, sizeof(advertisementPacket));
jurica238814 0:442d98af8cc7 49 ble.gap().setAdvertisingType(
jurica238814 0:442d98af8cc7 50 GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
jurica238814 0:442d98af8cc7 51 ble.gap().setAdvertisingInterval(ADV_INTERVAL_MS);
jurica238814 0:442d98af8cc7 52 ble.gap().setTxPower(TX_POWER_DB); // Set TX power to TX_POWER
jurica238814 0:442d98af8cc7 53 }
jurica238814 0:442d98af8cc7 54
jurica238814 0:442d98af8cc7 55 void scheduleBleEventsProcessing(BLE::OnEventsToProcessCallbackContext* context)
jurica238814 0:442d98af8cc7 56 {
jurica238814 0:442d98af8cc7 57 BLE &ble = BLE::Instance();
jurica238814 0:442d98af8cc7 58 eventQueue.call(Callback<void()>(&ble, &BLE::processEvents));
jurica238814 0:442d98af8cc7 59 }
jurica238814 0:442d98af8cc7 60
jurica238814 0:442d98af8cc7 61 int main()
jurica238814 0:442d98af8cc7 62 {
jurica238814 0:442d98af8cc7 63 BLE &ble = BLE::Instance();
jurica238814 0:442d98af8cc7 64 ble.init(bleInitComplete);
jurica238814 0:442d98af8cc7 65 ble.onEventsToProcess(scheduleBleEventsProcessing);
jurica238814 0:442d98af8cc7 66 while (ble.hasInitialized() == false) { /* spin loop */ }
jurica238814 0:442d98af8cc7 67
jurica238814 0:442d98af8cc7 68 updateDataThread.start(updateDataTask);
jurica238814 0:442d98af8cc7 69 sendDataThread.start(sendDataTask);
jurica238814 0:442d98af8cc7 70
jurica238814 0:442d98af8cc7 71 while(true)
jurica238814 0:442d98af8cc7 72 {
jurica238814 0:442d98af8cc7 73 Thread::wait(0xFFFFFFFF);
jurica238814 0:442d98af8cc7 74 }
jurica238814 0:442d98af8cc7 75 }