yusei sugimoeo / Mbed OS controllerForMbed_test_Re
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Controller.h Source File

Controller.h

00001 /*
00002  *https://os.mbed.com/users/kikuchi8810/code/controllerForMbed_test//file/ab1c94d6f4fb/main.cpp/
00003  *元データ
00004  *作:菊池
00005  */
00006 
00007 
00008 
00009 #ifndef CONTROLLER_H
00010 #define CONTROLLER_H
00011  
00012 #include "mbed.h"
00013 #include "RawSerial.h"
00014 #include "define.h"
00015  
00016 struct ControllerData{
00017     unsigned int ButtonState;
00018     uint8_t RJoyX, RJoyY, LJoyX, LJoyY;
00019 };
00020  
00021 class Controller{
00022     public:
00023         Controller(PinName tx, PinName rx, int baudrate);
00024         int count_ms, pre_count_ms; //受信時刻と前回の受信時刻
00025  
00026         bool readButton_bin(unsigned int ButtonNum); //押していない時はfalse(0),押してるときはtrue(1)を返す. ButtonNumはデータの欲しいボタンの名前を
00027         int  readButton(unsigned int ButtonNum);     //上にプラスして 押した瞬間は2,放した瞬間は-1を返す.    define.hを参考に数字を入力しても良い
00028         bool getComCheck(void); //値が更新されたときにtrueを返す.
00029         bool update(); //受信の処理+ボタンの情報の更新.受信割込みで処理
00030         bool clearBuffer(void);//buffer消去用.falseが返ってくれば消去完了.
00031         bool rate(void);//送信側で入力がある場合にtrue.
00032         
00033         void init(int _time_out_ms, int _int_time_ms); //コントローラの通信速度と通信のタイムアウト時間を設定
00034         bool available(void);
00035  
00036         unsigned int getButtonState();  //分解する前のButtonStateの情報をprint 0~255の値をとる
00037         void clearButtonState();
00038         ControllerData getConData();
00039         unsigned int getButtonFlagRise();
00040         unsigned int getButtonFlagFall();
00041     
00042                                 //       X
00043         double readJoyRX();     //       ^ 
00044         double readJoyRY();     //       | 
00045         double readJoyLX();     //  Y<---+----
00046         double readJoyLY();     //       | 
00047                                 //       | 
00048                                 //  1.0  ~   -1.0
00049  
00050                                    //       X
00051         uint8_t readJoyRXbyte();   //       ^ 
00052         uint8_t readJoyRYbyte();   //       |
00053         uint8_t readJoyLXbyte();   //  Y<---+----
00054         uint8_t readJoyLYbyte();   //       | 
00055                                    //       |
00056                                    //  255  ~    0
00057  
00058     private:
00059         
00060         RawSerial serial;
00061         //Timer timer;
00062  
00063         bool comCheck;
00064         ControllerData conData;
00065         ControllerData pre_conData;
00066         unsigned int lastButtonState;
00067  
00068         int time_out_ms;
00069         double int_time_ms;
00070         bool conAvailable;
00071  
00072         uint8_t serial_recieve(){
00073             char temp;
00074             do{
00075                 temp = serial.getc();
00076             }
00077             while(temp==-1);
00078             //CONTROL.write(temp);    //受け取ったデータをTXピンからそのまま送っている.他のマイコンにも流したいとき用.
00079             return temp;
00080         }
00081 };
00082  
00083 #endif