
simple project to control mirrorless camera
Dependencies: mbed BLE_API nRF51822
main.cpp@2:ed001667a2b6, 2015-10-22 (annotated)
- Committer:
- vilesovds
- Date:
- Thu Oct 22 09:08:15 2015 +0000
- Revision:
- 2:ed001667a2b6
- Parent:
- 0:81f1818af032
- Child:
- 3:38ec35b54db8
move to 128 bit UUID. Attempt to add Power Service
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 | |
suhamera | 0:81f1818af032 | 38 | static const uint16_t bleservices_uuid16_list[] = {GattService::UUID_DEVICE_INFORMATION_SERVICE, GattService::UUID_SCAN_PARAMETERS_SERVICE}; |
suhamera | 0:81f1818af032 | 39 | |
suhamera | 0:81f1818af032 | 40 | ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)bleservices_uuid16_list, sizeof(bleservices_uuid16_list)); |
suhamera | 0:81f1818af032 | 41 | ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); |
suhamera | 0:81f1818af032 | 42 | ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); |
suhamera | 0:81f1818af032 | 43 | |
suhamera | 0:81f1818af032 | 44 | ble.gap().setAdvertisingInterval(1000); |
suhamera | 0:81f1818af032 | 45 | ble.gap().startAdvertising(); |
suhamera | 0:81f1818af032 | 46 | |
suhamera | 0:81f1818af032 | 47 | while (true) { |
suhamera | 0:81f1818af032 | 48 | ble.waitForEvent(); |
suhamera | 0:81f1818af032 | 49 | } |
suhamera | 0:81f1818af032 | 50 | } |