Dmitry Vilesov / Mbed 2 deprecated power_switch

Dependencies:   mbed BLE_API nRF51822

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "ble/BLE.h"
00003 
00004 #include "PowerSwitch.h"
00005 #include "Light.h"
00006 
00007 #include "ServicePower.h"
00008 #include "FlashStore.h"
00009 
00010 BLE ble;
00011 PowerSwitch power(p30);
00012 Light light(p6);
00013 
00014 Serial serial(USBTX, USBRX); // tx, rx
00015 FlashStore store(serial);
00016                                       
00017 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *){
00018     ble.startAdvertising();
00019     serial.printf("BLE Disconnected!\r\n");
00020 }
00021 
00022 void connectionCallback(const Gap::ConnectionCallbackParams_t *params)
00023 {
00024     serial.printf("BLE Connected!\r\n");
00025     
00026 }
00027 
00028 
00029 int main(void){
00030     
00031     ble.init();
00032     ble.gap().onDisconnection(disconnectionCallback);
00033     ble.gap().onConnection(connectionCallback);
00034 
00035     //ServiceDeviceInformation deviceService(ble, "Seed", "AEAB00", "AEAB00-010000001", NULL, "1.0.0-alfa", NULL);
00036     ServicePower    powerService(ble, serial, power, light, store);  
00037     
00038 
00039     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
00040                                      (const uint8_t *)"POWER SWITCH", sizeof("POWER SWITCH") - 1);
00041     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
00042                                      (const uint8_t *)Power_service_UUID, sizeof(Power_service_UUID));
00043     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);    
00044     ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
00045 
00046     ble.gap().setAdvertisingInterval(1000); 
00047     ble.gap().startAdvertising();          
00048     
00049     while (true) {
00050         ble.waitForEvent(); 
00051     }
00052 }