1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#ifndef PS2MSE_H
#define PS2KSE_H
#include "mbed.h"
class PS2Mse {
public:
PS2Mse(PinName clk, PinName data);
unsigned char rd(void);
void rd_movement(void);
void wr(unsigned char);
void reset(void);
void set_defaults(void);
void enable_data_reporting(void);
void initialise(void);
float metric_x(bool); //0 = instantaneous movement vectors
float metric_y(bool); //1 = cumulative movement vectors
void button_status(void);
bool left_button;
bool middle_button;
bool right_button;
/* Class: PS2Mse
*
* a PS2 Mouse interface
*
* Constructor: PS2Mse
*
* Creates an instance of the PS2Mse class.
*
* Parameters:
*
* clk - connects to the clock line of the mouse
* data - conenct to the data IO of the mouse
*
* Functions: Mouse Commands
*
* rd - read a single byte without ignoring parity and START/STOP bits
* wr - write out a command
* rd_movement - read the movement vectors and button statuses
* reset - reset mouse
* set_defaults - set mouse defaults
* enable_data_reporting - enable movement data packages to be sent from the mouse
* initialise - configure the mouse
* metric_x - converts x-axis movement vectors into metric
* metric_y - converts y-axis movement vectors into metric
* button_status - turns the various button flags on and off depending on the status of the buttons
*/
protected:
DigitalInOut _ps2clk;
DigitalInOut _ps2data;
unsigned int _parity;
bool _parity_bit;
int _byte_1, _byte_2, _byte_3, _byte_4;
float _x, _y;
signed short int _x_vector, _y_vector;
signed long int x_vector(bool);
signed long int y_vector(bool);
long int _sum_x, _sum_y;
};
#endif