First Commit
Dependencies: mbed BLE_API nRF51822
Diff: main.cpp
- Revision:
- 6:1841ac6f3a87
- Parent:
- 5:95238da08cee
- Child:
- 7:176395d8287a
--- a/main.cpp Sat May 20 15:29:47 2017 +0000 +++ b/main.cpp Sat Dec 29 02:36:34 2018 +0000 @@ -1,32 +1,3 @@ -/* - -Copyright (c) 2012-2014 RedBearLab - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software -and associated documentation files (the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, -and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR -PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE -FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -*/ - -/* - * The application works with the BlueJelly.js - * - * http://jellyware.jp/ - * - */ - -//====================================================================== -//Grobal -//====================================================================== //------------------------------------------------------------ //Include Header Files //------------------------------------------------------------ @@ -38,7 +9,7 @@ //Definition //------------------------------------------------------------ #define TXRX_BUF_LEN 20 //max 20[byte] -#define DEVICE_LOCAL_NAME "BlueJelly" +#define DEVICE_LOCAL_NAME "NampassCar" #define ADVERTISING_INTERVAL 160 //160 * 0.625[ms] = 100[ms] #define TICKER_TIME 200000 //200000[us] = 200[ms] #define DIGITAL_OUT_PIN P0_9 @@ -49,8 +20,9 @@ //Object generation //------------------------------------------------------------ BLE ble; -DigitalOut LED_SET(DIGITAL_OUT_PIN); -AnalogIn ANALOG(ANALOG_IN_PIN); +DigitalOut ForwardPin(P0_6); +DigitalOut BackPin(P0_7); +AnalogIn ANALOG(ANALOG_IN_PIN); //------------------------------------------------------------ @@ -85,12 +57,23 @@ } +bool checkBuffMatch(uint8_t *buf1, uint8_t *buf2, uint8_t length){ + for(int i = 0; i < length; i++){ + if(*(buf1 + i) != *(buf2 + i)) return false; + } + + return true; +} + //====================================================================== //onDataWritten //====================================================================== void WrittenHandler(const GattWriteCallbackParams *Handler) { - uint8_t buf[TXRX_BUF_LEN]; + uint8_t ForwardComm[4] = {4, 1, 2, 6}; + uint8_t BackComm[4] = {6, 2, 1, 4}; + + uint8_t buf[4] = {0}; uint16_t bytesRead; if (Handler->handle == txCharacteristic.getValueAttribute().getHandle()) @@ -99,10 +82,21 @@ memset(txPayload, 0, TXRX_BUF_LEN); memcpy(txPayload, buf, TXRX_BUF_LEN); - if(buf[0] == 1) - LED_SET = 1; - else - LED_SET = 0; + if(checkBuffMatch(buf, ForwardComm, 4)){ + ForwardPin = 1; + BackPin = 0; + wait(1); + BackPin = 0; + ForwardPin = 0; + }else if(checkBuffMatch(buf, BackComm, 4)){ + ForwardPin = 0; + BackPin = 1; + wait(1); + BackPin = 0; + ForwardPin = 0; + }else{ + printf("failed\r\n"); + } } }