![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
syscom project
Dependencies: BLE_API mbed nRF51822
Fork of nRF51822_SimpleControls by
Diff: main.cpp
- Revision:
- 4:608e9604ca26
- Parent:
- 3:823f105078c7
--- a/main.cpp Thu Jan 07 02:49:37 2016 +0000 +++ b/main.cpp Sun Jan 08 22:06:54 2017 +0000 @@ -21,6 +21,8 @@ #include "ble/BLE.h" #include "Servo.h" #include "GattCallbackParamTypes.h" +#include "ble/FunctionPointerWithContext.h" +#include "BMP085.h" #define BLE_UUID_TXRX_SERVICE 0x0000 /**< The UUID of the Nordic UART Service. */ #define BLE_UUID_TX_CHARACTERISTIC 0x0002 /**< The UUID of the TX Characteristic. */ @@ -32,7 +34,7 @@ #define DIGITAL_IN_PIN P0_5 //A4 #define PWM_PIN P0_16 //D6 #define SERVO_PIN P0_14 //D10 -#define ANALOG_IN_PIN P0_6 //A5 +#define ANALOG_IN_PIN P0_1 //A0 BLE ble; @@ -41,11 +43,14 @@ PwmOut PWM(PWM_PIN); AnalogIn ANALOG(ANALOG_IN_PIN); Servo MYSERVO(SERVO_PIN); +BMP085 myCaptor(P0_29, P0_28); Serial pc(USBTX, USBRX); static uint8_t analog_enabled = 0; static uint8_t old_state = 0; +static uint8_t captor_enabled = 0; +static uint8_t captor_enabled_for_pressure = 0; // The Nordic UART Service static const uint8_t uart_base_uuid[] = {0x71, 0x3D, 0, 0, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E}; @@ -78,6 +83,12 @@ ble.startAdvertising(); } +void confirmationHandler(uint16_t Handler) +{ + if (captor_enabled) + captor_enabled = false; +} + void WrittenHandler(const GattWriteCallbackParams *Handler) { uint8_t buf[TXRX_BUF_LEN]; @@ -101,13 +112,17 @@ } else if(buf[0] == 0xA0) { - if(buf[1] == 0x01) + if(buf[1] == 0x01){ analog_enabled = 1; + captor_enabled = 1; + } else analog_enabled = 0; + } else if(buf[0] == 0x02) { + captor_enabled_for_pressure= 1; float value = (float)buf[1]/255; PWM = value; } @@ -159,6 +174,35 @@ ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), buf, 3); } + if (captor_enabled) + { + // Read and send out + captor_enabled = false; + myCaptor.update(); + float s = myCaptor.get_temperature() * 100; + int value = s; + buf[0] = (value >> 24); + buf[1] = (value >> 16); + buf[2] = (value >> 8); + buf[3] = value; + //for(int i = 0; i < 200000; ++i) + ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), buf, 4); + } + + if (captor_enabled_for_pressure) + { + // Read and send out + captor_enabled_for_pressure = false; + myCaptor.update(); + float s = myCaptor.get_pressure() * 100; + uint32_t value = s; + buf[0] = (value >> 24); + buf[1] = (value >> 16); + buf[2] = (value >> 8); + buf[3] = (uint8_t) value; + ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), buf, 4); + } + // If digital in changes, report the state if (BUTTON != old_state) { @@ -190,6 +234,7 @@ ble.init(); ble.onDisconnection(disconnectionCallback); ble.onDataWritten(WrittenHandler); + ble.onConfirmationReceived(confirmationHandler); pc.baud(9600); pc.printf("SimpleChat Init \r\n");