Indoor positioning. Central unit.
Dependencies: aconno_SEGGER_RTT
tasks/tasks.cpp@0:07a75b2fae14, 2018-03-06 (annotated)
- Committer:
- jurica238814
- Date:
- Tue Mar 06 09:52:46 2018 +0000
- Revision:
- 0:07a75b2fae14
- Child:
- 1:2bdc506d8baa
Publish commit.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jurica238814 | 0:07a75b2fae14 | 1 | /* |
jurica238814 | 0:07a75b2fae14 | 2 | * |
jurica238814 | 0:07a75b2fae14 | 3 | * |
jurica238814 | 0:07a75b2fae14 | 4 | */ |
jurica238814 | 0:07a75b2fae14 | 5 | |
jurica238814 | 0:07a75b2fae14 | 6 | #include "tasks.h" |
jurica238814 | 0:07a75b2fae14 | 7 | #include "aconno_ble.h" |
jurica238814 | 0:07a75b2fae14 | 8 | |
jurica238814 | 0:07a75b2fae14 | 9 | #if DEBUG_LED |
jurica238814 | 0:07a75b2fae14 | 10 | extern DigitalOut advLed; |
jurica238814 | 0:07a75b2fae14 | 11 | extern DigitalOut scanLed; |
jurica238814 | 0:07a75b2fae14 | 12 | extern DigitalOut periodicLed; |
jurica238814 | 0:07a75b2fae14 | 13 | #endif |
jurica238814 | 0:07a75b2fae14 | 14 | |
jurica238814 | 0:07a75b2fae14 | 15 | void periodicCallback(BLE *ble) |
jurica238814 | 0:07a75b2fae14 | 16 | { |
jurica238814 | 0:07a75b2fae14 | 17 | while(true) |
jurica238814 | 0:07a75b2fae14 | 18 | { |
jurica238814 | 0:07a75b2fae14 | 19 | ble->waitForEvent(); |
jurica238814 | 0:07a75b2fae14 | 20 | #if DEBUG_LED |
jurica238814 | 0:07a75b2fae14 | 21 | periodicLed = !periodicLed; |
jurica238814 | 0:07a75b2fae14 | 22 | #endif |
jurica238814 | 0:07a75b2fae14 | 23 | wait(PERIODIC_CALLBACK_S); |
jurica238814 | 0:07a75b2fae14 | 24 | } |
jurica238814 | 0:07a75b2fae14 | 25 | } |
jurica238814 | 0:07a75b2fae14 | 26 | |
jurica238814 | 0:07a75b2fae14 | 27 | void bleStartAdvertising(BLE *ble) |
jurica238814 | 0:07a75b2fae14 | 28 | { |
jurica238814 | 0:07a75b2fae14 | 29 | while(true) |
jurica238814 | 0:07a75b2fae14 | 30 | { |
jurica238814 | 0:07a75b2fae14 | 31 | ble->gap().startAdvertising(); |
jurica238814 | 0:07a75b2fae14 | 32 | printf("Advertisement started.\r\n"); |
jurica238814 | 0:07a75b2fae14 | 33 | #if DEBUG_LED |
jurica238814 | 0:07a75b2fae14 | 34 | advLed = 0; |
jurica238814 | 0:07a75b2fae14 | 35 | #endif |
jurica238814 | 0:07a75b2fae14 | 36 | wait(ADVERTISING_DURATION_S); |
jurica238814 | 0:07a75b2fae14 | 37 | wait_ms(1000); |
jurica238814 | 0:07a75b2fae14 | 38 | ble->gap().stopAdvertising(); |
jurica238814 | 0:07a75b2fae14 | 39 | printf("Advertisement stopped.\r\n"); |
jurica238814 | 0:07a75b2fae14 | 40 | #if DEBUG_LED |
jurica238814 | 0:07a75b2fae14 | 41 | advLed = 1; |
jurica238814 | 0:07a75b2fae14 | 42 | #endif |
jurica238814 | 0:07a75b2fae14 | 43 | wait(BLE_SLEEP_DURATION_S); |
jurica238814 | 0:07a75b2fae14 | 44 | wait_ms(1000); |
jurica238814 | 0:07a75b2fae14 | 45 | } |
jurica238814 | 0:07a75b2fae14 | 46 | } |
jurica238814 | 0:07a75b2fae14 | 47 | |
jurica238814 | 0:07a75b2fae14 | 48 | void bleStartScanning(BLE *ble) |
jurica238814 | 0:07a75b2fae14 | 49 | { |
jurica238814 | 0:07a75b2fae14 | 50 | while(true) |
jurica238814 | 0:07a75b2fae14 | 51 | { |
jurica238814 | 0:07a75b2fae14 | 52 | ble->gap().setScanParams(1500, 400); |
jurica238814 | 0:07a75b2fae14 | 53 | ble->gap().startScan(advertisementCallback); |
jurica238814 | 0:07a75b2fae14 | 54 | Thread::signal_wait(0x00023456); |
jurica238814 | 0:07a75b2fae14 | 55 | //Thread::signal_clr(ACC_INT_SIG); |
jurica238814 | 0:07a75b2fae14 | 56 | //bleT.signal_set(DISABLE_BLE_SIG); |
jurica238814 | 0:07a75b2fae14 | 57 | } |
jurica238814 | 0:07a75b2fae14 | 58 | } |