From 88e0716888b769522dfabb9d7af68d3757e7a53c Mon Sep 17 00:00:00 2001 From: Jon Langseth Date: Fri, 2 Sep 2011 19:54:11 +0200 Subject: [PATCH] Removed a nasty bug caused my a misplaced ';'. Also: added a debug-dumper serial_dump_model(). --- source/RCTXDuino/RCTXDuino.pde | 112 ++++++++++++++++++++++++--------- 1 file changed, 82 insertions(+), 30 deletions(-) diff --git a/source/RCTXDuino/RCTXDuino.pde b/source/RCTXDuino/RCTXDuino.pde index d238b75..5254bb6 100644 --- a/source/RCTXDuino/RCTXDuino.pde +++ b/source/RCTXDuino/RCTXDuino.pde @@ -9,7 +9,7 @@ // 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) @@ -34,6 +34,7 @@ #define MAX_MODELS 4 // Nice and random number.. + // --------------- ADC related stuffs.... -------------------- struct input_cal_t // Struct type for input calibration values @@ -171,12 +172,6 @@ void setup(){ 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. @@ -196,6 +191,13 @@ void setup(){ // 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 ) @@ -336,7 +338,7 @@ void calibrate() lcd.setCursor(0 , 1); lcd.print("Done calibrating"); - Serial.print("Done calibrating"); + Serial.print("Done calibrating"); delay(2000); } @@ -377,7 +379,7 @@ void read_settings(void) 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); @@ -385,14 +387,14 @@ void read_settings(void) // 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 ); @@ -407,18 +409,7 @@ void read_model_settings(unsigned char mod_no) // 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)) ) { @@ -437,9 +428,11 @@ void read_model_settings(unsigned char 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++) + 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); @@ -468,22 +461,81 @@ void write_model_settings(unsigned char mod_no) 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