Hayato Kikuchi
/
MonitoringTest
Communication Class and Controller Class (ControllerForMbed Class)
ControllerForMbed.h@2:fd0c21600586, 2021-12-23 (annotated)
- Committer:
- kikuchi8810
- Date:
- Thu Dec 23 08:56:26 2021 +0000
- Revision:
- 2:fd0c21600586
- Parent:
- 0:a33375289d79
modified
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kikuchi8810 | 0:a33375289d79 | 1 | //宇井コンとの通信をmbedで行えるように変更を加えたクラスでプロジェクトに公開していない. |
kikuchi8810 | 0:a33375289d79 | 2 | #ifndef CONTROLLERFORMBED_H |
kikuchi8810 | 0:a33375289d79 | 3 | #define CONTROLLERFORMBED_H |
kikuchi8810 | 0:a33375289d79 | 4 | |
kikuchi8810 | 0:a33375289d79 | 5 | #include "mbed.h" |
kikuchi8810 | 0:a33375289d79 | 6 | #include "RawSerial.h" |
kikuchi8810 | 0:a33375289d79 | 7 | #include "define.h" |
kikuchi8810 | 0:a33375289d79 | 8 | /* |
kikuchi8810 | 0:a33375289d79 | 9 | struct ControllerData{ |
kikuchi8810 | 0:a33375289d79 | 10 | unsigned int ButtonState; |
kikuchi8810 | 0:a33375289d79 | 11 | uint8_t RJoyX, RJoyY, LJoyX, LJoyY; |
kikuchi8810 | 0:a33375289d79 | 12 | }; |
kikuchi8810 | 0:a33375289d79 | 13 | */ |
kikuchi8810 | 0:a33375289d79 | 14 | class ControllerForMbed{ |
kikuchi8810 | 0:a33375289d79 | 15 | public: |
kikuchi8810 | 0:a33375289d79 | 16 | ControllerForMbed(PinName tx, PinName rx, int baudrate); |
kikuchi8810 | 0:a33375289d79 | 17 | |
kikuchi8810 | 0:a33375289d79 | 18 | bool readButton_bin(unsigned int ButtonNum); //押していない時はfalse(0),押してるときはtrue(1)を返す. ButtonNumはデータの欲しいボタンの名前を |
kikuchi8810 | 0:a33375289d79 | 19 | int readButton(unsigned int ButtonNum); //上にプラスして 押した瞬間は2,放した瞬間は-1を返す. define.hを参考に数字を入力しても良い |
kikuchi8810 | 0:a33375289d79 | 20 | bool getComCheck(void); //値が更新されたときにtrueを返す. |
kikuchi8810 | 0:a33375289d79 | 21 | bool update(); //受信の処理+ボタンの情報の更新.受信割込みで処理 |
kikuchi8810 | 0:a33375289d79 | 22 | |
kikuchi8810 | 0:a33375289d79 | 23 | void init(int _time_out_ms, int _int_time_ms); //コントローラの通信速度と通信のタイムアウト時間を設定 |
kikuchi8810 | 0:a33375289d79 | 24 | bool available(void); //コントローラーと通信できていたらtrueを返す. |
kikuchi8810 | 0:a33375289d79 | 25 | |
kikuchi8810 | 0:a33375289d79 | 26 | unsigned int getButtonState(); //分解する前のButtonStateの情報をprint 0~255の値をとる |
kikuchi8810 | 0:a33375289d79 | 27 | void clearButtonState(); |
kikuchi8810 | 0:a33375289d79 | 28 | ControllerData getConData(); |
kikuchi8810 | 0:a33375289d79 | 29 | unsigned int getButtonFlagRise(); |
kikuchi8810 | 0:a33375289d79 | 30 | unsigned int getButtonFlagFall(); |
kikuchi8810 | 0:a33375289d79 | 31 | |
kikuchi8810 | 0:a33375289d79 | 32 | // X |
kikuchi8810 | 0:a33375289d79 | 33 | double readJoyRX(); // ^ |
kikuchi8810 | 0:a33375289d79 | 34 | double readJoyRY(); // | |
kikuchi8810 | 0:a33375289d79 | 35 | double readJoyLX(); // Y<---+---- |
kikuchi8810 | 0:a33375289d79 | 36 | double readJoyLY(); // | |
kikuchi8810 | 0:a33375289d79 | 37 | // | |
kikuchi8810 | 0:a33375289d79 | 38 | // 1.0 ~ -1.0 |
kikuchi8810 | 0:a33375289d79 | 39 | |
kikuchi8810 | 0:a33375289d79 | 40 | // X |
kikuchi8810 | 0:a33375289d79 | 41 | uint8_t readJoyRXbyte(); // ^ |
kikuchi8810 | 0:a33375289d79 | 42 | uint8_t readJoyRYbyte(); // | |
kikuchi8810 | 0:a33375289d79 | 43 | uint8_t readJoyLXbyte(); // Y<---+---- |
kikuchi8810 | 0:a33375289d79 | 44 | uint8_t readJoyLYbyte(); // | |
kikuchi8810 | 0:a33375289d79 | 45 | // | |
kikuchi8810 | 0:a33375289d79 | 46 | // 255 ~ 0 |
kikuchi8810 | 0:a33375289d79 | 47 | |
kikuchi8810 | 0:a33375289d79 | 48 | private: |
kikuchi8810 | 0:a33375289d79 | 49 | |
kikuchi8810 | 0:a33375289d79 | 50 | RawSerial serial; |
kikuchi8810 | 0:a33375289d79 | 51 | //Timer timer; |
kikuchi8810 | 0:a33375289d79 | 52 | |
kikuchi8810 | 0:a33375289d79 | 53 | bool comCheck; |
kikuchi8810 | 0:a33375289d79 | 54 | ControllerData conData; |
kikuchi8810 | 0:a33375289d79 | 55 | ControllerData pre_conData; |
kikuchi8810 | 0:a33375289d79 | 56 | unsigned int lastButtonState; |
kikuchi8810 | 0:a33375289d79 | 57 | |
kikuchi8810 | 0:a33375289d79 | 58 | int time_out_ms; //通信のタイムアウト[ms] |
kikuchi8810 | 0:a33375289d79 | 59 | double int_time_ms; //update関数の呼び出し周期[ms] |
kikuchi8810 | 0:a33375289d79 | 60 | bool conAvailable; //コントローラ接続確認 |
kikuchi8810 | 0:a33375289d79 | 61 | |
kikuchi8810 | 0:a33375289d79 | 62 | uint8_t serial_recieve(){ |
kikuchi8810 | 0:a33375289d79 | 63 | char temp; |
kikuchi8810 | 0:a33375289d79 | 64 | do{ |
kikuchi8810 | 0:a33375289d79 | 65 | temp = serial.getc(); |
kikuchi8810 | 0:a33375289d79 | 66 | } |
kikuchi8810 | 0:a33375289d79 | 67 | while(temp==-1); |
kikuchi8810 | 0:a33375289d79 | 68 | //CONTROL.write(temp); //受け取ったデータをTXピンからそのまま送っている.他のマイコンにも流したいとき用. |
kikuchi8810 | 0:a33375289d79 | 69 | return temp; |
kikuchi8810 | 0:a33375289d79 | 70 | } |
kikuchi8810 | 0:a33375289d79 | 71 | }; |
kikuchi8810 | 0:a33375289d79 | 72 | |
kikuchi8810 | 0:a33375289d79 | 73 | #endif |
kikuchi8810 | 0:a33375289d79 | 74 |