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: Puck IRSender mbed
Fork of ir-puck by
Diff: IR.cpp
- Revision:
- 0:c94311378ec1
- Child:
- 1:e92c3b50191d
diff -r 000000000000 -r c94311378ec1 IR.cpp
--- /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
