diff --git a/IODevice.h b/IODevice.h index 6c70f5f..d507cd6 100644 --- a/IODevice.h +++ b/IODevice.h @@ -547,6 +547,6 @@ protected: #include "IO_duinoNodes.h" #include "IO_EXIOExpander.h" #include "IO_trainbrains.h" - +#include "IO_EncoderThrottle.h" #endif // iodevice_h diff --git a/IO_RocoDriver.h b/IO_EncoderThrottle.cpp similarity index 84% rename from IO_RocoDriver.h rename to IO_EncoderThrottle.cpp index 08ab73b..76a5f85 100644 --- a/IO_RocoDriver.h +++ b/IO_EncoderThrottle.cpp @@ -18,17 +18,14 @@ */ /* -* The IO_RocoDriver device driver uses a rotary encoder connected to vpins +* The IO_EncoderThrottle device driver uses a rotary encoder connected to vpins * to drive a loco. * Loco id is selected by writeAnalog. */ -#ifndef IO_ROCODRIVER_H -#define IO_ROCODRIVER_H - -#include "DCC.h" #include "IODevice.h" #include "DIAG.h" +#include "DCC.h" const byte _DIR_CW = 0x10; // Clockwise step const byte _DIR_CCW = 0x20; // Counter-clockwise step @@ -45,21 +42,14 @@ const byte _STATE_MASK = 0x07; const byte _DIR_MASK = 0x30; -class RocoDriver : public IODevice { -public: - - static void create(VPIN firstVpin, int dtPin, int clkPin, int clickPin, byte notch=10) { - if (checkNoOverlap(firstVpin)) new RocoDriver(firstVpin, dtPin,clkPin,clickPin,notch); - } -private: - int _dtPin,_clkPin,_clickPin, _locoid, _notch,_prevpinstate; - enum {xrSTOP,xrFWD,xrREV} _stopState; - byte _rocoState; + void EncoderThrottle::create(VPIN firstVpin, int dtPin, int clkPin, int clickPin, byte notch) { + if (checkNoOverlap(firstVpin)) new EncoderThrottle(firstVpin, dtPin,clkPin,clickPin,notch); + } // Constructor - RocoDriver(VPIN firstVpin, int dtPin, int clkPin, int clickPin, byte notch){ + EncoderThrottle::EncoderThrottle(VPIN firstVpin, int dtPin, int clkPin, int clickPin, byte notch){ _firstVpin = firstVpin; _nPins = 1; _I2CAddress = 0; @@ -80,7 +70,7 @@ private: - void _loop(unsigned long currentMicros) override { + void EncoderThrottle::_loop(unsigned long currentMicros) { if (_locoid==0) return; // not in use // Clicking down on the roco, stops the loco and sets the direction as unknown. @@ -129,7 +119,7 @@ private: // Selocoid as analog value to start drive // use - void _writeAnalogue(VPIN vpin, int value, uint8_t param1, uint16_t param2) override { + void EncoderThrottle::_writeAnalogue(VPIN vpin, int value, uint8_t param1, uint16_t param2) { (void) param2; _locoid=value; if (param1>0) _notch=param1; @@ -148,10 +138,7 @@ private: } - void _display() override { + void EncoderThrottle::_display() { DIAG(F("DRIVE vpin %d loco %d notch %d"),_firstVpin,_locoid,_notch); } - }; - -#endif diff --git a/IO_EncoderThrottle.h b/IO_EncoderThrottle.h new file mode 100644 index 0000000..05ce2eb --- /dev/null +++ b/IO_EncoderThrottle.h @@ -0,0 +1,53 @@ +/* + * © 2024, Chris Harlow. All rights reserved. + * + * This file is part of EX-CommandStation + * + * This is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * It is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with CommandStation. If not, see . +*/ + +/* +* The IO_EncoderThrottle device driver uses a rotary encoder connected to vpins +* to drive a loco. +* Loco id is selected by writeAnalog. +*/ + +#ifndef IO_EncoderThrottle_H +#define IO_EncoderThrottle_H +#include "IODevice.h" + +class EncoderThrottle : public IODevice { +public: + + static void create(VPIN firstVpin, int dtPin, int clkPin, int clickPin, byte notch=10); + +private: + int _dtPin,_clkPin,_clickPin, _locoid, _notch,_prevpinstate; + enum {xrSTOP,xrFWD,xrREV} _stopState; + byte _rocoState; + + // Constructor + EncoderThrottle(VPIN firstVpin, int dtPin, int clkPin, int clickPin, byte notch); + + void _loop(unsigned long currentMicros) override ; + + // Selocoid as analog value to start drive + // use + void _writeAnalogue(VPIN vpin, int value, uint8_t param1, uint16_t param2) override; + + void _display() override ; + + }; + +#endif diff --git a/version.h b/version.h index 084751d..1746bd5 100644 --- a/version.h +++ b/version.h @@ -3,7 +3,9 @@ #include "StringFormatter.h" -#define VERSION "5.2.69" +#define VERSION "5.2.70" +// 5.2.70 - IO_RocoDriver renamed to IO_EncoderThrottle. +// - and included in IODEvice.h (circular dependency removed) // 5.2.69 - IO_RocoDriver. Direct drive train with rotary encoder hw. // 5.2.68 - Revert function map to signed (from 5.2.66) to avoid // incompatibilities with ED etc for F31 frequency flag.