door
Dependencies: BLE_API mbed DOOR
Fork of BLE_iBeacon_POC by
main.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include "mbed.h" 00018 #include "iBeaconService.h" 00019 #include "UARTService.h" 00020 00021 /** 00022 * For this demo application, populate the beacon advertisement load 00023 * with 2 AD structures: FLAG and MSD (manufacturer specific data). 00024 * 00025 * Reference: 00026 * Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 11, 18 00027 */ 00028 00029 BLEDevice ble; 00030 UARTService *uart; 00031 00032 /** 00033 * The Beacon payload has the following composition: 00034 * 128-Bit / 16byte UUID = E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61 00035 * Major/Minor = 0x1122 / 0x3344 00036 * Tx Power = 0xC8 = 200, 2's compliment is 256-200 = (-56dB) 00037 * 00038 * Note: please remember to calibrate your beacons 00039 * TX Power for more accurate results. 00040 */ 00041 const uint8_t uuid[] = {0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4, 00042 0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x62 00043 }; 00044 uint16_t majorNumber = 1122; 00045 uint16_t minorNumber = 3345; 00046 uint16_t txPower = 0xC8; 00047 00048 00049 const uint8_t b1_id = 0x01; 00050 const uint8_t b2_id = 0x02; 00051 const uint8_t b3_id = 0x03; 00052 const uint8_t b4_id = 0x04; 00053 const uint8_t b5_id = 0x05; 00054 const uint8_t b6_id = 0x06; 00055 const uint8_t b7_id = 0x07; 00056 const uint8_t b8_id = 0x08; 00057 const uint8_t b9_id = 0x09; 00058 const uint8_t b0_id = 0x00; 00059 00060 const uint8_t bA1_id = 0x31; 00061 const uint8_t bA2_id = 0x32; 00062 const uint8_t bA3_id = 0x33; 00063 const uint8_t bA4_id = 0x34; 00064 const uint8_t bA5_id = 0x35; 00065 const uint8_t bA6_id = 0x36; 00066 const uint8_t bA7_id = 0x37; 00067 const uint8_t bA8_id = 0x38; 00068 const uint8_t bA9_id = 0x39; 00069 const uint8_t bA0_id = 0x30; 00070 00071 00072 PinName b1_p = P0_4; 00073 PinName b2_p = P0_5; 00074 PinName b3_p = P0_9; 00075 PinName b4_p = P0_10; 00076 00077 00078 //setup led 00079 DigitalOut led1(P0_19); 00080 00081 //setup digital outs 00082 00083 DigitalOut b1(b1_p); 00084 DigitalOut b2(b2_p); 00085 DigitalOut b3(b3_p); 00086 DigitalOut b4(b4_p); 00087 00088 00089 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason); 00090 void onDataWritten(const GattCharacteristicWriteCBParams *params); 00091 int flip(char value); 00092 void testAll(void); 00093 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) 00094 { 00095 ble.startAdvertising(); 00096 } 00097 00098 void onDataWritten(const GattCharacteristicWriteCBParams *params) 00099 { 00100 // TODO - this stuff will need to be retrofitted to deal with string commands 00101 /* 00102 if(*params->data == 0x33){ 00103 led1 = 0; 00104 } 00105 else if(*params->data == 0x34){ 00106 led1 = 1; 00107 }*/ 00108 00109 flip(params->data[0]); 00110 00111 } 00112 00113 int main(void) 00114 { 00115 /* initialize stuff */ 00116 led1 = 1; 00117 00118 b1 = 0; 00119 b2 = 1; 00120 b3 = 1; 00121 b4 = 1; 00122 00123 00124 00125 //testAll(); 00126 00127 ble.init(); 00128 00129 ble.onDisconnection(disconnectionCallback); 00130 ble.onDataWritten(onDataWritten); 00131 00132 00133 uart = new UARTService(ble); 00134 iBeaconService ibeacon(ble, uuid, majorNumber, minorNumber, txPower); 00135 00136 ble.setAdvertisingInterval(1000); /* 1000ms. */ 00137 ble.startAdvertising(); 00138 00139 while(1) { 00140 ble.waitForEvent(); // allows or low power operation 00141 } 00142 } 00143 00144 void testAll(void) 00145 { 00146 for(int i=0; i<2; i++) 00147 { 00148 led1 = !led1; 00149 b1 = !b1; 00150 b2 = !b2; 00151 b3 = !b3; 00152 b4 = !b4; 00153 /* 00154 b5 = !b5; 00155 b6 = !b6; 00156 b7 = !b7; 00157 b8 = !b5; 00158 b9 = !b6; 00159 b0 = !b7; 00160 */ 00161 wait(1); 00162 } 00163 } 00164 00165 void blinky(void) 00166 { 00167 for(int i=0; i<15; i++) 00168 { 00169 led1 = !led1; 00170 wait(.3); 00171 } 00172 } 00173 00174 int flip(char value) 00175 { 00176 int ret = 0; 00177 00178 00179 switch(value) 00180 { 00181 // close door 00182 case b1_id : 00183 case bA1_id : led1 = !led1; 00184 b1 = 1; 00185 break; 00186 // open door 00187 case b2_id : 00188 case bA2_id : led1 = !led1; 00189 b1 = 0; 00190 break; 00191 // timed open 10 seconds 00192 case b3_id : 00193 case bA3_id : led1 = !led1; 00194 b1 = 0; 00195 wait(10); 00196 b1 = 1; 00197 break; 00198 // light 1 on 00199 case b4_id : 00200 case bA4_id : led1 = !led1; 00201 b2 = 0; 00202 break; 00203 // light 1 off 00204 case b5_id : 00205 case bA5_id : led1 = !led1; 00206 b2 = 1; 00207 break; 00208 // light 2 on 00209 case b6_id : 00210 case bA6_id : led1 = !led1; 00211 b3 = 0; 00212 break; 00213 // light 2 off 00214 case b7_id : 00215 case bA7_id : led1 = !led1; 00216 b3 = 1; 00217 break; 00218 // light 3 on 00219 case b8_id : 00220 case bA8_id : led1 = !led1; 00221 b4 = 0; 00222 break; 00223 // light 3 off 00224 case b9_id : 00225 case bA9_id : led1 = !led1; 00226 b4 = 1; 00227 break; 00228 00229 default : blinky(); 00230 ret = 1; 00231 break; 00232 } 00233 00234 return ret; 00235 }
Generated on Fri Jul 29 2022 09:48:47 by
1.7.2
