Degree Computation
Dependencies: aconno_SEGGER_RTT LSM9DS1 Si7006A20 adc52832_common aconnoMPL115A1 aconno_bsp
source/main.cpp@0:442d98af8cc7, 2018-12-12 (annotated)
- Committer:
- jurica238814
- Date:
- Wed Dec 12 19:28:16 2018 +0100
- Revision:
- 0:442d98af8cc7
- Child:
- 3:b62a73dc76b7
Init commit
Who changed what in which revision?
User | Revision | Line number | New 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 | LSM9DS1 *mems; |
jurica238814 | 0:442d98af8cc7 | 26 | DigitalOut lightPower(p28); |
jurica238814 | 0:442d98af8cc7 | 27 | DigitalOut temperaturePower(p31); |
jurica238814 | 0:442d98af8cc7 | 28 | DigitalOut shdn(p6); |
jurica238814 | 0:442d98af8cc7 | 29 | DigitalOut power(p2); |
jurica238814 | 0:442d98af8cc7 | 30 | |
jurica238814 | 0:442d98af8cc7 | 31 | Thread updateDataThread; |
jurica238814 | 0:442d98af8cc7 | 32 | Thread sendDataThread; |
jurica238814 | 0:442d98af8cc7 | 33 | |
jurica238814 | 0:442d98af8cc7 | 34 | EventQueue eventQueue; |
jurica238814 | 0:442d98af8cc7 | 35 | |
jurica238814 | 0:442d98af8cc7 | 36 | /** |
jurica238814 | 0:442d98af8cc7 | 37 | * Callback triggered when the ble initialization process has finished |
jurica238814 | 0:442d98af8cc7 | 38 | */ |
jurica238814 | 0:442d98af8cc7 | 39 | void bleInitComplete(BLE::InitializationCompleteCallbackContext *params) |
jurica238814 | 0:442d98af8cc7 | 40 | { |
jurica238814 | 0:442d98af8cc7 | 41 | BLE &ble = BLE::Instance(); |
jurica238814 | 0:442d98af8cc7 | 42 | |
jurica238814 | 0:442d98af8cc7 | 43 | advertisementPacket.header = APPLICATION_ID; |
jurica238814 | 0:442d98af8cc7 | 44 | /* setup advertising */ |
jurica238814 | 0:442d98af8cc7 | 45 | ble.gap().accumulateAdvertisingPayload( |
jurica238814 | 0:442d98af8cc7 | 46 | GapAdvertisingData::BREDR_NOT_SUPPORTED); |
jurica238814 | 0:442d98af8cc7 | 47 | ble.gap().accumulateAdvertisingPayload( |
jurica238814 | 0:442d98af8cc7 | 48 | GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, |
jurica238814 | 0:442d98af8cc7 | 49 | (uint8_t *)&advertisementPacket, sizeof(advertisementPacket)); |
jurica238814 | 0:442d98af8cc7 | 50 | ble.gap().setAdvertisingType( |
jurica238814 | 0:442d98af8cc7 | 51 | GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED); |
jurica238814 | 0:442d98af8cc7 | 52 | ble.gap().setAdvertisingInterval(ADV_INTERVAL_MS); |
jurica238814 | 0:442d98af8cc7 | 53 | ble.gap().setTxPower(TX_POWER_DB); // Set TX power to TX_POWER |
jurica238814 | 0:442d98af8cc7 | 54 | } |
jurica238814 | 0:442d98af8cc7 | 55 | |
jurica238814 | 0:442d98af8cc7 | 56 | void scheduleBleEventsProcessing(BLE::OnEventsToProcessCallbackContext* context) |
jurica238814 | 0:442d98af8cc7 | 57 | { |
jurica238814 | 0:442d98af8cc7 | 58 | BLE &ble = BLE::Instance(); |
jurica238814 | 0:442d98af8cc7 | 59 | eventQueue.call(Callback<void()>(&ble, &BLE::processEvents)); |
jurica238814 | 0:442d98af8cc7 | 60 | } |
jurica238814 | 0:442d98af8cc7 | 61 | |
jurica238814 | 0:442d98af8cc7 | 62 | int main() |
jurica238814 | 0:442d98af8cc7 | 63 | { |
jurica238814 | 0:442d98af8cc7 | 64 | //printf("Main started.\r\n"); |
jurica238814 | 0:442d98af8cc7 | 65 | |
jurica238814 | 0:442d98af8cc7 | 66 | BLE &ble = BLE::Instance(); |
jurica238814 | 0:442d98af8cc7 | 67 | ble.init(bleInitComplete); |
jurica238814 | 0:442d98af8cc7 | 68 | ble.onEventsToProcess(scheduleBleEventsProcessing); |
jurica238814 | 0:442d98af8cc7 | 69 | while (ble.hasInitialized() == false) { /* spin loop */ } |
jurica238814 | 0:442d98af8cc7 | 70 | |
jurica238814 | 0:442d98af8cc7 | 71 | updateDataThread.start(updateDataTask); |
jurica238814 | 0:442d98af8cc7 | 72 | sendDataThread.start(sendDataTask); |
jurica238814 | 0:442d98af8cc7 | 73 | |
jurica238814 | 0:442d98af8cc7 | 74 | |
jurica238814 | 0:442d98af8cc7 | 75 | /* |
jurica238814 | 0:442d98af8cc7 | 76 | //DigitalOut bar(I2C_DATA); |
jurica238814 | 0:442d98af8cc7 | 77 | //DigitalOut foo(I2C_CLK); |
jurica238814 | 0:442d98af8cc7 | 78 | I2C *i2c; |
jurica238814 | 0:442d98af8cc7 | 79 | float result; |
jurica238814 | 0:442d98af8cc7 | 80 | while(true) |
jurica238814 | 0:442d98af8cc7 | 81 | { |
jurica238814 | 0:442d98af8cc7 | 82 | power = 1; |
jurica238814 | 0:442d98af8cc7 | 83 | ThisThread::sleep_for(500); |
jurica238814 | 0:442d98af8cc7 | 84 | i2c = new I2C(I2C_DATA, I2C_CLK); |
jurica238814 | 0:442d98af8cc7 | 85 | //I2C i2c(I2C_DATA, I2C_CLK); |
jurica238814 | 0:442d98af8cc7 | 86 | Si7006 si(i2c); |
jurica238814 | 0:442d98af8cc7 | 87 | si.getHumidity(&result); |
jurica238814 | 0:442d98af8cc7 | 88 | printf("Humidity is: %f\r\n", result); |
jurica238814 | 0:442d98af8cc7 | 89 | power = 0; |
jurica238814 | 0:442d98af8cc7 | 90 | //wait_ms(1000); |
jurica238814 | 0:442d98af8cc7 | 91 | |
jurica238814 | 0:442d98af8cc7 | 92 | //foo = 1; |
jurica238814 | 0:442d98af8cc7 | 93 | //bar = 1; |
jurica238814 | 0:442d98af8cc7 | 94 | |
jurica238814 | 0:442d98af8cc7 | 95 | //I2C fooI2C(I2C_DATA, I2C_CLK); |
jurica238814 | 0:442d98af8cc7 | 96 | ThisThread::sleep_for(1000); |
jurica238814 | 0:442d98af8cc7 | 97 | } |
jurica238814 | 0:442d98af8cc7 | 98 | */ |
jurica238814 | 0:442d98af8cc7 | 99 | |
jurica238814 | 0:442d98af8cc7 | 100 | while(true) |
jurica238814 | 0:442d98af8cc7 | 101 | { |
jurica238814 | 0:442d98af8cc7 | 102 | Thread::wait(0xFFFFFFFF); |
jurica238814 | 0:442d98af8cc7 | 103 | } |
jurica238814 | 0:442d98af8cc7 | 104 | } |