upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Data Structures | Functions | Typedefs
Include dependency graph for joystick12.h:

API Description

/*
* Author: Noel Eck <noel.eck@intel.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <signal.h>
#include "joystick12.h"
#include "upm_utilities.h"
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
// Instantiate a joystick12 sensor
// X = Analog pin A0
// Y = Analog pin A1
if (!sensor)
{
printf("joystick12_init() failed.\n");
return -1;
}
printf("Press any key to zero joystick...\n");
getchar();
// Zero x and y axis
joystick12_zero(sensor);
printf("Hold the X axis to the far neg or pos value, then press a key...\n");
getchar();
printf("Hold the Y axis to the far neg or pos value, then press a key...\n");
getchar();
// Every half a second, sample the sensor output
float x, y;
while (shouldRun)
{
printf("X: %5.02f Y: %5.02f\n", x, y);
upm_delay_ms(500);
}
printf("Exiting\n");
return 0;
}

Go to the source code of this file.

Data Structures

struct  _joystick12_context
 

Functions

joystick12_context joystick12_init (int16_t apin_x, int16_t apin_y)
 
void joystick12_close (joystick12_context dev)
 
upm_result_t joystick12_read_data (const joystick12_context dev, int *values)
 
upm_result_t joystick12_set_offset_x (const joystick12_context dev, float offset)
 
upm_result_t joystick12_set_offset_y (const joystick12_context dev, float offset)
 
upm_result_t joystick12_set_scale_x (const joystick12_context dev, float scale)
 
upm_result_t joystick12_set_scale_y (const joystick12_context dev, float scale)
 
upm_result_t joystick12_get_value_x (const joystick12_context dev, float *value)
 
upm_result_t joystick12_get_value_y (const joystick12_context dev, float *value)
 
upm_result_t joystick12_zero (const joystick12_context dev)
 
upm_result_t joystick12_calibrate_x (const joystick12_context dev)
 
upm_result_t joystick12_calibrate_y (const joystick12_context dev)
 

Typedefs

typedef struct _joystick12_contextjoystick12_context
 

Function Documentation

joystick12_context joystick12_init ( int16_t  apin_x,
int16_t  apin_y 
)

Initialize analog sensor

Parameters
pinis Analog pin
Returns
sensor context as void pointer
void joystick12_close ( joystick12_context  dev)

Analog sensor destructor

Parameters
sensorcontext pointer deallocate memory
upm_result_t joystick12_read_data ( const joystick12_context  dev,
int *  values 
)

Generic read joystick data method

Parameters
devsensor device context pointer
valuepointer to an int[2] in which data is returned

Here is the caller graph for this function:

upm_result_t joystick12_set_offset_x ( const joystick12_context  dev,
float  offset 
)

Set sensor offset. This offset is applied to the return value: counts = counts + offset

Parameters
devsensor context pointer
offsetcount offset value used
Returns
Function result code
upm_result_t joystick12_set_offset_y ( const joystick12_context  dev,
float  offset 
)

Set sensor offset. This offset is applied to the return value: counts = counts + offset

Parameters
devsensor context pointer
offsetcount offset value used
Returns
Function result code
upm_result_t joystick12_set_scale_x ( const joystick12_context  dev,
float  scale 
)

Set sensor scale. This scale is applied to the return value: counts = counts * scale

Parameters
devsensor context pointer
scalecount scale value used
Returns
Function result code
upm_result_t joystick12_set_scale_y ( const joystick12_context  dev,
float  scale 
)

Set sensor scale. This scale is applied to the return value: counts = counts * scale

Parameters
devsensor context pointer
scalecount scale value used
Returns
Function result code
upm_result_t joystick12_get_value_x ( const joystick12_context  dev,
float *  value 
)

Read value from sensor

Parameters
devsensor context pointer
*valuenormalized value from sensor, units depend on unit enum
unitEnum which specifies units returned in *value
Returns
Function result code

Here is the call graph for this function:

upm_result_t joystick12_get_value_y ( const joystick12_context  dev,
float *  value 
)

Read value from sensor

Parameters
devsensor context pointer
*valuenormalized value from sensor, units depend on unit enum
unitEnum which specifies units returned in *value
Returns
Function result code

Here is the call graph for this function:

upm_result_t joystick12_zero ( const joystick12_context  dev)

Zero out the sensor x and y axis

Parameters
devsensor context pointer
Returns
Function result code

Here is the call graph for this function:

upm_result_t joystick12_calibrate_x ( const joystick12_context  dev)

Set x scale. Move joystick to min or max x and call calibrate

Parameters
devsensor context pointer
Returns
Function result code

Here is the call graph for this function:

upm_result_t joystick12_calibrate_y ( const joystick12_context  dev)

Set y scale. Move joystick to min or max y and call calibrate

Parameters
devsensor context pointer
Returns
Function result code

Here is the call graph for this function:

Typedef Documentation

device context