2014-07-19 16:29:41 +00:00
|
|
|
/*
|
|
|
|
* Author: Alexander Komarov <alexander.komarov@intel.com>
|
|
|
|
* Copyright (c) 2014 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.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <mraa/gpio.h>
|
|
|
|
#include <mraa/aio.h>
|
|
|
|
|
|
|
|
namespace upm {
|
|
|
|
|
2014-09-22 16:37:36 +01:00
|
|
|
/**
|
2018-02-14 10:36:46 -08:00
|
|
|
* @brief Analog Joystick Library
|
2015-06-11 11:02:28 -07:00
|
|
|
* @defgroup joystick12 libupm-joystick12
|
2015-06-24 13:16:52 -07:00
|
|
|
* @ingroup generic analog ainput robok
|
2014-09-22 16:37:36 +01:00
|
|
|
*/
|
|
|
|
|
2014-07-19 16:29:41 +00:00
|
|
|
/**
|
2015-06-11 11:02:28 -07:00
|
|
|
* @library joystick12
|
|
|
|
* @sensor joystick12
|
2016-12-15 15:15:21 -08:00
|
|
|
* @comname 2-axis Analog Joystick
|
2015-04-13 12:55:23 -07:00
|
|
|
* @type ainput
|
|
|
|
* @man generic
|
|
|
|
* @con analog
|
2015-06-23 16:35:50 -07:00
|
|
|
* @kit robok
|
2015-04-13 12:55:23 -07:00
|
|
|
*
|
2015-08-09 22:51:25 +03:00
|
|
|
* @brief API for the ElecFreaks* Joystick v 1.2-1.4 Breakout
|
2014-07-19 16:29:41 +00:00
|
|
|
*
|
2015-09-08 11:03:36 -07:00
|
|
|
* This module defines the Joystick API, and implementation for the X and Y
|
2015-08-09 22:51:25 +03:00
|
|
|
* buttons could be treated as normal GPIO - this enables easier
|
2015-06-01 15:44:07 -07:00
|
|
|
* interrupt support. This driver should be compatible with any
|
2015-08-09 22:51:25 +03:00
|
|
|
* 2-axis analog joystick.
|
2014-07-19 16:29:41 +00:00
|
|
|
*
|
2015-05-26 15:58:34 -07:00
|
|
|
* @image html joystick12.jpg
|
2017-04-05 15:13:16 -07:00
|
|
|
* @snippet joystick12.cxx Interesting
|
2014-07-19 16:29:41 +00:00
|
|
|
*/
|
|
|
|
class Joystick12 {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Instantiates a Joystick object
|
|
|
|
*
|
2015-08-09 22:51:25 +03:00
|
|
|
* @param pinX Analog pin where the X input is connected
|
|
|
|
* @param pinY Analog pin where the Y input is connected
|
2014-07-19 16:29:41 +00:00
|
|
|
*/
|
|
|
|
Joystick12(int pinX, int pinY);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Joystick object destructor
|
|
|
|
*/
|
|
|
|
~Joystick12();
|
|
|
|
|
|
|
|
/**
|
2015-08-09 22:51:25 +03:00
|
|
|
* Gets the X input
|
|
|
|
* @return float X value, ranging from -1 to 1; 0 is mid
|
2014-07-19 16:29:41 +00:00
|
|
|
*/
|
|
|
|
float getXInput();
|
|
|
|
|
|
|
|
/**
|
2015-08-09 22:51:25 +03:00
|
|
|
* Gets the Y input
|
2014-07-19 16:29:41 +00:00
|
|
|
*
|
2015-08-09 22:51:25 +03:00
|
|
|
* @return float Y value, ranging from -1 to 1; 0 is mid
|
2014-07-19 16:29:41 +00:00
|
|
|
*/
|
|
|
|
float getYInput();
|
|
|
|
|
|
|
|
private:
|
|
|
|
mraa_aio_context m_joystickCtxX;
|
|
|
|
mraa_aio_context m_joystickCtxY;
|
|
|
|
|
|
|
|
static const int X_left;
|
|
|
|
static const int X_center;
|
|
|
|
static const int X_right;
|
|
|
|
static const int Y_left;
|
|
|
|
static const int Y_center;
|
|
|
|
static const int Y_right;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|