FabGL
ESP32 VGA Controller and Graphics Library
mouse.h
Go to the documentation of this file.
1 /*
2  Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - <http://www.fabgl.com>
3  Copyright (c) 2019 Fabrizio Di Vittorio.
4  All rights reserved.
5 
6  This file is part of FabGL Library.
7 
8  FabGL is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  FabGL is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with FabGL. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 
23 #ifndef _MOUSE_H_INCLUDED
24 #define _MOUSE_H_INCLUDED
25 
26 
34 #include "freertos/FreeRTOS.h"
35 #include "freertos/timers.h"
36 
37 #include "fabglconf.h"
38 #include "fabutils.h"
39 #include "ps2device.h"
40 
41 
42 namespace fabgl {
43 
44 
48 struct MouseButtons {
49  uint8_t left : 1;
50  uint8_t middle : 1;
51  uint8_t right : 1;
52 };
53 
54 
58 struct MouseDelta {
59  int16_t deltaX;
60  int16_t deltaY;
61  int8_t deltaZ;
63  uint8_t overflowX : 1;
64  uint8_t overflowY : 1;
65 };
66 
67 
71 enum MouseType {
74 };
75 
76 
80 struct MouseStatus {
81  int16_t X;
82  int16_t Y;
83  int8_t wheelDelta;
85 };
86 
87 
117 class MouseClass : public PS2DeviceClass {
118 
119 public:
120 
121  MouseClass();
122 
123  ~MouseClass();
124 
139  void begin(gpio_num_t clkGPIO, gpio_num_t dataGPIO);
140 
155  void begin(int PS2Port);
156 
162  bool reset();
163 
171  bool isMouseAvailable() { return m_mouseAvailable; }
172 
178  int deltaAvailable();
179 
194  bool getNextDelta(MouseDelta * delta, int timeOutMS = -1, bool requestResendOnTimeOut = false);
195 
205  bool setSampleRate(int value) { return send_cmdSetSampleRate(value); }
206 
217  bool setResolution(int value) { return send_cmdSetResolution(value); }
218 
228  bool setScaling(int value) { return send_cmdSetScaling(value); }
229 
246  void setupAbsolutePositioner(int width, int height, bool createAbsolutePositionsQueue, bool updateVGAController);
247 
268  void updateAbsolutePosition(MouseDelta * delta);
269 
273  MouseStatus & status() { return m_status; }
274 
283  int availableStatus();
284 
304  MouseStatus getNextStatus(int timeOutMS = -1);
305 
313  int & movementAcceleration() { return m_movementAcceleration; }
314 
322  int & wheelAcceleration() { return m_wheelAcceleration; }
323 
324 
325 private:
326 
327  int getPacketSize();
328  static void absoluteUpdateTimerFunc(TimerHandle_t xTimer);
329 
330 
331  bool m_mouseAvailable;
332  MouseType m_mouseType;
333 
334  // absolute position support
335  Size m_area;
336  MouseStatus m_status;
337  int64_t m_prevDeltaTime;
338  int m_movementAcceleration; // reasonable values: 0...2000
339  int m_wheelAcceleration; // reasonable values: 0...100000
340  TimerHandle_t m_absoluteUpdateTimer;
341  QueueHandle_t m_absoluteQueue; // a queue of messages generated by updateAbsolutePosition()
342  bool m_updateVGAController;
343 };
344 
345 
346 
347 } // end of namespace
348 
349 
350 
351 extern fabgl::MouseClass Mouse;
352 
353 
354 
355 #endif
356 
357 
358 
uint8_t middle
Definition: mouse.h:50
int16_t deltaY
Definition: mouse.h:60
uint8_t left
Definition: mouse.h:49
int8_t deltaZ
Definition: mouse.h:61
bool setResolution(int value)
Set the resolution.
Definition: mouse.h:217
MouseButtons buttons
Definition: mouse.h:84
MouseType
Describes mouse type.
Definition: mouse.h:71
int & wheelAcceleration()
Get or set wheel acceleration factor.
Definition: mouse.h:322
The PS2 Mouse controller class.
Definition: mouse.h:117
Describes mouse movement and buttons status.
Definition: mouse.h:58
bool getNextDelta(MouseDelta *delta, int timeOutMS=-1, bool requestResendOnTimeOut=false)
Get a mouse movement from the queue.
Definition: mouse.cpp:108
bool reset()
Send a Reset command to the mouse.
Definition: mouse.cpp:70
Describes mouse absolute position, scroll wheel delta and buttons status.
Definition: mouse.h:80
Definition: mouse.h:72
uint8_t overflowX
Definition: mouse.h:63
bool setScaling(int value)
Set the scaling.
Definition: mouse.h:228
Definition: canvas.cpp:37
int16_t deltaX
Definition: mouse.h:59
void setupAbsolutePositioner(int width, int height, bool createAbsolutePositionsQueue, bool updateVGAController)
Initialize absolute position handler.
Definition: mouse.cpp:140
Describes mouse buttons status.
Definition: mouse.h:48
This file contains FabGL library configuration settings, like number of supported colors...
int16_t X
Definition: mouse.h:81
void begin(gpio_num_t clkGPIO, gpio_num_t dataGPIO)
Initialize MouseClass specifying CLOCK and DATA GPIOs.
Definition: mouse.cpp:63
MouseStatus getNextStatus(int timeOutMS=-1)
Get the next status from the status queue.
Definition: mouse.cpp:235
Represents a bidimensional size.
Definition: fabutils.h:52
uint8_t right
Definition: mouse.h:51
int deltaAvailable()
Get the number of mouse movements available in the queue.
Definition: mouse.cpp:102
Base class for PS2 devices (like mouse or keyboard).
Definition: ps2device.h:69
bool setSampleRate(int value)
Set the maximum rate of mouse movements reporting.
Definition: mouse.h:205
MouseButtons buttons
Definition: mouse.h:62
int & movementAcceleration()
Get or set mouse movement acceleration factor.
Definition: mouse.h:313
bool isMouseAvailable()
Check if mouse has been detected and correctly initialized.
Definition: mouse.h:171
int16_t Y
Definition: mouse.h:82
MouseStatus & status()
Get or set current mouse status.
Definition: mouse.h:273
uint8_t overflowY
Definition: mouse.h:64
int availableStatus()
Get the number of available mouse status.
Definition: mouse.cpp:229
Definition: mouse.h:73
void updateAbsolutePosition(MouseDelta *delta)
Update absolute position from the specified mouse delta event.
Definition: mouse.cpp:169
int8_t wheelDelta
Definition: mouse.h:83
This file contains fabgl::PS2DeviceClass definition.