]> git.defcon.no Git - rctxduino/blobdiff - source/RCTXDuino/RCTXDuino.pde
Changes to debugging, battery alarm, ppm timing:
[rctxduino] / source / RCTXDuino / RCTXDuino.pde
index 0bc85626db0fc0992c86333e0fbb1029ae1a0151..ebe62ad503afde00aea28315d61861a35b48b52e 100644 (file)
@@ -2,6 +2,11 @@
 #include <TimerOne.h>
 #include <EEPROM.h>
 
+// Undefine this whenever a "release" or "flight-test" build is made.
+// Defining DEBUG sets some crazy values for things like battery warning,
+// and includes a whole bunch of debugging-related code ...
+#define DEBUG 1
+
 #define MAX_INPUTS 8
 
 // Update this _every_ time a change in datastructures that
@@ -83,10 +88,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  21500             // Max length of frame
-#define seplength      250             // Lenght of a channel separator
+#define framelength  21000             // Max length of frame
+#define seplength      300             // Lenght of a channel separator
 #define chmax         1600             // Max lenght of channel pulse
-#define chmin          480             // Min length of channel
+#define chmin          495             // Min length of channel
 #define chwidht  (chmax - chmin)// Useable time of channel pulse
 
 // ----------------- Menu/IU related stuffs --------------------
@@ -105,7 +110,15 @@ volatile bool do_channel = true;        // Is next operation a channel or a sepa
 
 // Voltage sense pin is connected to a 1/3'd voltage divider.
 #define BATTERY_CONV (10 * 3 * (5.0f/1024.0f))
+
+#ifdef DEBUG
+// The following values are for DEBUGGING ONLY!!
+#define BATTERY_LOW 92
+#define BATTERY_CRITICAL 0
+#else
 #define BATTERY_LOW 92
+#define BATTERY_CRITICAL 92
+#endif
 
 enum {
   VALUES,
@@ -121,7 +134,7 @@ enum {
   INVERTS,
   DUALRATES,
   EXPOS, // Some radios have "drawn curves", i.e. loopup tables stored in external EEPROM ...
-  DEBUG,
+  DEBUG_DUMP,
   SAVE
 } 
 menu_mainstate;
@@ -145,11 +158,12 @@ struct clock_timer_t
        boolean running;
 } clock_timer;
 
+#ifdef DEBUG
 // -----------------  DEBUG-STUFF --------------------
 unsigned long prev_loop_time;
 unsigned long avg_loop_time;
 unsigned long t;
-
+#endif
 
 // ---------- CODE! -----------------------------------
 
@@ -183,11 +197,12 @@ void setup(){
   if ( !keys[KEY_UP])
     calibrate();
   
+#ifdef DEBUG
   // Debugging: how long does the main loop take on avg...  
   t = micros();
   avg_loop_time = t;
   prev_loop_time = t;    
-
+#endif
   
   // Initializing the stopwatch timer/clock values...
   clock_timer = (clock_timer_t){0, 0, 0, false};
@@ -224,15 +239,8 @@ void model_defaults( void )
 }
 
 // ---------- Arduino main loop -----------------------
-void loop () {
-  
-  // Determine if the UI needs to run...
-  boolean disp;
-  if ( millis() - last > UI_INTERVAL ) { 
-    last = millis(); 
-    disp = true; 
-  }
-  else disp = false;
+void loop ()
+{  
 
   process_inputs();
 
@@ -240,13 +248,18 @@ void loop () {
   battery_val = analogRead(1) * BATTERY_CONV;
   if ( battery_val < BATTERY_LOW ) {
     digitalWrite(13, 1); // Simulate alarm :P
+  }
+  if ( battery_val < BATTERY_CRITICAL ) {
     displaystate = BATTERY;
   }
 
-  if ( disp )
-  {
+  if ( millis() - last > UI_INTERVAL ) 
+  { 
+    last = millis(); 
     ui_handler(); 
   }
+  
+#ifdef DEBUG
   if ( displaystate != MENU )
   {
     // Debugging: how long does the main loop take on avg,
@@ -255,6 +268,7 @@ void loop () {
     avg_loop_time = ( t - prev_loop_time + avg_loop_time ) / 2;
     prev_loop_time = t;    
   }
+#endif
 
   // Whoa! Slow down partner! Let everything settle down before proceeding.
   delay(5);
@@ -431,7 +445,9 @@ void read_model_settings(unsigned char mod_no)
   for (i = 0; i < sizeof(model_t); i++)
                *p++ = EEPROM.read( model_address++ );
 
+#ifdef DEBUG
   serial_dump_model();
+#endif
 
   lcd.setCursor(0 , 1);
   lcd.print("... Loaded.");
@@ -476,6 +492,7 @@ void write_model_settings(unsigned char mod_no)
   delay(200);    
 }
 
+#ifdef DEBUG
 void serial_dump_model ( void )
 {
   int i;
@@ -536,6 +553,7 @@ void serial_dump_model ( void )
     Serial.println();
   }  
 }
+#endif
 
 void scan_keys ( void )
 {
@@ -678,6 +696,7 @@ void ISR_timer(void)
   }
 }
 
+#ifdef DEBUG
 void serial_debug()
 {
   int current_input;
@@ -703,6 +722,7 @@ void serial_debug()
 
   Serial.println();
 }
+#endif
 
 void dr_inputselect( int no, int in )
 {
@@ -1021,13 +1041,22 @@ void ui_handler()
             menu_mainstate = DUALRATES; 
             return; 
           }          
+#ifdef DEBUG          
+          if ( check_key(KEY_DOWN ) ) {
+            menu_mainstate = DEBUG_DUMP;
+            return;
+          }
+#else
           if ( check_key(KEY_DOWN ) ) {
-            menu_mainstate = DEBUG;
+            menu_mainstate = TOP;
             return;
           }
+
+#endif
           break;
-          
-        case DEBUG:
+
+#ifdef DEBUG          
+        case DEBUG_DUMP:
           lcd.setCursor(0 , 0);
           lcd.print("Dumping debug to");
           lcd.setCursor(0 , 1);
@@ -1042,7 +1071,7 @@ void ui_handler()
             return;
           }
           break;
-    
+#endif    
         default:
           lcd.print("Not implemented");
           lcd.setCursor(0 , 1);