![](/media/cache/profiles/383df222b83e1c6dd536dd72ff48ce09.jpg.50x50_q85.jpg)
ir-puck
Dependencies: Puck IRSender mbed
Fork of ir-puck by
Diff: main.cpp
- Revision:
- 1:e92c3b50191d
- Parent:
- 0:c94311378ec1
- Child:
- 4:24d9873936e6
--- a/main.cpp Wed Jul 02 10:48:58 2014 +0000 +++ b/main.cpp Wed Jul 09 14:47:41 2014 +0000 @@ -25,6 +25,7 @@ extern GattService ir_service; extern GattCharacteristic header, one, zero, ptrail, predata, code; +int received_ir_transmission = 0; void onDataWritten(uint16_t handle) { py.printf("Data written! %i\n", handle); @@ -34,12 +35,15 @@ if (characteristic->getHandle() == handle) { uint16_t max_length = characteristic->getMaxLength(); ble.readCharacteristicValue(handle, characteristic->getValuePtr(), &max_length); + for (int i=0; i<max_length; i++) { + py.printf("Got value: %d\n", characteristic->getValuePtr()[i]); + } break; } } - + if (code.getHandle() == handle) { - fireIRCode(header.getValuePtr(), one.getValuePtr(), zero.getValuePtr(), ptrail.getValuePtr(), predata.getValuePtr(), code.getValuePtr()); + received_ir_transmission = 1; } } @@ -52,7 +56,7 @@ void connectionCallback(void) { - py.printf("Connected!\n"); + py.printf("Connected!\n"); } void onDataSent(uint16_t data) @@ -60,7 +64,10 @@ py.printf("onDataSent!\n"); } -int main() { +int main() +{ + py.printf("Start of main\n"); + ble.init(); ble.onConnection(connectionCallback); ble.onDisconnection(disconnectionCallback); @@ -69,24 +76,24 @@ 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)); - + beaconPayload, sizeof(beaconPayload)); + ble.startAdvertising(); ble.addService(ir_service); - + myled = 1; - - py.printf("Starting up.\n"); - - + + py.printf("Listening..\n"); while (true) { ble.waitForEvent(); + if (received_ir_transmission == 1) { + fireIRCode(header.getValuePtr(), one.getValuePtr(), zero.getValuePtr(), ptrail.getValuePtr(), predata.getValuePtr(), code.getValuePtr()); + received_ir_transmission = 0; + } myled = !myled; } - } \ No newline at end of file