battery: use set_pin() to allow pins to be changed at runtime

This commit is contained in:
Andrew Tridgell 2012-10-16 17:20:49 +11:00
parent a979fb6014
commit f828956cb8
2 changed files with 6 additions and 0 deletions

View File

@ -78,10 +78,12 @@ static void read_battery(void)
if(g.battery_monitoring == 3 || g.battery_monitoring == 4) { if(g.battery_monitoring == 3 || g.battery_monitoring == 4) {
static AP_AnalogSource_Arduino batt_volt_pin(g.battery_volt_pin); static AP_AnalogSource_Arduino batt_volt_pin(g.battery_volt_pin);
batt_volt_pin.set_pin(g.battery_volt_pin);
battery_voltage1 = BATTERY_VOLTAGE(batt_volt_pin.read_average()); battery_voltage1 = BATTERY_VOLTAGE(batt_volt_pin.read_average());
} }
if(g.battery_monitoring == 4) { if(g.battery_monitoring == 4) {
static AP_AnalogSource_Arduino batt_curr_pin(g.battery_curr_pin); static AP_AnalogSource_Arduino batt_curr_pin(g.battery_curr_pin);
batt_curr_pin.set_pin(g.battery_curr_pin);
current_amps1 = CURRENT_AMPS(batt_curr_pin.read_average()); current_amps1 = CURRENT_AMPS(batt_curr_pin.read_average());
current_total1 += current_amps1 * 0.02778; // called at 100ms on average, .0002778 is 1/3600 (conversion to hours) current_total1 += current_amps1 * 0.02778; // called at 100ms on average, .0002778 is 1/3600 (conversion to hours)
} }

View File

@ -41,10 +41,14 @@ static void read_battery(void)
if(g.battery_monitoring == 3 || g.battery_monitoring == 4) { if(g.battery_monitoring == 3 || g.battery_monitoring == 4) {
static AP_AnalogSource_Arduino batt_volt_pin(g.battery_volt_pin); static AP_AnalogSource_Arduino batt_volt_pin(g.battery_volt_pin);
// this copes with changing the pin at runtime
batt_volt_pin.set_pin(g.battery_volt_pin);
battery_voltage1 = BATTERY_VOLTAGE(batt_volt_pin.read_average()); battery_voltage1 = BATTERY_VOLTAGE(batt_volt_pin.read_average());
} }
if(g.battery_monitoring == 4) { if(g.battery_monitoring == 4) {
static AP_AnalogSource_Arduino batt_curr_pin(g.battery_curr_pin); static AP_AnalogSource_Arduino batt_curr_pin(g.battery_curr_pin);
// this copes with changing the pin at runtime
batt_curr_pin.set_pin(g.battery_curr_pin);
current_amps1 = CURRENT_AMPS(batt_curr_pin.read_average()); current_amps1 = CURRENT_AMPS(batt_curr_pin.read_average());
current_total1 += current_amps1 * (float)delta_ms_medium_loop * 0.0002778; // .0002778 is 1/3600 (conversion to hours) current_total1 += current_amps1 * (float)delta_ms_medium_loop * 0.0002778; // .0002778 is 1/3600 (conversion to hours)
} }