Snorktracker
 All Data Structures Files Functions Variables Macros Pages
Public Member Functions | Protected Attributes
MyVoltage Class Reference

#include <Voltage.h>

Public Member Functions

 MyVoltage (MyOptions &options, MyData &data)
 
bool begin ()
 
void readVoltage ()
 

Protected Attributes

MyOptionsmyOptions
 Reference to global options.
 
MyDatamyData
 Reference to global data.
 
long lowPowerStartSec
 Switch off timestamp.
 

Detailed Description

Voltage Reader. Works with the voltage divider resistors and the analog input reader.

Definition at line 28 of file Voltage.h.

Constructor & Destructor Documentation

MyVoltage::MyVoltage ( MyOptions options,
MyData data 
)

Constructor

Definition at line 47 of file Voltage.h.

48  : myOptions(options)
49  , myData(data)
50  , lowPowerStartSec(0)
51 {
52 }
long lowPowerStartSec
Switch off timestamp.
Definition: Voltage.h:34
MyOptions & myOptions
Reference to global options.
Definition: Voltage.h:31
MyData & myData
Reference to global data.
Definition: Voltage.h:32

Member Function Documentation

bool MyVoltage::begin ( )

Reads the voltage at startup.

Definition at line 55 of file Voltage.h.

References ANALOG_FACTOR, MyData::isLowPower, lowPowerStartSec, myData, MyDbg(), myOptions, MyOptions::powerSaveModeVoltage, and MyData::voltage.

Referenced by setup().

56 {
57  MyDbg(F("MyVoltage::begin"));
58  pinMode(A0, INPUT);
59  myData.voltage = ANALOG_FACTOR * analogRead(A0); // Volt
61  lowPowerStartSec = millis() / 1000;
62 }
double powerSaveModeVoltage
Minimum voltage to stay always alive.
Definition: Options.h:50
void MyDbg(String info, bool fromWebServer=false, bool newline=true)
Definition: Utils.h:94
long lowPowerStartSec
Switch off timestamp.
Definition: Voltage.h:34
double voltage
Current supply voltage.
Definition: Data.h:74
MyOptions & myOptions
Reference to global options.
Definition: Voltage.h:31
MyData & myData
Reference to global data.
Definition: Voltage.h:32
#define ANALOG_FACTOR
Factor to the analog voltage divider.
Definition: Voltage.h:23
bool isLowPower
Is the power below min voltage?
Definition: Data.h:67
void MyVoltage::readVoltage ( )

Reads the power supply voltage and save the value in the data class. Add the lowPower time to the lowPowerActive and lowPowerPowerOn time.

Definition at line 67 of file Voltage.h.

References ANALOG_FACTOR, MyData::isLowPower, MyData::isPowerOn, MyData::RtcData::lowPowerActiveTimeSec, MyData::RtcData::lowPowerPowerOnTimeSec, lowPowerStartSec, myData, MyDbg(), myOptions, MyOptions::powerSaveModeVoltage, MyData::rtcData, and MyData::voltage.

Referenced by loop().

68 {
69  bool isLowPower = false;
70  long currSec = millis() / 1000;
71 
72  myData.voltage = ANALOG_FACTOR * analogRead(A0); // Volt
74 
75  if (myData.isLowPower && !isLowPower) { // Change to high power
76  long lowPowerSec = currSec - lowPowerStartSec;
77 
78  myData.rtcData.lowPowerActiveTimeSec += lowPowerSec;
79  if (myData.isPowerOn) {
80  myData.rtcData.lowPowerPowerOnTimeSec += lowPowerSec;
81  }
82  MyDbg((String) F("Change to high power (V): ") + String(myData.voltage, 2));
83  }
84  if (!myData.isLowPower && isLowPower) { // Change to low power
85  lowPowerStartSec = currSec;
86  MyDbg((String) F("Change to low power (V): ") + String(myData.voltage, 2));
87  }
88  myData.isLowPower = isLowPower;
89 }
double powerSaveModeVoltage
Minimum voltage to stay always alive.
Definition: Options.h:50
long lowPowerPowerOnTimeSec
Timestamp of the last deep sleep start.
Definition: Data.h:43
class MyData::RtcData rtcData
Data to store in the RTC memory.
void MyDbg(String info, bool fromWebServer=false, bool newline=true)
Definition: Utils.h:94
long lowPowerActiveTimeSec
Timestamp of the last deep sleep start.
Definition: Data.h:42
long lowPowerStartSec
Switch off timestamp.
Definition: Voltage.h:34
bool isPowerOn
Is the power of the sim808 switched on?
Definition: Data.h:66
double voltage
Current supply voltage.
Definition: Data.h:74
MyOptions & myOptions
Reference to global options.
Definition: Voltage.h:31
MyData & myData
Reference to global data.
Definition: Voltage.h:32
#define ANALOG_FACTOR
Factor to the analog voltage divider.
Definition: Voltage.h:23
bool isLowPower
Is the power below min voltage?
Definition: Data.h:67

The documentation for this class was generated from the following file: