test

Dependencies:   mbed XBee

Revision:
2:cb2bd28bb66d
Parent:
1:cb2c4d733c1b
--- a/Controller.h	Fri Jan 15 08:50:35 2021 +0000
+++ b/Controller.h	Fri Apr 16 09:34:17 2021 +0000
@@ -2,84 +2,122 @@
 #define CONTROLLER_H
 
 #include "mbed.h"
+#include "XBee.h"
 #include "RawSerial.h"
 
-#define BUTTON_SIKAKU 0x01
-#define BUTTON_SANKAKU 0x02
-#define BUTTON_BATU 0x04
-#define BUTTON_MARU 0x08
-#define BUTTON_L1 0x10
-#define BUTTON_R1 0x20
-#define BUTTON_L2 0x40
-#define BUTTON_R2 0x80
-#define BUTTON_PAD 0x100
-#define BUTTON_PS 0x200
-#define BUTTON_SHARE 0x400
-#define BUTTON_OPTION 0x800
-#define BUTTON_UP 0x1000
-#define BUTTON_RIGHT 0x2000
-#define BUTTON_DOWN 0x4000
-#define BUTTON_LEFT 0x8000
+#define APIMODE 1
+#define TRANSPARENT_MODE 2
+
+#define XBEE_MODE ( APIMODE ) //カッコの中を変えて使う
+
+#if XBEE_MODE == TRANSPARENT_MODE
+ 
+    #define BUTTON_X  0x0001
+    #define BUTTON_Y  0x0002
+    #define BUTTON_A  0x0004
+    #define BUTTON_B  0x0008
+    
+    #define BUTTON_L1     0x0010
+    #define BUTTON_R1     0x0020
+    #define BUTTON_L2     0x0040
+    #define BUTTON_R2     0x0080
+    
+    // #define BUTTON_JOY_L   0x0100
+    // #define BUTTON_JOY_R   0x0200
+    // #define BUTTON_SHARE    0x0400
+    // #define BUTTON_OPTION   0x0800
+    #define BUTTON_PAD 0x0100
+    #define BUTTON_PS 0x0200
+    #define BUTTON_JOY_L 0x0400
+    #define BUTTON_JOY_R 0x0800
+    
+    #define BUTTON_UP     0x1000
+    #define BUTTON_RIGHT  0x2000
+    #define BUTTON_DOWN   0x4000
+    #define BUTTON_LEFT   0x8000
+
+#elif XBEE_MODE == API_MODE
 
-class Controller
+    #define BUTTON_SQUARE   0x0001
+    #define BUTTON_TRIANGLE 0x0002
+    #define BUTTON_CROSS    0x0004
+    #define BUTTON_CIRCLE   0x0008
+    
+    #define BUTTON_L1   0x0010
+    #define BUTTON_R1   0x0020
+    #define BUTTON_L2   0x0040
+    #define BUTTON_R2   0x0080
+    
+    #define BUTTON_UP     0x0100
+    #define BUTTON_RIGHT  0x0200
+    #define BUTTON_DOWN   0x0400
+    #define BUTTON_LEFT   0x0800
+    
+    #define BUTTON_SHARE    0x1000
+    #define BUTTON_OPTION   0x2000
+    #define BUTTON_PAD      0x4000
+    #define BUTTON_PS       0x8000
+    
+    #define BUTTON_JOY_L    0x0100
+    #define BUTTON_JOY_R    0x0200
+    
+#endif
+
+#define DATA_NUM_TRANS  10
+#define DATA_NUM_API    3
+#define BOUDRATE_TRANS  115200
+#define BOUDRATE_API    230400
+
+#define PUSHE 1
+#define RELEASE 0
+#define PUSHED 2
+#define RELEASED -1
+
+class XBee_TransparentMode
 {
 public:
-    Controller(PinName tx, PinName rx, int baudrate);
-    RawSerial XBee3;
-    //Controller(RawSerial* serial_xbee);
+    XBee_TransparentMode(PinName tx,PinName rx,int baudrate);
 
     void update();
-    void DRbegin();
-
-    /**
-     * コントローラのボタン入力状態を返す.
-     * 
-     * @param buttonNum ボタン番号 1~12
-     * @return 1:押されている 0:離されている 2:押された -1:離された
-     * 
-     */
     
-    int8_t readButton(int buttonNum) const;
-    unsigned int getButtonState() const;
-
-    /**
-     * ジョイスティックの値を読む
-     * @return -1.0 ~ 1.0
-     * 
-     *      X
-     *      ^
-     *      |
-     * Y<---+----
-     *      |
-     *      |
-     */
+    bool readButton(unsigned int button,int status);
+    unsigned int getButtonState();
     
-    double readJoyLX() const;
-    double readJoyLY() const;
-    double readJoyRX() const;
-    double readJoyRY() const;
-
-    unsigned int readJoyLXbyte() const;
-    unsigned int readJoyLYbyte() const;
-    unsigned int readJoyRXbyte() const;
-    unsigned int readJoyRYbyte() const;
-
-    bool getButtonChanged() const; //スイッチの状態を確認する
+    unsigned int ButtonState, preButtonState;
+    unsigned int LJoyX, LJoyY, RJoyX, RJoyY;
 
 
 private:
 
-    unsigned int ButtonState, preButtonState;
-    unsigned int LJoyX, LJoyY, RJoyX, RJoyY;
     int boudrate;
+    RawSerial serialXbee3;
 
     bool buttonChanged;
     
 
 private:
     int recv_num;
+};
 
-    char recv_msgs[9];
+class  XBee_APIMode
+{
+public:
+    XBee_APIMode(PinName tx,PinName rx);
+    
+    void begin(int baudrate);
+    int update();
+    
+    bool readButton(unsigned int button,int status);
+    unsigned int getButtonState();
+    
+    unsigned int ButtonState, preButtonState;
+
+private:
+
+    int boudrate;
+    XBee xbee;
+
+    bool buttonChanged;
 };
 
 #endif
\ No newline at end of file