Junichi Katsu
/
ChuckChoroQ
ヌンチャクでコントロールするチョロQ機能に限定した物です。
Fork of StarBoardOrangeExample3 by
Diff: main.cpp
- Revision:
- 1:03c8bc666945
- Parent:
- 0:127b9ca59547
- Child:
- 2:1d9c1cd90695
--- a/main.cpp Tue Aug 24 11:58:09 2010 +0000 +++ b/main.cpp Mon Sep 20 02:09:54 2010 +0000 @@ -8,21 +8,66 @@ * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems) * http://shinta.main.jp/ */ - + +/* + * Connection map. + * + * +---+----------------+---------+ + * |Pin|Target |Direction| + * +---+----------------+---------+ + * |p21|IR transmitter |OUT | + * +---+----------------+---------+ + */ + +/* + * Include files. + */ + #include <mbed.h> #include <algorithm> -#include <RemoteIR.h> -#include <TransmitterIR.h> +#include <ChoroQ.h> #include <I2CConfig.h> #include <WiiNunchuckReader.h> #include <TextLCD.h> -#include "ChoroQ.h" +#include "appconf.h" + +/* + * Objects. + */ WiiNunchuckReader wn(I2CPort_A::SDA, I2CPort_A::SCL); -ChoroQ cq(p21, ChoroQ::ChC); +ChoroQ cq(p21); TextLCD lcd(p24, p26, p27, p28, p29, p30); BusOut led(LED4, LED3, LED2, LED1); +/** + * 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.3"); + lcd.locate(0, 1); + lcd.printf(" CHORO Q HYBRID "); + wait(3); +} + +/** + * Get an action from a coordinate. + * + * @param x X axis. + * @param y Y axis. + * @param dash State of dash. + * + * @return An action. + */ ChoroQ::Action getAction(const int x, const int y, bool dash) { static const int MAX_X = 200; static const int MIN_X = 20; @@ -37,6 +82,10 @@ return ChoroQ::Stop; } + if ((x == 0) && (y == 0)) { + return ChoroQ::Stop; + } + if (std::abs(px) < 10) { if (py < 0) { if (dash) { @@ -54,26 +103,10 @@ } if (std::abs(py) < 10) { if (px < -20) { -#if 0 return ChoroQ::Left; -#else - if (dash) { - return ChoroQ::UpLeftDash; - } else { - return ChoroQ::UpLeft; - } -#endif } if (20 < px) { -#if 0 return ChoroQ::Right; -#else - if (dash) { - return ChoroQ::UpRightDash; - } else { - return ChoroQ::UpRight; - } -#endif } } if ((10 < px) && (10 < py)) { @@ -107,72 +140,90 @@ return ChoroQ::Stop; } +/** + * Entry point. + */ int main() { + /* + * Splash. + */ + splash(); lcd.cls(); + + /* + * Setup a configuration. + */ + appconf_t conf; + appconf_init(&conf); + appconf_read(&conf); + + /* + * Application loop. + */ while (true) { wn.RequestRead(); ChoroQ::Action ac = getAction(wn.getJoyX(), wn.getJoyY(), (wn.getButtonZ() == 1) ? true : false); - cq.execute(ac); + cq.execute(conf.channel, ac); lcd.locate(0, 0); - lcd.printf("(%3d,%3d) %-6.6s", wn.getJoyX(), wn.getJoyY(), ((wn.getButtonZ() == 1) ? "-Dash-" : " ")); + lcd.printf("JS :(%3d,%3d) %s", wn.getJoyX(), wn.getJoyY(), ((wn.getButtonZ() == 1) ? "D" : " ")); - lcd.locate(0, 1); + char *stattext = ""; switch (ac) { case ChoroQ::Undef: - lcd.printf("%-16.16s", "Undef"); + stattext = "Undef"; break; case ChoroQ::Up: - lcd.printf("%-16.16s", "Up"); + stattext = "Up"; break; case ChoroQ::Down: - lcd.printf("%-16.16s", "Down"); + stattext = "Down"; break; case ChoroQ::Left: - lcd.printf("%-16.16s", "Left"); + stattext = "Left"; break; case ChoroQ::Right: - lcd.printf("%-16.16s", "Right"); + stattext = "Right"; break; case ChoroQ::UpDash: - lcd.printf("%-16.16s", "UpDash"); + stattext = "Up +D"; break; case ChoroQ::UpLeft: - lcd.printf("%-16.16s", "UpLeft"); + stattext = "UpLeft"; break; case ChoroQ::UpRight: - lcd.printf("%-16.16s", "UpRight"); + stattext = "UpRight"; break; case ChoroQ::UpRightDash: - lcd.printf("%-16.16s", "UpRightDash"); + stattext = "UpRight +D"; break; case ChoroQ::UpLeftDash: - lcd.printf("%-16.16s", "UpLeftDash"); + stattext = "UpLeft +D"; break; case ChoroQ::DownLeft: - lcd.printf("%-16.16s", "DownLeft"); + stattext = "DownLeft"; break; case ChoroQ::DownRight: - lcd.printf("%-16.16s", "DownRight"); + stattext = "DownRight"; break; case ChoroQ::DownDash: - lcd.printf("%-16.16s", "DownDash"); + stattext = "Down +D"; break; case ChoroQ::DownLeftDash: - lcd.printf("%-16.16s", "DownLeftDash"); + stattext = "DownLeft +D"; break; case ChoroQ::DownRightDash: - lcd.printf("%-16.16s", "DownRightDash"); + stattext = "DownRight+D"; break; case ChoroQ::Stop: - lcd.printf("%-16.16s", "Stop"); + stattext = "Stop"; break; } + lcd.locate(0, 1); + lcd.printf("Ch.%c:%-11.11s", 'A' + (int)conf.channel, stattext); wait_ms(50); led = led + 1; } - - return EXIT_SUCCESS; }