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-2022 Fabrizio Di Vittorio.
4 All rights reserved.
5
6
7* Please contact fdivitto2013@gmail.com if you need a commercial license.
8
9
10* This library and related software is available under GPL v3.
11
12 FabGL is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
16
17 FabGL is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with FabGL. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26
27#pragma once
28
29
30
38#include "freertos/FreeRTOS.h"
39#include "freertos/timers.h"
40
41#include "fabglconf.h"
42#include "fabutils.h"
44#include "fabui.h"
45
46
47namespace fabgl {
48
49
50
51
55struct MouseDelta {
56 int16_t deltaX;
57 int16_t deltaY;
58 int8_t deltaZ;
60 uint8_t overflowX : 1;
61 uint8_t overflowY : 1;
62};
63
64
69 uint8_t data[4];
70};
71
72
79};
80
81
111class Mouse : public PS2Device {
112
113public:
114
115 Mouse();
116
117 ~Mouse();
118
136 void begin(gpio_num_t clkGPIO, gpio_num_t dataGPIO);
137
152 void begin(int PS2Port);
153
159 bool reset();
160
168 bool isMouseAvailable() { return m_mouseAvailable; }
169
175 int getPacketSize();
176
182 bool packetAvailable();
183
198 bool getNextPacket(MousePacket * packet, int timeOutMS = -1, bool requestResendOnTimeOut = false);
199
205 bool deltaAvailable();
206
221 bool getNextDelta(MouseDelta * delta, int timeOutMS = -1, bool requestResendOnTimeOut = false);
222
232 bool setSampleRate(int value) { return send_cmdSetSampleRate(value); }
233
244 bool setResolution(int value) { return send_cmdSetResolution(value); }
245
255 bool setScaling(int value) { return send_cmdSetScaling(value); }
256
274 void setupAbsolutePositioner(int width, int height, bool createAbsolutePositionsQueue, BitmappedDisplayController * updateDisplayController = nullptr, uiApp * app = nullptr);
275
281 void setUIApp(uiApp * app) { m_uiApp = app; }
282
287
309
313 MouseStatus & status() { return m_status; }
314
323 int availableStatus();
324
344 MouseStatus getNextStatus(int timeOutMS = -1);
345
353 int & movementAcceleration() { return m_movementAcceleration; }
354
362 int & wheelAcceleration() { return m_wheelAcceleration; }
363
367 void emptyQueue();
368
369
373 static void quickCheckHardware() { s_quickCheckHardware = true; }
374
375
376private:
377
378 static void mouseUpdateTask(void * arg);
379 bool decodeMousePacket(MousePacket * mousePacket, MouseDelta * delta);
380
381 static bool s_quickCheckHardware;
382
383 bool m_mouseAvailable;
384 MouseType m_mouseType;
385
386 TaskHandle_t m_mouseUpdateTask;
387
388 // queue of one mouse packet
389 QueueHandle_t m_receivedPacket;
390
391 // absolute position support
392 bool m_absoluteUpdate;
393 Size m_area;
394 MouseStatus m_status;
395 MouseStatus m_prevStatus;
396 int64_t m_prevDeltaTime;
397 int m_movementAcceleration; // reasonable values: 0...2000
398 int m_wheelAcceleration; // reasonable values: 0...100000
399 QueueHandle_t m_absoluteQueue; // a queue of messages generated by updateAbsolutePosition()
400 BitmappedDisplayController * m_updateDisplayController;
401
402 uiApp * m_uiApp;
403};
404
405
406
407} // end of namespace
408
409
410
411
412
413
414
415
416
417
Represents the base abstract class for bitmapped display controllers.
MouseStatus & status()
Gets or sets current mouse status.
Definition: mouse.h:313
bool setResolution(int value)
Sets the resolution.
Definition: mouse.h:244
bool getNextPacket(MousePacket *packet, int timeOutMS=-1, bool requestResendOnTimeOut=false)
Gets a mouse raw movement (packet) from the queue.
Definition: mouse.cpp:134
bool setScaling(int value)
Sets the scaling.
Definition: mouse.h:255
bool deltaAvailable()
Determines if there is a mouse movement available in the queue.
Definition: mouse.cpp:140
int & wheelAcceleration()
Gets or sets wheel acceleration factor.
Definition: mouse.h:362
void setupAbsolutePositioner(int width, int height, bool createAbsolutePositionsQueue, BitmappedDisplayController *updateDisplayController=nullptr, uiApp *app=nullptr)
Initializes absolute position handler.
Definition: mouse.cpp:194
void terminateAbsolutePositioner()
Terminates absolute position handler.
Definition: mouse.cpp:224
bool packetAvailable()
Determines if there is a raw mouse movement available in the queue.
Definition: mouse.cpp:128
bool setSampleRate(int value)
Sets the maximum rate of mouse movements reporting.
Definition: mouse.h:232
bool reset()
Sends a Reset command to the mouse.
Definition: mouse.cpp:91
void begin(gpio_num_t clkGPIO, gpio_num_t dataGPIO)
Initializes Mouse specifying CLOCK and DATA GPIOs.
Definition: mouse.cpp:83
bool isMouseAvailable()
Checks if mouse has been detected and correctly initialized.
Definition: mouse.h:168
bool getNextDelta(MouseDelta *delta, int timeOutMS=-1, bool requestResendOnTimeOut=false)
Gets a mouse movement from the queue.
Definition: mouse.cpp:187
void setUIApp(uiApp *app)
Sets current UI app.
Definition: mouse.h:281
int & movementAcceleration()
Gets or set mouse movement acceleration factor.
Definition: mouse.h:353
int getPacketSize()
Gets mouse packet size.
Definition: mouse.cpp:122
MouseStatus getNextStatus(int timeOutMS=-1)
Gets the next status from the status queue.
Definition: mouse.cpp:377
int availableStatus()
Gets the number of available mouse status.
Definition: mouse.cpp:371
void emptyQueue()
Empties the mouse status and events queue.
Definition: mouse.cpp:386
void updateAbsolutePosition(MouseDelta *delta)
Updates absolute position from the specified mouse delta event.
Definition: mouse.cpp:236
static void quickCheckHardware()
Disable re-try when a mouse is not found.
Definition: mouse.h:373
The PS2 Mouse controller class.
Definition: mouse.h:111
Base class for PS2 devices (like mouse or keyboard).
Definition: ps2device.h:70
Represents the whole application base class.
Definition: fabui.h:3105
uint8_t width
uint8_t height
This file contains FabGL library configuration settings, like number of supported colors,...
This file contains all classes related to FabGL Graphical User Interface.
This file contains some utility classes and functions.
MouseType
Describes mouse type.
Definition: mouse.h:76
@ Intellimouse
Definition: mouse.h:78
@ LegacyMouse
Definition: mouse.h:77
This file contains fabgl::PS2Device definition.
Describes mouse buttons status.
Definition: fabutils.h:286
int8_t deltaZ
Definition: mouse.h:58
MouseButtons buttons
Definition: mouse.h:59
uint8_t overflowY
Definition: mouse.h:61
uint8_t overflowX
Definition: mouse.h:60
int16_t deltaY
Definition: mouse.h:57
int16_t deltaX
Definition: mouse.h:56
Describes mouse movement and buttons status.
Definition: mouse.h:55
Contains raw data received from mouse.
Definition: mouse.h:68
Describes mouse absolute position, scroll wheel delta and buttons status.
Definition: fabutils.h:299
Represents a bidimensional size.
Definition: fabutils.h:231