1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-26 17:46:14 +01:00

fix version.h of merge

This commit is contained in:
Harald Barth 2021-07-31 15:40:32 +02:00
commit 50fcbc088a
7 changed files with 70 additions and 27 deletions

View File

@ -578,7 +578,11 @@ bool DCCEXParser::parseZ(Print *stream, int16_t params, int16_t p[])
} }
return true; return true;
case 3: // <Z ID PIN INVERT> case 3: // <Z ID PIN IFLAG>
if (p[0] < 0 ||
p[1] > 255 || p[1] <= 1 || // Pins 0 and 1 are Serial to USB
p[2] < 0 || p[2] > 7 )
return false;
if (!Output::create(p[0], p[1], p[2], 1)) if (!Output::create(p[0], p[1], p[2], 1))
return false; return false;
StringFormatter::send(stream, F("<O>\n")); StringFormatter::send(stream, F("<O>\n"));

View File

@ -33,9 +33,9 @@ extern ExternalEEPROM EEPROM;
struct EEStoreData{ struct EEStoreData{
char id[sizeof(EESTORE_ID)]; char id[sizeof(EESTORE_ID)];
int nTurnouts; uint16_t nTurnouts;
int nSensors; uint16_t nSensors;
int nOutputs; uint16_t nOutputs;
}; };
struct EEStore{ struct EEStore{

View File

@ -100,14 +100,14 @@ void Output::activate(int s){
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
Output* Output::get(int n){ Output* Output::get(uint16_t n){
Output *tt; Output *tt;
for(tt=firstOutput;tt!=NULL && tt->data.id!=n;tt=tt->nextOutput); for(tt=firstOutput;tt!=NULL && tt->data.id!=n;tt=tt->nextOutput);
return(tt); return(tt);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
bool Output::remove(int n){ bool Output::remove(uint16_t n){
Output *tt,*pp=NULL; Output *tt,*pp=NULL;
for(tt=firstOutput;tt!=NULL && tt->data.id!=n;pp=tt,tt=tt->nextOutput); for(tt=firstOutput;tt!=NULL && tt->data.id!=n;pp=tt,tt=tt->nextOutput);
@ -127,17 +127,46 @@ bool Output::remove(int n){
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void Output::load(){ void Output::load(){
struct OutputData data; struct BrokenOutputData bdata;
Output *tt; Output *tt;
bool isBroken=1;
for(int i=0;i<EEStore::eeStore->data.nOutputs;i++){ // This is a scary kluge. As we have two formats in EEPROM due to an
EEPROM.get(EEStore::pointer(),data); // earlier bug, we don't know which we encounter now. So we guess
tt=create(data.id,data.pin,data.iFlag); // that if in all entries this byte has value of 7 or lower this is
tt->data.oStatus=bitRead(tt->data.iFlag,1)?bitRead(tt->data.iFlag,2):data.oStatus; // restore status to EEPROM value is bit 1 of iFlag=0, otherwise set to value of bit 2 of iFlag // an iFlag and thus the broken format. Otherwise it would be a pin
digitalWrite(tt->data.pin,tt->data.oStatus ^ bitRead(tt->data.iFlag,0)); // id. If someone uses only pins 0 to 7 of their arduino, they
pinMode(tt->data.pin,OUTPUT); // loose. This is (if you look at an arduino) however unlikely.
tt->num=EEStore::pointer();
EEStore::advance(sizeof(tt->data)); for(uint16_t i=0;i<EEStore::eeStore->data.nOutputs;i++){
EEPROM.get(EEStore::pointer()+ i*sizeof(struct BrokenOutputData),bdata);
if (bdata.iFlag > 7) { // it's a pin and not an iFlag!
isBroken=0;
break;
}
}
if ( isBroken ) {
for(uint16_t i=0;i<EEStore::eeStore->data.nOutputs;i++){
EEPROM.get(EEStore::pointer(),bdata);
tt=create(bdata.id,bdata.pin,bdata.iFlag);
tt->data.oStatus=bitRead(tt->data.iFlag,1)?bitRead(tt->data.iFlag,2):bdata.oStatus; // restore status to EEPROM value is bit 1 of iFlag=0, otherwise set to value of bit 2 of iFlag
digitalWrite(tt->data.pin,tt->data.oStatus ^ bitRead(tt->data.iFlag,0));
pinMode(tt->data.pin,OUTPUT);
tt->num=EEStore::pointer();
EEStore::advance(sizeof(struct BrokenOutputData));
}
} else {
struct OutputData data;
for(uint16_t i=0;i<EEStore::eeStore->data.nOutputs;i++){
EEPROM.get(EEStore::pointer(),data);
tt=create(data.id,data.pin,data.iFlag);
tt->data.oStatus=bitRead(tt->data.iFlag,1)?bitRead(tt->data.iFlag,2):data.oStatus; // restore status to EEPROM value is bit 1 of iFlag=0, otherwise set to value of bit 2 of iFlag
digitalWrite(tt->data.pin,tt->data.oStatus ^ bitRead(tt->data.iFlag,0));
pinMode(tt->data.pin,OUTPUT);
tt->num=EEStore::pointer();
EEStore::advance(sizeof(struct OutputData));
}
} }
} }
@ -160,7 +189,7 @@ void Output::store(){
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
Output *Output::create(int id, int pin, int iFlag, int v){ Output *Output::create(uint16_t id, uint8_t pin, uint8_t iFlag, uint8_t v){
Output *tt; Output *tt;
if(firstOutput==NULL){ if(firstOutput==NULL){

View File

@ -23,25 +23,34 @@
struct OutputData { struct OutputData {
uint8_t oStatus; uint8_t oStatus;
uint8_t id; uint16_t id;
uint8_t pin; uint8_t pin;
uint8_t iFlag; uint8_t iFlag;
}; };
struct BrokenOutputData {
uint8_t oStatus;
uint8_t id;
uint8_t pin;
uint8_t iFlag;
};
class Output{ class Output{
public:
public:
void activate(int s); void activate(int s);
static Output* get(int); static Output* get(uint16_t);
static bool remove(int); static bool remove(uint16_t);
static void load(); static void load();
static void store(); static void store();
static Output *create(int, int, int, int=0); static Output *create(uint16_t, uint8_t, uint8_t, uint8_t=0);
static Output *firstOutput; static Output *firstOutput;
struct OutputData data; struct OutputData data;
Output *nextOutput; Output *nextOutput;
static void printAll(Print *); static void printAll(Print *);
private:
int num; // Chris has no idea what this is all about! private:
int num; // EEPROM pointer (Chris has no idea what this is all about!)
}; // Output }; // Output

View File

@ -184,7 +184,7 @@ void Sensor::load(){
struct SensorData data; struct SensorData data;
Sensor *tt; Sensor *tt;
for(int i=0;i<EEStore::eeStore->data.nSensors;i++){ for(uint16_t i=0;i<EEStore::eeStore->data.nSensors;i++){
EEPROM.get(EEStore::pointer(),data); EEPROM.get(EEStore::pointer(),data);
tt=create(data.snum,data.pin,data.pullUp); tt=create(data.snum,data.pin,data.pullUp);
EEStore::advance(sizeof(tt->data)); EEStore::advance(sizeof(tt->data));

View File

@ -103,7 +103,7 @@ void Turnout::load(){
struct TurnoutData data; struct TurnoutData data;
Turnout *tt; Turnout *tt;
for(int i=0;i<EEStore::eeStore->data.nTurnouts;i++){ for(uint16_t i=0;i<EEStore::eeStore->data.nTurnouts;i++){
EEPROM.get(EEStore::pointer(),data); EEPROM.get(EEStore::pointer(),data);
if (data.tStatus & STATUS_PWM) tt=create(data.id,data.tStatus & STATUS_PWMPIN, data.inactiveAngle,data.moveAngle); if (data.tStatus & STATUS_PWM) tt=create(data.id,data.tStatus & STATUS_PWMPIN, data.inactiveAngle,data.moveAngle);
else tt=create(data.id,data.address,data.subAddress); else tt=create(data.id,data.address,data.subAddress);

View File

@ -3,8 +3,9 @@
#include "StringFormatter.h" #include "StringFormatter.h"
#define VERSION "3.1.5"
// 3.1.6 Make output ID two bytes (reserved version number for that merge/branch) #define VERSION "3.1.6"
// 3.1.6 Make output ID two bytes and guess format/size of registered outputs found in EEPROM
// 3.1.5 Fix LCD corruption on power-up // 3.1.5 Fix LCD corruption on power-up
// 3.1.4 Refactor OLED and LCD drivers and remove unused code // 3.1.4 Refactor OLED and LCD drivers and remove unused code
// 3.1.3 Add a loop delay to give more time for sensing an Ethernet cable connection // 3.1.3 Add a loop delay to give more time for sensing an Ethernet cable connection