Shinichiro Nakamura
/
StarBoardOrangeExample2
StarBoard Orange - Example application No.2 (Version 0.0.4)
main.cpp
- Committer:
- shintamainjp
- Date:
- 2010-08-13
- Revision:
- 0:5d79cd4ac81d
- Child:
- 3:469de11d1e1d
File content as of revision 0:5d79cd4ac81d:
/** * StarBoard Orange - Example application No.2 (Version 0.0.1) * Remote IR receiver with StarBoard Orange * * See also ... http://mbed.org/users/shintamainjp/notebook/starboard_example2_ja/ * See also ... http://mbed.org/users/shintamainjp/notebook/starboard_example2_en/ * * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems) * http://shinta.main.jp/ */ #include <mbed.h> #include "ReceiverIR.h" #include "TextLCD.h" ReceiverIR ir(p17); BusOut led(LED4, LED3, LED2, LED1); TextLCD lcd(p24, p25, p26, p27, p28, p29, p30); /** * Display a splash screen. */ void splash(void) { lcd.cls(); lcd.locate(0, 0); lcd.printf("StarBoard Orange"); lcd.locate(0, 1); lcd.printf("mbed NXP LPC1768"); wait(3); lcd.cls(); lcd.locate(0, 0); lcd.printf("Example app No.2"); lcd.locate(0, 1); lcd.printf(" Remote IR "); wait(3); } /** * Entry point. */ int main(void) { /* * Splash. */ splash(); /* * Initialize. */ led = 0; lcd.cls(); lcd.locate(0, 0); lcd.printf("Press a button "); lcd.locate(0, 1); lcd.printf("on a controller."); while (1) { static int latest_bits = 0; static ReceiverIR::State prev = ReceiverIR::Idle; /* * Get a current state. */ ReceiverIR::State curr = ir.getState(); if (prev != curr) { lcd.locate(0, 0); switch (curr) { case ReceiverIR::Idle: lcd.printf("Idle (%2d) \n", latest_bits); break; case ReceiverIR::Receiving: lcd.printf("Receiving \n"); break; case ReceiverIR::Received: lcd.printf("Received \n"); break; } } prev = curr; /* * Update statuses if it updated. */ if (ReceiverIR::Received == curr) { led = led + 1; ReceiverIR::Format format; uint8_t buf[32]; int bc = ir.getData(&format, buf, sizeof(buf)); latest_bits = bc; lcd.locate(10, 0); switch (format) { case ReceiverIR::UNKNOWN: lcd.printf(": ????"); break; case ReceiverIR::NEC: lcd.printf(": NEC "); break; case ReceiverIR::AEHA: lcd.printf(": AEHA"); break; case ReceiverIR::SONY: lcd.printf(": SONY"); break; default: break; } lcd.locate(0, 1); for (int i = 0; i < (bc / 8); i++) { lcd.printf("%02X", buf[i]); } for (int i = 0; i < 8 - (bc / 8); i++) { lcd.printf("--"); } } } }