FabGL
ESP32 Display 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-2020 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 "comdrivers/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 Mouse : public PS2Device {
100 
101 public:
102 
103  Mouse();
104 
105  ~Mouse();
106 
124  void begin(gpio_num_t clkGPIO, gpio_num_t dataGPIO);
125 
140  void begin(int PS2Port);
141 
147  bool reset();
148 
156  bool isMouseAvailable() { return m_mouseAvailable; }
157 
163  int deltaAvailable();
164 
179  bool getNextDelta(MouseDelta * delta, int timeOutMS = -1, bool requestResendOnTimeOut = false);
180 
190  bool setSampleRate(int value) { return send_cmdSetSampleRate(value); }
191 
202  bool setResolution(int value) { return send_cmdSetResolution(value); }
203 
213  bool setScaling(int value) { return send_cmdSetScaling(value); }
214 
232  void setupAbsolutePositioner(int width, int height, bool createAbsolutePositionsQueue, BitmappedDisplayController * updateDisplayController = nullptr, uiApp * app = nullptr);
233 
239  void setUIApp(uiApp * app) { m_uiApp = app; }
240 
245 
266  void updateAbsolutePosition(MouseDelta * delta);
267 
271  MouseStatus & status() { return m_status; }
272 
281  int availableStatus();
282 
302  MouseStatus getNextStatus(int timeOutMS = -1);
303 
311  int & movementAcceleration() { return m_movementAcceleration; }
312 
320  int & wheelAcceleration() { return m_wheelAcceleration; }
321 
325  void emptyQueue();
326 
327 
331  static void quickCheckHardware() { s_quickCheckHardware = true; }
332 
333 
334 private:
335 
336  int getPacketSize();
337  static void absoluteUpdateTimerFunc(TimerHandle_t xTimer);
338 
339 
340  static bool s_quickCheckHardware;
341 
342  bool m_mouseAvailable;
343  MouseType m_mouseType;
344 
345  // absolute position support
346  Size m_area;
347  MouseStatus m_status;
348  MouseStatus m_prevStatus;
349  int64_t m_prevDeltaTime;
350  int m_movementAcceleration; // reasonable values: 0...2000
351  int m_wheelAcceleration; // reasonable values: 0...100000
352  TimerHandle_t m_absoluteUpdateTimer;
353  QueueHandle_t m_absoluteQueue; // a queue of messages generated by updateAbsolutePosition()
354  BitmappedDisplayController * m_updateDisplayController;
355 
356  uiApp * m_uiApp;
357 };
358 
359 
360 
361 } // end of namespace
362 
363 
364 
365 
366 
367 
368 
369 
370 
371 
static void quickCheckHardware()
Disable re-try when a mouse is not found.
Definition: mouse.h:331
bool setScaling(int value)
Sets the scaling.
Definition: mouse.h:213
uint8_t overflowX
Definition: mouse.h:56
bool setResolution(int value)
Sets the resolution.
Definition: mouse.h:202
Represents the whole application base class.
Definition: fabui.h:2561
This file contains all classes related to FabGL Graphical User Interface.
uint8_t overflowY
Definition: mouse.h:57
bool setSampleRate(int value)
Sets the maximum rate of mouse movements reporting.
Definition: mouse.h:190
int & wheelAcceleration()
Gets or sets wheel acceleration factor.
Definition: mouse.h:320
int & movementAcceleration()
Gets or set mouse movement acceleration factor.
Definition: mouse.h:311
MouseType
Describes mouse type.
Definition: mouse.h:64
Represents the base abstract class for bitmapped display controllers.
int16_t deltaY
Definition: mouse.h:53
Describes mouse movement and buttons status.
Definition: mouse.h:51
int8_t deltaZ
Definition: mouse.h:54
Describes mouse absolute position, scroll wheel delta and buttons status.
Definition: fabutils.h:242
MouseStatus getNextStatus(int timeOutMS=-1)
Gets the next status from the status queue.
Definition: mouse.cpp:318
void emptyQueue()
Empties the mouse status and events queue.
Definition: mouse.cpp:327
This file contains some utility classes and functions.
Definition: canvas.cpp:31
bool isMouseAvailable()
Checks if mouse has been detected and correctly initialized.
Definition: mouse.h:156
MouseButtons buttons
Definition: mouse.h:55
Describes mouse buttons status.
Definition: fabutils.h:229
void terminateAbsolutePositioner()
Terminates absolute position handler.
Definition: mouse.cpp:197
Base class for PS2 devices (like mouse or keyboard).
Definition: ps2device.h:66
This file contains FabGL library configuration settings, like number of supported colors...
bool getNextDelta(MouseDelta *delta, int timeOutMS=-1, bool requestResendOnTimeOut=false)
Gets a mouse movement from the queue.
Definition: mouse.cpp:119
Represents a bidimensional size.
Definition: fabutils.h:176
void setUIApp(uiApp *app)
Sets current UI app.
Definition: mouse.h:239
MouseStatus & status()
Gets or sets current mouse status.
Definition: mouse.h:271
int availableStatus()
Gets the number of available mouse status.
Definition: mouse.cpp:312
void begin(gpio_num_t clkGPIO, gpio_num_t dataGPIO)
Initializes Mouse specifying CLOCK and DATA GPIOs.
Definition: mouse.cpp:69
int16_t deltaX
Definition: mouse.h:52
void updateAbsolutePosition(MouseDelta *delta)
Updates absolute position from the specified mouse delta event.
Definition: mouse.cpp:212
uint8_t height
int deltaAvailable()
Determines the number of mouse movements available in the queue.
Definition: mouse.cpp:113
The PS2 Mouse controller class.
Definition: mouse.h:99
void setupAbsolutePositioner(int width, int height, bool createAbsolutePositionsQueue, BitmappedDisplayController *updateDisplayController=nullptr, uiApp *app=nullptr)
Initializes absolute position handler.
Definition: mouse.cpp:165
bool reset()
Sends a Reset command to the mouse.
Definition: mouse.cpp:78
uint8_t width
This file contains fabgl::PS2Device definition.