libOpenWinControls
Multiplatform open-source library to interact with the dual-mode controller in GPD devices
Loading...
Searching...
No Matches
ControllerV2.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#include "../include/BackButtonMode.h"
23
24namespace OWC {
29 class OWC_EXPORT ControllerV2 final: public Controller {
30 private:
31 enum struct CMD: int {
32 Init1 = 0x21,
33 Init2 = 0x2b,
34 Version = 0x41,
35 Read = 0x44,
36 Write = 0x43,
37 Commit1 = 0x27,
38 Commit2 = 0x22
39 };
40
41 static constexpr int sendPacketLen = 64;
42 static constexpr int respPacketLen = 64 + 1;
43 static constexpr int configBufLen = 1024;
44 uint8_t writeReqHeader[12] = {0};
45 uint8_t *sendBuf = nullptr;
46 uint8_t *respBuf = nullptr;
47 uint8_t *configBuf = nullptr;
48 int8_t *configI8 = nullptr; // alias
49 uint16_t *configU16 = nullptr; // alias
50 std::pair<int, int> version;
51
52 [[nodiscard]] bool readVersion();
53 [[nodiscard]] bool initReadCommunication() const;
54 [[nodiscard]] bool initWriteCommunication() const;
55 [[nodiscard]] bool sendReadRequest(int *respBytesCount = nullptr) const;
56 [[nodiscard]] bool sendWriteRequest() const;
57 void prepareSendBuffer(CMD cmd) const;
58 void prepareRespBuffer() const;
59 [[nodiscard]] bool isValidRespPacket() const;
60 [[nodiscard]] int getBackButtonModeIdx(int num) const;
61 [[nodiscard]] int getBackButtonKeyPos(int num, int slot) const;
62
63 protected:
64 [[nodiscard]] int getVID() const override { return 0x2f24; }
65 [[nodiscard]] int getPID() const override { return 0x137; }
66
67 public:
72 explicit ControllerV2(int controllerFeatures = 0);
73 ~ControllerV2() override;
74
75 [[nodiscard]] int getControllerType() const override { return 2; }
76
81 [[nodiscard]] std::pair<int, int> getVersion() const { return version; }
82
87 [[nodiscard]] EmulationMode getEmulationMode() const;
88
96 void setBackButtonActiveSlots(int num, uint8_t count) const;
97
105 [[nodiscard]] int getBackButtonActiveSlots(int num) const;
106
115 void setBackButtonHoldTime(int num, int slot, int timeMs) const;
116
125 [[nodiscard]] int getBackButtonHoldTime(int num, int slot) const;
126
127 [[nodiscard]] bool readConfig() override;
128 [[nodiscard]] bool writeConfig() const override;
129 [[nodiscard]] bool setButton(Button btn, const std::string &key) const override;
130 [[nodiscard]] std::string getButton(Button btn) const override;
131 void setBackButtonMode(int num, BackButtonMode mode) const;
132 [[nodiscard]] BackButtonMode getBackButtonMode(int num) const;
133 //void setBackButtonMacroType(int num, BackButtonMacroType type) const;
134 //[[nodiscard]] BackButtonMacroType getBackButtonMacroType(int num) const;
135 [[nodiscard]] bool setBackButton(int num, int slot, const std::string &key) const override;
136 [[nodiscard]] std::string getBackButton(int num, int slot) const override;
137 void setBackButtonStartTime(int num, int slot, int timeMs) const override;
138 [[nodiscard]] int getBackButtonStartTime(int num, int slot) const override;
139 void setRumble(RumbleMode mode) const override;
140 [[nodiscard]] RumbleMode getRumbleMode() const override;
141 void setLedMode(LedMode mode) const override;
142 [[nodiscard]] LedMode getLedMode() const override;
143 void setLedColor(int r, int g, int b) const override;
144 [[nodiscard]] std::tuple<int, int, int> getLedColor() const override;
145 void setAnalogCenter(int center, bool left) const override;
146 [[nodiscard]] int getAnalogCenter(bool left) const override;
147 void setAnalogBoundary(int boundary, bool left) const override;
148 [[nodiscard]] int getAnalogBoundary(bool left) const override;
149 };
150}
Button
enum to refer to a physical button and its mode
Definition Button.h:28
EmulationMode
controller emulation mode
Definition EmulationMode.h:28
LedMode
led mode
Definition LedMode.h:28
RumbleMode
vibration intensity
Definition RumbleMode.h:28
int getControllerType() const override
int value of the controller class version
Definition ControllerV2.h:75
std::pair< int, int > getVersion() const
get the firmware version
Definition ControllerV2.h:81
ControllerV2(int controllerFeatures=0)
create a new ControllerV2 controller
Definition ControllerV2.cpp:34
Controller abstract base class.
Definition Controller.h:35