Make saveing and loading to epprop a user controlled operation
This commit is contained in:
23
main.cpp
23
main.cpp
@ -48,10 +48,12 @@ inline static void printHelp(Serial* serial)
|
||||
|
||||
serial->write_p(PSTR("Available Commands: \n\
|
||||
help : Show this prompt.\n\
|
||||
relay add [id] [name] : Add Wireless Relay.\n\
|
||||
relay delete [n] : Delete n'th Relay.\n\
|
||||
relay add [id] [name] : Add Wireless Relay. Save to make permant.\n\
|
||||
relay delete [n] : Delete n'th Relay. Save to make permant.\n\
|
||||
relay [on/off] [nn] : Turn on/off nth relay.\n\
|
||||
relay resend [on/off] : Turn on/off periodic auto resend.\n\
|
||||
relay resend [on/off] : Turn on/off periodic auto resend. Save to make permant.\n\
|
||||
save : Save current state as startup state.\n\
|
||||
load : load startup state.\n\
|
||||
state : Get machine readable state.\n\
|
||||
erase : Erase epprom.\n\
|
||||
dump : Dump epprom.\n\
|
||||
@ -127,7 +129,6 @@ void relayDispatch(SVector<WirelessRelay, MAX_RELAYS>* relays, Pwm16b* auxPwm, c
|
||||
relays->push_back(relay);
|
||||
}
|
||||
writeRelayState(serial, &relays->back(), relays->count()-1);
|
||||
save();
|
||||
}
|
||||
else if(relays->remainingCapacity() == 0) serial->write_p(PSTR("Relay storage full.\n"));
|
||||
else serial->write_p(PSTR("Usage: relay add [id] [name]\n [id] being a 16bit binary nummber and [name] an optional string\n"));
|
||||
@ -142,7 +143,6 @@ void relayDispatch(SVector<WirelessRelay, MAX_RELAYS>* relays, Pwm16b* auxPwm, c
|
||||
snprintf(buffer, SNPRINTF_BUFFER_SIZE, "Deleting relay NUMBER: %u NAME: %s\n", index, relays->at(index).getName());
|
||||
serial->write(buffer, SNPRINTF_BUFFER_SIZE);
|
||||
relays->erase(index);
|
||||
save();
|
||||
}
|
||||
}
|
||||
else if( strcmp(token, "on") == 0 )
|
||||
@ -186,7 +186,6 @@ void relayDispatch(SVector<WirelessRelay, MAX_RELAYS>* relays, Pwm16b* auxPwm, c
|
||||
serial->write_p(PSTR("now "));
|
||||
if(strcmp(token, "on") == 0) resendEnabled = true;
|
||||
else resendEnabled = false;
|
||||
save();
|
||||
}
|
||||
resendEnabled ? serial->write_p(PSTR("enabled.\n")) : serial->write_p(PSTR("disabled.\n")) ;
|
||||
}
|
||||
@ -311,11 +310,11 @@ void serialDispatch(Serial* serial, SVector<WirelessRelay, MAX_RELAYS>* relays,
|
||||
char* token = strtok(buffer, " \n");
|
||||
if(strcmp(token, "relay") == 0)
|
||||
{
|
||||
reciver->waitForReciveIdle();
|
||||
relayDispatch(relays, auxPwm, strtok(NULL, " \n"), serial);
|
||||
}
|
||||
else if(strcmp(token, "rgb") == 0)
|
||||
{
|
||||
reciver->waitForReciveIdle();
|
||||
rgbDispatch(rgbled, strtok(NULL, " \n"), serial);
|
||||
}
|
||||
else if(strcmp(token, "aux") == 0)
|
||||
@ -342,6 +341,16 @@ void serialDispatch(Serial* serial, SVector<WirelessRelay, MAX_RELAYS>* relays,
|
||||
}
|
||||
serial->write_p(PSTR("EOL\n"));
|
||||
}
|
||||
else if(strcmp(token, "save") == 0)
|
||||
{
|
||||
save();
|
||||
serial->write_p(PSTR("State saved to EEPROM.\n"));
|
||||
}
|
||||
else if(strcmp(token, "save") == 0)
|
||||
{
|
||||
load();
|
||||
serial->write_p(PSTR("Loaded state from EEPROM.\n"));
|
||||
}
|
||||
else if(strcmp(token, "erase") == 0)
|
||||
{
|
||||
for(uint16_t i = 0; i < 1024; i++) EEPROM_write_char(i, 0);
|
||||
|
Reference in New Issue
Block a user