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 #pragma once
24 
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 #include "fabui.h"
41 
42 
43 namespace fabgl {
44 
45 
46 
47 
51 struct MouseDelta {
52  int16_t deltaX;
53  int16_t deltaY;
54  int8_t deltaZ;
56  uint8_t overflowX : 1;
57  uint8_t overflowY : 1;
58 };
59 
60 
64 enum MouseType {
67 };
68 
69 
99 class MouseClass : public PS2DeviceClass {
100 
101 public:
102 
103  MouseClass();
104 
105  ~MouseClass();
106 
121  void begin(gpio_num_t clkGPIO, gpio_num_t dataGPIO);
122 
137  void begin(int PS2Port);
138 
144  bool reset();
145 
153  bool isMouseAvailable() { return m_mouseAvailable; }
154 
160  int deltaAvailable();
161 
176  bool getNextDelta(MouseDelta * delta, int timeOutMS = -1, bool requestResendOnTimeOut = false);
177 
187  bool setSampleRate(int value) { return send_cmdSetSampleRate(value); }
188 
199  bool setResolution(int value) { return send_cmdSetResolution(value); }
200 
210  bool setScaling(int value) { return send_cmdSetScaling(value); }
211 
229  void setupAbsolutePositioner(int width, int height, bool createAbsolutePositionsQueue, bool updateVGAController, uiApp * app);
230 
251  void updateAbsolutePosition(MouseDelta * delta);
252 
256  MouseStatus & status() { return m_status; }
257 
266  int availableStatus();
267 
287  MouseStatus getNextStatus(int timeOutMS = -1);
288 
296  int & movementAcceleration() { return m_movementAcceleration; }
297 
305  int & wheelAcceleration() { return m_wheelAcceleration; }
306 
307 
308 private:
309 
310  int getPacketSize();
311  static void absoluteUpdateTimerFunc(TimerHandle_t xTimer);
312 
313 
314  bool m_mouseAvailable;
315  MouseType m_mouseType;
316 
317  // absolute position support
318  Size m_area;
319  MouseStatus m_status;
320  MouseStatus m_prevStatus;
321  int64_t m_prevDeltaTime;
322  int m_movementAcceleration; // reasonable values: 0...2000
323  int m_wheelAcceleration; // reasonable values: 0...100000
324  TimerHandle_t m_absoluteUpdateTimer;
325  QueueHandle_t m_absoluteQueue; // a queue of messages generated by updateAbsolutePosition()
326  bool m_updateVGAController;
327 
328  uiApp * m_uiApp;
329 };
330 
331 
332 
333 } // end of namespace
334 
335 
336 
337 extern fabgl::MouseClass Mouse;
338 
339 
340 
341 
342 
343 
int16_t deltaY
Definition: mouse.h:53
int8_t deltaZ
Definition: mouse.h:54
Represents the whole application base class.
Definition: fabui.h:2082
This file contains all classes related to FabGL Graphical User Interface.
MouseType
Describes mouse type.
Definition: mouse.h:64
bool setResolution(int value)
Sets the resolution.
Definition: mouse.h:199
Definition: mouse.h:66
int & wheelAcceleration()
Gets or sets wheel acceleration factor.
Definition: mouse.h:305
The PS2 Mouse controller class.
Definition: mouse.h:99
Describes mouse movement and buttons status.
Definition: mouse.h:51
bool getNextDelta(MouseDelta *delta, int timeOutMS=-1, bool requestResendOnTimeOut=false)
Gets a mouse movement from the queue.
Definition: mouse.cpp:108
bool reset()
Sends a Reset command to the mouse.
Definition: mouse.cpp:70
Describes mouse absolute position, scroll wheel delta and buttons status.
Definition: fabutils.h:206
uint8_t overflowX
Definition: mouse.h:56
bool setScaling(int value)
Sets the scaling.
Definition: mouse.h:210
This file contains some utility classes and functions.
Definition: canvas.cpp:47
int16_t deltaX
Definition: mouse.h:52
Describes mouse buttons status.
Definition: fabutils.h:195
void setupAbsolutePositioner(int width, int height, bool createAbsolutePositionsQueue, bool updateVGAController, uiApp *app)
Initializes absolute position handler.
Definition: mouse.cpp:145
This file contains FabGL library configuration settings, like number of supported colors...
void begin(gpio_num_t clkGPIO, gpio_num_t dataGPIO)
Initializes MouseClass specifying CLOCK and DATA GPIOs.
Definition: mouse.cpp:63
MouseStatus getNextStatus(int timeOutMS=-1)
Gets the next status from the status queue.
Definition: mouse.cpp:283
Represents a bidimensional size.
Definition: fabutils.h:143
int deltaAvailable()
Determines 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:68
Definition: mouse.h:65
bool setSampleRate(int value)
Sets the maximum rate of mouse movements reporting.
Definition: mouse.h:187
MouseButtons buttons
Definition: mouse.h:55
int & movementAcceleration()
Gets or set mouse movement acceleration factor.
Definition: mouse.h:296
bool isMouseAvailable()
Checks if mouse has been detected and correctly initialized.
Definition: mouse.h:153
MouseStatus & status()
Gets or sets current mouse status.
Definition: mouse.h:256
uint8_t overflowY
Definition: mouse.h:57
int availableStatus()
Gets the number of available mouse status.
Definition: mouse.cpp:277
void updateAbsolutePosition(MouseDelta *delta)
Updates absolute position from the specified mouse delta event.
Definition: mouse.cpp:177
This file contains fabgl::PS2DeviceClass definition.