Controller Class for Mbed.

Committer:
kikuchi8810
Date:
Fri Dec 17 10:04:13 2021 +0000
Revision:
1:ab1c94d6f4fb
Parent:
0:4f5b9889cbc4
update

Who changed what in which revision?

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