fork/GramFirmware
git clone https://git.julia.blue/fork/GramFirmware
3ab6a9b
v0.1.2
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 () { 18if (serial::available_for_write ()< 32 ) { 19return ; 20 } 21 22// Report clock is used to limit input viewer reports to being sent only once every 5 23// increments. 24if (_clock < 5 ) { 25_clock ++ ; 26return ; 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. 32ScanInputs (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}