More cleanup.

This commit is contained in:
James Goppert 2011-10-19 00:31:59 -04:00
parent a48206f468
commit 8397fea4f4
2 changed files with 29 additions and 25 deletions

View File

@ -8,3 +8,5 @@
namespace apo {
} // apo
// vim:ts=4:sw=4:expandtab

View File

@ -13,39 +13,41 @@ namespace apo {
class AP_BatteryMonitor {
public:
AP_BatteryMonitor(uint8_t pin, float voltageDivRatio, float minVolt, float maxVolt) :
_pin(pin), _voltageDivRatio(voltageDivRatio),
_minVolt(minVolt), _maxVolt(maxVolt), _voltage(maxVolt) {
}
AP_BatteryMonitor(uint8_t pin, float voltageDivRatio, float minVolt, float maxVolt) :
_pin(pin), _voltageDivRatio(voltageDivRatio),
_minVolt(minVolt), _maxVolt(maxVolt), _voltage(maxVolt) {
}
void update() {
// low pass filter on voltage
_voltage = _voltage*.9 + (analogRead(_pin)/255)*_voltageDivRatio*0.1;
}
void update() {
// low pass filter on voltage
_voltage = _voltage*.9 + (analogRead(_pin)/255)*_voltageDivRatio*0.1;
}
/**
* Accessors
*/
float getVoltage() {
return _voltage;
}
/**
* Accessors
*/
float getVoltage() {
return _voltage;
}
uint8_t getPercentage() {
float norm = (_voltage-_minVolt)/(_maxVolt-_minVolt);
if (norm < 0) norm = 0;
else if (norm > 1) norm = 1;
return 100*norm;
}
uint8_t getPercentage() {
float norm = (_voltage-_minVolt)/(_maxVolt-_minVolt);
if (norm < 0) norm = 0;
else if (norm > 1) norm = 1;
return 100*norm;
}
private:
uint8_t _pin;
float _voltageDivRatio;
float _voltage;
float _minVolt;
float _maxVolt;
uint8_t _pin;
float _voltageDivRatio;
float _voltage;
float _minVolt;
float _maxVolt;
};
} // namespace apo
#endif /* AP_BATTERYMONITOR_H_ */
// vim:ts=4:sw=4:expandtab