fork/GramFirmware

git clone https://git.julia.blue/fork/GramFirmware

CarVacrebase to configurator818d962

gram
1.4 KiB65 linesraw
1#ifndef _COMMS_NINTENDOSWITCHBACKEND_HPP
2#define _COMMS_NINTENDOSWITCHBACKEND_HPP
3
4#include "core/CommunicationBackend.hpp"
5
6typedef enum {
7    SWITCH_HAT_UP,
8    SWITCH_HAT_UP_RIGHT,
9    SWITCH_HAT_RIGHT,
10    SWITCH_HAT_DOWN_RIGHT,
11    SWITCH_HAT_DOWN,
12    SWITCH_HAT_DOWN_LEFT,
13    SWITCH_HAT_LEFT,
14    SWITCH_HAT_UP_LEFT,
15    SWITCH_HAT_CENTERED,
16} switch_gamepad_hat_t;
17
18typedef struct __attribute__((packed, aligned(1))) {
19    bool y : 1;
20    bool b : 1;
21    bool a : 1;
22    bool x : 1;
23    bool l : 1;
24    bool r : 1;
25    bool zl : 1;
26    bool zr : 1;
27    bool minus : 1;
28    bool plus : 1;
29    bool l3 : 1;
30    bool r3 : 1;
31    bool home : 1;
32    bool capture : 1;
33    uint8_t reserved0 : 2;
34    switch_gamepad_hat_t hat;
35    uint8_t lx;
36    uint8_t ly;
37    uint8_t rx;
38    uint8_t ry;
39    uint8_t reserved1;
40} switch_gamepad_report_t;
41
42class NintendoSwitchBackend : public CommunicationBackend {
43  public:
44    NintendoSwitchBackend(
45        InputState &inputs,
46        InputSource **input_sources,
47        size_t input_source_count
48    );
49    ~NintendoSwitchBackend();
50
51    static void RegisterDescriptor();
52
53    CommunicationBackendId BackendId();
54    void SendReport();
55
56  protected:
57    static const uint8_t _report_id = 0;
58    static uint8_t _descriptor[];
59
60    switch_gamepad_report_t _report;
61
62    static switch_gamepad_hat_t GetHatPosition(bool left, bool right, bool down, bool up);
63};
64
65#endif