From 4c3782349f8722006c85faf2f86676df5bde7c73 Mon Sep 17 00:00:00 2001 From: kouichi Date: Wed, 11 Sep 2013 21:43:34 +0900 Subject: [PATCH] =?utf8?q?=E3=81=A8=E3=82=8A=E3=81=82=E3=81=88=E3=81=9A?= =?utf8?q?=E3=81=AEbluetooth=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- main.cpp | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/main.cpp b/main.cpp index 1942f49..6c22418 100644 --- a/main.cpp +++ b/main.cpp @@ -21,6 +21,13 @@ using namespace ecrobot; +/* sample_c4ƒ}ƒNƒ */ +#define DEVICE_NAME "ET277" /* Bluetooth’ʐM—pƒfƒoƒCƒX–¼ */ /* ƒ`[ƒ€ID‚ɕύX‚µ‚Ä‚­‚¾‚³‚¢ */ +#define PASS_KEY "2345" /* Bluetooth’ʐM—pƒpƒXƒL[ */ /* ŒÅ—L‚̃pƒXƒL[‚ðÝ’肵‚Ä‚­‚¾‚³‚¢ */ +#define CMD_START '1' /* ƒŠƒ‚[ƒgƒXƒ^[ƒgƒRƒ}ƒ“ƒh */ +#define CMD_STOP '9' /* ƒŠƒ‚[ƒgƒXƒgƒbƒvƒRƒ}ƒ“ƒh */ + + extern "C" { #include "kernel.h" @@ -49,6 +56,31 @@ ETLinePos linepos(light); ETLineTracer tracer(linepos,runner); ETTailControl tailcontroler(motorT,0); ContextStuff::Context context; + +/* ƒfƒoƒCƒX‰Šú‰»—pƒtƒbƒNŠÖ” */ +/* ‚±‚̊֐”‚ÍnxtOSEK‹N“®Žž‚ÉŽÀs‚³‚ê‚Ü‚·B */ +void ecrobot_device_initialize() +{ + /* ƒZƒ“ƒTAƒ‚[ƒ^‚È‚Ç‚ÌŠeƒfƒoƒCƒX‚̏‰Šú‰»ŠÖ”‚ð + * ‚±‚±‚ÅŽÀ‘•‚·‚邱‚Æ‚ª‚Å‚«‚Ü‚· + * Ë@ŒõƒZƒ“ƒTÔFLED‚ðON‚É‚·‚é + */ + //ecrobot_set_light_sensor_active(SENSOR_LIGHT); + ecrobot_init_bt_slave(PASS_KEY); /* Bluetooth’ʐM‰Šú‰» */ //ex4 +} + +/* ƒfƒoƒCƒXI—¹—pƒtƒbƒNŠÖ” */ +/* ‚±‚̊֐”‚ÍSTOP‚Ü‚½‚ÍEXITƒ{ƒ^ƒ“‚ª‰Ÿ‚³‚ꂽŽž‚ÉŽÀs‚³‚ê‚Ü‚·B */ +void ecrobot_device_terminate() +{ + /* ƒZƒ“ƒTAƒ‚[ƒ^‚È‚Ç‚ÌŠeƒfƒoƒCƒX‚̏I—¹ŠÖ”‚ð + * ‚±‚±‚ÅŽÀ‘•‚·‚邱‚Æ‚ª‚Å‚«‚Ü‚·B + * Ë@ŒõƒZƒ“ƒTÔFLED‚ðOFF‚É‚·‚é + */ + //ecrobot_set_light_sensor_inactive(SENSOR_LIGHT); + ecrobot_term_bt_connection(); /* Bluetooth’ʐM‚ðI—¹ */ //ex4 +} + // nxtOSEK hook to be invoked from an ISR in category 2 void user_1ms_isr_type2(void) @@ -63,8 +95,45 @@ void user_1ms_isr_type2(void) } } +/* Bluetooth’ʐM—pƒf[ƒ^ŽóMƒoƒbƒtƒ@ */ +static char rx_buf[BT_MAX_RX_BUF_SIZE]; + +/***************************************************************************** + ŠÖ”–¼ : Bluetooth_isReceived + ˆø ” : ŽóM‘Ò‚¿ƒRƒ}ƒ“ƒh + •Ô‚è’l : 1(ƒXƒ^[ƒg)/0(‘Ò‹@) + ŠT —v : Bluetooth’ʐM‚É‚æ‚郊ƒ‚[ƒgƒXƒ^[ƒgB Tera Term‚Ȃǂ̃^[ƒ~ƒiƒ‹ƒ\ƒtƒg‚©‚çA + ASCIIƒR[ƒh‚Å1‚𑗐M‚·‚é‚ƁAƒŠƒ‚[ƒgƒXƒ^[ƒg‚·‚éB + *****************************************************************************/ +BOOL Bluetooth_isReceived(char cmd) +{ + int i; + unsigned int rx_len; + unsigned char come = 0; + + for (i=0; i 0) + { + /* ŽóMƒf[ƒ^‚ ‚è */ + if (rx_buf[0] == cmd) + { + come = 1; /* ƒRƒ}ƒ“ƒhŽóM */ + } + ecrobot_send_bt(rx_buf, 0, rx_len); /* ŽóMƒf[ƒ^‚ðƒGƒR[ƒoƒbƒN */ + } + + return (BOOL)come; +} + + TASK(TaskMain) { + bt.setFriendlyName(DEVICE_NAME); lcd.clear(); lcd.putf("s", "Hello World"); lcd.disp(); @@ -132,11 +201,19 @@ TASK(TaskMain) lcd.disp(); speaker.playTone(1400,100,50); + while(!touch.isPressed()){ tailcontroler.Control(); } while(touch.isPressed()){ } +/* while(1){ + tailcontroler.Control(); + if(Bluetooth_isReceived(CMD_START)){ + break; + } + } +*/ tailcontroler.SetAngle(ETTailControl::ANGLE_DRIVE); context.SetETLineTracer(&tracer); TerminateTask(); -- 2.11.0