fork/GramFirmware
git clone https://git.julia.blue/fork/GramFirmware
3ab6a9b
gram
1#include "input/NunchukInput.hpp" 2 3#include "gpio.hpp" 4 5#include <ArduinoNunchuk.hpp> 6#include <Wire.h> 7 8NunchukInput ::NunchukInput (int detect_pin ) { 9delay (50 ); 10 11if (detect_pin > -1 ) { 12 gpio::init_pin (detect_pin , gpio::GpioMode ::GPIO_INPUT_PULLUP ); 13if (gpio::read_digital (detect_pin )) { 14_nunchuk = nullptr ; 15return ; 16 } 17 } 18 19_nunchuk = new ArduinoNunchuk (Wire ); 20 21if (!_nunchuk -> init ()|| !_nunchuk -> update ()) { 22// If a Nunchuk isn't connected we don't want i2c to stay enabled because it might interfere 23// with inputs if i2c pins are also used for buttons. The destructor of ArduinoNunchuk 24// ends the i2c communication. 25delete _nunchuk ; 26_nunchuk = nullptr ; 27 } 28} 29 30NunchukInput ::~NunchukInput () { 31delete _nunchuk ; 32} 33 34InputScanSpeed NunchukInput ::ScanSpeed () { 35return InputScanSpeed ::SLOW ; 36} 37 38void NunchukInput ::UpdateInputs (InputState & inputs ) { 39if (_nunchuk != nullptr && _nunchuk -> update ()) { 40inputs .nunchuk_connected = true; 41inputs .nunchuk_x = _nunchuk -> stickX (); 42inputs .nunchuk_y = _nunchuk -> stickY (); 43inputs .nunchuk_c = _nunchuk -> buttonC (); 44inputs .nunchuk_z = _nunchuk -> buttonZ (); 45 } 46}