mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-07-04 22:32:57 +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
|
#pragma once
|
||||||
|
#include "bitfield.hpp"
|
||||||
#include "services/ir/ir_device.hpp"
|
#include "services/ir/ir_device.hpp"
|
||||||
#include "services/ir/ir_types.hpp"
|
#include "services/ir/ir_types.hpp"
|
||||||
|
|
||||||
namespace IR {
|
namespace IR {
|
||||||
class CirclePadPro : public IR::Device {
|
class CirclePadPro : public IR::Device {
|
||||||
public:
|
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 connect() override;
|
||||||
virtual void disconnect() override;
|
virtual void disconnect() override;
|
||||||
virtual void receivePayload(Payload payload) override;
|
virtual void receivePayload(Payload payload) override;
|
||||||
|
|
||||||
CirclePadPro(SendCallback sendCallback) : IR::Device(sendCallback) {}
|
CirclePadPro(SendCallback sendCallback) : IR::Device(sendCallback) {}
|
||||||
|
ButtonState state;
|
||||||
};
|
};
|
||||||
} // namespace IR
|
} // namespace IR
|
|
@ -116,22 +116,6 @@ namespace IR {
|
||||||
u32 maxDataSize;
|
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 {
|
namespace CPPResponseID {
|
||||||
enum : u8 {
|
enum : u8 {
|
||||||
PollButtons = 0x10, // This response contains the current Circlepad Pro button/stick state
|
PollButtons = 0x10, // This response contains the current Circlepad Pro button/stick state
|
||||||
|
|
|
@ -322,18 +322,12 @@ void IRUserService::updateCirclePadPro() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr int C_STICK_CENTER = 0x800;
|
auto& response = cpp.state;
|
||||||
constexpr int C_STICK_RADIUS = 0x7FF;
|
response.cStick.x = rand() & 0xFFF;
|
||||||
|
response.cStick.y = static_cast<u32>(CirclePadPro::ButtonState::C_STICK_CENTER);
|
||||||
CPPResponse response;
|
response.buttons.zlNotPressed = 1;
|
||||||
response.c_stick.header = static_cast<u8>(CPPResponseID::PollButtons);
|
response.buttons.zrNotPressed = rand() & 1;
|
||||||
response.c_stick.c_stick_x = rand() & 0xFFF;
|
response.buttons.rNotPressed = 1;
|
||||||
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;
|
|
||||||
|
|
||||||
std::vector<u8> response_buffer(sizeof(response));
|
std::vector<u8> response_buffer(sizeof(response));
|
||||||
std::memcpy(response_buffer.data(), &response, sizeof(response));
|
std::memcpy(response_buffer.data(), &response, sizeof(response));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue