refactored handling of settings '$' command out of gcode module and into settings module

This commit is contained in:
Simen Svale Skogsrud
2011-02-18 22:59:16 +01:00
parent 6893463e80
commit 9876e14f0b
9 changed files with 93 additions and 68 deletions

View File

@ -25,6 +25,7 @@
#include "eeprom.h"
#include "wiring_serial.h"
#include <avr/pgmspace.h>
#include "protocol.h"
settings_t settings;
@ -81,6 +82,28 @@ void settings_dump() {
printPgmString(PSTR("\r\n'$x=value' to set parameter or just '$' to dump current settings\r\n"));
}
// Parameter lines are on the form '$4=374.3' or '$' to dump current settings
uint8_t settings_execute_line(char *line) {
uint8_t char_counter = 1;
double parameter, value;
if(line[0] != '$') {
return(STATUS_UNSUPPORTED_STATEMENT);
}
if(line[char_counter] == 0) {
settings_dump(); return(STATUS_OK);
}
read_double(line, &char_counter, &parameter);
if(line[char_counter++] != '=') {
return(STATUS_UNSUPPORTED_STATEMENT);
}
read_double(line, &char_counter, &value);
if(line[char_counter] != 0) {
return(STATUS_UNSUPPORTED_STATEMENT);
}
settings_store_setting(parameter, value);
return(STATUS_OK);
}
void write_settings() {
eeprom_put_char(0, SETTINGS_VERSION);
memcpy_to_eeprom_with_checksum(1, (char*)&settings, sizeof(settings_t));