File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,17 @@ static const uint8_t _hidReportDescriptor[] PROGMEM = {
60
60
// ================================================================================
61
61
// Mouse
62
62
63
+ /* This function is for limiting the input value for x and y
64
+ * axis to -127 <= x/y <= 127 since this is the allowed value
65
+ * range for a USB HID device.
66
+ */
67
+ signed char limit_xy (int const xy)
68
+ {
69
+ if (xy < -127 ) return -127 ;
70
+ else if (xy > 127 ) return 127 ;
71
+ else return xy;
72
+ }
73
+
63
74
Mouse_::Mouse_ (void ) : _buttons(0 )
64
75
{
65
76
static HIDSubDescriptor node (_hidReportDescriptor, sizeof (_hidReportDescriptor));
@@ -82,12 +93,12 @@ void Mouse_::click(uint8_t b)
82
93
move (0 ,0 ,0 );
83
94
}
84
95
85
- void Mouse_::move (signed char x, signed char y, signed char wheel)
96
+ void Mouse_::move (int x, int y, signed char wheel)
86
97
{
87
98
uint8_t m[4 ];
88
99
m[0 ] = _buttons;
89
- m[1 ] = x ;
90
- m[2 ] = y ;
100
+ m[1 ] = limit_xy (x) ;
101
+ m[2 ] = limit_xy (y) ;
91
102
m[3 ] = wheel;
92
103
HID ().SendReport (1 ,m,4 );
93
104
}
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ class Mouse_
49
49
void begin (void );
50
50
void end (void );
51
51
void click (uint8_t b = MOUSE_LEFT);
52
- void move (signed char x, signed char y, signed char wheel = 0 );
52
+ void move (int x, int y, signed char wheel = 0 );
53
53
void press (uint8_t b = MOUSE_LEFT); // press LEFT by default
54
54
void release (uint8_t b = MOUSE_LEFT); // release LEFT by default
55
55
bool isPressed (uint8_t b = MOUSE_LEFT); // check LEFT by default
You can’t perform that action at this time.
0 commit comments