Skip to content

Commit 9fc1c44

Browse files
committed
Replace setEncoderType(...) with individual methods
1 parent 0c1a9c5 commit 9fc1c44

File tree

6 files changed

+36
-44
lines changed

6 files changed

+36
-44
lines changed

examples/BasicRotaryEncoder/BasicRotaryEncoder.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ void setup()
4141
{
4242
Serial.begin( 115200 );
4343

44-
// This tells the library that the encoder has its own pull-up resistors
45-
rotaryEncoder.setEncoderType( RotaryEncoder::Type::HAS_PULLUP );
44+
// Uncomment if your encoder does not have its own pull-up resistors
45+
//rotaryEncoder.enableEncoderPinPullup();
46+
//rotaryEncoder.enableButtonPinPullup();
4647

4748
// Range of values to be returned by the encoder: minimum is 1, maximum is 10
4849
// The third argument specifies whether turning past the minimum/maximum will

examples/ButtonPressDuration/ButtonPressDuration.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ void setup()
6262
{
6363
Serial.begin( 115200 );
6464

65-
// This tells the library that the encoder has its own pull-up resistors
66-
rotaryEncoder.setEncoderType( RotaryEncoder::Type::HAS_PULLUP );
65+
// Uncomment if your encoder does not have its own pull-up resistors
66+
//rotaryEncoder.enableEncoderPinPullup();
67+
//rotaryEncoder.enableButtonPinPullup();
6768

6869
// Range of values to be returned by the encoder: minimum is 1, maximum is 10
6970
// The third argument specifies whether turning past the minimum/maximum will

examples/LeftOrRight/LeftOrRight.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ void setup()
8282
{
8383
Serial.begin( 115200 );
8484

85-
// This tells the library that the encoder has its own pull-up resistors
86-
rotaryEncoder.setEncoderType( RotaryEncoder::Type::HAS_PULLUP );
85+
// Uncomment if your encoder does not have its own pull-up resistors
86+
//rotaryEncoder.enableEncoderPinPullup();
87+
//rotaryEncoder.enableButtonPinPullup();
8788

8889
// The encoder will only return -1, 0, or 1, and will not wrap around.
8990
rotaryEncoder.setBoundaries( -1, 1, false );

examples/TwoRotaryEncoders/TwoRotaryEncoders.ino

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ void button2ToggleRE1( unsigned long duration )
8181

8282
void setup_RE1()
8383
{
84-
// This tells the library that the encoder has its own pull-up resistors
85-
rotaryEncoder1.setEncoderType( RotaryEncoder::Type::HAS_PULLUP );
84+
// Uncomment if your encoder does not have its own pull-up resistors
85+
//rotaryEncoder.enableEncoderPinPullup();
86+
//rotaryEncoder.enableButtonPinPullup();
8687

8788
// Range of values to be returned by the encoder: minimum is 1, maximum is 10
8889
// The third argument specifies whether turning past the minimum/maximum will
@@ -104,9 +105,9 @@ void setup_RE1()
104105

105106
void setup_RE2()
106107
{
107-
// This tells the library that the encoder does not have its own pull-up
108-
// resistors, so the internal pull-up resistors will be enabled
109-
rotaryEncoder2.setEncoderType( RotaryEncoder::Type::FLOATING );
108+
// Uncomment if your encoder does not have its own pull-up resistors
109+
//rotaryEncoder.enableEncoderPinPullup();
110+
//rotaryEncoder.enableButtonPinPullup();
110111

111112
// Range of values to be returned by the encoder: minimum is -100, maximum is 100
112113
// The third argument specifies whether turning past the minimum/maximum will wrap

src/ESP32RotaryEncoder.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,6 @@ RotaryEncoder::~RotaryEncoder()
3939
esp_timer_delete( loopTimer );
4040
}
4141

42-
void RotaryEncoder::setEncoderType( Type type )
43-
{
44-
switch( type )
45-
{
46-
case FLOATING:
47-
encoderPinMode = INPUT_PULLUP;
48-
buttonPinMode = INPUT_PULLUP;
49-
break;
50-
51-
case HAS_PULLUP:
52-
encoderPinMode = INPUT;
53-
buttonPinMode = INPUT;
54-
break;
55-
56-
case SW_FLOAT:
57-
encoderPinMode = INPUT;
58-
buttonPinMode = INPUT_PULLUP;
59-
break;
60-
61-
default:
62-
ESP_LOGE( LOG_TAG, "Invalid encoder type %i", type );
63-
return;
64-
}
65-
66-
ESP_LOGD( LOG_TAG, "Encoder type set to %i", type );
67-
}
68-
6942
void RotaryEncoder::setBoundaries( long minValue, long maxValue, bool circleValues )
7043
{
7144
ESP_LOGD( LOG_TAG, "boundary minValue = %ld, maxValue = %ld, circular = %s", minValue, maxValue, ( circleValues ? "true" : "false" ) );

src/ESP32RotaryEncoder.h

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,30 @@ class RotaryEncoder {
5858
~RotaryEncoder();
5959

6060
/**
61-
* @brief Specifies whether the encoder pins need to use the internal pull-up resistors.
61+
* @brief Enable the internal pull-up resistor for the encoder pin.
6262
*
63-
* @note Call this in `setup()`.
63+
* By default, the encoder pin on the ESP32 is floating - which requires that
64+
* the encoder module has its own pull-up resistors or external pull-ups are used.
6465
*
65-
* @param type FLOATING if you're using a raw encoder not mounted to a PCB (internal pull-ups will be used);
66-
* HAS_PULLUP if your encoder is a module that has pull-up resistors, (internal pull-ups will not be used);
67-
* SW_FLOAT your encoder is a module that has pull-up resistors, but the resistor for the switch is missing (internal pull-up will be used for switch input only)
66+
* If the encoder module does not have its own pull-ups, calling this method
67+
* will enable the internal pull-up in the ESP32.
68+
*
69+
* @note Call this before `begin()`. It has no effect after.
70+
*/
71+
void enableEncoderPinPullup() { encoderPinMode = INPUT_PULLUP; }
72+
73+
/**
74+
* @brief Enable the internal pull-up resistor for the button pin.
75+
*
76+
* By default, the button pin on the ESP32 is floating - which requires that
77+
* the button has its own pull-up resistors or external pull-ups are used.
78+
*
79+
* If the button does not have its own pull-ups, calling this method
80+
* will enable the internal pull-up in the ESP32.
81+
*
82+
* @note Call this before `begin()`. It has no effect after.
6883
*/
69-
void setEncoderType( Type type );
84+
void enableButtonPinPullup() { buttonPinMode = INPUT_PULLUP; }
7085

7186
/**
7287
* @brief Set the minimum and maximum values that the encoder will return.

0 commit comments

Comments
 (0)