DCC-EX / EX-Turntable

Turntable-EX is a new feature to control a stepper motor based turntable from DCC++ EX
GNU General Public License v3.0
6 stars 5 forks source link

Feature Request: Select position via a rotary encoder #86

Closed peteGSX closed 1 year ago

peteGSX commented 2 years ago

Is your feature request related to a problem? Please describe.

Feature request from pcgamer7055 on Discord:

Is it possible to control a turntable via a rotary encoder?

Describe the solution you'd like

Two options:

The first one I suspect won't require any code changes, and would simply be a matter of how to get the position to the device driver, which EX-RAIL should in theory be able to simply respond to.

The second option can be with very similar approach for option 1 except the user always has to reset the button to a physical start position and probably add a button to tell the Arduino the rotary encoder is ready for use.

peteGSX commented 2 years ago

Good choice for rotary encoder library: https://github.com/buxtronix/arduino

peteGSX commented 2 years ago

Creating a device driver to support this with two new EX-RAIL commands:

ATRE(vpin, value) - trigger when position is received IFRE(vpin, value) - test to see if position has been received

Need to add these to EXRAIL2.cpp as well as EXRAILMacros.h and EXRAIL2MacroReset.h.

peteGSX commented 2 years ago

PR raised for this: https://github.com/DCC-EX/CommandStation-EX/pull/255

Adds IO_RotaryEncoder.h device driver, IFRE(vpin, position), and ONCHANGE(vpin) EX-RAIL commands.

Example myHal.cpp:

#include "IO_RotaryEncoder.h"

void halSetup() {
  RotaryEncoder::create(700, 1, 0x80);
}

Example myAutomation.h (assuming there are 2 defined EX-Turntable routes with aliases):

ONCHANGE(700)
  IFRE(700, 1)
    START(TTRoute1)
  ENDIF
  IFRE(700, 2)
    START(TTRoute2)
  ENDIF
DONE

IFRE() is specific for the rotary encoder, ONCHANGE() can be used for any sensor changing state provided the appropriate device driver is updated to flag the change and use the event handler.