X-Git-Url: https://git.defcon.no/?a=blobdiff_plain;f=source%2FRCTXDuino%2FRCTXDuino.pde;h=0bc85626db0fc0992c86333e0fbb1029ae1a0151;hb=12dcaa4691c9b1b2f7c8873b51ff01f34886a5de;hp=d238b753edeece29ec1549d730be5011a6e29f91;hpb=3c5f990b9bde180af15b5755df660aa11f5b7caf;p=rctxduino diff --git a/source/RCTXDuino/RCTXDuino.pde b/source/RCTXDuino/RCTXDuino.pde index d238b75..0bc8562 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 @@ -82,10 +83,10 @@ volatile bool do_channel = true; // Is next operation a channel or a sepa // The timing here (and/or in the ISR) needs to be tweaked to provide valid // RC PPM signals accepted by standard RC RX'es and the Microcopter... -#define framelength 21000 // Max length of frame -#define seplength 300 // Lenght of a channel separator -#define chmax 1550 // Max lenght of channel pulse -#define chmin 620 // Min length of channel +#define framelength 21500 // Max length of frame +#define seplength 250 // Lenght of a channel separator +#define chmax 1600 // Max lenght of channel pulse +#define chmin 480 // Min length of channel #define chwidht (chmax - chmin)// Useable time of channel pulse // ----------------- Menu/IU related stuffs -------------------- @@ -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 ) @@ -213,7 +215,7 @@ void model_defaults( void ) // data format changes. // NOTE: This means that stored model conficuration is reset // to defaults when the EEPROM version/format changes. - model.channels = 6; + model.channels = 8; model.rev[0] = model.rev[1] = model.rev[2] = model.rev[3] = model.rev[4] = model.rev[5] = model.rev[6] = model.rev[7] = false; model.dr[0] = model.dr[1] = model.dr[2] = model.dr[3] = 0; @@ -296,7 +298,7 @@ void mplx_select(int pin) void calibrate() { - int i, r0, r1, r2, adc_in; + int i, adc_in; int num_calibrations = 200; lcd.clear(); @@ -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,33 +461,91 @@ 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