1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-07-28 18:03:45 +02:00

Narrowing Turnout publics

This commit is contained in:
Asbelos
2021-08-18 18:55:22 +01:00
parent 9dacd24d27
commit 36f6e2f9ce
7 changed files with 66 additions and 36 deletions

View File

@@ -18,6 +18,12 @@
* You should have received a copy of the GNU General Public License
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
*/
// >>>>>> ATTENTION: This class requires major cleaning.
// The public interface has been narrowed to avoid the ambuguity of "activated".
//#define EESTOREDEBUG
#include "defines.h"
#include "Turnouts.h"
@@ -40,6 +46,10 @@ enum unit8_t {
TURNOUT_LCN = 4,
};
///////////////////////////////////////////////////////////////////////////////
// Static function to print all Turnout states to stream in form "<H id state>"
@@ -82,10 +92,25 @@ void Turnout::print(Print *stream){
}
}
// Public interface to turnout throw/close
bool Turnout::setClosed(int id, bool closed) {
// hides the internal activate argument to a single place
return activate(id, closed? false: true ); /// Needs cleaning up
}
bool Turnout::isClosed(int id) {
// hides the internal activate argument to a single place
return !isActive(id); /// Needs cleaning up
}
int Turnout::getId() {
return data.id;
}
///////////////////////////////////////////////////////////////////////////////
// Static function to activate/deactivate Turnout with ID 'n'.
// Returns false if turnout not found.
bool Turnout::activate(int n, bool state){
Turnout * tt=get(n);
if (!tt) return false;
@@ -145,7 +170,7 @@ void Turnout::activate(bool state) {
EEPROM.put(num, data.tStatus);
#if defined(RMFT_ACTIVE)
RMFT2::turnoutEvent(data.id, state);
RMFT2::turnoutEvent(data.id, !state);
#endif
}