fork/GramFirmware

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

Jonathan HaylettMerge pull request #7 from JonnyHaystack/v23ab6a9b

WASD_NeutralSOCD
1.9 KiB61 linesraw
1#include "comms/B0XXInputViewer.hpp"
2
3#include "core/InputSource.hpp"
4#include "serial.hpp"
5
6#define ASCII_BIT(x) (x ? '1' : '0');
7
8B0XXInputViewer::B0XXInputViewer(InputSource **input_sources, size_t input_source_count)
9    : CommunicationBackend(input_sources, input_source_count) {
10    serial::init(115200);
11}
12
13B0XXInputViewer::~B0XXInputViewer() {
14    serial::close();
15}
16
17void B0XXInputViewer::SendReport() {
18    if (serial::available_for_write() < 32) {
19        return;
20    }
21
22    // Report clock is used to limit input viewer reports to being sent only once every 5
23    // increments.
24    if (_clock < 5) {
25        _clock++;
26        return;
27    }
28    _clock = 0;
29
30    // Only scan fast input sources because we don't want to waste any more time than necessary
31    // on the input viewer and we can't afford to read from something like a Nunchuk twice.
32    ScanInputs(InputScanSpeed::FAST);
33
34    _report[0] = ASCII_BIT(_inputs.start);
35    _report[1] = ASCII_BIT(_inputs.y);
36    _report[2] = ASCII_BIT(_inputs.x);
37    _report[3] = ASCII_BIT(_inputs.b);
38    _report[4] = ASCII_BIT(_inputs.a);
39    _report[5] = ASCII_BIT(_inputs.l);
40    _report[6] = ASCII_BIT(_inputs.r);
41    _report[7] = ASCII_BIT(_inputs.z);
42    _report[8] = ASCII_BIT(_inputs.up);
43    _report[9] = ASCII_BIT(_inputs.down);
44    _report[10] = ASCII_BIT(_inputs.right);
45    _report[11] = ASCII_BIT(_inputs.left);
46    _report[12] = ASCII_BIT(_inputs.mod_x);
47    _report[13] = ASCII_BIT(_inputs.mod_y);
48    _report[14] = ASCII_BIT(_inputs.c_left);
49    _report[15] = ASCII_BIT(_inputs.c_right);
50    _report[16] = ASCII_BIT(_inputs.c_up);
51    _report[17] = ASCII_BIT(_inputs.c_down);
52    _report[18] = ASCII_BIT(_inputs.lightshield);
53    _report[19] = ASCII_BIT(_inputs.midshield);
54    _report[20] = ASCII_BIT(false);
55    _report[21] = ASCII_BIT(false);
56    _report[22] = ASCII_BIT(false);
57    _report[23] = ASCII_BIT(true);
58    _report[24] = '\n';
59
60    serial::write(_report, 25);
61}