@@ -225,15 +225,15 @@ void SwitchInput::pushSwitch(pinid_t pin, bool held) {
225225 keys.getByKey (pin)->trigger (held);
226226}
227227
228- void SwitchInput::changeEncoderPrecision (uint8_t slot, uint16_t precision, uint16_t currentValue, bool rollover) {
228+ void SwitchInput::changeEncoderPrecision (uint8_t slot, uint16_t precision, uint16_t currentValue, bool rollover, int step ) {
229229 if (slot < MAX_ROTARY_ENCODERS && encoder[slot] != nullptr ) {
230- encoder[slot]->changePrecision (precision, currentValue, rollover);
230+ encoder[slot]->changePrecision (precision, ( int ) currentValue, rollover, step );
231231 }
232232}
233233
234- void SwitchInput::setEncoder (uint8_t slot, RotaryEncoder* encoder ) {
234+ void SwitchInput::setEncoder (uint8_t slot, RotaryEncoder* enc ) {
235235 if (slot < MAX_ROTARY_ENCODERS) {
236- this ->encoder [slot] = encoder ;
236+ this ->encoder [slot] = enc ;
237237 }
238238}
239239
@@ -276,15 +276,17 @@ RotaryEncoder::RotaryEncoder(EncoderListener* listener) : notify{} {
276276 this ->notify .encoderListener = listener;
277277 this ->currentReading = 0 ;
278278 this ->maximumValue = 0 ;
279+ this ->stepSize = 1 ;
279280 this ->flags = 0U ;
280281 bitWrite (flags, LAST_SYNC_STATUS, 1 );
281282 bitWrite (flags, OO_LISTENER_CALLBACK, 1 );
282283 this ->intent = CHANGE_VALUE;
283284}
284285
285- void RotaryEncoder::changePrecision (uint16_t maxValue, int currentValue, bool rolloverOnMax) {
286+ void RotaryEncoder::changePrecision (uint16_t maxValue, int currentValue, bool rolloverOnMax, int step ) {
286287 this ->maximumValue = maxValue;
287288 this ->currentReading = currentValue;
289+ this ->stepSize = step;
288290 bitWrite (flags, WRAP_AROUND_MODE, rolloverOnMax);
289291 if (maxValue == 0U && currentValue == 0 ) intent = DIRECTION_ONLY;
290292 runCallback ((int )currentReading);
@@ -387,22 +389,21 @@ void onSwitchesInterrupt(__attribute__((unused)) pinid_t pin) {
387389}
388390
389391int HardwareRotaryEncoder::amountFromChange (unsigned long change) {
390- if (change > 250000 || maximumValue < ONE_TURN_OF_ENCODER) return 1 ;
392+ if (change > 250000 || maximumValue < ONE_TURN_OF_ENCODER) return stepSize ;
391393
392394 if (accelerationMode == HWACCEL_NONE) {
393- return 1 ;
395+ return stepSize ;
394396 }
395397 else if (accelerationMode == HWACCEL_REGULAR) {
396- if (change > 120000 ) return 2 ;
397- else if (change > 70000 ) return 4 ;
398- else if (change > 30000 ) return 6 ;
399- else return 10 ;
398+ if (change > 120000 ) return stepSize + stepSize ;
399+ else if (change > 70000 ) return stepSize << 2 ;
400+ else if (change > 30000 ) return stepSize << 3 ;
401+ else return stepSize << 4 ;
400402 }
401403 else { // slower, very slight acceleration..
402-
403- if (change > 100000 ) return 2 ;
404- else if (change > 30000 ) return 3 ;
405- else return 4 ;
404+ if (change > 100000 ) return stepSize + stepSize;
405+ else if (change > 30000 ) return stepSize + stepSize + stepSize;
406+ else return stepSize << 2 ;
406407 }
407408
408409}
@@ -452,10 +453,10 @@ EncoderUpDownButtons::EncoderUpDownButtons(pinid_t pinUp, pinid_t pinDown, Encod
452453
453454void EncoderUpDownButtons::onPressed (pinid_t pin, bool held) {
454455 if (pin == upPin) {
455- int8_t dir = (switches.getEncoder ()->getUserIntention () == SCROLL_THROUGH_ITEMS) ? -1 : 1 ;
456+ int8_t dir = (switches.getEncoder ()->getUserIntention () == SCROLL_THROUGH_ITEMS) ? -stepSize : stepSize ;
456457 increment (dir);
457458 } else if (pin == downPin) {
458- int8_t dir = (switches.getEncoder ()->getUserIntention () == SCROLL_THROUGH_ITEMS) ? 1 : -1 ;
459+ int8_t dir = (switches.getEncoder ()->getUserIntention () == SCROLL_THROUGH_ITEMS) ? stepSize : -stepSize ;
459460 increment (dir);
460461 }
461462}
0 commit comments