| 1 | extern HID::Null hidNull; |
| 2 | |
| 3 | struct AbstractInput { |
| 4 | string name; |
| 5 | string mapping; |
| 6 | bool logic = 0; //0 = OR, 1 = AND |
| 7 | bool state = 0; |
| 8 | |
| 9 | struct Input { |
| 10 | HID::Device* device = nullptr; |
| 11 | uint64_t id = 0; |
| 12 | unsigned group = 0; |
| 13 | unsigned input = 0; |
| 14 | enum class Qualifier : unsigned { None, Lo, Hi } qualifier; |
| 15 | }; |
| 16 | vector<Input> inputList; |
| 17 | |
| 18 | void bind(); |
| 19 | bool append(string mapping); |
| 20 | virtual bool bind(HID::Device& device, unsigned group, unsigned input, int16_t oldValue, int16_t newValue) { return false; } |
| 21 | virtual int16_t poll() { return 0; } |
| 22 | virtual void rumble(bool enable) {} |
| 23 | }; |
| 24 | |
| 25 | struct DigitalInput : AbstractInput { |
| 26 | using AbstractInput::bind; |
| 27 | bool bind(HID::Device& device, unsigned group, unsigned input, int16_t oldValue, int16_t newValue); |
| 28 | int16_t poll(); |
| 29 | }; |
| 30 | |
| 31 | struct RelativeInput : AbstractInput { |
| 32 | using AbstractInput::bind; |
| 33 | bool bind(HID::Device& device, unsigned group, unsigned input, int16_t oldValue, int16_t newValue); |
| 34 | int16_t poll(); |
| 35 | }; |
| 36 | |
| 37 | struct RumbleInput : AbstractInput { |
| 38 | using AbstractInput::bind; |
| 39 | bool bind(HID::Device& device, unsigned group, unsigned input, int16_t oldValue, int16_t newValue); |
| 40 | void rumble(bool enable); |
| 41 | }; |
| 42 | |
| 43 | struct HotkeyInput : DigitalInput { |
| 44 | function<void ()> press; |
| 45 | function<void ()> release; |
| 46 | HotkeyInput(); |
| 47 | }; |
| 48 | |
| 49 | struct InputManager { |
| 50 | vector<HID::Device*> devices; |
| 51 | vector<AbstractInput*> inputMap; |
| 52 | vector<HotkeyInput*> hotkeyMap; |
| 53 | |
| 54 | string sanitize(string mapping, string concatenate) const; |
| 55 | void onChange(HID::Device& device, unsigned group, unsigned input, int16_t oldValue, int16_t newValue); |
| 56 | HID::Device* findMouse(); |
| 57 | void bind(); |
| 58 | void poll(); |
| 59 | void saveConfiguration(); |
| 60 | void bootstrap(); |
| 61 | InputManager(); |
| 62 | |
| 63 | //hotkeys.cpp |
| 64 | void appendHotkeys(); |
| 65 | void pollHotkeys(); |
| 66 | |
| 67 | private: |
| 68 | Configuration::Document config; |
| 69 | }; |
| 70 | |
| 71 | extern InputManager* inputManager; |