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 uint8_t resetBuf[] = {0x4b, 0x00, 0x4e, 0x00, 0x4a, 0x00, 0x4d, 0x00, 0x2c, 0x00, 0x06, 0x00, 0x15, 0x00, 0x1e, 0x00, 0x1a, 0x00, 0x16, 0x00, 0x04, 0x00, 0x07, 0x00, 0xe1, 0x00, 0x08, 0x00, 0x09, 0x00, 0x2b, 0x00, 0x29, 0x00, 0xeb, 0x00, 0xea, 0x00, 0x14, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x21, 0xff, 0x00, 0x00, 0xf7, 0xff, 0xf7, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
42 static constexpr int configBufLen = 128;
43 uint8_t *configBuf = nullptr;
44 int8_t *configI8 = nullptr; // alias
45 uint16_t *configU16 = nullptr; // alias
46 std::pair<int, int> xVersion;
47 std::pair<int, int> kVersion;
48
49 [[nodiscard]] bool initCommunication(Mode mode) const;
50 void prepareSendPacket(Mode mode, CMD cmd, uint8_t page = 0) const;
51 [[nodiscard]] bool isChecksumValid(Mode mode) const;
52
53 protected:
54 [[nodiscard]] int getVID() const override { return 0x2f24; }
55 [[nodiscard]] int getPID() const override { return 0x135; }
56
57 public:
62 explicit ControllerV1(int controllerFeatures = 0);
63 ~ControllerV1() override;
64
65 [[nodiscard]] int getControllerType() const override { return 1; }
66
71 [[nodiscard]] std::pair<int, int> getXVersion() const { return xVersion; }
72
77 [[nodiscard]] std::pair<int, int> getKVersion() const { return kVersion; }
78
79 [[nodiscard]] bool readVersion() override;
80 [[nodiscard]] bool readConfig() override;
81 [[nodiscard]] bool writeConfig() const override;
82 [[nodiscard]] bool resetConfig() const override;
83 [[nodiscard]] bool setButton(Button btn, const std::string &key) const override;
84 [[nodiscard]] std::string getButton(Button btn) const override;
85 [[nodiscard]] bool setBackButton(int num, int slot, const std::string &key) const override;
86 [[nodiscard]] std::string getBackButton(int num, int slot) const override;
87 void setBackButtonStartTime(int num, int slot, int timeMs) const override;
88 [[nodiscard]] int getBackButtonStartTime(int num, int slot) const override;
89 void setRumble(RumbleMode mode) const override;
90 [[nodiscard]] RumbleMode getRumbleMode() const override;
91 void setLedMode(LedMode mode) const override;
92 [[nodiscard]] LedMode getLedMode() const override;
93 void setLedColor(int r, int g, int b) const override;
94 [[nodiscard]] std::tuple<int, int, int> getLedColor() const override;
95 void setAnalogCenter(int center, bool left) const override;
96 [[nodiscard]] int getAnalogCenter(bool left) const override;
97 void setAnalogBoundary(int boundary, bool left) const override;
98 [[nodiscard]] int getAnalogBoundary(bool left) const override;
99 };
100}
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:77
int getControllerType() const override
int value of the controller class version
Definition ControllerV1.h:65
std::pair< int, int > getXVersion() const
get the firmware xinput mode version
Definition ControllerV1.h:71
ControllerV1(int controllerFeatures=0)
create a new ControllerV1 controller
Definition ControllerV1.cpp:27