// read/written torectly into/from the data structures using
// pointers, so every time a data-set change occurs, the EEPROM
// format changes as well..
-#define EEPROM_VERSION 3
+#define EEPROM_VERSION 7
// Some data is stored in fixed locations, e.g.:
// * The EEPROM version number for the stored data (loc 0)
#define MAX_MODELS 4 // Nice and random number..
+
// --------------- ADC related stuffs.... --------------------
struct input_cal_t // Struct type for input calibration values
model_defaults();
read_settings();
- pinMode(A5, OUTPUT); // PPM output pin
- do_channel = false;
- set_timer( seplength );
- Timer1.initialize(framelength);
- Timer1.attachInterrupt(ISR_timer);
-
displaystate = VALUES;
// Arduino believes all pins on Port C are Analog.
// Initializing the stopwatch timer/clock values...
clock_timer = (clock_timer_t){0, 0, 0, false};
+
+ pinMode(A5, OUTPUT); // PPM output pin
+ do_channel = false;
+ set_timer( seplength );
+ Timer1.initialize(framelength);
+ Timer1.attachInterrupt(ISR_timer);
+
}
void model_defaults( void )
lcd.setCursor(0 , 1);
lcd.print("Done calibrating");
- Serial.print("Done calibrating");
+ Serial.print("Done calibrating");
delay(2000);
}
calibrate();
model_defaults();
// The following does not yet work...
- for ( i = 0; i < MAX_MODELS; i++);
+ for ( i = 0; i < MAX_MODELS; i++)
write_model_settings(i);
// update the saved version-identifier to the current ver.
EEPROM.write(0, EEPROM_VERSION);
}
-
+
// Read calibration values from EEPROM.
// This uses simple pointer-arithmetic and byte-by-byte
// to put bytes read from EEPROM to the data-struct.
p = (byte*)(void*)&input_cal;
for (i = 0; i < sizeof(input_cal_t); i++)
*p++ = EEPROM.read( EE_BASE_ADDR + i);
-
+
// Get the previously selected model from EEPROM.
current_model = EEPROM.read(1);
read_model_settings( current_model );
// 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)) )
{
// 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++)
+ 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);
lcd.clear();
lcd.print("Saving model ");
- lcd.print(mod_no);
+ 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(input_cal_t); i++)
- EEPROM.write( model_address++, *p++);
-
+ for (i = 0; i < sizeof(model_t); i++)
+ EEPROM.write( model_address++, *p++);
+
lcd.setCursor(0 , 1);
lcd.print(".. done saving.");
- delay(1000);
+ 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();
+ }
+}
void scan_keys ( void )
{