Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init analog input w/o pullup #348

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,14 @@ void readConfigFromMemory(bool configFromFlash)
#endif

#if MF_ANALOG_SUPPORT == 1
case kTypeAnalogInputDeprecated:
case kTypeAnalogInput:
params[0] = readUint(&addrMem, configFromFlash); // pin number
params[1] = readUint(&addrMem, configFromFlash); // sensitivity
Analog::Add(params[0], &nameBuffer[pNameBuffer], params[1]); // MUST be before readName because readName returns the pointer for the NEXT Name
if (command == kTypeAnalogInputDeprecated)
Analog::Add(params[0], &nameBuffer[pNameBuffer], params[1], true); // MUST be before readName because readName returns the pointer for the NEXT Name
else
Analog::Add(params[0], &nameBuffer[pNameBuffer], params[1], false); // MUST be before readName because readName returns the pointer for the NEXT Name
copy_success = readName(&addrMem, nameBuffer, &pNameBuffer, configFromFlash); // copy the NULL terminated name to to nameBuffer and set to next free memory location
// copy_success = readEndCommand(&addrMem, ':'); // once the nameBuffer is not required anymore uncomment this line and delete the line before
break;
Expand Down
4 changes: 2 additions & 2 deletions src/MF_Analog/Analog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ namespace Analog
return true;
}

void Add(uint8_t pin, char const *name, uint8_t sensitivity)
void Add(uint8_t pin, char const *name, uint8_t sensitivity, bool deprecated)
{
if (analogRegistered == maxAnalogIn)
return;

analog[analogRegistered] = MFAnalog();
analog[analogRegistered].attach(pin, name, sensitivity);
analog[analogRegistered].attach(pin, name, sensitivity, deprecated);
MFAnalog::attachHandler(handlerOnAnalogChange);
analogRegistered++;
#ifdef DEBUG2CMDMESSENGER
Expand Down
2 changes: 1 addition & 1 deletion src/MF_Analog/Analog.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Analog
{
bool setupArray(uint16_t count);
void Add(uint8_t pin, char const *name = "AnalogInput", uint8_t sensitivity = 3);
void Add(uint8_t pin, char const *name = "AnalogInput", uint8_t sensitivity = 3, bool deprecated = true);
void Clear();
void read();
void readAverage();
Expand Down
7 changes: 5 additions & 2 deletions src/MF_Analog/MFAnalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ MFAnalog::MFAnalog()
_initialized = false;
}

void MFAnalog::attach(uint8_t pin, const char *name, uint8_t sensitivity)
void MFAnalog::attach(uint8_t pin, const char *name, uint8_t sensitivity, bool deprecated)
{
_sensitivity = sensitivity;
_pin = pin;
Expand All @@ -27,7 +27,10 @@ void MFAnalog::attach(uint8_t pin, const char *name, uint8_t sensitivity)
else if (_pin == 6)
_pin = A7;
#endif
pinMode(_pin, INPUT_PULLUP); // set pin to input. Could use OUTPUT for analog, but shows the intention :-)
// enabling PullUp makes a nonlinear behaviour if pot is used
if (deprecated)
pinMode(_pin, INPUT_PULLUP);

// Fill averaging buffers with initial reading
for (uint8_t i = 0; i < ADC_MAX_AVERAGE; i++) {
readBuffer();
Expand Down
2 changes: 1 addition & 1 deletion src/MF_Analog/MFAnalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MFAnalog
public:
MFAnalog();
static void attachHandler(analogEvent handler);
void attach(uint8_t pin, const char *name, uint8_t sensitivity);
void attach(uint8_t pin, const char *name, uint8_t sensitivity, bool deprecated);
void update();
void retrigger();
void readBuffer();
Expand Down
3 changes: 2 additions & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ enum {
kTypeEncoder, // 8
kTypeStepperDeprecated2, // 9 (keep for backwards compatibility, stepper type with auto zero support if btnPin is > 0)
kTypeOutputShifter, // 10 Shift register support (example: 74HC595, TLC592X)
kTypeAnalogInput, // 11 Analog Device with 1 pin
kTypeAnalogInputDeprecated,// 11 Analog Device with 1 pin
kTypeInputShifter, // 12 Input shift register support (example: 74HC165)
kTypeMuxDriver, // 13 Multiplexer selector support (generates select outputs)
kTypeDigInMux, // 14 Digital input multiplexer support (example: 74HCT4067, 74HCT4051)
kTypeStepper, // 15 new stepper type with settings for backlash and deactivate output
kTypeLedSegmentMulti, // 16 new led segment with MAX7219 and TM1637 support
kTypeCustomDevice, // 17 Custom Device
kTypeAnalogInput, // 18 Analog Device without PullUp enabled
kTypeMax // if new device types are added, this MUST be before this one!
};

Expand Down
Loading