FreeStick  0.3
Cross Platform Open Sorce Joystick Lib
FSUSBJoyStickInputElement.h
Go to the documentation of this file.
1 /**************************************************************************
2 Created by Alan Uthoff on 11/12/2013
3 Copyright (C) 2013
4 
5 This Code is free software; you can redistribute it and/or
6 modify it under the terms of the zlib/libpng License as published
7 by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9 This software is provided 'as-is', without any express or implied warranty.
10 
11 In no event will the authors be held liable for any damages arising from the use of this software.
12 
13 Permission is granted to anyone to use this software for any purpose,
14 including commercial applications, and to alter it and redistribute
15 it freely, subject to the following restrictions:
16 
17 1. The origin of this software must not be misrepresented;
18 you must not claim that you wrote the original software.
19 If you use this software in a product, an acknowledgment
20 in the product documentation would be appreciated but is not required.
21 
22 2. Altered source versions must be plainly marked as such,
23 and must not be misrepresented as being the original software.
24 
25 3. This notice may not be removed or altered from any source distribution.
26 **************************************************************************/
27 
28 #pragma once
29 #include "FSUSBDevice.h"
30 #include <map>
31 #include "FSUSBDeviceManager.h"
32 #include <stack>
33 #include <queue>
34 namespace freestick
35 {
36 
37 
39  {
40  private:
45  minMaxNumber _elementMin;
46  minMaxNumber _elementMax;
47  minMaxNumber _oldValue;
48  minMaxNumber _value;
49  minMaxNumber _deadZoneMin;
50  minMaxNumber _deadZoneMax;
51  bool _needsDeadZone;
52  bool _calibrated;
53  bool _intialized;
54  FSUSBDeviceManager * _usbDeviceManager;
55  time_t firstTime;
56  std::queue<minMaxNumber> _lastValueStack;
57  bool _useLastValueStack;
58  unsigned int _parentID;
59  minMaxNumber _buttonNumber;
60  float _calibrationOffsetPrecent = 0.05f; //Offset used to calibrate deadzones
61  protected:
62  void calibrate(physicalValueNumber currentValue, minMaxNumber elementMin, minMaxNumber elementMax );
63  void EmptyQue(std::stack<FSUSBElementInfoMap> & infoMapsToReturn,unsigned int sizeToleft);
64  public:
65  //FSUSBJoyStickInputElement(const & FSUSBJoyStickInputElement copy){}
67  FSUSBJoyStickInputElement(unsigned int id, unsigned int parentID, minMaxNumber elementMin, minMaxNumber elementMax, vendorIDType vendorID,productIDType productID,FSUSBDeviceManager & _manager,physicalValueNumber currentValue,minMaxNumber buttonNumber);
68  FSUSBJoyStickInputElement(unsigned int id, unsigned int parentID, minMaxNumber elementMin, minMaxNumber elementMax, vendorIDType vendorID,productIDType productID,FSUSBDeviceManager * _manager,physicalValueNumber currentValue,minMaxNumber buttonNumber);
69  void getMapping(int inputValue,std::stack<FSUSBElementInfoMap> & infoMapsToReturn) ;
70  inline minMaxNumber getValue() const {return _value;}
71  void setValue(minMaxNumber newValue);
72  minMaxNumber getOldValue() const {return _oldValue;};
73  bool isValueInDeadZone(minMaxNumber value);
74  bool isIntialized();
75  inline minMaxNumber getMaxValue() const {return _elementMax;}
76  inline minMaxNumber getMinValue() const {return _elementMin;}
77  inline minMaxNumber getDeadZoneMin() const {return _deadZoneMin;}
78  inline minMaxNumber getDeadZoneMax() const {return _deadZoneMax;}
79  inline minMaxNumber getButtonNumber() const {return _buttonNumber;}
80  void recalibrate(physicalValueNumber currentValue, minMaxNumber elementMin, minMaxNumber elementMax );
81  uint16_t getHIDUsage();
82  uint16_t getHIDUsagePage();
83  //used to pad out the dead zone when calibrating
84  void setCalibrationOffsetPrecent(float offset ) ;
85  };
86 }
Definition: FSUSBJoyStickInputElement.h:38
void setCalibrationOffsetPrecent(float offset)
Definition: FSUSBJoyStickInputElement.cpp:187
void recalibrate(physicalValueNumber currentValue, minMaxNumber elementMin, minMaxNumber elementMax)
Definition: FSUSBJoyStickInputElement.cpp:232
minMaxNumber getButtonNumber() const
Definition: FSUSBJoyStickInputElement.h:79
minMaxNumber getDeadZoneMin() const
Definition: FSUSBJoyStickInputElement.h:77
Definition: FSUSBDeviceManager.h:96
minMaxNumber getMaxValue() const
Definition: FSUSBJoyStickInputElement.h:75
void calibrate(physicalValueNumber currentValue, minMaxNumber elementMin, minMaxNumber elementMax)
Definition: FSUSBJoyStickInputElement.cpp:192
void setValue(minMaxNumber newValue)
Definition: FSUSBJoyStickInputElement.cpp:95
minMaxNumber getOldValue() const
Definition: FSUSBJoyStickInputElement.h:72
minMaxNumber getValue() const
Definition: FSUSBJoyStickInputElement.h:70
minMaxNumber getDeadZoneMax() const
Definition: FSUSBJoyStickInputElement.h:78
void getMapping(int inputValue, std::stack< FSUSBElementInfoMap > &infoMapsToReturn)
Definition: FSUSBJoyStickInputElement.cpp:54
uint32_t productIDType
Definition: FSTypes.h:39
Definition: FSBaseDevice.h:32
Definition: FSUSBDevice.h:43
bool isIntialized()
Definition: FSUSBJoyStickInputElement.cpp:237
uint32_t vendorIDType
Definition: FSTypes.h:38
FSUSBJoyStickInputElement()
Definition: FSUSBJoyStickInputElement.cpp:35
int32_t physicalValueNumber
Definition: FSTypes.h:35
bool isValueInDeadZone(minMaxNumber value)
Definition: FSUSBJoyStickInputElement.cpp:79
void EmptyQue(std::stack< FSUSBElementInfoMap > &infoMapsToReturn, unsigned int sizeToleft)
Definition: FSUSBJoyStickInputElement.cpp:39
int32_t minMaxNumber
Definition: FSTypes.h:34
minMaxNumber getMinValue() const
Definition: FSUSBJoyStickInputElement.h:76