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.
main.cpp@0:276a6b2e2aab, 2015-12-23 (annotated)
- Committer:
- mbed_Cookbook_SE
- Date:
- Wed Dec 23 16:55:05 2015 +0000
- Revision:
- 0:276a6b2e2aab
??
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| mbed_Cookbook_SE | 0:276a6b2e2aab | 1 | #include <mbed.h> | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 2 | |
| mbed_Cookbook_SE | 0:276a6b2e2aab | 3 | #include "ReceiverIR.h" | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 4 | |
| mbed_Cookbook_SE | 0:276a6b2e2aab | 5 | ReceiverIR ir_rx(p14); | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 6 | |
| mbed_Cookbook_SE | 0:276a6b2e2aab | 7 | int receive(RemoteIR::Format *format, uint8_t *buf, int bufsiz, int timeout = 100) { | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 8 | int cnt = 0; | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 9 | while (ir_rx.getState() != ReceiverIR::Received) { | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 10 | cnt++; | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 11 | if (timeout <cnt) { | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 12 | return -1; | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 13 | } | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 14 | } | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 15 | return ir_rx.getData(format, buf, bufsiz * 8); | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 16 | } | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 17 | |
| mbed_Cookbook_SE | 0:276a6b2e2aab | 18 | int main(void) { | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 19 | while (1) { | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 20 | uint8_t buf[32]; | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 21 | int bitlength1; | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 22 | RemoteIR::Format format; | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 23 | |
| mbed_Cookbook_SE | 0:276a6b2e2aab | 24 | memset(buf, 0x00, sizeof(buf)); | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 25 | |
| mbed_Cookbook_SE | 0:276a6b2e2aab | 26 | bitlength1 = receive(&format, buf, sizeof(buf)); | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 27 | if (bitlength1 < 0) { | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 28 | continue; | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 29 | } | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 30 | for(int i=0;i<bitlength1/8+((bitlength1 % 8) != 0) ? 1 : 0;i++) | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 31 | { | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 32 | printf("%02X",buf[i]); | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 33 | } | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 34 | printf("\r\n"); | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 35 | } | 
| mbed_Cookbook_SE | 0:276a6b2e2aab | 36 | } |