Hayato Kikuchi
/
MonitoringTest
Communication Class and Controller Class (ControllerForMbed Class)
Controller.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 | // DS4のみ通信が確認できているバージョンで,プロジェクトに公開しているクラス |
kikuchi8810 | 0:a33375289d79 | 2 | #ifndef CONTROLLER_H |
kikuchi8810 | 0:a33375289d79 | 3 | #define CONTROLLER_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 Controller{ |
kikuchi8810 | 0:a33375289d79 | 15 | public: |
kikuchi8810 | 0:a33375289d79 | 16 | Controller(PinName tx, PinName rx, int baudrate); |
kikuchi8810 | 0:a33375289d79 | 17 | int count_ms, pre_count_ms; //受信時刻と前回の受信時刻 |
kikuchi8810 | 0:a33375289d79 | 18 | |
kikuchi8810 | 0:a33375289d79 | 19 | bool readButton_bin(unsigned int ButtonNum); //押していない時はfalse(0),押してるときはtrue(1)を返す. ButtonNumはデータの欲しいボタンの名前を |
kikuchi8810 | 0:a33375289d79 | 20 | int readButton(unsigned int ButtonNum); //上にプラスして 押した瞬間は2,放した瞬間は-1を返す. define.hを参考に数字を入力しても良い |
kikuchi8810 | 0:a33375289d79 | 21 | bool getComCheck(void); //値が更新されたときにtrueを返す. |
kikuchi8810 | 0:a33375289d79 | 22 | bool update(); //受信の処理+ボタンの情報の更新.受信割込みで処理 |
kikuchi8810 | 0:a33375289d79 | 23 | |
kikuchi8810 | 0:a33375289d79 | 24 | void init(int _time_out_ms, int _int_time_ms); //コントローラの通信速度と通信のタイムアウト時間を設定 |
kikuchi8810 | 0:a33375289d79 | 25 | bool available(void); |
kikuchi8810 | 0:a33375289d79 | 26 | |
kikuchi8810 | 0:a33375289d79 | 27 | unsigned int getButtonState(); //分解する前のButtonStateの情報をprint 0~255の値をとる |
kikuchi8810 | 0:a33375289d79 | 28 | void clearButtonState(); |
kikuchi8810 | 0:a33375289d79 | 29 | ControllerData getConData(); |
kikuchi8810 | 0:a33375289d79 | 30 | unsigned int getButtonFlagRise(); |
kikuchi8810 | 0:a33375289d79 | 31 | unsigned int getButtonFlagFall(); |
kikuchi8810 | 0:a33375289d79 | 32 | |
kikuchi8810 | 0:a33375289d79 | 33 | // X |
kikuchi8810 | 0:a33375289d79 | 34 | double readJoyRX(); // ^ |
kikuchi8810 | 0:a33375289d79 | 35 | double readJoyRY(); // | |
kikuchi8810 | 0:a33375289d79 | 36 | double readJoyLX(); // Y<---+---- |
kikuchi8810 | 0:a33375289d79 | 37 | double readJoyLY(); // | |
kikuchi8810 | 0:a33375289d79 | 38 | // | |
kikuchi8810 | 0:a33375289d79 | 39 | // 1.0 ~ -1.0 |
kikuchi8810 | 0:a33375289d79 | 40 | |
kikuchi8810 | 0:a33375289d79 | 41 | // X |
kikuchi8810 | 0:a33375289d79 | 42 | uint8_t readJoyRXbyte(); // ^ |
kikuchi8810 | 0:a33375289d79 | 43 | uint8_t readJoyRYbyte(); // | |
kikuchi8810 | 0:a33375289d79 | 44 | uint8_t readJoyLXbyte(); // Y<---+---- |
kikuchi8810 | 0:a33375289d79 | 45 | uint8_t readJoyLYbyte(); // | |
kikuchi8810 | 0:a33375289d79 | 46 | // | |
kikuchi8810 | 0:a33375289d79 | 47 | // 255 ~ 0 |
kikuchi8810 | 0:a33375289d79 | 48 | |
kikuchi8810 | 0:a33375289d79 | 49 | private: |
kikuchi8810 | 0:a33375289d79 | 50 | |
kikuchi8810 | 0:a33375289d79 | 51 | RawSerial serial; |
kikuchi8810 | 0:a33375289d79 | 52 | //Timer timer; |
kikuchi8810 | 0:a33375289d79 | 53 | |
kikuchi8810 | 0:a33375289d79 | 54 | bool comCheck; |
kikuchi8810 | 0:a33375289d79 | 55 | ControllerData conData; |
kikuchi8810 | 0:a33375289d79 | 56 | ControllerData pre_conData; |
kikuchi8810 | 0:a33375289d79 | 57 | unsigned int lastButtonState; |
kikuchi8810 | 0:a33375289d79 | 58 | |
kikuchi8810 | 0:a33375289d79 | 59 | int time_out_ms; |
kikuchi8810 | 0:a33375289d79 | 60 | double int_time_ms; |
kikuchi8810 | 0:a33375289d79 | 61 | bool conAvailable; |
kikuchi8810 | 0:a33375289d79 | 62 | |
kikuchi8810 | 0:a33375289d79 | 63 | uint8_t serial_recieve(){ |
kikuchi8810 | 0:a33375289d79 | 64 | char temp; |
kikuchi8810 | 0:a33375289d79 | 65 | do{ |
kikuchi8810 | 0:a33375289d79 | 66 | temp = serial.getc(); |
kikuchi8810 | 0:a33375289d79 | 67 | } |
kikuchi8810 | 0:a33375289d79 | 68 | while(temp==-1); |
kikuchi8810 | 0:a33375289d79 | 69 | //CONTROL.write(temp); //受け取ったデータをTXピンからそのまま送っている.他のマイコンにも流したいとき用. |
kikuchi8810 | 0:a33375289d79 | 70 | return temp; |
kikuchi8810 | 0:a33375289d79 | 71 | } |
kikuchi8810 | 0:a33375289d79 | 72 | }; |
kikuchi8810 | 0:a33375289d79 | 73 | |
kikuchi8810 | 0:a33375289d79 | 74 | #endif |