/* \brief battery Monitor Tick function. */ void batMonTick() { float v; int i; measureBattery(); v = batteryVoltage / (float)batteryNumCells; if (0.0 == v_bat_ave) v_bat_ave = v; if (v > 1.0 ) /* There is a battery connected */ { v_bat_ave = alpha * v_bat_ave + (1.0-alpha) * v; for ( i = 0 ; i < thresholdsNUM; ++i ) if (v_bat_ave < thresholds[i].value ) { if ( thresholdCount[i] < thresholdThreshold ) if ( ++thresholdCount[i] == thresholdThreshold ) thresholds[i].func() ; } else if ( thresholdCount[i] > 0 ) --thresholdCount[i] ; } }
void batteryInit(void) { measureBattery(); if (eepromConfig.batteryCells == 0) batteryNumCells = batteryVoltage / 3; else batteryNumCells = eepromConfig.batteryCells; }
/* \brief battery Monitor Tick function. */ void batMonTick(void) { float v; int i; measureBattery(); v = batteryVoltage / (float)batteryNumCells; if ((v > thresholds[2].value) || (batConnectedFirstPass == true)) // There is a battery connected { if (batConnectedFirstPass == false) { v_bat_ave = v; batConnectedFirstPass = true; } v_bat_ave = alpha * v_bat_ave + (1.0f - alpha) * v; for ( i = 0 ; i < thresholdsNUM; ++i ) if (v_bat_ave < thresholds[i].value) { if ( thresholdCount[i] < thresholdThreshold ) if ( ++thresholdCount[i] == thresholdThreshold ) thresholds[i].func(); } else if ( thresholdCount[i] > 0 ) --thresholdCount[i]; } if ((armed == false) && (lastArmed == true)) { if (batMonLowWarningTriggered == true) { batMonLowWarningTriggered = false; batMonLowWarning = 0; } if (batMonVeryLowWarningTriggered == true) { batMonVeryLowWarningTriggered = false; batMonVeryLowWarning = 0; } if (batMonMaxLowWarningTriggered == true) { batMonMaxLowWarningTriggered = false; } LED1_OFF; } lastArmed = armed; }
void batteryInit(void) { thresholds[BATTERY_LOW].value = eepromConfig.batteryLow; thresholds[BATTERY_VERY_LOW].value = eepromConfig.batteryVeryLow; thresholds[BATTRY_MAX_LOW].value = eepromConfig.batteryMaxLow; thresholds[BATTERY_LOW].func = batMonLow; thresholds[BATTERY_VERY_LOW].func = batMonVeryLow; thresholds[BATTRY_MAX_LOW].func = batMonMaxLow; measureBattery(); if (eepromConfig.batteryCells == 0) batteryNumCells = batteryVoltage / 3; else batteryNumCells = eepromConfig.batteryCells; }