mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-22 08:33:12 -05:00
The call now returns 0x1e as the firmware does instead of throwing, so guest_bluetooth_hid checks that value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK
93 lines
3.0 KiB
C++
93 lines
3.0 KiB
C++
#include "prx/libc/include/general/VabiMacros.hpp"
|
|
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <stdexcept>
|
|
|
|
extern "C" {
|
|
std::int32_t APS5_VABI sceBluetoothHidInit();
|
|
std::int32_t APS5_VABI sceBluetoothHidRegisterCallback(void* callback, std::int32_t flags, void* param);
|
|
std::int32_t APS5_VABI sceBluetoothHidUnregisterCallback();
|
|
std::int32_t APS5_VABI sceBluetoothHidRegisterDevice(std::uint16_t vendorId, std::uint16_t productId);
|
|
std::int32_t APS5_VABI sceBluetoothHidUnregisterDevice(std::uint16_t vendorId, std::uint16_t productId);
|
|
int APS5_VABI sceBluetoothHidGetInputReport();
|
|
int APS5_VABI sceBluetoothHidDebugGetVersion();
|
|
int APS5_VABI sceBluetoothHidGetDeviceInfo();
|
|
int APS5_VABI sceBluetoothHidDisconnectDevice();
|
|
int APS5_VABI sceBluetoothHidGetFeatureReport();
|
|
int APS5_VABI sceBluetoothHidSetFeatureReport();
|
|
}
|
|
|
|
namespace {
|
|
|
|
int callbackCalls = 0;
|
|
|
|
void APS5_VABI Callback() {
|
|
++callbackCalls;
|
|
}
|
|
|
|
void Require(bool condition, const char* message) {
|
|
if (!condition) {
|
|
std::fprintf(stderr, "BluetoothHid: %s\n", message);
|
|
std::abort();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
int main() {
|
|
Require(sceBluetoothHidInit() == 0, "initialization failed");
|
|
std::uint8_t param[16]{};
|
|
Require(sceBluetoothHidRegisterCallback(reinterpret_cast<void*>(&Callback), 0, param) == 0, "callback registration failed");
|
|
Require(sceBluetoothHidRegisterDevice(0x44f, 0x1000) == 0, "device registration failed");
|
|
Require(callbackCalls == 0, "a device connection was reported");
|
|
bool threw = false;
|
|
try {
|
|
sceBluetoothHidRegisterCallback(nullptr, 0, param);
|
|
} catch (const std::invalid_argument&) {
|
|
threw = true;
|
|
}
|
|
Require(threw, "a null callback was accepted");
|
|
threw = false;
|
|
try {
|
|
sceBluetoothHidGetInputReport();
|
|
} catch (const std::runtime_error&) {
|
|
threw = true;
|
|
}
|
|
Require(threw, "an input report without a device did not throw");
|
|
Require(sceBluetoothHidDebugGetVersion() == 0x1e, "debug get version did not return the firmware version");
|
|
threw = false;
|
|
try {
|
|
sceBluetoothHidGetDeviceInfo();
|
|
} catch (const std::runtime_error&) {
|
|
threw = true;
|
|
}
|
|
Require(threw, "get device info did not throw");
|
|
threw = false;
|
|
try {
|
|
sceBluetoothHidDisconnectDevice();
|
|
} catch (const std::runtime_error&) {
|
|
threw = true;
|
|
}
|
|
Require(threw, "disconnect device did not throw");
|
|
threw = false;
|
|
try {
|
|
sceBluetoothHidGetFeatureReport();
|
|
} catch (const std::runtime_error&) {
|
|
threw = true;
|
|
}
|
|
Require(threw, "get feature report did not throw");
|
|
threw = false;
|
|
try {
|
|
sceBluetoothHidSetFeatureReport();
|
|
} catch (const std::runtime_error&) {
|
|
threw = true;
|
|
}
|
|
Require(threw, "set feature report did not throw");
|
|
Require(sceBluetoothHidUnregisterDevice(0x44f, 0x1000) == 0, "device unregistration failed");
|
|
Require(sceBluetoothHidUnregisterCallback() == 0, "callback unregistration failed");
|
|
std::puts("BluetoothHid tests passed");
|
|
return 0;
|
|
}
|