Skip to content

Commit

Permalink
Documentation of Battery, Buzzer and Capability classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sugaravel committed Sep 20, 2024
1 parent 9e4ae3f commit 3608d89
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 0 deletions.
32 changes: 32 additions & 0 deletions firmware/Battery.cpp
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';
}
5 changes: 5 additions & 0 deletions firmware/Battery.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
#include <Arduino.h>
#include <HardwareSerial.h>

/**
* Battery is a class that looks over the pin off of which we read the voltage that the battery is giving to MILOJE.
* It is one of the capabilities.
*/

class Battery : public Capability {
public:
Battery(int pin);
Expand Down
25 changes: 25 additions & 0 deletions firmware/Buzzer.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
#include "Buzzer.h"

/**
* @brief Constructor for the Buzzer class.
*
* @param pin The pin number to which the buzzer is connected.
*/
Buzzer::Buzzer(int pin) : pin(pin) {}

/**
* @brief Sets up the pin mode for the buzzer.
*/
void Buzzer::setup() {
pinMode(pin, OUTPUT);
}

/**
* This method is a placeholder for decoding functionality.
* Currently, it will buzz at a frequency of 880 Hz.
*
* @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 (not used in this method).
*/
void Buzzer::decode(String* strs, HardwareSerial& serial) {
buzz(880);
}

/**
* This method plays a tone on the buzzer at the given frequency with a melody
*
* @param frequency The frequency of the tone in Hertz.
*/
void Buzzer::buzz(int frequency) {
tone(pin, frequency);
delay(100);
Expand All @@ -19,6 +39,11 @@ void Buzzer::buzz(int frequency) {
delay(20);
}

/**
* This method returns a character "Z" representing the type of the buzzer.
*
* @return A character representing the buzzer type ('Z').
*/
char Buzzer::type() {
return 'Z';
}
4 changes: 4 additions & 0 deletions firmware/Buzzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#define _BUZZER_H
#include "Capability.h"

/**
* Buzzer is a class for the buzzer extension, which is one of the capabilities.
*/

class Buzzer : public Capability {
public:
Buzzer(int pin);
Expand Down
20 changes: 20 additions & 0 deletions firmware/Capability.cpp
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;
}
4 changes: 4 additions & 0 deletions firmware/Capability.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include <Arduino.h>
#include <HardwareSerial.h>

/**
* Capability is an abstract class for all capabilities.
*/

class Capability {
public:
virtual char type() = 0;
Expand Down
4 changes: 4 additions & 0 deletions firmware/Communication.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#define _COMMUNICATION_H
#include "Capability.h"

/**
* Communication
*/

class Communication
{
public:
Expand Down

0 comments on commit 3608d89

Please sign in to comment.