v2

Dependencies:   BLE_API mbed DOOR

Fork of DOOR by Aura-Tech Solutions

Committer:
peteratsl
Date:
Mon Nov 16 19:10:31 2015 +0000
Revision:
71:468aa9135c41
Parent:
69:bc2f5bfe5e33
Child:
72:371bb75cdd1a
v2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ktownsend 0:7613d21e5974 1 /* mbed Microcontroller Library
ktownsend 0:7613d21e5974 2 * Copyright (c) 2006-2013 ARM Limited
ktownsend 0:7613d21e5974 3 *
ktownsend 0:7613d21e5974 4 * Licensed under the Apache License, Version 2.0 (the "License");
ktownsend 0:7613d21e5974 5 * you may not use this file except in compliance with the License.
ktownsend 0:7613d21e5974 6 * You may obtain a copy of the License at
ktownsend 0:7613d21e5974 7 *
ktownsend 0:7613d21e5974 8 * http://www.apache.org/licenses/LICENSE-2.0
ktownsend 0:7613d21e5974 9 *
ktownsend 0:7613d21e5974 10 * Unless required by applicable law or agreed to in writing, software
ktownsend 0:7613d21e5974 11 * distributed under the License is distributed on an "AS IS" BASIS,
ktownsend 0:7613d21e5974 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ktownsend 0:7613d21e5974 13 * See the License for the specific language governing permissions and
ktownsend 0:7613d21e5974 14 * limitations under the License.
ktownsend 0:7613d21e5974 15 */
ktownsend 0:7613d21e5974 16
ktownsend 0:7613d21e5974 17 #include "mbed.h"
mbedAustin 53:f9ec2c7a47f5 18 #include "iBeaconService.h"
fallenfate 67:81b595625ce0 19 #include "UARTService.h"
ktownsend 0:7613d21e5974 20
mbedAustin 56:56bc0cab3916 21 /**
peteratsl 69:bc2f5bfe5e33 22 * For this demo application, populate the beacon advertisement load
mbedAustin 56:56bc0cab3916 23 * with 2 AD structures: FLAG and MSD (manufacturer specific data).
mbedAustin 56:56bc0cab3916 24 *
mbedAustin 56:56bc0cab3916 25 * Reference:
mbedAustin 56:56bc0cab3916 26 * Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 11, 18
mbedAustin 56:56bc0cab3916 27 */
mbedAustin 56:56bc0cab3916 28
mbedAustin 50:7bc38f01d2d3 29 BLEDevice ble;
fallenfate 67:81b595625ce0 30 UARTService *uart;
mbedAustin 50:7bc38f01d2d3 31
mbedAustin 56:56bc0cab3916 32 /**
mbedAustin 56:56bc0cab3916 33 * The Beacon payload has the following composition:
mbedAustin 56:56bc0cab3916 34 * 128-Bit / 16byte UUID = E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61
mbedAustin 56:56bc0cab3916 35 * Major/Minor = 0x1122 / 0x3344
mbedAustin 56:56bc0cab3916 36 * Tx Power = 0xC8 = 200, 2's compliment is 256-200 = (-56dB)
mbedAustin 56:56bc0cab3916 37 *
mbedAustin 56:56bc0cab3916 38 * Note: please remember to calibrate your beacons
mbedAustin 56:56bc0cab3916 39 * TX Power for more accurate results.
mbedAustin 56:56bc0cab3916 40 */
rgrover1 57:9782cb35c494 41 const uint8_t uuid[] = {0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4,
fallenfate 68:4a8fdfe70ab3 42 0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x62
rgrover1 57:9782cb35c494 43 };
mbedAustin 56:56bc0cab3916 44 uint16_t majorNumber = 1122;
peteratsl 69:bc2f5bfe5e33 45 uint16_t minorNumber = 3345;
mbedAustin 56:56bc0cab3916 46 uint16_t txPower = 0xC8;
peteratsl 69:bc2f5bfe5e33 47
peteratsl 69:bc2f5bfe5e33 48
peteratsl 69:bc2f5bfe5e33 49 const uint8_t b1_id = 0x01;
peteratsl 69:bc2f5bfe5e33 50 const uint8_t b2_id = 0x02;
peteratsl 69:bc2f5bfe5e33 51 const uint8_t b3_id = 0x03;
peteratsl 69:bc2f5bfe5e33 52 const uint8_t b4_id = 0x04;
peteratsl 69:bc2f5bfe5e33 53 const uint8_t b5_id = 0x05;
peteratsl 69:bc2f5bfe5e33 54 const uint8_t b6_id = 0x06;
peteratsl 69:bc2f5bfe5e33 55 const uint8_t b7_id = 0x07;
peteratsl 69:bc2f5bfe5e33 56 const uint8_t b8_id = 0x08;
peteratsl 69:bc2f5bfe5e33 57 const uint8_t b9_id = 0x09;
peteratsl 69:bc2f5bfe5e33 58 const uint8_t b0_id = 0x00;
peteratsl 69:bc2f5bfe5e33 59
peteratsl 69:bc2f5bfe5e33 60 const uint8_t bA1_id = 0x31;
peteratsl 69:bc2f5bfe5e33 61 const uint8_t bA2_id = 0x32;
peteratsl 69:bc2f5bfe5e33 62 const uint8_t bA3_id = 0x33;
peteratsl 69:bc2f5bfe5e33 63 const uint8_t bA4_id = 0x34;
peteratsl 69:bc2f5bfe5e33 64 const uint8_t bA5_id = 0x35;
peteratsl 69:bc2f5bfe5e33 65 const uint8_t bA6_id = 0x36;
peteratsl 69:bc2f5bfe5e33 66 const uint8_t bA7_id = 0x37;
peteratsl 69:bc2f5bfe5e33 67 const uint8_t bA8_id = 0x38;
peteratsl 69:bc2f5bfe5e33 68 const uint8_t bA9_id = 0x39;
peteratsl 69:bc2f5bfe5e33 69 const uint8_t bA0_id = 0x30;
peteratsl 69:bc2f5bfe5e33 70
peteratsl 69:bc2f5bfe5e33 71
peteratsl 69:bc2f5bfe5e33 72 PinName b1_p = P0_4;
peteratsl 69:bc2f5bfe5e33 73 PinName b2_p = P0_5;
peteratsl 69:bc2f5bfe5e33 74 PinName b3_p = P0_9;
peteratsl 69:bc2f5bfe5e33 75 PinName b4_p = P0_10;
peteratsl 69:bc2f5bfe5e33 76
peteratsl 69:bc2f5bfe5e33 77
peteratsl 69:bc2f5bfe5e33 78 //setup led
peteratsl 69:bc2f5bfe5e33 79 DigitalOut led1(P0_19);
peteratsl 69:bc2f5bfe5e33 80
peteratsl 69:bc2f5bfe5e33 81 //setup digital outs
peteratsl 69:bc2f5bfe5e33 82
peteratsl 69:bc2f5bfe5e33 83 DigitalOut b1(b1_p);
peteratsl 69:bc2f5bfe5e33 84 DigitalOut b2(b2_p);
peteratsl 69:bc2f5bfe5e33 85 DigitalOut b3(b3_p);
peteratsl 69:bc2f5bfe5e33 86 DigitalOut b4(b4_p);
peteratsl 69:bc2f5bfe5e33 87
fallenfate 67:81b595625ce0 88
fallenfate 67:81b595625ce0 89 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason);
fallenfate 67:81b595625ce0 90 void onDataWritten(const GattCharacteristicWriteCBParams *params);
peteratsl 69:bc2f5bfe5e33 91 int flip(char value);
peteratsl 69:bc2f5bfe5e33 92 void testAll(void);
fallenfate 67:81b595625ce0 93 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
fallenfate 67:81b595625ce0 94 {
fallenfate 67:81b595625ce0 95 ble.startAdvertising();
fallenfate 67:81b595625ce0 96 }
fallenfate 67:81b595625ce0 97
fallenfate 67:81b595625ce0 98 void onDataWritten(const GattCharacteristicWriteCBParams *params)
fallenfate 67:81b595625ce0 99 {
fallenfate 67:81b595625ce0 100 // TODO - this stuff will need to be retrofitted to deal with string commands
peteratsl 69:bc2f5bfe5e33 101 /*
fallenfate 67:81b595625ce0 102 if(*params->data == 0x33){
fallenfate 67:81b595625ce0 103 led1 = 0;
fallenfate 67:81b595625ce0 104 }
fallenfate 67:81b595625ce0 105 else if(*params->data == 0x34){
fallenfate 67:81b595625ce0 106 led1 = 1;
peteratsl 69:bc2f5bfe5e33 107 }*/
peteratsl 69:bc2f5bfe5e33 108
peteratsl 69:bc2f5bfe5e33 109 flip(params->data[0]);
fallenfate 67:81b595625ce0 110
fallenfate 67:81b595625ce0 111 }
mbedAustin 56:56bc0cab3916 112
ktownsend 0:7613d21e5974 113 int main(void)
ktownsend 0:7613d21e5974 114 {
peteratsl 69:bc2f5bfe5e33 115 /* initialize stuff */
peteratsl 69:bc2f5bfe5e33 116 led1 = 1;
peteratsl 69:bc2f5bfe5e33 117
peteratsl 69:bc2f5bfe5e33 118 b1 = 0;
peteratsl 69:bc2f5bfe5e33 119 b2 = 1;
peteratsl 69:bc2f5bfe5e33 120 b3 = 1;
peteratsl 69:bc2f5bfe5e33 121 b4 = 1;
peteratsl 69:bc2f5bfe5e33 122
peteratsl 69:bc2f5bfe5e33 123
peteratsl 69:bc2f5bfe5e33 124
peteratsl 69:bc2f5bfe5e33 125 //testAll();
fallenfate 67:81b595625ce0 126
Rohit Grover 11:6774f4827024 127 ble.init();
fallenfate 67:81b595625ce0 128
fallenfate 67:81b595625ce0 129 ble.onDisconnection(disconnectionCallback);
fallenfate 67:81b595625ce0 130 ble.onDataWritten(onDataWritten);
fallenfate 67:81b595625ce0 131
fallenfate 67:81b595625ce0 132
fallenfate 67:81b595625ce0 133 uart = new UARTService(ble);
mbedAustin 56:56bc0cab3916 134 iBeaconService ibeacon(ble, uuid, majorNumber, minorNumber, txPower);
mbedAustin 53:f9ec2c7a47f5 135
rgrover1 60:3034dc913ea1 136 ble.setAdvertisingInterval(1000); /* 1000ms. */
Rohit Grover 19:869d8c7306b4 137 ble.startAdvertising();
ktownsend 0:7613d21e5974 138
mbedAustin 56:56bc0cab3916 139 while(1) {
mbedAustin 56:56bc0cab3916 140 ble.waitForEvent(); // allows or low power operation
ktownsend 0:7613d21e5974 141 }
Rohit Grover 10:391c1acf4b9d 142 }
peteratsl 69:bc2f5bfe5e33 143
peteratsl 69:bc2f5bfe5e33 144 void testAll(void)
peteratsl 69:bc2f5bfe5e33 145 {
peteratsl 69:bc2f5bfe5e33 146 for(int i=0; i<2; i++)
peteratsl 69:bc2f5bfe5e33 147 {
peteratsl 69:bc2f5bfe5e33 148 led1 = !led1;
peteratsl 69:bc2f5bfe5e33 149 b1 = !b1;
peteratsl 69:bc2f5bfe5e33 150 b2 = !b2;
peteratsl 69:bc2f5bfe5e33 151 b3 = !b3;
peteratsl 69:bc2f5bfe5e33 152 b4 = !b4;
peteratsl 69:bc2f5bfe5e33 153 /*
peteratsl 69:bc2f5bfe5e33 154 b5 = !b5;
peteratsl 69:bc2f5bfe5e33 155 b6 = !b6;
peteratsl 69:bc2f5bfe5e33 156 b7 = !b7;
peteratsl 69:bc2f5bfe5e33 157 b8 = !b5;
peteratsl 69:bc2f5bfe5e33 158 b9 = !b6;
peteratsl 69:bc2f5bfe5e33 159 b0 = !b7;
peteratsl 69:bc2f5bfe5e33 160 */
peteratsl 69:bc2f5bfe5e33 161 wait(1);
peteratsl 69:bc2f5bfe5e33 162 }
peteratsl 69:bc2f5bfe5e33 163 }
peteratsl 69:bc2f5bfe5e33 164
peteratsl 69:bc2f5bfe5e33 165 void blinky(void)
peteratsl 69:bc2f5bfe5e33 166 {
peteratsl 69:bc2f5bfe5e33 167 for(int i=0; i<15; i++)
peteratsl 69:bc2f5bfe5e33 168 {
peteratsl 69:bc2f5bfe5e33 169 led1 = !led1;
peteratsl 69:bc2f5bfe5e33 170 wait(.3);
peteratsl 69:bc2f5bfe5e33 171 }
peteratsl 69:bc2f5bfe5e33 172 }
peteratsl 69:bc2f5bfe5e33 173
peteratsl 69:bc2f5bfe5e33 174 int flip(char value)
peteratsl 69:bc2f5bfe5e33 175 {
peteratsl 69:bc2f5bfe5e33 176 int ret = 0;
peteratsl 69:bc2f5bfe5e33 177
peteratsl 69:bc2f5bfe5e33 178
peteratsl 69:bc2f5bfe5e33 179 switch(value)
peteratsl 69:bc2f5bfe5e33 180 {
peteratsl 71:468aa9135c41 181 // close door
peteratsl 69:bc2f5bfe5e33 182 case b1_id :
peteratsl 69:bc2f5bfe5e33 183 case bA1_id : led1 = !led1;
peteratsl 69:bc2f5bfe5e33 184 b1 = 1;
peteratsl 69:bc2f5bfe5e33 185 break;
peteratsl 71:468aa9135c41 186 // open door
peteratsl 69:bc2f5bfe5e33 187 case b2_id :
peteratsl 69:bc2f5bfe5e33 188 case bA2_id : led1 = !led1;
peteratsl 69:bc2f5bfe5e33 189 b1 = 0;
peteratsl 69:bc2f5bfe5e33 190 break;
peteratsl 69:bc2f5bfe5e33 191 // timed open 10 seconds
peteratsl 69:bc2f5bfe5e33 192 case b3_id :
peteratsl 69:bc2f5bfe5e33 193 case bA3_id : led1 = !led1;
peteratsl 71:468aa9135c41 194 b1 = 0;
peteratsl 69:bc2f5bfe5e33 195 wait(10);
peteratsl 71:468aa9135c41 196 b1 = 1;
peteratsl 69:bc2f5bfe5e33 197 break;
peteratsl 69:bc2f5bfe5e33 198 // light 1 on
peteratsl 69:bc2f5bfe5e33 199 case b4_id :
peteratsl 69:bc2f5bfe5e33 200 case bA4_id : led1 = !led1;
peteratsl 69:bc2f5bfe5e33 201 b2 = 0;
peteratsl 69:bc2f5bfe5e33 202 break;
peteratsl 69:bc2f5bfe5e33 203 // light 1 off
peteratsl 69:bc2f5bfe5e33 204 case b5_id :
peteratsl 69:bc2f5bfe5e33 205 case bA5_id : led1 = !led1;
peteratsl 69:bc2f5bfe5e33 206 b2 = 1;
peteratsl 69:bc2f5bfe5e33 207 break;
peteratsl 69:bc2f5bfe5e33 208 // light 2 on
peteratsl 69:bc2f5bfe5e33 209 case b6_id :
peteratsl 69:bc2f5bfe5e33 210 case bA6_id : led1 = !led1;
peteratsl 69:bc2f5bfe5e33 211 b3 = 0;
peteratsl 69:bc2f5bfe5e33 212 break;
peteratsl 69:bc2f5bfe5e33 213 // light 2 off
peteratsl 69:bc2f5bfe5e33 214 case b7_id :
peteratsl 69:bc2f5bfe5e33 215 case bA7_id : led1 = !led1;
peteratsl 69:bc2f5bfe5e33 216 b3 = 1;
peteratsl 69:bc2f5bfe5e33 217 break;
peteratsl 69:bc2f5bfe5e33 218 // light 3 on
peteratsl 69:bc2f5bfe5e33 219 case b8_id :
peteratsl 69:bc2f5bfe5e33 220 case bA8_id : led1 = !led1;
peteratsl 69:bc2f5bfe5e33 221 b4 = 0;
peteratsl 69:bc2f5bfe5e33 222 break;
peteratsl 69:bc2f5bfe5e33 223 // light 3 off
peteratsl 69:bc2f5bfe5e33 224 case b9_id :
peteratsl 69:bc2f5bfe5e33 225 case bA9_id : led1 = !led1;
peteratsl 69:bc2f5bfe5e33 226 b4 = 1;
peteratsl 69:bc2f5bfe5e33 227 break;
peteratsl 69:bc2f5bfe5e33 228
peteratsl 69:bc2f5bfe5e33 229 default : blinky();
peteratsl 69:bc2f5bfe5e33 230 ret = 1;
peteratsl 69:bc2f5bfe5e33 231 break;
peteratsl 69:bc2f5bfe5e33 232 }
peteratsl 69:bc2f5bfe5e33 233
peteratsl 69:bc2f5bfe5e33 234 return ret;
peteratsl 69:bc2f5bfe5e33 235 }