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
47 [[nodiscard]] bool initCommunication(Mode mode) const;
48 void prepareSendPacket(Mode mode, CMD cmd, uint8_t page = 0) const;
49 [[nodiscard]] bool isChecksumValid(Mode mode) const;
50
51 protected:
52 [[nodiscard]] int getVID() const override { return 0x2f24; }
53 [[nodiscard]] int getPID() const override { return 0x135; }
54
55 public:
60 explicit ControllerV1(int controllerFeatures = 0);
61 ~ControllerV1() override;
62
63 [[nodiscard]] int getControllerType() const override { return 1; }
64
65 [[nodiscard]] bool readVersion() override;
66 [[nodiscard]] bool readConfig() override;
67 [[nodiscard]] bool writeConfig() const override;
68 [[nodiscard]] bool resetConfig() const override;
69 [[nodiscard]] bool setButton(Button btn, const std::string &key) const override;
70 [[nodiscard]] std::string getButton(Button btn) const override;
71 [[nodiscard]] bool setBackButton(int num, int slot, const std::string &key) const override;
72 [[nodiscard]] std::string getBackButton(int num, int slot) const override;
73 void setBackButtonStartTime(int num, int slot, int timeMs) const override;
74 [[nodiscard]] int getBackButtonStartTime(int num, int slot) const override;
75 void setRumble(RumbleMode mode) const override;
76 [[nodiscard]] RumbleMode getRumbleMode() const override;
77 void setLedMode(LedMode mode) const override;
78 [[nodiscard]] LedMode getLedMode() const override;
79 void setLedColor(int r, int g, int b) const override;
80 [[nodiscard]] std::tuple<int, int, int> getLedColor() const override;
81 void setAnalogCenter(int center, bool left) const override;
82 [[nodiscard]] int getAnalogCenter(bool left) const override;
83 void setAnalogBoundary(int boundary, bool left) const override;
84 [[nodiscard]] int getAnalogBoundary(bool left) const override;
85 };
86}
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
int getControllerType() const override
int value of the controller class version
Definition ControllerV1.h:63
ControllerV1(int controllerFeatures=0)
create a new ControllerV1 controller
Definition ControllerV1.cpp:27