1 #ifndef _JOYSTICK_SWITCH_INPUT_H_
2 #define _JOYSTICK_SWITCH_INPUT_H_
7 #ifndef MAX_JOYSTICK_ACCEL
8 #define MAX_JOYSTICK_ACCEL 10.1F
32 float tolerance = 0.03F;
33 float midPoint = 0.5F;
34 float accelerationFactor = 1000.0F;
35 float initialDelay = 750.0F;
36 float delayAcceleration = 3.0F;
46 this->analogPin = analogPin;
47 this->analogDevice = analogDevice;
48 analogDevice->
initPin(analogPin, DIR_IN);
59 this->analogPin = analogPin;
60 this->analogDevice = analogDevice;
61 analogDevice->
initPin(analogPin, DIR_IN);
71 this->initialDelay = initialDelayPeriod;
72 this->delayAcceleration = decreaseDivisor;
83 tolerance = tolerance_;
87 int nextInterval(
int forceApplied) {
88 switch(forceApplied) {
102 float readVal = analogDevice->getCurrentFloat(analogPin) - midPoint;
106 if(readVal > tolerance) {
107 int dir = (scrolling) ? -1 : 1;
110 else if(readVal < (-tolerance)) {
111 int dir = (scrolling) ? 1 : -1;
115 accelerationFactor = initialDelay;
116 taskManager.scheduleOnce(250,
this);
120 auto delay = nextInterval(abs(readVal * MAX_JOYSTICK_ACCEL)) + accelerationFactor;
121 taskManager.scheduleOnce(delay,
this);
122 if(accelerationFactor > 1.0F) {
123 accelerationFactor /= delayAcceleration;
128 #define ANALOG_JOYSTICK_LOWER_PIN 0
129 #define ANALOG_JOYSTICK_HIGHER_PIN 1
133 enum CurrentJoystickDirection : uint8_t { LEFT = 0x01, RIGHT = 0x02, NONE = 0x00 };
136 CurrentJoystickDirection currentDir = NONE;
137 bool errorOccurred =
false;
138 bool initialisedYet =
false;
139 bool inverted =
false;
144 analogDevice = device;
145 centrePoint = centre;
151 bool ret = (pin == 0) ? currentDir == LEFT : currentDir == RIGHT;
152 if(inverted) ret = !ret;
157 return inverted ? ~currentDir : currentDir;
161 auto value = analogDevice->getCurrentFloat(joystickPin);
162 auto offLowest = centrePoint - 0.15;
163 auto offHighest = centrePoint + 0.15;
164 if(value < offLowest) {
167 else if(value > offHighest) {
177 if(!initialisedYet) {
178 initialisedYet =
true;
179 analogDevice->
initPin(joystickPin, DIR_IN);
185 if(mode == INPUT_PULLUP) {
190 errorOccurred =
true;
193 bool hasErrorOccurred()
const {
return errorOccurred; }
201 void writePort(pinid_t pin, uint8_t portVal)
override { }
217 taskManager.scheduleOnce(250, joystickEncoder);
Contains a series of helper classes for dealing with analog devices, these are compatible across a wi...
Definition: AnalogDeviceAbstraction.h:31
virtual void initPin(pinid_t pin, AnalogDirection direction)=0
Definition: BasicIoAbstraction.h:38
Definition: SwitchInput.h:188
Definition: SwitchInput.h:203
void increment(int8_t incVal)
Definition: SwitchInput.cpp:316