Khangai Robot Play - Naive  01
THe naive play of the Khangai Robot
joystick.h
Go to the documentation of this file.
1 /*
2  * joystick.h
3  *
4  * Created : 02/19/2019
5  * Author : n-is
6  * email : 073bex422.nischal@pcampus.edu.np
7  */
8 
9 #ifndef _JOYSTICK_H_
10 #define _JOYSTICK_H_
11 
12 #include "vec3.h"
13 #include "usart.h"
14 #include "queue_custom.h"
15 #include "FreeRTOS.h"
16 #include "task.h"
17 
18 
19 // Button's bit position in the byte
20 #define B_X (7)
21 #define B_Y (6)
22 #define B_A (5)
23 #define B_B (4)
24 #define B_UP (3)
25 #define B_DOWN (2)
26 #define B_LB (1)
27 #define B_RB (0)
28 
29 #define B_START (7)
30 #define B_BACK (6)
31 #define B_XBOX (5)
32 #define B_LEFT (4)
33 #define B_RIGHT (3)
34 
35 #define MANUAL_KEY (B_LB)
36 #define AUTO_KEY (B_A)
37 #define RESET_KEY (B_RB)
38 #define SHAGAI_GRIP_KEY (B_X)
39 #define THROW_SHAGAI_KEY (B_Y)
40 #define ACTUATE_ARM_KEY (B_B)
41 
42 #define START_THROW_KEY (B_START)
43 
44 #ifndef _BV
45  #define _BV(x) (1 << x)
46 #endif
47 
49 {
50  uint8_t button1;
51  uint8_t button2;
52  uint8_t lt;
53  uint8_t rt;
54  uint8_t l_hatx;
55  uint8_t l_haty;
56  uint8_t r_hatx;
57  uint8_t r_haty;
58 };
59 
61 {
62  UART_HandleTypeDef *huart;
64 };
65 
66 enum class Control_Mode {
67  MANUAL,
68  AUTO,
69  NONE
70 };
71 
73 {
75  bool reset_pos;
77  uint8_t brake;
78  uint8_t accel;
83  int8_t rotate_dir;
84 };
85 
86 class JoyStick
87 {
88 public:
89  JoyStick(UART_HandleTypeDef *huart) {
90  huart_ = huart;
91  }
92  JoyStick(JoyStick &&) = default;
93  JoyStick(const JoyStick &) = default;
94  JoyStick &operator=(JoyStick &&) = default;
95  JoyStick &operator=(const JoyStick &) = default;
96  ~JoyStick() { }
97 
98  static JoyStick& get_Instance(UART_HandleTypeDef *huart);
99  int init();
100  bool is_Empty();
101 
103 
104 private:
105  UART_HandleTypeDef *huart_;
107 
109  void parse_JoyData(JoyStick_Data joy);
110 };
111 
113 
114 #endif // !_JOYSTICK_H_
static JoyStick & get_Instance(UART_HandleTypeDef *huart)
Definition: joystick.cpp:129
bool start_throw
Definition: joystick.h:82
bool actuate_arm
Definition: joystick.h:81
uint8_t l_haty
Definition: joystick.h:55
UART_HandleTypeDef * huart
Definition: joystick.h:62
uint8_t rt
Definition: joystick.h:53
Definition: joystick.h:60
bool grip_shagai
Definition: joystick.h:79
UART_HandleTypeDef * huart_
Definition: joystick.h:105
uint8_t r_haty
Definition: joystick.h:57
void JoyStick_Handle_RxCplt()
Definition: joystick.cpp:36
bool throw_shagai
Definition: joystick.h:80
Control_Mode mode
Definition: joystick.h:74
JoyStick_Command & parse()
Definition: joystick.cpp:169
uint8_t r_hatx
Definition: joystick.h:56
Control_Mode
Definition: joystick.h:66
uint8_t button2
Definition: joystick.h:51
bool is_Empty()
Definition: joystick.cpp:156
uint8_t l_hatx
Definition: joystick.h:54
Vec3< float > vels
Definition: joystick.h:76
uint8_t accel
Definition: joystick.h:78
uint8_t button1
Definition: joystick.h:50
~JoyStick()
Definition: joystick.h:96
JoyStick(UART_HandleTypeDef *huart)
Definition: joystick.h:89
JoyStick_Data read()
Definition: joystick.cpp:161
JoyStick & operator=(JoyStick &&)=default
uint8_t lt
Definition: joystick.h:52
int init()
Definition: joystick.cpp:136
int8_t rotate_dir
Definition: joystick.h:83
Definition: joystick.h:72
bool reset_pos
Definition: joystick.h:75
struct JoyStick_Command Joy_Command
Definition: joystick.h:106
Queue< JoyStick_Data, 2 > data
Definition: joystick.h:63
void parse_JoyData(JoyStick_Data joy)
Definition: joystick.cpp:177
Definition: joystick.h:48
Definition: joystick.h:86
uint8_t brake
Definition: joystick.h:77