+ 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 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(model_t); i++)
+ *p++ = EEPROM.read( model_address++ );
+
+ serial_dump_model();
+
+ 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( (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;
+
+ // Write/serialize the model data struct to EEPROM...
+ for (i = 0; i < sizeof(model_t); i++)
+ EEPROM.write( model_address++, *p++);
+
+ lcd.setCursor(0 , 1);
+ lcd.print(".. done saving.");
+ delay(200);
+}
+
+void serial_dump_model ( void )
+{
+ int i;
+ int model_address;
+ // Calculate the EEPROM start adress for the given model (mod_no)
+ model_address = EE_MDL_BASE_ADDR + (current_model * sizeof(model_t));
+ Serial.print("Current model: ");
+ Serial.println( (int)current_model );
+ Serial.print("Models base addr: ");
+ Serial.println( EE_MDL_BASE_ADDR );
+ Serial.print("Model no: ");
+ Serial.println( current_model, 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) );
+
+ Serial.println();
+
+ Serial.print("Channel reversions: ");
+ for ( i = 0; i<8; i++)
+ {
+ Serial.print(i);
+ Serial.print("=");
+ Serial.print(model.rev[i], 10);
+ Serial.print(" ");
+ }
+ Serial.println();
+
+ Serial.print("DR1 inp 0: ");
+ Serial.println(model.dr[0]);
+ Serial.print("DR1 inp 1: ");
+ Serial.println(model.dr[1]);
+ Serial.print("DR1 LO val: ");
+ Serial.println(model.dr[4]);
+ Serial.print("DR1 HI val: ");
+ Serial.println(model.dr[5]);
+ Serial.print("DR2 inp 0: ");
+ Serial.println(model.dr[2]);
+ Serial.print("DR2 inp 1: ");
+ Serial.println(model.dr[3]);
+ Serial.print("DR2 LO val: ");
+ Serial.println(model.dr[6]);
+ Serial.print("DR2 HI val: ");
+ Serial.println(model.dr[7]);
+
+ for (i=0; i<MAX_INPUTS; i++) {
+ Serial.print("Input #");
+ Serial.print(i);
+ Serial.print(" pct: ");
+ Serial.print(model.stick[i]);
+ Serial.print(" min: ");
+ Serial.print(input_cal.min[i]);
+ Serial.print(" max: ");
+ Serial.print(input_cal.max[i]);
+ Serial.println();
+ }