6 #ifndef _DF_ROBOT_INPUT_ABSTRACTION_H
7 #define _DF_ROBOT_INPUT_ABSTRACTION_H
20 #define DF_KEY_RIGHT 0
24 #define DF_KEY_SELECT 4
34 #ifndef ALLOWABLE_RANGE
35 #define ALLOWABLE_RANGE 0.01F
38 #if defined(IOA_USE_MBED) || defined(BUILD_FOR_PICO_CMAKE)
39 #define pgmAsFloat(x) ((float)(*x))
42 #define pgmAsFloat(x) ((float)pgm_read_float_near(x))
72 analogRanges = &ranges;
78 void initAbstraction() {
79 device->
initPin(analogPin, DIR_IN);
81 readCache = mapAnalogToPin(lastReading);
94 analogRanges = ranges;
96 this->device = device;
101 return bitRead(readCache, pin);
109 auto newReading = device->getCurrentFloat(analogPin);
110 if(abs(newReading - lastReading) > ALLOWABLE_RANGE) {
111 readCache = mapAnalogToPin(newReading);
113 lastReading = newReading;
117 uint8_t mapAnalogToPin(
float reading) {
119 if(reading < pgmAsFloat(&analogRanges->right)) ret = DF_KEY_RIGHT;
120 else if(reading < pgmAsFloat(&analogRanges->up)) ret = DF_KEY_UP;
121 else if(reading < pgmAsFloat(&analogRanges->down)) ret = DF_KEY_DOWN;
122 else if(reading < pgmAsFloat(&analogRanges->left)) ret = DF_KEY_LEFT;
123 else if(reading < pgmAsFloat(&analogRanges->select)) ret = DF_KEY_SELECT;
Contains a series of helper classes for dealing with analog devices, these are compatible across a wi...
AnalogDevice * internalAnalogIo()
Provides the core IoAbstraction interface and Arduino implementation of that interface.
Definition: AnalogDeviceAbstraction.h:31
virtual void initPin(pinid_t pin, AnalogDirection direction)=0
virtual unsigned int getCurrentValue(pinid_t pin)=0
Definition: BasicIoAbstraction.h:38