Skip to content

Commit

Permalink
Fixed printf formats for long and unsigned long
Browse files Browse the repository at this point in the history
  • Loading branch information
MaffooClock committed Nov 1, 2023
1 parent 931d9a5 commit 91de74f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions examples/BasicRotaryEncoder/BasicRotaryEncoder.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ RotaryEncoder rotaryEncoder( DI_ENCODER_A, DI_ENCODER_B, DI_ENCODER_SW, DO_ENCOD

void knobCallback( long value )
{
Serial.printf( "Value: %i\n", value );
Serial.printf( "Value: %ld\n", value );
}

void buttonCallback( unsigned long duration )
{
Serial.printf( "boop! button was down for %u ms\n", duration );
Serial.printf( "boop! button was down for %lu ms\n", duration );
}

void setup()
Expand Down
2 changes: 1 addition & 1 deletion examples/ButtonPressDuration/ButtonPressDuration.ino
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void buttonLongPress()

void knobCallback( long value )
{
Serial.printf( "Value: %i\n", value );
Serial.printf( "Value: %ld\n", value );
}

void buttonCallback( unsigned long duration )
Expand Down
2 changes: 1 addition & 1 deletion examples/LeftOrRight/LeftOrRight.ino
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void knobCallback( long value )

void buttonCallback( unsigned long duration )
{
Serial.printf( "boop! button was down for %u ms\n", duration );
Serial.printf( "boop! button was down for %lu ms\n", duration );
}

void setup()
Expand Down
4 changes: 2 additions & 2 deletions examples/TwoRotaryEncoders/TwoRotaryEncoders.ino
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ RotaryEncoder rotaryEncoder2( RE2_DI_ENCODER_A, RE2_DI_ENCODER_B, RE2_DI_ENCODER

void printKnob1Value( long value )
{
Serial.printf( "RE1 value: %i\n", value );
Serial.printf( "RE1 value: %ld\n", value );
}

void printKnob2Value( long value )
{
Serial.printf( "RE2 value: %i\n", value );
Serial.printf( "RE2 value: %ld\n", value );
}

void button1ToggleRE2( unsigned long duration )
Expand Down
20 changes: 10 additions & 10 deletions src/ESP32RotaryEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RotaryEncoder::RotaryEncoder( uint8_t encoderPinA, uint8_t encoderPinB, int8_t e
this->encoderPinVcc = encoderPinVcc;
this->encoderTripPoint = encoderSteps - 1;

ESP_LOGD( LOG_TAG, "Initialized: A = %i, B = %i, Button = %i, VCC = %i, Steps = %u", encoderPinA, encoderPinB, encoderPinButton, encoderPinVcc, encoderSteps );
ESP_LOGD( LOG_TAG, "Initialized: A = %u, B = %u, Button = %i, VCC = %i, Steps = %u", encoderPinA, encoderPinB, encoderPinButton, encoderPinVcc, encoderSteps );
}

RotaryEncoder::~RotaryEncoder()
Expand Down Expand Up @@ -49,7 +49,7 @@ void RotaryEncoder::setEncoderType( EncoderType type )
void RotaryEncoder::setBoundaries( long minValue, long maxValue, bool circleValues )
{
if( minValue > maxValue )
ESP_LOGW( LOG_TAG, "Minimum value (%i) is greater than maximum value (%i); behavior is undefined.", minValue, maxValue );
ESP_LOGW( LOG_TAG, "Minimum value (%ld) is greater than maximum value (%ld); behavior is undefined.", minValue, maxValue );

setMinValue( minValue );
setMaxValue( maxValue );
Expand All @@ -58,14 +58,14 @@ void RotaryEncoder::setBoundaries( long minValue, long maxValue, bool circleValu

void RotaryEncoder::setMinValue( long minValue )
{
ESP_LOGD( LOG_TAG, "minValue = %i", minValue );
ESP_LOGD( LOG_TAG, "minValue = %ld", minValue );

this->minEncoderValue = minValue;
}

void RotaryEncoder::setMaxValue( long maxValue )
{
ESP_LOGD( LOG_TAG, "maxValue = %i", maxValue );
ESP_LOGD( LOG_TAG, "maxValue = %ld", maxValue );

this->maxEncoderValue = maxValue;
}
Expand All @@ -79,10 +79,10 @@ void RotaryEncoder::setCircular( bool circleValues )

void RotaryEncoder::setStepValue( long stepValue )
{
ESP_LOGD( LOG_TAG, "stepValue = %i", stepValue );
ESP_LOGD( LOG_TAG, "stepValue = %ld", stepValue );

if( stepValue > maxEncoderValue || stepValue < minEncoderValue )
ESP_LOGW( LOG_TAG, "Step value (%i) is outside the bounds (%i...%i); behavior is undefined.", stepValue, minEncoderValue, maxEncoderValue );
ESP_LOGW( LOG_TAG, "Step value (%ld) is outside the bounds (%ld...%ld); behavior is undefined.", stepValue, minEncoderValue, maxEncoderValue );

this->stepValue = stepValue;
}
Expand Down Expand Up @@ -220,7 +220,7 @@ bool RotaryEncoder::buttonPressed()
return false;

if( buttonPressedFlag )
ESP_LOGD( LOG_TAG, "Button pressed for %u ms", buttonPressedDuration );
ESP_LOGD( LOG_TAG, "Button pressed for %lu ms", buttonPressedDuration );

bool wasPressed = buttonPressedFlag;

Expand All @@ -235,7 +235,7 @@ bool RotaryEncoder::encoderChanged()
return false;

if( encoderChangedFlag )
ESP_LOGD( LOG_TAG, "Knob turned; value: %i", getEncoderValue() );
ESP_LOGD( LOG_TAG, "Knob turned; value: %ld", getEncoderValue() );

bool hasChanged = encoderChangedFlag;

Expand All @@ -262,13 +262,13 @@ void RotaryEncoder::constrainValue()
currentValue = circleValues ? minEncoderValue : maxEncoderValue;

if( unconstrainedValue != currentValue )
ESP_LOGD( LOG_TAG, "Encoder value '%i' constrained to '%i'", unconstrainedValue, currentValue );
ESP_LOGD( LOG_TAG, "Encoder value '%ld' constrained to '%ld'", unconstrainedValue, currentValue );
}

void RotaryEncoder::setEncoderValue( long newValue )
{
if( newValue != currentValue )
ESP_LOGD( LOG_TAG, "Overriding encoder value from '%i' to '%i'", currentValue, newValue );
ESP_LOGD( LOG_TAG, "Overriding encoder value from '%ld' to '%ld'", currentValue, newValue );

currentValue = newValue;

Expand Down

0 comments on commit 91de74f

Please sign in to comment.