Kaleidoscope
Mouse.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2014-2015 NicoHood
3 See the readme for credit to other people.
4 
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11 
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14 
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 THE SOFTWARE.
22 */
23 
24 // Include guard
25 #pragma once
26 
27 #include <Arduino.h>
28 #include "PluggableUSB.h"
29 #include "HID.h"
30 #include "HID-Settings.h"
31 #include "../MouseButtons.h"
32 
33 typedef union {
34  // Mouse report: 8 buttons, position, wheel
35  struct {
36  uint8_t buttons;
37  int8_t xAxis;
38  int8_t yAxis;
39  int8_t wheel;
40  };
42 
43 
44 class Mouse_ {
45  public:
46  Mouse_(void);
47  void begin(void);
48  void end(void);
49  void click(uint8_t b = MOUSE_LEFT);
50  void move(signed char x, signed char y, signed char wheel = 0);
51  void press(uint8_t b = MOUSE_LEFT); // press LEFT by default
52  void release(uint8_t b = MOUSE_LEFT); // release LEFT by default
53  bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default
54 
55  void sendReport(void* data, int length);
56 
57  protected:
58  uint8_t _buttons;
59  void buttons(uint8_t b);
60 };
61 extern Mouse_ Mouse;
void end(void)
Definition: Mouse.cpp:69
void press(uint8_t b=MOUSE_LEFT)
Definition: Mouse.cpp:97
void buttons(uint8_t b)
Definition: Mouse.cpp:90
void click(uint8_t b=MOUSE_LEFT)
Definition: Mouse.cpp:74
Definition: Mouse.h:44
void sendReport(void *data, int length)
Definition: Mouse.cpp:112
int8_t wheel
Definition: Mouse.h:39
void move(signed char x, signed char y, signed char wheel=0)
Definition: Mouse.cpp:81
Mouse_ Mouse
Definition: Mouse.cpp:116
Definition: Mouse.h:33
uint8_t buttons
Definition: Mouse.h:36
int8_t xAxis
Definition: Mouse.h:37
int8_t yAxis
Definition: Mouse.h:38
#define MOUSE_LEFT
Definition: MouseButtons.h:3
Mouse_(void)
Definition: Mouse.cpp:60
void begin(void)
Definition: Mouse.cpp:65
bool isPressed(uint8_t b=MOUSE_LEFT)
Definition: Mouse.cpp:105
void release(uint8_t b=MOUSE_LEFT)
Definition: Mouse.cpp:101
uint8_t _buttons
Definition: Mouse.h:58