* Added a #define DEBUG statement, and a bunch of #ifdef/#else/#endif that includes or excludes debugging code depending on this #define
* Added BATTERY_CRITICAL, and changed the way BATTERY_LOW was handled. We now have two states of "severity" on the battery
* Set the debugging-value of BATTERY_CRITICAL to 0, to be able to debug without a battery connected :P
* Changed PPM timings again, had problems with some RF recievers. Tested OK with: fmsusb2, Graupner RX700, Corona RS810II, Corona RP8D1.
#include <TimerOne.h>
#include <EEPROM.h>
#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
#define MAX_INPUTS 8
// Update this _every_ time a change in datastructures that
// 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...
// 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 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 --------------------
#define chwidht (chmax - chmin)// Useable time of channel pulse
// ----------------- Menu/IU related stuffs --------------------
// Voltage sense pin is connected to a 1/3'd voltage divider.
#define BATTERY_CONV (10 * 3 * (5.0f/1024.0f))
// 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_CRITICAL 0
+#else
+#define BATTERY_LOW 92
+#define BATTERY_CRITICAL 92
+#endif
INVERTS,
DUALRATES,
EXPOS, // Some radios have "drawn curves", i.e. loopup tables stored in external EEPROM ...
INVERTS,
DUALRATES,
EXPOS, // Some radios have "drawn curves", i.e. loopup tables stored in external EEPROM ...
boolean running;
} clock_timer;
boolean running;
} clock_timer;
// ----------------- DEBUG-STUFF --------------------
unsigned long prev_loop_time;
unsigned long avg_loop_time;
unsigned long t;
// ----------------- DEBUG-STUFF --------------------
unsigned long prev_loop_time;
unsigned long avg_loop_time;
unsigned long t;
// ---------- CODE! -----------------------------------
// ---------- CODE! -----------------------------------
if ( !keys[KEY_UP])
calibrate();
if ( !keys[KEY_UP])
calibrate();
// Debugging: how long does the main loop take on avg...
t = micros();
avg_loop_time = t;
prev_loop_time = t;
// Debugging: how long does the main loop take on avg...
t = micros();
avg_loop_time = t;
prev_loop_time = t;
// Initializing the stopwatch timer/clock values...
clock_timer = (clock_timer_t){0, 0, 0, false};
// Initializing the stopwatch timer/clock values...
clock_timer = (clock_timer_t){0, 0, 0, false};
battery_val = analogRead(1) * BATTERY_CONV;
if ( battery_val < BATTERY_LOW ) {
digitalWrite(13, 1); // Simulate alarm :P
battery_val = analogRead(1) * BATTERY_CONV;
if ( battery_val < BATTERY_LOW ) {
digitalWrite(13, 1); // Simulate alarm :P
+ }
+ if ( battery_val < BATTERY_CRITICAL ) {
displaystate = BATTERY;
}
displaystate = BATTERY;
}
if ( displaystate != MENU )
{
// Debugging: how long does the main loop take on avg,
if ( displaystate != MENU )
{
// Debugging: how long does the main loop take on avg,
avg_loop_time = ( t - prev_loop_time + avg_loop_time ) / 2;
prev_loop_time = t;
}
avg_loop_time = ( t - prev_loop_time + avg_loop_time ) / 2;
prev_loop_time = t;
}
// Whoa! Slow down partner! Let everything settle down before proceeding.
delay(5);
// Whoa! Slow down partner! Let everything settle down before proceeding.
delay(5);
for (i = 0; i < sizeof(model_t); i++)
*p++ = EEPROM.read( model_address++ );
for (i = 0; i < sizeof(model_t); i++)
*p++ = EEPROM.read( model_address++ );
lcd.setCursor(0 , 1);
lcd.print("... Loaded.");
lcd.setCursor(0 , 1);
lcd.print("... Loaded.");
void serial_dump_model ( void )
{
int i;
void serial_dump_model ( void )
{
int i;
void scan_keys ( void )
{
void scan_keys ( void )
{
void serial_debug()
{
int current_input;
void serial_debug()
{
int current_input;
void dr_inputselect( int no, int in )
{
void dr_inputselect( int no, int in )
{
menu_mainstate = DUALRATES;
return;
}
menu_mainstate = DUALRATES;
return;
}
if ( check_key(KEY_DOWN ) ) {
if ( check_key(KEY_DOWN ) ) {
- menu_mainstate = DEBUG;
+ menu_mainstate = DEBUG_DUMP;
+#else
+ if ( check_key(KEY_DOWN ) ) {
+ menu_mainstate = TOP;
+ return;
+ }
+
+#endif
+
+#ifdef DEBUG
+ case DEBUG_DUMP:
lcd.setCursor(0 , 0);
lcd.print("Dumping debug to");
lcd.setCursor(0 , 1);
lcd.setCursor(0 , 0);
lcd.print("Dumping debug to");
lcd.setCursor(0 , 1);
default:
lcd.print("Not implemented");
lcd.setCursor(0 , 1);
default:
lcd.print("Not implemented");
lcd.setCursor(0 , 1);