1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-23 21:01:25 +01:00

optimize for loops for size (and speed)

This commit is contained in:
Harald Barth 2021-08-01 15:07:06 +02:00
parent 55b7091d5a
commit c4f659243e
3 changed files with 10 additions and 5 deletions

View File

@ -138,15 +138,18 @@ void Output::load(){
// id. If someone uses only pins 0 to 7 of their arduino, they
// loose. This is (if you look at an arduino) however unlikely.
for(uint16_t i=0;i<EEStore::eeStore->data.nOutputs;i++){
uint16_t i=EEStore::eeStore->data.nOutputs;
while(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;
}
}
i=EEStore::eeStore->data.nOutputs;
if ( isBroken ) {
for(uint16_t i=0;i<EEStore::eeStore->data.nOutputs;i++){
while(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
@ -158,7 +161,7 @@ void Output::load(){
} else {
struct OutputData data;
for(uint16_t i=0;i<EEStore::eeStore->data.nOutputs;i++){
while(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

View File

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

View File

@ -103,7 +103,8 @@ void Turnout::load(){
struct TurnoutData data;
Turnout *tt;
for(uint16_t i=0;i<EEStore::eeStore->data.nTurnouts;i++){
uint16_t i=EEStore::eeStore->data.nTurnouts;
while(i--){
EEPROM.get(EEStore::pointer(),data);
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);