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: BLE_API TxIR mbed nRF51822
Fork of ir-puck by
Revision 0:c94311378ec1, committed 2014-07-02
- Comitter:
- sigveseb
- Date:
- Wed Jul 02 10:48:58 2014 +0000
- Child:
- 1:6ba27220d1da
- Commit message:
- .
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BLE_API.lib Wed Jul 02 10:48:58 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#6f4c8e545d38
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/IR.cpp Wed Jul 02 10:48:58 2014 +0000
@@ -0,0 +1,37 @@
+#include "mbed.h"
+#include "IR.h"
+#include "TxIR.hpp"
+
+#define WORD(x, i) ((x)[(i)] << 8 | (x)[(i) + 1])
+
+TxIR txir(p14);
+Serial px(USBTX, USBRX);
+
+void fireIRCode(uint8_t* header, uint8_t* one, uint8_t* zero, uint8_t* ptrail, uint8_t* predata, uint8_t* code) {
+ px.printf("Going to fire.\n");
+ int raw_codes_length = 67;
+ unsigned raw_codes[raw_codes_length];
+ raw_codes[0] = WORD(header, 0);
+ raw_codes[1] = WORD(header, 2);
+ int offset = 2;
+ for(int i = 0; i < 16 * 2; i += 2) {
+ int bit = predata[i / 16] & 0x80;
+ uint8_t* signal = bit ? one : zero;
+ raw_codes[i + offset] = WORD(signal, 0);
+ raw_codes[i + offset + 1] = WORD(signal, 2);
+ predata[i / 16] <<= 1;
+ }
+ offset = 34;
+ for(int i = 0; i < 16 * 2; i += 2) {
+ int bit = code[i / 16] & 0x80;
+ uint8_t* signal = bit ? one : zero;
+ raw_codes[i + offset] = WORD(signal, 0);
+ raw_codes[i + offset + 1] = WORD(signal, 2);
+ code[i / 16] <<= 1;
+ }
+ raw_codes[67] = WORD(ptrail, 0);
+
+ txir.txSeq(26.32 / 1000000.0, 67, raw_codes);
+
+ px.printf("Wrote message :)\n");
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/IR.h Wed Jul 02 10:48:58 2014 +0000 @@ -0,0 +1,6 @@ +#ifndef __IR_H__ +#define __IR_H__ + +void fireIRCode(uint8_t* header, uint8_t* one, uint8_t* zero, uint8_t* ptrail, uint8_t* predata, uint8_t* code); + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TxIR.lib Wed Jul 02 10:48:58 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/Nordic-Pucks/code/TxIR/#cc8371213c85
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ir_service.cpp Wed Jul 02 10:48:58 2014 +0000
@@ -0,0 +1,40 @@
+#include "BLEDevice.h"
+
+uint8_t uuid_array_service[16] = {'b', 'f', 't', 'j', ' ', 'i', 'r', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '};
+uint8_t uuid_array_header[16] = {'b', 'f', 't', 'j', ' ', 'i', 'r', ' ', 'h', 'e', 'a', 'd', 'e', 'r', ' ', ' '};
+uint8_t uuid_array_one[16] = {'b', 'f', 't', 'j', ' ', 'i', 'r', ' ', 'o', 'n', 'e', ' ', ' ', ' ', ' ', ' '};
+uint8_t uuid_array_zero[16] = {'b', 'f', 't', 'j', ' ', 'i', 'r', ' ', 'z', 'e', 'r', 'o', ' ', ' ', ' ', ' '};
+uint8_t uuid_array_ptrail[16] = {'b', 'f', 't', 'j', ' ', 'i', 'r', ' ', 'p', 't', 'r', 'a', 'i', 'l', ' ', ' '};
+uint8_t uuid_array_predata[16] = {'b', 'f', 't', 'j', ' ', 'i', 'r', ' ', 'p', 'r', 'e', 'd', 'a', 't', 'a', ' '};
+uint8_t uuid_array_code[16] = {'b', 'f', 't', 'j', ' ', 'i', 'r', ' ', 'c', 'o', 'd', 'e', ' ', ' ', ' ', ' '};
+
+const UUID uuid_service = UUID(uuid_array_service);
+const UUID uuid_header = UUID(uuid_array_header);
+const UUID uuid_one = UUID(uuid_array_one);
+const UUID uuid_zero = UUID(uuid_array_zero);
+const UUID uuid_ptrail = UUID(uuid_array_ptrail);
+const UUID uuid_predata = UUID(uuid_array_predata);
+const UUID uuid_code = UUID(uuid_array_code);
+
+uint8_t header_data[4];
+uint16_t header_data_length = 4;
+uint8_t one_data[4];
+uint16_t one_data_length = 4;
+uint8_t zero_data[4];
+uint16_t zero_data_length = 4;
+uint8_t ptrail_data[2];
+uint16_t ptrail_data_length = 2;
+uint8_t predata_data[2];
+uint16_t predata_data_length = 2;
+uint8_t code_data[2];
+uint16_t code_data_length = 2;
+
+GattCharacteristic header = GattCharacteristic(uuid_header, header_data, sizeof(header_data), sizeof(header_data), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ);
+GattCharacteristic one = GattCharacteristic(uuid_one, one_data, sizeof(one_data), sizeof(one_data), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ);
+GattCharacteristic zero = GattCharacteristic(uuid_zero, zero_data, sizeof(zero_data), sizeof(zero_data), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE);
+GattCharacteristic ptrail = GattCharacteristic(uuid_ptrail, ptrail_data, sizeof(ptrail_data), sizeof(ptrail_data), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE);
+GattCharacteristic predata = GattCharacteristic(uuid_predata, predata_data, sizeof(predata_data), sizeof(predata_data), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE);
+GattCharacteristic code = GattCharacteristic(uuid_code, code_data, sizeof(code_data), sizeof(code_data), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE);
+
+GattCharacteristic *characteristics[] = {&header, &one, &zero, &ptrail, &predata, &code};
+GattService ir_service = GattService(uuid_service, characteristics, sizeof(characteristics) / sizeof(GattCharacteristic *));
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Jul 02 10:48:58 2014 +0000
@@ -0,0 +1,92 @@
+#include "mbed.h"
+#include "BLEDevice.h"
+#include "IR.h"
+#include "nRF51822n.h"
+
+BLEDevice ble;
+
+DigitalOut myled(LED1);
+DigitalOut yourled(LED2);
+nRF51822n nrf;
+
+Serial py(USBTX, USBRX);
+
+const static uint8_t beaconPayload[] = {
+ 0x00, 0x4C, // Company identifier code (0x004C == Apple)
+ 0x02, // ID
+ 0x15, // length of the remaining payload
+ 0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4, // UUID
+ 0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61,
+ 0x13, 0x37, // the major value to differenciate a location
+ 0xFA, 0xCE, // the minor value to differenciate a location
+ 0xC8 // 2's complement of the Tx power (-56dB)
+};
+
+extern GattService ir_service;
+extern GattCharacteristic header, one, zero, ptrail, predata, code;
+
+void onDataWritten(uint16_t handle)
+{
+ py.printf("Data written! %i\n", handle);
+ for (int i = 0; i < ir_service.getCharacteristicCount(); i++) {
+ GattCharacteristic* characteristic = ir_service.getCharacteristic(i);
+ characteristic->getMaxLength();
+ if (characteristic->getHandle() == handle) {
+ uint16_t max_length = characteristic->getMaxLength();
+ ble.readCharacteristicValue(handle, characteristic->getValuePtr(), &max_length);
+ break;
+ }
+ }
+
+ if (code.getHandle() == handle) {
+ fireIRCode(header.getValuePtr(), one.getValuePtr(), zero.getValuePtr(), ptrail.getValuePtr(), predata.getValuePtr(), code.getValuePtr());
+ }
+}
+
+void disconnectionCallback(void)
+{
+ py.printf("Disconnected!\n");
+ py.printf("Restarting the advertising process\n");
+ ble.startAdvertising();
+}
+
+void connectionCallback(void)
+{
+ py.printf("Connected!\n");
+}
+
+void onDataSent(uint16_t data)
+{
+ py.printf("onDataSent!\n");
+}
+
+int main() {
+ ble.init();
+ ble.onConnection(connectionCallback);
+ ble.onDisconnection(disconnectionCallback);
+ ble.onDataWritten(onDataWritten);
+ ble.onDataSent(onDataSent);
+ ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
+ ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
+ ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
+
+
+ ble.accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA,
+ beaconPayload, sizeof(beaconPayload));
+
+ ble.startAdvertising();
+
+ ble.addService(ir_service);
+
+ myled = 1;
+
+ py.printf("Starting up.\n");
+
+
+
+ while (true) {
+ ble.waitForEvent();
+ myled = !myled;
+ }
+
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Jul 02 10:48:58 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/024bf7f99721 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nRF51822.lib Wed Jul 02 10:48:58 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#7174913c9d67
