arduino_nunchuk

library to get data out of a Nintendo Wii nunchuk
git clone https://git.e1e0.net/arduino_nunchuk.git
Log | Files | Refs | README

nunchuk.h (2418B)


      1 /*
      2  * Copyright (c) 2020, Paco Esteban <paco@e1e0.net>
      3  * Copyright (c) 2016, Robert Eisele <robert@xarg.org>
      4  *
      5  * Permission is hereby granted, free of charge, to any person obtaining a copy
      6  * of this software and associated documentation files (the "Software"), to deal
      7  * in the Software without restriction, including without limitation the rights
      8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      9  * copies of the Software, and to permit persons to whom the Software is
     10  * furnished to do so, subject to the following conditions:
     11  *
     12  * The above copyright notice and this permission notice shall be included in
     13  * all copies or substantial portions of the Software.
     14  *
     15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     21  * SOFTWARE.
     22  */
     23 
     24 #ifndef NUNCHUK_H
     25 #define NUNCHUK_H
     26 
     27 #include "Arduino.h"
     28 #include "Print.h"
     29 
     30 /*
     31  * Whether to disable encryption. Enabling encryption means that every packet
     32  * must be decrypted, which wastes cpu cycles. Cheap Nunchuk clones have
     33  * problems with the encrypted init sequence, so be sure you know what you're
     34  * doing
     35  */
     36 #define NUNCHUK_DISABLE_ENCRYPTION
     37 
     38 /* Print debug information instead of a CSV stream to the serial port */
     39 /* #define NUNCHUK_DEBUG */
     40 
     41 /* The Nunchuk I2C address */
     42 #define NUNCHUK_ADDRESS 0x52
     43 
     44 class Nunchuk {
     45 	public:
     46 		Nunchuk(uint16_t, uint16_t, uint16_t, uint16_t, uint16_t);
     47 		void	    print();
     48 		float	    roll();
     49 		float	    pitch();
     50 		int16_t	    accelZ();
     51 		int16_t	    accelY();
     52 		int16_t	    accelX();
     53 		float	    joystick_angle();
     54 		uint8_t	    buttonC();
     55 		uint8_t	    buttonZ();
     56 		int16_t	    joystickY();
     57 		int16_t	    joystickX();
     58 		uint8_t	    read();
     59 		void	    init();
     60 	private:
     61 		uint8_t		_nunchuk_data[6];
     62 		uint16_t	_accelX_zero, _accelY_zero, _accelZ_zero;
     63 		uint16_t	_joystickX_zero, _joystickY_zero;
     64 
     65 		uint8_t		decode_byte(uint8_t);
     66 		uint16_t	accelZ_raw();
     67 		uint16_t	accelY_raw();
     68 		uint16_t	accelX_raw();
     69 		uint8_t		joystickY_raw();
     70 		uint8_t		joystickX_raw();
     71 };
     72 
     73 #endif