Arduino Universal Inputs
A collection of libraries for managing/processing input devices on Arduino.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator
IJoystick.h
Go to the documentation of this file.
1 
3 #ifndef _ARDUINOUNIVERSALINPUTS_IJOYSTICK_H
4 #define _ARDUINOUNIVERSALINPUTS_IJOYSTICK_H
5 
6 #include "IInputDevice.h"
7 #include "IValueTransform.h"
8 
13 class IJoystick : public IInputDevice
14 {
15 public:
16  IJoystick(inputid_t id);
17  virtual ~IJoystick();
18 
22  inputtype_t type() const { return UIT_JOYSTICK; }
23 
27  bool poll();
28 
33  inputanalog_t getRawValue() const { return m_value; }
34 
36  inputanalog_t getValue() const;
37 
38  void setTransformation(IValueTransform *transform);
39 
40  bool setThreshold(inputanalog_t threshold);
41 
46  inputanalog_t getThreshold() const { return m_threshold; }
47 
48  bool setPoints(inputanalog_t low, inputanalog_t centre, inputanalog_t high);
49  bool setPoints(inputanalog_t low, inputanalog_t high);
50  bool setDeadbands(inputanalog_t low, inputanalog_t centre,
51  inputanalog_t high);
53 
58  inputanalog_t getLowPoint() const { return m_low; }
59 
64  inputanalog_t getCentrePoint() const { return m_centre; }
65 
70  inputanalog_t getHighPoint() const { return m_high; }
71 
76  inputanalog_t getLowDeadband() const { return m_deadbandLow; }
77 
82  inputanalog_t getCentreDeadband() const { return m_deadbandCentre; }
83 
88  inputanalog_t getHighDeadband() const { return m_deadbandHigh; }
89 
90 protected:
95  virtual inputanalog_t getPhysicalValue() const = 0;
96 
97 private:
98  bool withinTolerance(inputanalog_t a, inputanalog_t b,
99  inputanalog_t tolerance) const;
100 
101  IValueTransform *m_transform;
103  m_threshold;
104 
105  inputanalog_t m_value;
106 
107  inputanalog_t m_low;
108  inputanalog_t m_centre;
109  inputanalog_t m_high;
110 
111  inputanalog_t m_deadbandLow;
112  inputanalog_t m_deadbandCentre;
113  inputanalog_t m_deadbandHigh;
114 };
115 
116 #endif
inputanalog_t getCentreDeadband() const
Gets the deadband width at the centre point.
Definition: IJoystick.h:82
Represents an input device.
Definition: IInputDevice.h:14
uint16_t inputid_t
Holds the value of a device ID.
Definition: UniversalInputTypes.h:13
inputtype_t type() const
Retrieves the type of this device.
Definition: IJoystick.h:22
inputanalog_t getRawValue() const
Gets last read raw value.
Definition: IJoystick.h:33
int32_t inputanalog_t
Holds the value of an analog input value.
Definition: UniversalInputTypes.h:31
bool poll()
Polls this input device for change.
Definition: IJoystick.cpp:23
inputanalog_t getValue() const
Gets the transformed value.
Definition: IJoystick.cpp:70
IJoystick(inputid_t id)
Creates a new joystick.
Definition: IJoystick.cpp:11
inputanalog_t getLowDeadband() const
Gets the deadband width at the low end point.
Definition: IJoystick.h:76
bool setThreshold(inputanalog_t threshold)
Sets the minimum change in raw value that will fire an event.
Definition: IJoystick.cpp:169
void setTransformation(IValueTransform *transform)
Sets the transformation to use between the centred value and outout value.
Definition: IJoystick.cpp:85
inputtype_t
Enumeration of all input device types.
Definition: UniversalInputTypes.h:37
bool setDeadbands(inputanalog_t low, inputanalog_t centre, inputanalog_t high)
Sets the low, centre and high deadband widths.
Definition: IJoystick.cpp:137
inputanalog_t getLowPoint() const
Gets the low end point raw value.
Definition: IJoystick.h:58
bool setPoints(inputanalog_t low, inputanalog_t centre, inputanalog_t high)
Sets the low, centre and high points.
Definition: IJoystick.cpp:100
Joysticks inheriting from IJoystick.
Definition: UniversalInputTypes.h:40
Interface for a value transformation.
Definition: IValueTransform.h:12
inputanalog_t getThreshold() const
Returns the threshold value.
Definition: IJoystick.h:46
inputanalog_t getHighPoint() const
Gets the high end point raw value.
Definition: IJoystick.h:70
Represents a joystick or potentiometer.
Definition: IJoystick.h:13
inputanalog_t getCentredValue() const
Gets the value centered at zero at the centre point and clamped if within the deadbands.
Definition: IJoystick.cpp:43
inputanalog_t getCentrePoint() const
Gets the centre point raw value.
Definition: IJoystick.h:64
inputanalog_t getHighDeadband() const
Gets the deadband width at the high end point.
Definition: IJoystick.h:88
virtual inputanalog_t getPhysicalValue() const =0
Gets the raw value form the joystick.