Library for receiving 2021NHK Bteam Controller
Dependents: 2021NHK_Bcon_RX 2021NHK_B_syudo 2021NHK_B_main 2022kouroboBv2 ... more
controller.h
00001 /** 00002 * @file controller.h 00003 * @brief 2021Bcon受信用ライブラリ 00004 * @author 安澤瑠 00005 * @date 21/10/16 00006 */ 00007 #ifndef CONTROLLER_H 00008 #define CONTROLLER_H 00009 00010 #define TIMEOUT_COUNT 5 00011 #define DATANUM 5 // ボタン(BusIn)が1 スティックが4 BController_TX側のFEPライブラリと連携していないとダメ 00012 00013 #include "mbed.h" 00014 00015 /** 00016 * @class con 00017 * @brief class for receiving 2021Bcon data 00018 * 0 4 00019 * 1 3 5 7 00020 * 2 6 00021 * 00022 * 0 1 00023 * @note mbed-os 6 では使えません。 Not compatible with mbed-os 6 00024 */ 00025 class Bcon : public RawSerial { 00026 public : 00027 /** constructor 00028 * @param tx FEPと接続するSerialTX pin 00029 * @param rx FEPと接続するSerialRX pin 00030 * @param addr コントローラーについてるFEPのアドレス 00031 * @param baud 通信速度(デフォルト115200) 00032 */ 00033 Bcon(PinName tx, PinName rx, uint8_t addr_, int baud=115200); 00034 00035 /** Start receiving 00036 */ 00037 void StartReceive(); 00038 00039 /** Check timeout 00040 * @brief 0.1秒毎のループで受信のタイムアウトをチェック 00041 */ 00042 void TimeoutLoop(); 00043 00044 /** Interrupt input 00045 */ 00046 void ReceiveBytes(); 00047 00048 /** extract the message 00049 */ 00050 void CheckData(); 00051 00052 /** Write the received message 00053 * @param data 受信メッセージを格納する配列 00054 */ 00055 void GetData(uint8_t *data); 00056 00057 bool getButton(uint8_t n); //! BusInの計算をしてボタンの値を返す。 00058 int16_t getStick(uint8_t n); //! スティックの値を返す。中心を0,範囲は-128 ~ 128とする。 00059 00060 bool status; //! (TIMEOUT_COUNT * 0.1)秒間通信が来ていないと0 00061 uint8_t sum; //! BusInの値を格納 00062 00063 private : 00064 00065 Ticker timeoutTimer; 00066 00067 uint8_t addr; //! 通信相手のアドレス 00068 uint8_t buffer[256]; //! 全受信データを格納するリングバッファ配列 00069 uint8_t retdata[128]; //! メッセージのみを格納する配列 00070 uint8_t bufindex; //! buffer の添え字変数 00071 uint8_t retindex; //! retdata の添え字変数 00072 uint8_t timeout; //! 0.1秒間通信が成功していないと1増える 00073 uint8_t stick[4]; //! スティックの値を格納 00074 }; 00075 00076 #endif
Generated on Wed Aug 10 2022 07:24:18 by
1.7.2