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: mbed TextLCD RemoteIR
Fork of RemoteIR_TestProgram by
Revision 6:ce137a1bd5a2, committed 2013-05-23
- Comitter:
- MasudaToshio
- Date:
- Thu May 23 10:12:05 2013 +0000
- Parent:
- 5:40750d5779ca
- Commit message:
- ir
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Oct 13 10:51:41 2010 +0000
+++ b/main.cpp Thu May 23 10:12:05 2013 +0000
@@ -1,33 +1,13 @@
-/**
- * RemoteIR library - Test program.
- *
- * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems)
- * http://shinta.main.jp/
- */
-
#include <mbed.h>
#include "ReceiverIR.h"
-#include "TransmitterIR.h"
#include "TextLCD.h"
-#define TEST_LOOP_BACK 0
-
-ReceiverIR ir_rx(p15);
-TransmitterIR ir_tx(p21);
+ReceiverIR ir_rx(p17);
TextLCD lcd(p24, p26, p27, p28, p29, p30);
BusOut led(LED4, LED3, LED2, LED1);
Ticker ledTicker;
-/**
- * Receive.
- *
- * @param format Pointer to a format.
- * @param buf Pointer to a buffer.
- * @param bufsiz Size of the buffer.
- *
- * @return Bit length of the received data.
- */
int receive(RemoteIR::Format *format, uint8_t *buf, int bufsiz, int timeout = 100) {
int cnt = 0;
while (ir_rx.getState() != ReceiverIR::Received) {
@@ -39,37 +19,11 @@
return ir_rx.getData(format, buf, bufsiz * 8);
}
-/**
- * Transmit.
- *
- * @param format Format.
- * @param buf Pointer to a buffer.
- * @param bitlength Bit length of the data.
- *
- * @return Bit length of the received data.
- */
-int transmit(RemoteIR::Format format, uint8_t *buf, int bitlength, int timeout = 100) {
- int cnt = 0;
- while (ir_tx.getState() != TransmitterIR::Idle) {
- cnt++;
- if (timeout < cnt) {
- return -1;
- }
- }
- return ir_tx.setData(format, buf, bitlength);
-}
-
-/**
- * Display a current status.
- */
void display_status(char *status, int bitlength) {
lcd.locate(8, 0);
lcd.printf("%-5.5s:%02d", status, bitlength);
}
-/**
- * Display a format of a data.
- */
void display_format(RemoteIR::Format format) {
lcd.locate(0, 0);
switch (format) {
@@ -94,12 +48,6 @@
}
}
-/**
- * Display a data.
- *
- * @param buf Pointer to a buffer.
- * @param bitlength Bit length of a data.
- */
void display_data(uint8_t *buf, int bitlength) {
lcd.locate(0, 1);
const int n = bitlength / 8 + (((bitlength % 8) != 0) ? 1 : 0);
@@ -115,26 +63,9 @@
led = led + 1;
}
-/**
- * Entry point.
- */
int main(void) {
-
ledTicker.attach(&ledfunc, 0.5);
- /*
- * Splash.
- */
- lcd.cls();
- lcd.locate(0, 0);
- lcd.printf("RemoteIR ");
- lcd.locate(0, 1);
- lcd.printf("Program example.");
- wait(3);
-
- /*
- * Initialize.
- */
led = 0;
lcd.cls();
lcd.locate(0, 0);
@@ -142,9 +73,6 @@
lcd.locate(0, 1);
lcd.printf("on a controller.");
- /*
- * Execute.
- */
while (1) {
uint8_t buf1[32];
uint8_t buf2[32];
@@ -165,42 +93,5 @@
display_format(format);
}
-#if TEST_LOOP_BACK
- wait_ms(100);
-
- {
- bitlength1 = transmit(format, buf1, bitlength1);
- if (bitlength1 < 0) {
- continue;
- }
- display_status("TRAN", bitlength1);
- display_data(buf1, bitlength1);
- display_format(format);
- }
-
- wait_ms(100);
-
- {
- bitlength2 = receive(&format, buf2, sizeof(buf2));
- if (bitlength2 < 0) {
- continue;
- }
- display_status("RECV", bitlength2);
- display_data(buf2, bitlength2);
- display_format(format);
- }
-
- wait_ms(100);
-
- {
- for (int i = 0; i < sizeof(buf1); i++) {
- if (buf1[i] != buf2[i]) {
- display_status("CPERR", bitlength2);
- wait(1);
- continue;
- }
- }
- }
-#endif
}
}
\ No newline at end of file
