+ int model_address;
+ int i;
+ unsigned char v;
+ byte *p;
+
+ // Calculate the EEPROM start adress for the given model (mod_no)
+ model_address = EE_MDL_BASE_ADDR + (mod_no * sizeof(model_t));
+
+ Serial.print("Models base addr: ");
+ Serial.println( EE_MDL_BASE_ADDR );
+ Serial.print("Model no: ");
+ Serial.println( mod_no, 10 );
+ Serial.print("Size of struct: ");
+ Serial.println( sizeof( model_t) );
+ Serial.print("Model address: ");
+ Serial.println( model_address );
+ Serial.print("End of model: ");
+ Serial.println( model_address + sizeof(model_t) );
+
+ // Do not try to write the model to EEPROM if it won't fit.
+ if ( INT_EEPROM_SIZE < (model_address + sizeof(model_t)) )
+ {
+ lcd.clear();
+ lcd.print("Aborting READ");
+ lcd.setCursor(0 , 1);
+ lcd.print("Invalid location");
+ delay(2000);
+ return;
+ }
+
+ lcd.clear();
+ lcd.print("Reading model ");
+ lcd.print( (int)mod_no );
+
+ // Pointer to the start of the model_t data struct,
+ // used for byte-by-byte reading of data...
+ p = (byte*)(void*)&model;
+ for (i = 0; i < sizeof(input_cal_t); i++)
+ *p++ = EEPROM.read( model_address++ );
+
+ lcd.setCursor(0 , 1);
+ lcd.print("... Loaded.");
+ delay(1000);
+}
+
+void write_model_settings(unsigned char mod_no)
+{
+ int model_address;
+ int i;
+ unsigned char v;
+ byte *p;
+
+ // Calculate the EEPROM start adress for the given model (mod_no)
+ model_address = EE_MDL_BASE_ADDR + (mod_no * sizeof(model_t));
+
+ // Do not try to write the model to EEPROM if it won't fit.
+ if ( INT_EEPROM_SIZE < (model_address + sizeof(model_t)) )
+ {
+ lcd.clear();
+ lcd.print("Aborting SAVE");
+ lcd.setCursor(0 , 1);
+ lcd.print("No room for data");
+ delay(2000);
+ return;
+ }
+
+ lcd.clear();
+ lcd.print("Saving model ");
+ lcd.print(mod_no);
+
+ // Pointer to the start of the model_t data struct,
+ // used for byte-by-byte reading of data...
+ p = (byte*)(void*)&model;
+
+ // Write/serialize the model data struct to EEPROM...
+ for (i = 0; i < sizeof(input_cal_t); i++)
+ EEPROM.write( model_address++, *p++);
+
+ lcd.setCursor(0 , 1);
+ lcd.print(".. done saving.");
+ delay(1000);