#include <MotorVoltage.h>
#include <AnalogPin.h>
MotorVoltage* MotorVoltage::motorVoltage = NULL;
void
MotorVoltage::New(
char* data,
String* msgPtr ) {
if ( motorVoltage )
delete motorVoltage;
motorVoltage = new MotorVoltage(
data,
msgPtr );
if ( ! motorVoltage->valid() ) {
delete motorVoltage;
motorVoltage = NULL; }; };
bool
MotorVoltage::Low() {
return
motorVoltage
&& motorVoltage->low(); };
MotorVoltage::MotorVoltage(
char* data,
String* msgPtr ) {
if ( pvddPin )
delete pvddPin;
char pvddPinString [8];
thresholdPct = 0;
maxValue = 0;
sscanf( data,
" %s %lu",
pvddPinString,
&thresholdPct );
*msgPtr += "\n pvdd";
pvddPin = new AnalogPin(
pvddPinString,
msgPtr );
if ( ! pvddPin->valid() ) {
delete pvddPin;
pvddPin = NULL; };
*msgPtr += " threshold % ";
*msgPtr += String( thresholdPct ); };
bool
MotorVoltage::valid() {
return
pvddPin
&& thresholdPct; };
bool
MotorVoltage::low() {
uint32_t analogValue = pvddPin->analogValue();
if ( analogValue > maxValue )
maxValue = analogValue;
return
analogValue < ( maxValue * thresholdPct / 100 ); };