mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-07-04 14:26:20 +12:00
Clean up CirclePad Pro state
This commit is contained in:
parent
382c0f953d
commit
10d11cb3c9
3 changed files with 37 additions and 28 deletions
|
@ -1,14 +1,45 @@
|
|||
#pragma once
|
||||
#include "bitfield.hpp"
|
||||
#include "services/ir/ir_device.hpp"
|
||||
#include "services/ir/ir_types.hpp"
|
||||
|
||||
namespace IR {
|
||||
class CirclePadPro : public IR::Device {
|
||||
public:
|
||||
struct ButtonState {
|
||||
static constexpr int C_STICK_CENTER = 0x800;
|
||||
static constexpr int C_STICK_RADIUS = 0x7FF;
|
||||
|
||||
union {
|
||||
BitField<0, 8, u32> header;
|
||||
BitField<8, 12, u32> x;
|
||||
BitField<20, 12, u32> y;
|
||||
} cStick;
|
||||
|
||||
union {
|
||||
BitField<0, 5, u8> batteryLevel;
|
||||
BitField<5, 1, u8> zlNotPressed;
|
||||
BitField<6, 1, u8> zrNotPressed;
|
||||
BitField<7, 1, u8> rNotPressed;
|
||||
} buttons;
|
||||
|
||||
u8 unknown;
|
||||
|
||||
ButtonState() {
|
||||
// Response header for button state reads
|
||||
cStick.header = static_cast<u8>(CPPResponseID::PollButtons);
|
||||
// Fully charged
|
||||
buttons.batteryLevel = 0x1F;
|
||||
unknown = 0;
|
||||
}
|
||||
};
|
||||
static_assert(sizeof(ButtonState) == 6, "Circlepad Pro button state has wrong size");
|
||||
|
||||
virtual void connect() override;
|
||||
virtual void disconnect() override;
|
||||
virtual void receivePayload(Payload payload) override;
|
||||
|
||||
CirclePadPro(SendCallback sendCallback) : IR::Device(sendCallback) {}
|
||||
ButtonState state;
|
||||
};
|
||||
} // namespace IR
|
|
@ -116,22 +116,6 @@ namespace IR {
|
|||
u32 maxDataSize;
|
||||
};
|
||||
|
||||
struct CPPResponse {
|
||||
union {
|
||||
BitField<0, 8, u32> header;
|
||||
BitField<8, 12, u32> c_stick_x;
|
||||
BitField<20, 12, u32> c_stick_y;
|
||||
} c_stick;
|
||||
union {
|
||||
BitField<0, 5, u8> battery_level;
|
||||
BitField<5, 1, u8> zl_not_held;
|
||||
BitField<6, 1, u8> zr_not_held;
|
||||
BitField<7, 1, u8> r_not_held;
|
||||
} buttons;
|
||||
u8 unknown;
|
||||
};
|
||||
static_assert(sizeof(CPPResponse) == 6, "Circlepad Pro response has wrong size");
|
||||
|
||||
namespace CPPResponseID {
|
||||
enum : u8 {
|
||||
PollButtons = 0x10, // This response contains the current Circlepad Pro button/stick state
|
||||
|
|
|
@ -322,18 +322,12 @@ void IRUserService::updateCirclePadPro() {
|
|||
return;
|
||||
}
|
||||
|
||||
constexpr int C_STICK_CENTER = 0x800;
|
||||
constexpr int C_STICK_RADIUS = 0x7FF;
|
||||
|
||||
CPPResponse response;
|
||||
response.c_stick.header = static_cast<u8>(CPPResponseID::PollButtons);
|
||||
response.c_stick.c_stick_x = rand() & 0xFFF;
|
||||
response.c_stick.c_stick_y = static_cast<u32>(C_STICK_CENTER);
|
||||
response.buttons.battery_level = 0x1F;
|
||||
response.buttons.zl_not_held = 1;
|
||||
response.buttons.zr_not_held = rand() & 1;
|
||||
response.buttons.r_not_held = 1;
|
||||
response.unknown = 0;
|
||||
auto& response = cpp.state;
|
||||
response.cStick.x = rand() & 0xFFF;
|
||||
response.cStick.y = static_cast<u32>(CirclePadPro::ButtonState::C_STICK_CENTER);
|
||||
response.buttons.zlNotPressed = 1;
|
||||
response.buttons.zrNotPressed = rand() & 1;
|
||||
response.buttons.rNotPressed = 1;
|
||||
|
||||
std::vector<u8> response_buffer(sizeof(response));
|
||||
std::memcpy(response_buffer.data(), &response, sizeof(response));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue