fork/GramFirmware

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

Julia RyanGram slim smashdccae31

gram
1.7 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(
9    InputState &inputs,
10    InputSource **input_sources,
11    size_t input_source_count
12)
13    : CommunicationBackend(inputs, input_sources, input_source_count) {
14    serial::init(115200);
15}
16
17B0XXInputViewer::~B0XXInputViewer() {
18    serial::close();
19}
20
21void B0XXInputViewer::SendReport() {
22    if (serial::available_for_write() < 32) {
23        return;
24    }
25
26    // Report clock is used to limit input viewer reports to being sent only once every 5
27    // increments.
28    if (_clock < 5) {
29        _clock++;
30        return;
31    }
32    _clock = 0;
33
34    _report[0] = ASCII_BIT(_inputs.mb1);
35    _report[1] = ASCII_BIT(_inputs.rf6);
36    _report[2] = ASCII_BIT(_inputs.rf2);
37    _report[3] = ASCII_BIT(_inputs.rf1);
38    _report[4] = ASCII_BIT(_inputs.rt1);
39    _report[5] = ASCII_BIT(_inputs.lf4);
40    _report[6] = ASCII_BIT(_inputs.rf5);
41    _report[7] = ASCII_BIT(_inputs.rf3);
42    _report[8] = ASCII_BIT(_inputs.rf4);
43    _report[9] = ASCII_BIT(_inputs.lf2);
44    _report[10] = ASCII_BIT(_inputs.lf1);
45    _report[11] = ASCII_BIT(_inputs.lf3);
46    _report[12] = ASCII_BIT(_inputs.lt1);
47    _report[13] = ASCII_BIT(_inputs.lt2);
48    _report[14] = ASCII_BIT(_inputs.rt3);
49    _report[15] = ASCII_BIT(_inputs.rt5);
50    _report[16] = ASCII_BIT(_inputs.rt4);
51    _report[17] = ASCII_BIT(_inputs.rt2);
52    _report[18] = ASCII_BIT(_inputs.rf7);
53    _report[19] = ASCII_BIT(_inputs.rf8);
54    _report[20] = ASCII_BIT(_inputs.lf6);
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}