2020-06-02 21:24:40 +00:00
|
|
|
#pragma once
|
|
|
|
#include "bluetoothcontroller.hpp"
|
|
|
|
|
2020-07-01 13:21:05 +00:00
|
|
|
#define UINT12_MAX 0xfff
|
2020-07-01 15:52:15 +00:00
|
|
|
#define STICK_ZERO 0x800
|
2020-07-01 13:21:05 +00:00
|
|
|
|
2020-06-02 21:24:40 +00:00
|
|
|
namespace controller {
|
|
|
|
|
2020-06-09 20:39:30 +00:00
|
|
|
enum BatteryLevel {
|
|
|
|
BatteryLevel_Empty,
|
|
|
|
BatteryLevel_Critical,
|
|
|
|
BatteryLevel_Low,
|
|
|
|
BatteryLevel_Medium,
|
|
|
|
BatteryLevel_Full
|
|
|
|
};
|
2020-06-02 21:24:40 +00:00
|
|
|
|
2020-06-09 20:39:30 +00:00
|
|
|
union SwitchStickData {
|
|
|
|
struct __attribute__ ((__packed__)) {
|
|
|
|
uint16_t x : 12;
|
|
|
|
uint16_t : 0;
|
|
|
|
uint8_t : 8;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct __attribute__ ((__packed__)) {
|
|
|
|
uint8_t : 8;
|
|
|
|
uint16_t : 4;
|
|
|
|
uint16_t y : 12;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SwitchButtonData {
|
|
|
|
uint8_t Y : 1;
|
|
|
|
uint8_t X : 1;
|
|
|
|
uint8_t B : 1;
|
|
|
|
uint8_t A : 1;
|
|
|
|
uint8_t : 2; // SR, SL (Right Joy)
|
|
|
|
uint8_t R : 1;
|
|
|
|
uint8_t ZR : 1;
|
|
|
|
|
|
|
|
uint8_t minus : 1;
|
|
|
|
uint8_t plus : 1;
|
|
|
|
uint8_t rstick_press : 1;
|
|
|
|
uint8_t lstick_press : 1;
|
|
|
|
uint8_t home : 1;
|
|
|
|
uint8_t capture : 1;
|
|
|
|
uint8_t : 0;
|
|
|
|
|
|
|
|
uint8_t dpad_down : 1;
|
|
|
|
uint8_t dpad_up : 1;
|
|
|
|
uint8_t dpad_right : 1;
|
|
|
|
uint8_t dpad_left : 1;
|
|
|
|
uint8_t : 2; // SR, SL (Left Joy)
|
|
|
|
uint8_t L : 1;
|
|
|
|
uint8_t ZL : 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Switch6AxisData {
|
|
|
|
uint16_t accel_x;
|
|
|
|
uint16_t accel_y;
|
|
|
|
uint16_t accel_z;
|
|
|
|
uint16_t gyro_1;
|
|
|
|
uint16_t gyro_2;
|
|
|
|
uint16_t gyro_3;
|
|
|
|
};
|
|
|
|
|
|
|
|
union SwitchReportData {
|
|
|
|
struct {
|
|
|
|
uint8_t conn_info : 4;
|
|
|
|
uint8_t battery : 4;
|
|
|
|
uint8_t timer;
|
|
|
|
SwitchButtonData buttons;
|
|
|
|
SwitchStickData left_stick;
|
|
|
|
SwitchStickData right_stick;
|
|
|
|
uint8_t vibrator;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
uint8_t ack;
|
|
|
|
uint8_t id;
|
|
|
|
uint8_t reply;
|
|
|
|
uint8_t data[0x22];
|
|
|
|
} subcmd;
|
|
|
|
|
|
|
|
} report0x21;
|
2020-06-02 21:24:40 +00:00
|
|
|
|
2020-07-01 08:39:48 +00:00
|
|
|
struct __attribute__ ((__packed__)) {
|
2020-06-09 20:39:30 +00:00
|
|
|
uint8_t timer;
|
|
|
|
uint8_t conn_info : 4;
|
|
|
|
uint8_t battery : 4;
|
|
|
|
SwitchButtonData buttons;
|
|
|
|
SwitchStickData left_stick;
|
|
|
|
SwitchStickData right_stick;
|
|
|
|
uint8_t vibrator;
|
2020-06-02 21:24:40 +00:00
|
|
|
|
2020-06-09 20:39:30 +00:00
|
|
|
Switch6AxisData imu_0ms;
|
|
|
|
Switch6AxisData imu_5ms;
|
|
|
|
Switch6AxisData imu_10ms;
|
|
|
|
} report0x30;
|
2020-06-02 21:24:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SwitchProController : public BluetoothController {
|
|
|
|
|
|
|
|
public:
|
|
|
|
static constexpr const HardwareID hardwareIds[] = {
|
|
|
|
{0x057e, 0x2009} // Official Switch Pro Controller
|
|
|
|
};
|
|
|
|
|
2020-06-10 21:07:18 +00:00
|
|
|
SwitchProController(const BluetoothAddress *address) : BluetoothController(ControllerType_SwitchPro, address) {};
|
2020-06-02 21:24:40 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class JoyconController : public BluetoothController {
|
|
|
|
|
|
|
|
public:
|
|
|
|
static constexpr const HardwareID hardwareIds[] = {
|
2020-06-09 20:39:30 +00:00
|
|
|
{0x057e, 0x2006}, // Official Joycon(L) Controller
|
|
|
|
{0x057e, 0x2007}, // Official Joycon(R) Controller
|
2020-06-02 21:24:40 +00:00
|
|
|
};
|
|
|
|
|
2020-06-10 21:07:18 +00:00
|
|
|
JoyconController(const BluetoothAddress *address) : BluetoothController(ControllerType_Joycon, address) {};
|
2020-06-02 21:24:40 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|