upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
nunchuck.h
Go to the documentation of this file.
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2017 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <upm.h>
29 
30 #include <mraa/i2c.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
47  typedef struct _nunchuck_context {
48  mraa_i2c_context i2c;
49 
50  // sticks - x, y
51  int stickX;
52  int stickY;
53 
54  // accel
55  int accelX;
56  int accelY;
57  int accelZ;
58 
59  // buttons
60  bool buttonC;
61  bool buttonZ;
62 
64 
72 
79 
86  upm_result_t nunchuck_update(const nunchuck_context dev);
87 
97  void nunchuck_get_stick(const nunchuck_context dev, int *x, int *y);
98 
109  int *x, int *y, int *z);
110 
119  void nunchuck_get_buttons(const nunchuck_context dev, bool *c, bool *z);
120 
121 #ifdef __cplusplus
122 }
123 #endif
upm_result_t nunchuck_update(const nunchuck_context dev)
Definition: nunchuck.c:129
Definition: nunchuck.h:47
nunchuck_context nunchuck_init(int bus)
Definition: nunchuck.c:71
struct _nunchuck_context * nunchuck_context
void nunchuck_get_stick(const nunchuck_context dev, int *x, int *y)
Definition: nunchuck.c:176
void nunchuck_close(nunchuck_context dev)
Definition: nunchuck.c:119
void nunchuck_get_acceleration(const nunchuck_context dev, int *x, int *y, int *z)
Definition: nunchuck.c:186
void nunchuck_get_buttons(const nunchuck_context dev, bool *c, bool *z)
Definition: nunchuck.c:199