libOpenWinControls
Multiplatform open-source library to interact with the dual-mode controller in GPD devices
Loading...
Searching...
No Matches
ControllerV1.h
1/*
2 * This file is part of libOpenWinControls.
3 * Copyright (C) 2026 kylon
4 *
5 * libOpenWinControls is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * libOpenWinControls is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18#pragma once
19
20#include "Controller.h"
21
22namespace OWC {
27 class OWC_EXPORT ControllerV1 final: public Controller {
28 private:
29 enum struct Mode: int {
30 Read = 1,
31 Write = 2
32 };
33
34 enum struct CMD: int {
35 Init = 0,
36 ReadWrite = 1,
37 Checksum = 2,
38 Commit = 3
39 };
40
41 static constexpr int sendPacketLen = 32 + 1;
42 static constexpr int respPacketLen = 64 + 1;
43 static constexpr int configBufLen = respPacketLen * 2;
44 std::pair<int, int> xVersion;
45 std::pair<int, int> kVersion;
46 uint8_t *sendBuf = nullptr;
47 uint8_t *respBuf = nullptr;
48 uint8_t *configBuf = nullptr;
49 int8_t *configI8 = nullptr; // alias
50 uint16_t *configU16 = nullptr; // alias
51
52 [[nodiscard]] bool initCommunication(Mode mode) const;
53 [[nodiscard]] bool sendReadRequest() const;
54 [[nodiscard]] bool sendWriteRequest() const;
55 void prepareSendPacket(Mode mode, CMD cmd, uint8_t page = 0) const;
56 void prepareRespBuffer() const;
57 [[nodiscard]] bool isConfigValid(int configChecksum, Mode mode) const;
58 void parseVersion();
59
60 protected:
61 [[nodiscard]] int getVID() const override { return 0x2f24; }
62 [[nodiscard]] int getPID() const override { return 0x135; }
63
64 public:
69 explicit ControllerV1(int controllerFeatures = 0);
70 ~ControllerV1() override;
71
72 [[nodiscard]] int getControllerType() const override { return 1; }
73
78 [[nodiscard]] std::pair<int, int> getXVersion() const { return xVersion; }
79
84 [[nodiscard]] std::pair<int, int> getKVersion() const { return kVersion; }
85
86 [[nodiscard]] bool readConfig() override;
87 [[nodiscard]] bool writeConfig() const override;
88 [[nodiscard]] bool setButton(Button btn, const std::string &key) const override;
89 [[nodiscard]] std::string getButton(Button btn) const override;
90 [[nodiscard]] bool setBackButton(int num, int slot, const std::string &key) const override;
91 [[nodiscard]] std::string getBackButton(int num, int slot) const override;
92 void setBackButtonStartTime(int num, int slot, int timeMs) const override;
93 [[nodiscard]] int getBackButtonStartTime(int num, int slot) const override;
94 void setRumble(RumbleMode mode) const override;
95 [[nodiscard]] RumbleMode getRumbleMode() const override;
96 void setLedMode(LedMode mode) const override;
97 [[nodiscard]] LedMode getLedMode() const override;
98 void setLedColor(int r, int g, int b) const override;
99 [[nodiscard]] std::tuple<int, int, int> getLedColor() const override;
100 void setAnalogCenter(int center, bool left) const override;
101 [[nodiscard]] int getAnalogCenter(bool left) const override;
102 void setAnalogBoundary(int boundary, bool left) const override;
103 [[nodiscard]] int getAnalogBoundary(bool left) const override;
104 };
105}
Button
enum to refer to a physical button and its mode
Definition Button.h:28
LedMode
led mode
Definition LedMode.h:28
RumbleMode
vibration intensity
Definition RumbleMode.h:28
std::pair< int, int > getKVersion() const
get the firmware keyboard mode version
Definition ControllerV1.h:84
int getControllerType() const override
int value of the controller class version
Definition ControllerV1.h:72
std::pair< int, int > getXVersion() const
get the firmware xinput mode version
Definition ControllerV1.h:78
ControllerV1(int controllerFeatures=0)
create a new ControllerV1 controller
Definition ControllerV1.cpp:33
Controller abstract base class.
Definition Controller.h:35