mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-07-28 18:03:45 +02:00
Merge branch 'master' into Broadcast
This commit is contained in:
32
Turnouts.cpp
32
Turnouts.cpp
@@ -22,7 +22,9 @@
|
||||
|
||||
|
||||
#include "defines.h" // includes config.h
|
||||
#ifndef DISABLE_EEPROM
|
||||
#include "EEStore.h"
|
||||
#endif
|
||||
#include "StringFormatter.h"
|
||||
#include "CommandDistributor.h"
|
||||
#include "RMFT2.h"
|
||||
@@ -135,11 +137,13 @@
|
||||
|
||||
if (ok) {
|
||||
turnoutlistHash++; // let withrottle know something changed
|
||||
|
||||
|
||||
#ifndef DISABLE_EEPROM
|
||||
// Write byte containing new closed/thrown state to EEPROM if required. Note that eepromAddress
|
||||
// is always zero for LCN turnouts.
|
||||
if (EEStore::eeStore->data.nTurnouts > 0 && tt->_eepromAddress > 0)
|
||||
EEPROM.put(tt->_eepromAddress, tt->_turnoutData.flags);
|
||||
EEPROM.put(tt->_eepromAddress, tt->_turnoutData.flags);
|
||||
#endif
|
||||
|
||||
#if defined(RMFT_ACTIVE)
|
||||
RMFT2::turnoutEvent(id, closeFlag);
|
||||
@@ -151,6 +155,7 @@
|
||||
return ok;
|
||||
}
|
||||
|
||||
#ifndef DISABLE_EEPROM
|
||||
// Load all turnout objects
|
||||
/* static */ void Turnout::load() {
|
||||
for (uint16_t i=0; i<EEStore::eeStore->data.nTurnouts; i++) {
|
||||
@@ -204,7 +209,7 @@
|
||||
#endif
|
||||
return tt;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*************************************************************************************
|
||||
* ServoTurnout - Turnout controlled by servo device.
|
||||
@@ -263,6 +268,7 @@
|
||||
|
||||
// Load a Servo turnout definition from EEPROM. The common Turnout data has already been read at this point.
|
||||
Turnout *ServoTurnout::load(struct TurnoutData *turnoutData) {
|
||||
#ifndef DISABLE_EEPROM
|
||||
ServoTurnoutData servoTurnoutData;
|
||||
// Read class-specific data from EEPROM
|
||||
EEPROM.get(EEStore::pointer(), servoTurnoutData);
|
||||
@@ -272,6 +278,10 @@
|
||||
Turnout *tt = ServoTurnout::create(turnoutData->id, servoTurnoutData.vpin, servoTurnoutData.thrownPosition,
|
||||
servoTurnoutData.closedPosition, servoTurnoutData.profile, turnoutData->closed);
|
||||
return tt;
|
||||
#else
|
||||
(void)turnoutData;
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
// For DCC++ classic compatibility, state reported to JMRI is 1 for thrown and 0 for closed
|
||||
@@ -294,6 +304,7 @@
|
||||
}
|
||||
|
||||
void ServoTurnout::save() {
|
||||
#ifndef DISABLE_EEPROM
|
||||
// Write turnout definition and current position to EEPROM
|
||||
// First write common servo data, then
|
||||
// write the servo-specific data
|
||||
@@ -301,6 +312,7 @@
|
||||
EEStore::advance(sizeof(_turnoutData));
|
||||
EEPROM.put(EEStore::pointer(), _servoTurnoutData);
|
||||
EEStore::advance(sizeof(_servoTurnoutData));
|
||||
#endif
|
||||
}
|
||||
|
||||
/*************************************************************************************
|
||||
@@ -353,6 +365,7 @@
|
||||
|
||||
// Load a DCC turnout definition from EEPROM. The common Turnout data has already been read at this point.
|
||||
/* static */ Turnout *DCCTurnout::load(struct TurnoutData *turnoutData) {
|
||||
#ifndef DISABLE_EEPROM
|
||||
DCCTurnoutData dccTurnoutData;
|
||||
// Read class-specific data from EEPROM
|
||||
EEPROM.get(EEStore::pointer(), dccTurnoutData);
|
||||
@@ -362,6 +375,10 @@
|
||||
DCCTurnout *tt = new DCCTurnout(turnoutData->id, dccTurnoutData.address, dccTurnoutData.subAddress);
|
||||
|
||||
return tt;
|
||||
#else
|
||||
(void)turnoutData;
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
void DCCTurnout::print(Print *stream) {
|
||||
@@ -382,6 +399,7 @@
|
||||
}
|
||||
|
||||
void DCCTurnout::save() {
|
||||
#ifndef DISABLE_EEPROM
|
||||
// Write turnout definition and current position to EEPROM
|
||||
// First write common servo data, then
|
||||
// write the servo-specific data
|
||||
@@ -389,6 +407,7 @@
|
||||
EEStore::advance(sizeof(_turnoutData));
|
||||
EEPROM.put(EEStore::pointer(), _dccTurnoutData);
|
||||
EEStore::advance(sizeof(_dccTurnoutData));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -427,6 +446,7 @@
|
||||
|
||||
// Load a VPIN turnout definition from EEPROM. The common Turnout data has already been read at this point.
|
||||
/* static */ Turnout *VpinTurnout::load(struct TurnoutData *turnoutData) {
|
||||
#ifndef DISABLE_EEPROM
|
||||
VpinTurnoutData vpinTurnoutData;
|
||||
// Read class-specific data from EEPROM
|
||||
EEPROM.get(EEStore::pointer(), vpinTurnoutData);
|
||||
@@ -436,6 +456,10 @@
|
||||
VpinTurnout *tt = new VpinTurnout(turnoutData->id, vpinTurnoutData.vpin, turnoutData->closed);
|
||||
|
||||
return tt;
|
||||
#else
|
||||
(void)turnoutData;
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Report 1 for thrown, 0 for closed.
|
||||
@@ -451,6 +475,7 @@
|
||||
}
|
||||
|
||||
void VpinTurnout::save() {
|
||||
#ifndef DISABLE_EEPROM
|
||||
// Write turnout definition and current position to EEPROM
|
||||
// First write common servo data, then
|
||||
// write the servo-specific data
|
||||
@@ -458,6 +483,7 @@
|
||||
EEStore::advance(sizeof(_turnoutData));
|
||||
EEPROM.put(EEStore::pointer(), _vpinTurnoutData);
|
||||
EEStore::advance(sizeof(_vpinTurnoutData));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user