OSDN Git Service

キャリブレーションの処理をリファクタリングした。
[tondenhei/et2013.git] / ETUtility.cpp
1 #include "ETUtility.h"
2 #include "Lcd.h"
3 #include "Bluetooth.h"
4 #include "BTConnection.h"
5 #include "TouchSensor.h"
6 #include "ETTailControl.h"
7 #include "Speaker.h"
8 #include "tsprintf.h"
9
10 using namespace ecrobot;
11
12 //#define PASS_KEY
13 /* 固有のパスキーを設定してください */
14 const char* ecrobot::ETBluetoothString::PASS_KEY = "1234"; 
15 /* リモートスタートコマンド */
16 const char ecrobot::ETBluetoothString::CMD_START = '1';
17 /* リモートストップコマンド */    
18 const char ecrobot::ETBluetoothString::CMD_STOP  = '9';    
19
20 bool ETUtilityStuff::IsBluetoothReceived(char cmd)
21 {
22         int i;
23     /* Bluetooth通信用データ受信バッファ */
24     char rx_buf[BT_MAX_RX_BUF_SIZE];
25         unsigned int rx_len;
26         unsigned char come = 0;
27
28         for (i=0; i<BT_MAX_RX_BUF_SIZE; i++)
29         {
30                 rx_buf[i] = 0; /* 受信バッファをクリア */
31         }
32
33         rx_len = ecrobot_read_bt(rx_buf, 0, BT_MAX_RX_BUF_SIZE);
34         if (rx_len > 0)
35         {
36                 /* 受信データあり */
37                 if (rx_buf[0] == cmd)
38                 {
39                         come = 1; /* コマンド受信 */
40                 }
41                 ecrobot_send_bt(rx_buf, 0, rx_len); /* 受信データをエコーバック */
42         }
43
44         return (BOOL)come;
45 }
46
47 bool ETUtilityStuff::Istouched(ecrobot::TouchSensor& touch,ecrobot::ETTailControl& tailcontroler)
48 {
49     tailcontroler.Control();
50     if(touch.isPressed()){
51             systick_wait_ms(30);
52         while(touch.isPressed()){
53             tailcontroler.Control();
54         }
55             systick_wait_ms(30);
56         return true;
57     }
58     return false;
59 }
60
61 void ETUtilityStuff::Waitstart(ecrobot::TouchSensor& touch,ecrobot::ETTailControl& tailcontroler,char cmd)
62 {
63     /* タッチセンサが押されるまで、待ち続ける */
64     while(1){
65             if (Istouched(touch,tailcontroler)){
66                     break;
67             }
68             if (IsBluetoothReceived(ETBluetoothString::CMD_START)){                                                                     
69                     break;
70             }
71     }
72 }
73
74 void ETUtilityStuff::DisplayCalibResult(Lcd& lcd,
75                                         Speaker& speaker,
76                                         char* disp,
77                                         const unsigned long offset,
78                                         const int tone,
79                                         const unsigned long y)
80 {
81         char str[16+1];
82         tsprintf(str,disp,offset);
83         lcd.cursor(0,y);
84         lcd.putf("s",str);
85         lcd.disp();
86         speaker.playTone(tone,100,50);
87 }
88