fork/GramFirmware

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

Jonathan HaylettSOCD revamp (#57)1f92ae6

codespace-scaling-space-guide-56rpxqvxpg2v57v
1.7 KiB54 linesraw
1#include "core/InputMode.hpp"
2
3#include "core/socd.hpp"
4#include "core/state.hpp"
5
6InputMode::InputMode() {}
7
8InputMode::~InputMode() {
9    delete[] _socd_pairs;
10    delete[] _socd_states;
11}
12
13void InputMode::HandleSocd(InputState &inputs) {
14    if (_socd_pairs == nullptr) {
15        return;
16    }
17
18    // Initialize SOCD states if they aren't initialized.
19    if (_socd_states == nullptr) {
20        _socd_states = new socd::SocdState[_socd_pair_count];
21    }
22
23    // Handle SOCD resolution for each SOCD button pair.
24    for (size_t i = 0; i < _socd_pair_count; i++) {
25        socd::SocdPair pair = _socd_pairs[i];
26        switch (pair.socd_type) {
27            case socd::SOCD_NEUTRAL:
28                socd::neutral(inputs.*(pair.input_dir1), inputs.*(pair.input_dir2));
29                break;
30            case socd::SOCD_2IP:
31                socd::second_input_priority(
32                    inputs.*(pair.input_dir1),
33                    inputs.*(pair.input_dir2),
34                    _socd_states[i]
35                );
36                break;
37            case socd::SOCD_2IP_NO_REAC:
38                socd::second_input_priority_no_reactivation(
39                    inputs.*(pair.input_dir1),
40                    inputs.*(pair.input_dir2),
41                    _socd_states[i]
42                );
43                break;
44            case socd::SOCD_DIR1_PRIORITY:
45                socd::dir1_priority(inputs.*(pair.input_dir1), inputs.*(pair.input_dir2));
46                break;
47            case socd::SOCD_DIR2_PRIORITY:
48                socd::dir1_priority(inputs.*(pair.input_dir2), inputs.*(pair.input_dir1));
49                break;
50            case socd::SOCD_NONE:
51                break;
52        }
53    }
54}