MakeBlock Drive Updated
Updated library for MakeBlock Ranger
Loading...
Searching...
No Matches
MePS2.h
Go to the documentation of this file.
1
47#ifndef MePS2_H
48#define MePS2_H
49
50#include <stdbool.h>
51#include <stdint.h>
52#include <Arduino.h>
53#include "MeConfig.h"
54#include "MeSerial.h"
55
56#ifdef ME_PORT_DEFINED
57#include "MePort.h"
58#endif
59
60#define MeJOYSTICK_RX 6
61#define MeJOYSTICK_RY 8
62#define MeJOYSTICK_LX 2
63#define MeJOYSTICK_LY 4
64
65#define MeJOYSTICK_R1 1
66#define MeJOYSTICK_R2 3
67#define MeJOYSTICK_L1 5
68#define MeJOYSTICK_L2 7
69#define MeJOYSTICK_TRIANGLE 9
70#define MeJOYSTICK_XSHAPED 10
71#define MeJOYSTICK_SQUARE 11
72#define MeJOYSTICK_ROUND 12
73#define MeJOYSTICK_START 13
74#define MeJOYSTICK_UP 14
75#define MeJOYSTICK_DOWN 15
76#define MeJOYSTICK_LEFT 16
77#define MeJOYSTICK_RIGHT 17
78#define MeJOYSTICK_SELECT 18
79#define MeJOYSTICK_MODE 19
80#define MeJOYSTICK_BUTTON_L 20
81#define MeJOYSTICK_BUTTON_R 21
82#define MeJOYSTICK_INIT_VALUE 0
83#define MeJOYSTICK_ANALOG_ERROR 0
84
90#ifndef ME_PORT_DEFINED
91 class MePS2
92#else /* !ME_PORT_DEFINED */
93 class MePS2 : public MeSerial
94#endif /* !ME_PORT_DEFINED */
95
96{
97public:
98
99#ifdef ME_PORT_DEFINED
106 MePS2();
107
114 MePS2(uint8_t port);
115#else // ME_PORT_DEFINED
116
127 MePS2(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic);
128#endif // ME_PORT_DEFINED
129
144 void readSerial(void);
145
160 uint8_t readBuffer(int16_t index);
161
176 void writeBuffer(int16_t index,uint8_t c);
177
192 boolean readjoystick(void);
193
208 int16_t MeAnalog(uint8_t button);
209
224 boolean ButtonPressed(uint8_t button);
225
240 void loop(void);
241
242private:
243 uint8_t _serialRead;
244 uint8_t _dataLen;
245 uint8_t _index = 0;
246 uint8_t _prevc = 0;
247 uint8_t buffer[16];
248 uint8_t ps2_data_list[23];
249 uint8_t ps2_data_list_bak[23];
250 long _lasttime;
251
252 boolean _isStart;
253 boolean _isAvailable;
254 boolean _isReady;
255};
256#endif
Configuration file of library.
Header for MePort.cpp module.
Header for for MeSerial.cpp module.
Driver for MePS2 handle device.
Definition MePS2.h:96
MePS2()
Definition MePS2.cpp:60
uint8_t readBuffer(int16_t index)
Definition MePS2.cpp:117
void readSerial(void)
Definition MePS2.cpp:157
void loop(void)
Definition MePS2.cpp:335
boolean readjoystick(void)
Definition MePS2.cpp:181
void writeBuffer(int16_t index, uint8_t c)
Definition MePS2.cpp:137
int16_t MeAnalog(uint8_t button)
Definition MePS2.cpp:261
boolean ButtonPressed(uint8_t button)
Definition MePS2.cpp:308
Driver for serial.
Definition MeSerial.h:67