| 1 | #ifndef ESP32_BLE_MOUSE_H |
| 2 | #define ESP32_BLE_MOUSE_H |
| 3 | #include "sdkconfig.h" |
| 4 | #if defined(CONFIG_BT_ENABLED) |
| 5 | |
| 6 | #include "BleConnectionStatus.h" |
| 7 | #include "BLEHIDDevice.h" |
| 8 | #include "BLECharacteristic.h" |
| 9 | |
| 10 | #define MOUSE_LEFT 1 |
| 11 | #define MOUSE_RIGHT 2 |
| 12 | #define MOUSE_MIDDLE 4 |
| 13 | #define MOUSE_BACK 8 |
| 14 | #define MOUSE_FORWARD 16 |
| 15 | #define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE) # For compatibility with the Mouse library |
| 16 | |
| 17 | class BleMouse { |
| 18 | private: |
| 19 | uint8_t _buttons; |
| 20 | BleConnectionStatus* connectionStatus; |
| 21 | BLEHIDDevice* hid; |
| 22 | BLECharacteristic* inputMouse; |
| 23 | void buttons(uint8_t b); |
| 24 | void rawAction(uint8_t msg[], char msgSize); |
| 25 | static void taskServer(void* pvParameter); |
| 26 | public: |
| 27 | BleMouse(std::string deviceName = "ESP32 Bluetooth Mouse", std::string deviceManufacturer = "Espressif", uint8_t batteryLevel = 100); |
| 28 | void begin(void); |
| 29 | void end(void); |
| 30 | void click(uint8_t b = MOUSE_LEFT); |
| 31 | void move(signed char x, signed char y, signed char wheel = 0, signed char hWheel = 0); |
| 32 | void press(uint8_t b = MOUSE_LEFT); // press LEFT by default |
| 33 | void release(uint8_t b = MOUSE_LEFT); // release LEFT by default |
| 34 | bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default |
| 35 | bool isConnected(void); |
| 36 | void setBatteryLevel(uint8_t level); |
| 37 | uint8_t batteryLevel; |
| 38 | std::string deviceManufacturer; |
| 39 | std::string deviceName; |
| 40 | protected: |
| 41 | virtual void onStarted(BLEServer *pServer) { }; |
| 42 | }; |
| 43 | |
| 44 | #endif // CONFIG_BT_ENABLED |
| 45 | #endif // ESP32_BLE_MOUSE_H |