-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Documentation of Battery, Buzzer and Capability classes
- Loading branch information
Showing
7 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,51 @@ | ||
#include "Battery.h" | ||
|
||
/** | ||
* Resolution of the ADC (10-bit) | ||
*/ | ||
const float ADCResolution = 1024.0; | ||
/** | ||
* Voltage reference of the Arduino | ||
*/ | ||
const float arduinoVoltage = 5.0; | ||
/** | ||
* Offset for accurate battery level measurement | ||
*/ | ||
const float measurementOffset = 0.7; | ||
|
||
/** | ||
* Constructor for the Battery class. | ||
* | ||
* @param pin The pin number used for reading the battery voltage. | ||
*/ | ||
Battery::Battery(int pin) : pin(pin) {} | ||
|
||
/** | ||
* This method reads the battery level and sends it over the | ||
* provided serial. | ||
* | ||
* @param strs Pointer to an array of strings that were used as an input (not used in this method). | ||
* @param serial Reference to a HardwareSerial object for serial communication. | ||
*/ | ||
void Battery::decode(String* strs, HardwareSerial& serial) { | ||
serial.println(getLevel()); | ||
} | ||
|
||
/** | ||
* This method reads the analog value from the specified pin, | ||
* converts it to a voltage level, and applies an offset for accuracy. | ||
* | ||
* @return The calculated battery voltage level. | ||
*/ | ||
float Battery::getLevel() { | ||
return (float(analogRead(pin)) / ADCResolution) * 3 * arduinoVoltage + measurementOffset; | ||
} | ||
|
||
/** | ||
* This method returns a character "B" representing the type of the buzzer. | ||
* | ||
* @return A character representing the buzzer type ('B'). | ||
*/ | ||
char Battery::type() { | ||
return 'B'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,36 @@ | ||
#include "Capability.h" | ||
|
||
/** | ||
* This method is intended for initialization tasks specific to derived classes. | ||
* It is currently empty and should be overridden in subclasses. | ||
*/ | ||
void Capability::setup() {} | ||
|
||
/** | ||
* This method is intended for executing the capability's main logic. | ||
* It is currently empty and should be overridden in subclasses. | ||
*/ | ||
void Capability::run() {} | ||
|
||
/** | ||
* This method returns the current state of the capability's enabled status. | ||
* | ||
* @return true if the capability is enabled, false otherwise. | ||
*/ | ||
bool Capability::isEnabled() { | ||
return enabled; | ||
} | ||
|
||
/** | ||
* This method sets the enabled state of the capability to true. | ||
*/ | ||
void Capability::enable() { | ||
enabled = true; | ||
} | ||
|
||
/** | ||
* This method sets the enabled state of the capability to false. | ||
*/ | ||
void Capability::disable() { | ||
enabled = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters