
simple project to control mirrorless camera
Dependencies: mbed BLE_API nRF51822
main.cpp@3:38ec35b54db8, 2015-10-22 (annotated)
- Committer:
- vilesovds
- Date:
- Thu Oct 22 19:52:59 2015 +0000
- Revision:
- 3:38ec35b54db8
- Parent:
- 2:ed001667a2b6
added: ServicePower src
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
suhamera | 0:81f1818af032 | 1 | #include "mbed.h" |
vilesovds | 2:ed001667a2b6 | 2 | #include "ble/BLE.h" |
suhamera | 0:81f1818af032 | 3 | |
suhamera | 0:81f1818af032 | 4 | #include "PowerSwitch.h" |
suhamera | 0:81f1818af032 | 5 | #include "Light.h" |
suhamera | 0:81f1818af032 | 6 | |
suhamera | 0:81f1818af032 | 7 | #include "ServicePower.h" |
suhamera | 0:81f1818af032 | 8 | #include "FlashStore.h" |
suhamera | 0:81f1818af032 | 9 | |
vilesovds | 2:ed001667a2b6 | 10 | BLE ble; |
suhamera | 0:81f1818af032 | 11 | PowerSwitch power(p30); |
suhamera | 0:81f1818af032 | 12 | Light light(p6); |
suhamera | 0:81f1818af032 | 13 | |
suhamera | 0:81f1818af032 | 14 | Serial serial(USBTX, USBRX); // tx, rx |
suhamera | 0:81f1818af032 | 15 | FlashStore store(serial); |
suhamera | 0:81f1818af032 | 16 | |
vilesovds | 2:ed001667a2b6 | 17 | void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *){ |
suhamera | 0:81f1818af032 | 18 | ble.startAdvertising(); |
suhamera | 0:81f1818af032 | 19 | serial.printf("BLE Disconnected!\r\n"); |
suhamera | 0:81f1818af032 | 20 | } |
suhamera | 0:81f1818af032 | 21 | |
suhamera | 0:81f1818af032 | 22 | void connectionCallback(const Gap::ConnectionCallbackParams_t *params) |
suhamera | 0:81f1818af032 | 23 | { |
suhamera | 0:81f1818af032 | 24 | serial.printf("BLE Connected!\r\n"); |
suhamera | 0:81f1818af032 | 25 | |
suhamera | 0:81f1818af032 | 26 | } |
suhamera | 0:81f1818af032 | 27 | |
suhamera | 0:81f1818af032 | 28 | |
suhamera | 0:81f1818af032 | 29 | int main(void){ |
suhamera | 0:81f1818af032 | 30 | |
suhamera | 0:81f1818af032 | 31 | ble.init(); |
suhamera | 0:81f1818af032 | 32 | ble.gap().onDisconnection(disconnectionCallback); |
suhamera | 0:81f1818af032 | 33 | ble.gap().onConnection(connectionCallback); |
suhamera | 0:81f1818af032 | 34 | |
vilesovds | 2:ed001667a2b6 | 35 | //ServiceDeviceInformation deviceService(ble, "Seed", "AEAB00", "AEAB00-010000001", NULL, "1.0.0-alfa", NULL); |
suhamera | 0:81f1818af032 | 36 | ServicePower powerService(ble, serial, power, light, store); |
suhamera | 0:81f1818af032 | 37 | |
vilesovds | 3:38ec35b54db8 | 38 | |
vilesovds | 3:38ec35b54db8 | 39 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, |
vilesovds | 3:38ec35b54db8 | 40 | (const uint8_t *)"POWER SWITCH", sizeof("POWER SWITCH") - 1); |
vilesovds | 3:38ec35b54db8 | 41 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, |
vilesovds | 3:38ec35b54db8 | 42 | (const uint8_t *)Power_service_UUID, sizeof(Power_service_UUID)); |
vilesovds | 3:38ec35b54db8 | 43 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); |
vilesovds | 3:38ec35b54db8 | 44 | ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); |
suhamera | 0:81f1818af032 | 45 | |
suhamera | 0:81f1818af032 | 46 | ble.gap().setAdvertisingInterval(1000); |
suhamera | 0:81f1818af032 | 47 | ble.gap().startAdvertising(); |
suhamera | 0:81f1818af032 | 48 | |
suhamera | 0:81f1818af032 | 49 | while (true) { |
suhamera | 0:81f1818af032 | 50 | ble.waitForEvent(); |
suhamera | 0:81f1818af032 | 51 | } |
suhamera | 0:81f1818af032 | 52 | } |