Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ADT7410 BLE_API mbed nRF51822
Diff: main.cpp
- Revision:
- 5:95238da08cee
- Parent:
- 4:7e5d4a18cd22
- Child:
- 6:84aa3914b00d
diff -r 7e5d4a18cd22 -r 95238da08cee main.cpp
--- a/main.cpp Sat May 20 11:54:14 2017 +0000
+++ b/main.cpp Sat May 20 15:29:47 2017 +0000
@@ -18,7 +18,10 @@
*/
/*
- * The application works with the BlueJelly.js
+ * The application works with the BlueJelly.js
+ *
+ * http://jellyware.jp/
+ *
*/
//======================================================================
@@ -34,18 +37,20 @@
//------------------------------------------------------------
//Definition
//------------------------------------------------------------
-#define TXRX_BUF_LEN 20 //max 20
-#define DEVICE_LOCAL_NAME "BlueJelly!!"
+#define TXRX_BUF_LEN 20 //max 20[byte]
+#define DEVICE_LOCAL_NAME "BlueJelly"
#define ADVERTISING_INTERVAL 160 //160 * 0.625[ms] = 100[ms]
-#define TICKER_TIME 200000 //[us]
-#define ANALOG_IN_PIN P0_4
+#define TICKER_TIME 200000 //200000[us] = 200[ms]
+#define DIGITAL_OUT_PIN P0_9
+#define ANALOG_IN_PIN P0_4
//------------------------------------------------------------
//Object generation
//------------------------------------------------------------
BLE ble;
-AnalogIn ANALOG(ANALOG_IN_PIN);
+DigitalOut LED_SET(DIGITAL_OUT_PIN);
+AnalogIn ANALOG(ANALOG_IN_PIN);
//------------------------------------------------------------
@@ -63,7 +68,7 @@
uint8_t rxPayload[TXRX_BUF_LEN] = {0,};
//Characteristic Property Setting etc
-GattCharacteristic txCharacteristic (tx_uuid, txPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE);
+GattCharacteristic txCharacteristic (tx_uuid, txPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ);
GattCharacteristic rxCharacteristic (rx_uuid, rxPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY| GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ);
GattCharacteristic *myChars[] = {&txCharacteristic, &rxCharacteristic};
@@ -91,8 +96,13 @@
if (Handler->handle == txCharacteristic.getValueAttribute().getHandle())
{
ble.readCharacteristicValue(txCharacteristic.getValueAttribute().getHandle(), buf, &bytesRead);
- memset(txPayload, 0, TXRX_BUF_LEN); //todo
- memcpy(txPayload, buf, TXRX_BUF_LEN); //todo
+ memset(txPayload, 0, TXRX_BUF_LEN);
+ memcpy(txPayload, buf, TXRX_BUF_LEN);
+
+ if(buf[0] == 1)
+ LED_SET = 1;
+ else
+ LED_SET = 0;
}
}
@@ -108,7 +118,7 @@
float s = ANALOG;
uint16_t value = s*1024;
buf[0] = (value >> 8);
- buf[1] = (value);
+ buf[1] = value;
//Send out
ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), buf, 2);