Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FEP
Dependents: kourobo_Controller_FEP199_198 kourobo_controller_FEP209_208 kourobo2019 kouroboA_2019 ... more
controller.h
00001 /** 00002 * @file controller.h 00003 * @brief FEPを使ったコントローラ受信部 00004 * 00005 * Example : 00006 * @code 00007 * #include "mbed.h" 00008 * #include "controller.h" 00009 * 00010 * Controller pad(PA_9, PA_10, 200); 00011 * Serial pc(USBTX, USBRX, 115200); 00012 * 00013 * int main() 00014 * { 00015 * while(1) { 00016 * if(pad.receiveState()) { 00017 * for(int i = 0; i < 7; i++) pc.printf("%d, ", pad.getButton1(i)); 00018 * for(int i = 0; i < 6; i++) pc.printf("%d, ", pad.getButton2(i)); 00019 * pc.printf("\r\n"); 00020 * } else { 00021 * pc.printf("ERROR\n\r"); 00022 * } 00023 * } 00024 * } 00025 * @endcode 00026 */ 00027 #ifndef CONTROLLER_H 00028 #define CONTROLLER_H 00029 00030 #include "mbed.h" 00031 #include <math.h> 00032 00033 #include "FEP.h" 00034 00035 // const double M_PI = 3.141592653589793; 00036 const int ADDR = 203; 00037 const bool FEP_SUCCESS =0; 00038 const int DATA_SIZE = 6; 00039 const float STICK_DIVIDE = 255.0; 00040 const float STICK_NEWTRAL = 0.1; 00041 const float STICK_NORM_MAX =1.0; 00042 00043 /** 00044 * @brief FEPを使ったコントローラのクラス 00045 */ 00046 class Controller : public FEP 00047 { 00048 public : 00049 /** 00050 * @brief コンストラクタ 00051 * @param FEPtx FEPtx 00052 * @param FEPrx FEPrx 00053 * @param addr address 00054 */ 00055 Controller(PinName FEPtx, PinName FEPrx,int addr); 00056 00057 /** 00058 * @brief メンバ変数にボタンのステートを格納 00059 */ 00060 bool receiveState(); 00061 00062 /** 00063 * ボタン1の状態を取得 00064 * @param number button number 00065 * @return status 00066 */ 00067 bool getButton1(int number) const; 00068 00069 /** 00070 * ボタン2の状態を取得 00071 * @param number button number 00072 * @return status 00073 */ 00074 bool getButton2(int number) const; 00075 00076 /** 00077 * スティックの値を取得 00078 * @param number sticknumber(x, y, x, y) 00079 * @return stick value 00080 */ 00081 float getStick(int number) const; 00082 00083 /** 00084 * スチィックの角度を取得 00085 * @param number left...0 right...1 00086 * @return radian 00087 */ 00088 float getRadian(int number) const; 00089 00090 /** 00091 * スティックの距離を取得 00092 * @param number left..0 right..1 00093 * @return norm 00094 */ 00095 float getNorm(int number) const; 00096 00097 private : 00098 void setStick(); 00099 00100 char data[6]; 00101 uint8_t fepTemp; 00102 00103 protected : 00104 bool button1[7]; 00105 bool button2[6]; 00106 double stick[4]; 00107 double radian[2]; 00108 double norm[2]; 00109 }; 00110 00111 #endif//CONTROLLER_H
Generated on Sun Jul 17 2022 01:43:24 by
