tttapa / tttapa/Control-Surface

rotary encoder acceleration

Open
#175 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
1.7k
Forks
168
Avg merge
7h 30m
Merged PRs (30d)
1

Description

Hi,

I trying to implement "accelaration" to rotary encoder like on Elektron boxes (when encoder-switch is press, value inc/dec 4 by 4, if switch is not press the encoder inc/dec 1 by 1)

The idea is to multiply "speedMultiply" by 4 when the switch is press.

I've modifie couple of file from the lib to add encoder switch pin "spin"

I think the problem is in the "void update" part, maybe someone can help me a bit.


#pragma once

#if not defined(Encoder_h_) && not defined(IDE)
#error                                                                         \
"The PJRC Encoder library should be included before the Control-Surface "  \
"library. (#include <Encoder.h>)"
#endif

#include <Def/Def.hpp>
#include <Encoder.h>
#include <MIDI_Outputs/Abstract/MIDIOutputElement.hpp>

BEGIN_CS_NAMESPACE

/**
   @brief   An abstract class for rotary encoders that send MIDI events.
*/
template <class Sender>
class MIDIRotaryEncoder : public MIDIOutputElement {
  protected:
    /**
       @brief   Construct a new MIDIRotaryEncoder.

       @todo    Documentation
    */
    MIDIRotaryEncoder(const EncoderPinList &pins,
                      int8_t spin,
                      const MIDIAddress &address,
                      int8_t speedMultiply, uint8_t pulsesPerStep,
                      const Sender &sender)
      : encoder{pins.A, pins.B}, spin(spin), address(address),
        speedMultiply(speedMultiply),
        pulsesPerStep(pulsesPerStep), sender(sender) {}

    // For tests only
#ifndef ARDUINO
    MIDIRotaryEncoder(const Encoder &encoder,
                      int8_t spin,
                      const MIDIAddress &address,
                      int8_t speedMultiply, uint8_t pulsesPerStep,
                      const Sender &sender)
      : encoder{encoder}, spin(spin), address(address), speedMultiply(speedMultiply),
        pulsesPerStep(pulsesPerStep), sender(sender) {}
#endif

  public:
    void begin() final override {}
    void update() final override {
      int Speed;
      int spinV = digitalRead(spin);
      if (spinV == HIGH) {
        Speed = (speedMultiply * 4);
      }
      else {
        Speed = speedMultiply;
      }
      long currentPosition = encoder.read();
      long difference = (currentPosition - previousPosition) / pulsesPerStep;
      if (difference) {
        sender.send(difference * Speed, address);
        previousPosition += difference * pulsesPerStep;
      }
    }

  private:
    Encoder encoder;
    int8_t spin;
    const MIDIAddress address;
    const int8_t speedMultiply;
    const uint8_t pulsesPerStep;
    long previousPosition = 0;

  public:
    Sender sender;
};

END_CS_NAMESPACE

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue includes a modified MIDIRotaryEncoder template but does not name the repository file or any tests. Locate the MIDIRotaryEncoder update() implementation, inspect how Encoder and digitalRead are used, and identify or add coverage for pressed and unpressed encoder-switch behavior. Done means the requested acceleration works without breaking normal encoder updates.

Written by the indexing model from the issue text.

Assessment

Tech stack
arduino, cpp
Domain
embedded-iot
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.