// The PPM generation is handled by Timer0 interrupts, and needs
// all modifiable variables to be global and volatile...
-//int max_channels = 6; // How many channels should PPM generate ...
-// Moved to model_t struct...
-
volatile long sum = 0; // Frame-time spent so far
volatile int cchannel = 0; // Current channnel
volatile bool do_channel = true; // Is next operation a channel or a separator
void calibrate()
{
- int i, r0, r1, r2, adc_in;
+ int i, adc_in;
int num_calibrations = 200;
lcd.clear();
void scan_keys ( void )
{
- int i, r0, r1, r2;
boolean key_in;
// To get more inputs, another 4051 analog multiplexer is used,
// but this time it is used for digital inputs. 8 digital inputs
// on one input line, as long as proper debouncing and filtering
// is done in hardware :P
- for (i=0; i<=7; i++) {
+ for (int i=0; i<=7; i++) {
// To be able to detect that a key has changed state, preserve the previous..
prev_keys[i] = keys[i];
model.raw[current_input] = adc_in;
// New format on stick values
+ // The calculations happen around the center point, the values
+ // need to arrive at 0...100 of the range "center-to-edge",
+ // and must end up as negative on the ... negative side of center.
+
if ( adc_in < input_cal.center[current_input] )
{
+ // The stick is on the negative side, so the range is
+ // from the lowest possible value to center, and we must
+ // make this a negative percentage value.
max = input_cal.min[current_input];
min = input_cal.center[current_input];
fact = -100;
}
else
{
+ // The stick is at center, or on the positive side.
+ // Thus, the range is from center to max, and
+ // we need positive percentages.
min = input_cal.center[current_input];
max = input_cal.max[current_input];
fact = 100;
}
+ // Calculate the percentage that the current stick position is at
+ // in the given range, referenced to or from center, depending :P
model.stick[current_input] = fact * ((float)adc_in - min ) / (max - min);
+
+ // If this input is configured to be reversed, simply do a sign-flip :D
if ( model.rev[current_input] ) model.stick[current_input] *= -1;
- // Old format on stick values...
- /*
- model.stick[current_input] = ((float)adc_in - (float)input_cal.min[current_input]) / (float)(input_cal.max[current_input]-input_cal.min[current_input]);
- if ( model.rev[current_input] ) model.stick[current_input] = 1.0f - model.stick[current_input];
- */
-
// Dual-rate calculation :D
// This is very repetitive code. It should be fast, but it may waste code-space.
float dr_val;
// range in half, and finally dividing by 100, we should get the ratio value.
// Some loss of presicion occurs, perhaps the algo' should be reconsidered :P
long next_timer = (( chwidht * ((model.stick[cchannel]+100)/200) ) + chmin);
- // Do sanity-check of next_timer compared to chmax ...
+ // Do sanity-check of next_timer compared to chmax and chmin...
while ( chmax < next_timer ) next_timer--;
while ( next_timer < chmin ) next_timer++;
+
+ // Update the sum of elapsed time
sum += next_timer;
// Done with channel separator and value,
void serial_debug()
{
int current_input;
- for (current_input=0; current_input<=7; current_input++) {
+ for (current_input=0; current_input<MAX_INPUTS; current_input++) {
Serial.print("Input #");
Serial.print(current_input);
Serial.println();
}
+
void dr_inputselect( int no, int in )
{
if ( model.dr[menu_substate] < 0 ) model.dr[menu_substate] = 4;
{
case VALUES:
int current_input;
- for (current_input=0; current_input<=7; current_input++) {
+ for (current_input=0; current_input<MAX_INPUTS; current_input++) {
// In channel value display, do a simple calc
// of the LCD row & column location. With 8 channels
// we can fit eight channels as percentage values on
// Run in wolfram to see result, adjust the 1.0 factor to inc/red effect.
// Problem: -100 to 100 is terribly bad presicion, esp. considering that
// the values started as 0...1024, and we have 1000usec to "spend" on channels.
+
+ // NEW IDEA provided my ivarf @ hig: use bezier curves og hermite curves!
+ // Looks like a promising idea, but the implementation is still a bitt off
+ // on the time-horizon :P
if ( check_key(KEY_UP ) ) {
menu_mainstate = DUALRATES;
return;