From 91d059af3e7da8d37bc0297b144efd89e0c77899 Mon Sep 17 00:00:00 2001 From: kouichi Date: Mon, 16 Sep 2013 16:56:25 +0900 Subject: [PATCH] =?utf8?q?=E3=82=BF=E3=83=83=E3=83=81=E3=82=BB=E3=83=B3?= =?utf8?q?=E3=82=B5=E3=83=BC=E3=80=81Bluetooth=E5=91=A8=E8=BE=BA=E3=82=92?= =?utf8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF=E3=82=BF=E3=83=AA=E3=83=B3?= =?utf8?q?=E3=82=B0=E3=80=82main.cpp=E3=81=AB=E7=9B=B4=E6=9B=B8=E3=81=8D?= =?utf8?q?=E3=82=92=E6=AD=A2=E3=82=81=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- ETUtility.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ ETUtility.h | 20 +++++++++++++++ Makefile | 1 + main.cpp | 82 +++++------------------------------------------------------ 4 files changed, 99 insertions(+), 76 deletions(-) create mode 100644 ETUtility.cpp create mode 100644 ETUtility.h diff --git a/ETUtility.cpp b/ETUtility.cpp new file mode 100644 index 0000000..b38a653 --- /dev/null +++ b/ETUtility.cpp @@ -0,0 +1,72 @@ +#include "ETUtility.h" +#include "Lcd.h" +#include "Bluetooth.h" +#include "BTConnection.h" +#include "Clock.h" +#include "TouchSensor.h" +#include "ETTailControl.h" + +using namespace ecrobot; + +//#define PASS_KEY +/* 固有のパスキーを設定してください */ +const char* ecrobot::ETBluetoothString::PASS_KEY = "1234"; +/* リモートスタートコマンド */ +const char ecrobot::ETBluetoothString::CMD_START = '1'; +/* リモートストップコマンド */ +const char ecrobot::ETBluetoothString::CMD_STOP = '9'; + +bool ETUtilityStuff::IsBluetoothReceived(char cmd) +{ + int i; + /* Bluetooth通信用データ受信バッファ */ + char rx_buf[BT_MAX_RX_BUF_SIZE]; + unsigned int rx_len; + unsigned char come = 0; + + for (i=0; i 0) + { + /* 受信データあり */ + if (rx_buf[0] == cmd) + { + come = 1; /* コマンド受信 */ + } + ecrobot_send_bt(rx_buf, 0, rx_len); /* 受信データをエコーバック */ + } + + return (BOOL)come; +} + +bool ETUtilityStuff::Istouched(ecrobot::TouchSensor& touch,ecrobot::ETTailControl& tailcontroler) +{ + tailcontroler.Control(); + if(touch.isPressed()){ + systick_wait_ms(30); + while(touch.isPressed()){ + tailcontroler.Control(); + } + systick_wait_ms(30); + return true; + } + return false; +} + +void ETUtilityStuff::Waitstart(ecrobot::TouchSensor& touch,ecrobot::ETTailControl& tailcontroler,char cmd) +{ + /* タッチセンサが押されるまで、待ち続ける */ + while(1){ + if (Istouched(touch,tailcontroler)){ + break; + } + if (IsBluetoothReceived(ETBluetoothString::CMD_START)){ + break; + } + } +} + diff --git a/ETUtility.h b/ETUtility.h new file mode 100644 index 0000000..3362b0e --- /dev/null +++ b/ETUtility.h @@ -0,0 +1,20 @@ +#ifndef ET_UTILITYSTUFF_H +#define ET_UTILITYSTUFF + +namespace ecrobot{ + class TouchSensor; + class ETTailControl; + + struct ETBluetoothString{ + static const char* PASS_KEY; + static const char CMD_START; + static const char CMD_STOP; + }; + + namespace ETUtilityStuff{ + bool IsBluetoothReceived(char cmd); + bool Istouched(ecrobot::TouchSensor& touch,ecrobot::ETTailControl& tailcontroler); + void Waitstart(ecrobot::TouchSensor& touch,ecrobot::ETTailControl& tailcontroler,char cmd); + } +} +#endif /* ET_UTILITYSTUFF */ diff --git a/Makefile b/Makefile index c302026..3e70001 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ context.cpp \ runstate.cpp \ exceptionstate.cpp \ ETTailControl.cpp \ +ETUtility.cpp TARGET_SOURCES = tsprintf.c balancer_param.c diff --git a/main.cpp b/main.cpp index 0711261..f49dc61 100644 --- a/main.cpp +++ b/main.cpp @@ -19,16 +19,10 @@ #include "ETBalanceRunner.h" #include "ETTailControl.h" #include "context.h" +#include "ETUtility.h" using namespace ecrobot; -/* sample_c4ƒ}ƒNƒ */ -#define DEVICE_NAME "ET277" /* Bluetooth’ʐM—pƒfƒoƒCƒX–¼ */ /* ƒ`[ƒ€ID‚ɕύX‚µ‚Ä‚­‚¾‚³‚¢ */ -#define PASS_KEY "1234" /* 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" @@ -84,87 +78,23 @@ 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; -} - -bool is_touched(TouchSensor& touch,ETTailControl& tailcontroler) -{ - tailcontroler.Control(); - if(touch.isPressed()){ - systick_wait_ms(30); - while(touch.isPressed()){ - tailcontroler.Control(); - } - systick_wait_ms(30); - return true; - } - return false; -} - - -void waitstart(TouchSensor& touch,ETTailControl& tailcontroler,char cmd) -{ - /* ƒ^ƒbƒ`ƒZƒ“ƒT‚ª‰Ÿ‚³‚ê‚é‚܂ŁA‘Ò‚¿‘±‚¯‚é */ - while(1){ - if (is_touched(touch,tailcontroler)){ - break; - } - if (Bluetooth_isReceived(CMD_START)){ - break; - } - } -} - TASK(TaskMain) { //bt.setFriendlyName(DEVICE_NAME); BTConnection btConnection(bt, lcd, nxt); - btConnection.connect(PASS_KEY); + btConnection.connect(ETBluetoothString::PASS_KEY); lcd.clear(); lcd.putf("s", "Hello World"); lcd.disp(); tailcontroler.Init(); tailcontroler.SetAngle(ETTailControl::ANGLE_STAND_UP); - // TODO:‚Æ‚è‚ ‚¦‚¸‚̃LƒƒƒŠƒuƒŒ[ƒVƒ‡ƒ“ static const int sum_num = 256; unsigned long sum = 0; char str[16+1]; // ƒWƒƒƒCƒ - while(!is_touched(touch,tailcontroler)) {} + while(!ETUtilityStuff::Istouched(touch,tailcontroler)) {} for(int i=0;i