v2

Dependencies:   BLE_API mbed DOOR

Fork of DOOR by Aura-Tech Solutions

Committer:
peteratsl
Date:
Mon Nov 16 23:25:36 2015 +0000
Revision:
70:08932e600a5e
Parent:
69:bc2f5bfe5e33
v1

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 70:08932e600a5e 45 uint16_t minorNumber = 3346;
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 70:08932e600a5e 71 int triger_base = 0;
peteratsl 70:08932e600a5e 72 int sense_base = 0;
peteratsl 69:bc2f5bfe5e33 73
peteratsl 70:08932e600a5e 74 AnalogIn pin_sense_an = P0_5;
peteratsl 70:08932e600a5e 75 PinName pin_sense = P0_5;
peteratsl 70:08932e600a5e 76 PinName pin_triger = P0_10;
peteratsl 69:bc2f5bfe5e33 77
peteratsl 69:bc2f5bfe5e33 78
peteratsl 69:bc2f5bfe5e33 79 //setup led
peteratsl 69:bc2f5bfe5e33 80 DigitalOut led1(P0_19);
peteratsl 69:bc2f5bfe5e33 81
peteratsl 70:08932e600a5e 82 //setup digital input/output
peteratsl 70:08932e600a5e 83 DigitalOut triger(pin_triger);
peteratsl 70:08932e600a5e 84 DigitalIn sensor(pin_sense);
peteratsl 69:bc2f5bfe5e33 85
fallenfate 67:81b595625ce0 86
fallenfate 67:81b595625ce0 87 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason);
fallenfate 67:81b595625ce0 88 void onDataWritten(const GattCharacteristicWriteCBParams *params);
peteratsl 69:bc2f5bfe5e33 89 int flip(char value);
peteratsl 70:08932e600a5e 90 void blinky(void);
peteratsl 69:bc2f5bfe5e33 91 void testAll(void);
fallenfate 67:81b595625ce0 92 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
fallenfate 67:81b595625ce0 93 {
fallenfate 67:81b595625ce0 94 ble.startAdvertising();
fallenfate 67:81b595625ce0 95 }
fallenfate 67:81b595625ce0 96
fallenfate 67:81b595625ce0 97 void onDataWritten(const GattCharacteristicWriteCBParams *params)
fallenfate 67:81b595625ce0 98 {
fallenfate 67:81b595625ce0 99 // TODO - this stuff will need to be retrofitted to deal with string commands
peteratsl 69:bc2f5bfe5e33 100 /*
fallenfate 67:81b595625ce0 101 if(*params->data == 0x33){
fallenfate 67:81b595625ce0 102 led1 = 0;
fallenfate 67:81b595625ce0 103 }
fallenfate 67:81b595625ce0 104 else if(*params->data == 0x34){
fallenfate 67:81b595625ce0 105 led1 = 1;
peteratsl 69:bc2f5bfe5e33 106 }*/
peteratsl 69:bc2f5bfe5e33 107
fallenfate 67:81b595625ce0 108
fallenfate 67:81b595625ce0 109 }
mbedAustin 56:56bc0cab3916 110
ktownsend 0:7613d21e5974 111 int main(void)
ktownsend 0:7613d21e5974 112 {
peteratsl 69:bc2f5bfe5e33 113 /* initialize stuff */
peteratsl 69:bc2f5bfe5e33 114 led1 = 1;
peteratsl 69:bc2f5bfe5e33 115
peteratsl 70:08932e600a5e 116 triger = triger_base = 0;
peteratsl 70:08932e600a5e 117 sense_base = sensor.read();
peteratsl 70:08932e600a5e 118
peteratsl 69:bc2f5bfe5e33 119
peteratsl 69:bc2f5bfe5e33 120
peteratsl 69:bc2f5bfe5e33 121
peteratsl 69:bc2f5bfe5e33 122 //testAll();
fallenfate 67:81b595625ce0 123
Rohit Grover 11:6774f4827024 124 ble.init();
fallenfate 67:81b595625ce0 125
fallenfate 67:81b595625ce0 126 ble.onDisconnection(disconnectionCallback);
fallenfate 67:81b595625ce0 127 ble.onDataWritten(onDataWritten);
fallenfate 67:81b595625ce0 128
fallenfate 67:81b595625ce0 129
fallenfate 67:81b595625ce0 130 uart = new UARTService(ble);
mbedAustin 56:56bc0cab3916 131 iBeaconService ibeacon(ble, uuid, majorNumber, minorNumber, txPower);
mbedAustin 53:f9ec2c7a47f5 132
rgrover1 60:3034dc913ea1 133 ble.setAdvertisingInterval(1000); /* 1000ms. */
Rohit Grover 19:869d8c7306b4 134 ble.startAdvertising();
ktownsend 0:7613d21e5974 135
peteratsl 70:08932e600a5e 136 while(1)
peteratsl 70:08932e600a5e 137 {
peteratsl 70:08932e600a5e 138 //ble.waitForEvent(); // allows or low power operation
peteratsl 70:08932e600a5e 139 if(sensor.read() == !sense_base)
peteratsl 70:08932e600a5e 140 //if(pin_sense_an > 2.5f)
peteratsl 70:08932e600a5e 141 {
peteratsl 70:08932e600a5e 142 triger = !triger_base;
peteratsl 70:08932e600a5e 143 }
peteratsl 70:08932e600a5e 144 else
peteratsl 70:08932e600a5e 145 {
peteratsl 70:08932e600a5e 146 triger = triger_base;
peteratsl 70:08932e600a5e 147 }
ktownsend 0:7613d21e5974 148 }
Rohit Grover 10:391c1acf4b9d 149 }
peteratsl 69:bc2f5bfe5e33 150
peteratsl 69:bc2f5bfe5e33 151 void testAll(void)
peteratsl 69:bc2f5bfe5e33 152 {
peteratsl 69:bc2f5bfe5e33 153 for(int i=0; i<2; i++)
peteratsl 69:bc2f5bfe5e33 154 {
peteratsl 69:bc2f5bfe5e33 155 led1 = !led1;
peteratsl 70:08932e600a5e 156 triger = !triger;
peteratsl 69:bc2f5bfe5e33 157 wait(1);
peteratsl 69:bc2f5bfe5e33 158 }
peteratsl 69:bc2f5bfe5e33 159 }
peteratsl 69:bc2f5bfe5e33 160
peteratsl 69:bc2f5bfe5e33 161 void blinky(void)
peteratsl 69:bc2f5bfe5e33 162 {
peteratsl 69:bc2f5bfe5e33 163 for(int i=0; i<15; i++)
peteratsl 69:bc2f5bfe5e33 164 {
peteratsl 69:bc2f5bfe5e33 165 led1 = !led1;
peteratsl 69:bc2f5bfe5e33 166 wait(.3);
peteratsl 69:bc2f5bfe5e33 167 }
peteratsl 69:bc2f5bfe5e33 168 }
peteratsl 69:bc2f5bfe5e33 169