Aura-Tech Solutions / Mbed 2 deprecated FLOOD

Dependencies:   BLE_API mbed DOOR

Fork of DOOR by Aura-Tech Solutions

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

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 #include "stdbool.h"
00021 
00022 /**
00023  * For this demo application, populate the beacon advertisement load
00024  * with 2 AD structures: FLAG and MSD (manufacturer specific data).
00025  *
00026  * Reference:
00027  *  Bluetooth Core Specification 4.0 (Vol. 3), Part C, Section 11, 18
00028  */
00029 
00030 BLEDevice ble;
00031 UARTService *uart;
00032 
00033 /**
00034  * The Beacon payload has the following composition:
00035  * 128-Bit / 16byte UUID = E2 0A 39 F4 73 F5 4B C4 A1 2F 17 D1 AD 07 A9 61
00036  * Major/Minor  = 0x1122 / 0x3344
00037  * Tx Power     = 0xC8 = 200, 2's compliment is 256-200 = (-56dB)
00038  *
00039  * Note: please remember to calibrate your beacons
00040  * TX Power for more accurate results.
00041  */
00042 const uint8_t uuid[] = {0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4,
00043                         0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x62
00044                        };
00045 uint16_t majorNumber = 1122;
00046 uint16_t minorNumber = 3346;
00047 uint16_t txPower = 0xC8;
00048 
00049 
00050 const uint8_t b1_id   = 0x01;
00051 const uint8_t bA1_id  = 0x31;
00052 
00053 
00054 PinName sensor_pin         = P0_5;
00055 PinName trigger_pin        = P0_10;
00056 
00057 const _Bool turn_on = 0;
00058 const _Bool turn_off = 1;
00059 
00060 //setup led
00061 DigitalOut led1(P0_19);
00062 
00063 //setup digital ins/outs
00064 DigitalIn digi_sensor(sensor_pin);
00065 DigitalOut digi_trigger(trigger_pin);
00066 
00067 //set interrupt pin
00068 InterruptIn intrpt_sensor(sensor_pin);
00069 
00070 
00071 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason);
00072 void onDataWritten(const GattCharacteristicWriteCBParams *params);
00073 int flip(char value);
00074 void testAll(void);
00075 void signal_off(void);
00076 void signal_on(void);
00077 
00078 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
00079 {
00080     ble.startAdvertising();
00081 }
00082 
00083 void onDataWritten(const GattCharacteristicWriteCBParams *params)
00084 {
00085 
00086 }
00087 
00088 void signal_off(void)
00089 {
00090     digi_trigger = turn_off;
00091     wait(.5);
00092     //ble.updateCharacteristicValue(readChar.getValueHandle(),"OFF",sizeof("OFF"));
00093 }
00094 
00095 void signal_on(void)
00096 {
00097     digi_trigger = turn_on;
00098     wait(.5);
00099 }
00100 
00101 
00102 int main(void)
00103 {
00104     /* initialize stuff */
00105     led1 = 1;
00106 
00107     
00108     ble.init();
00109     digi_trigger = turn_on;
00110     
00111     
00112     ble.onDisconnection(disconnectionCallback);
00113     ble.onDataWritten(onDataWritten);
00114     uart = new UARTService(ble);    
00115     iBeaconService ibeacon(ble, uuid, majorNumber, minorNumber, txPower);
00116     ble.setAdvertisingInterval(1000); /* 1000ms. */
00117     ble.startAdvertising();
00118 
00119     while(1)
00120     {
00121         intrpt_sensor.rise(&signal_on);
00122         intrpt_sensor.fall(&signal_off);
00123         ble.waitForEvent(); // allows or low power operation
00124     }
00125 }
00126 
00127 void testAll(void)
00128 {
00129     for(int i=0; i<2; i++)    
00130     {
00131         led1 = !led1;
00132         digi_trigger = !digi_trigger;
00133         wait(1);
00134     }
00135 }
00136 
00137 void blinky(void)
00138 {
00139     for(int i=0; i<15; i++)    
00140     {
00141         led1 = !led1;
00142         wait(.3);
00143     }
00144 }
00145 
00146 int flip(char value)
00147 {
00148     int ret = 0;
00149 /*    
00150     
00151     switch(value)
00152     {
00153         // close door
00154         case b1_id  :
00155         case bA1_id :       led1 = !led1;
00156                             b1 = 1;
00157                             break;
00158         // open door
00159         case b2_id  :
00160         case bA2_id :       led1 = !led1;
00161                             b1 = 0;
00162                             break;
00163         // timed open 10 seconds
00164         case b3_id  :
00165         case bA3_id :       led1 = !led1;
00166                             b1 = 0;
00167                             wait(10);
00168                             b1 = 1;
00169                             break;
00170         // light 1 on
00171         case b4_id  :
00172         case bA4_id :       led1 = !led1;
00173                             b2 = 0;
00174                             break;
00175         // light 1 off
00176         case b5_id  :
00177         case bA5_id :       led1 = !led1;
00178                             b2 = 1;
00179                             break;
00180         // light 2 on
00181         case b6_id  :
00182         case bA6_id :       led1 = !led1;
00183                             b3 = 0;
00184                             break;
00185         // light 2 off
00186         case b7_id  :
00187         case bA7_id :       led1 = !led1;
00188                             b3 = 1;
00189                             break;
00190         // light 3 on
00191         case b8_id  :
00192         case bA8_id :       led1 = !led1;
00193                             b4 = 0;
00194                             break;
00195         // light 3 off
00196         case b9_id  :
00197         case bA9_id :       led1 = !led1;
00198                             b4 = 1;
00199                             break;
00200                             
00201         default :           blinky();
00202                             ret = 1;
00203                             break;
00204     }
00205 */
00206     return ret;
00207 }