add class comment

This commit is contained in:
Siwat Sirichai 2024-01-01 01:56:49 +07:00
parent 039e65e6df
commit 4031b7555a
9 changed files with 159 additions and 1 deletions

View file

@ -4,9 +4,23 @@
// (34 Bytes) Address 0-33 for Built-in Digital Output Card
// (266 Bytes) Address 34-300 for ESPMegaPRO IoT Module
/**
* @brief Create a new ESPMegaPRO object
*
* @warning Only one ESPMegaPRO object can be created, creating more than one will result in undefined behavior
*/
ESPMegaPRO::ESPMegaPRO() {
}
/**
* @brief Initializes the ESPMegaPRO object.
*
* This function initializes the ESPMegaPRO object and all of its components.
* It also initializes the built-in Digital Input and Digital Output cards.
*
* @return True if the initialization is successful, false otherwise.
*/
bool ESPMegaPRO::begin() {
Wire.begin(14, 33);
fram.begin(FRAM_ADDRESS);
@ -24,6 +38,15 @@ bool ESPMegaPRO::begin() {
inputs.loadPinMap(pinMap);
return true;
}
/**
* @brief The main loop for the ESPMegaPRO object.
*
* @note This function must be called in the main loop of the program.
*
* It will call the loop() function of all installed expansion cards, the ESPMegaIoT module, and the internal display.
*
*/
void ESPMegaPRO::loop() {
inputs.loop();
outputs.loop();
@ -39,6 +62,17 @@ void ESPMegaPRO::loop() {
display->loop();
}
}
/**
* @brief Installs an expansion card to the specified slot.
*
* @note This function automatically initializes the expansion card.
*
* @param slot The slot to install the card to.
* @param card Pointer to the ExpansionCard object.
*
* @return True if the installation is successful, false otherwise.
*/
bool ESPMegaPRO::installCard(uint8_t slot, ExpansionCard* card) {
if (slot > 255) return false;
if (cardInstalled[slot]) {
@ -53,8 +87,15 @@ bool ESPMegaPRO::installCard(uint8_t slot, ExpansionCard* card) {
cardInstalled[slot] = true;
cardCount++;
return true;
}
/**
* @brief Updates the internal RTC from NTP.
*
* @note Network must be connected before calling this function (see ESPMegaPRO.ESPMegaIoT::connectNetwork()).
*
* @return True if the update is successful, false otherwise.
*/
bool ESPMegaPRO::updateTimeFromNTP() {
struct tm timeinfo;
if (getLocalTime(&timeinfo))
@ -72,6 +113,12 @@ bool ESPMegaPRO::updateTimeFromNTP() {
}
return false;
}
/**
* @brief Gets the current time from the internal RTC.
*
* @return The current time as a rtctime_t struct.
*/
rtctime_t ESPMegaPRO::getTime() {
tmElements_t timeElement;
RTC.read(timeElement);
@ -85,6 +132,16 @@ rtctime_t ESPMegaPRO::getTime() {
return time;
}
/**
* @brief Sets the current time of the internal RTC.
*
* @param hours The hours.
* @param minutes The minutes.
* @param seconds The seconds.
* @param day The day.
* @param month The month.
* @param year The year.
*/
void ESPMegaPRO::setTime(int hours, int minutes, int seconds, int day, int month, int year)
{
tmElements_t timeElement;
@ -97,6 +154,11 @@ void ESPMegaPRO::setTime(int hours, int minutes, int seconds, int day, int month
RTC.write(timeElement);
}
/**
* @brief Enables, Instanitates, and Initializes the ESPMegaIoT module.
*
* @note This function must be called before using the ESPMegaIoT module.
*/
void ESPMegaPRO::enableIotModule() {
if (iotEnabled) return;
this->iot = new ESPMegaIoT();
@ -105,12 +167,27 @@ void ESPMegaPRO::enableIotModule() {
iotEnabled = true;
}
/**
* @brief Gets the expansion card installed at the specified slot.
*
* @param slot The slot to get the card from.
*
* @return Pointer to the ExpansionCard object, or nullptr if no card is installed at the specified slot.
*/
ExpansionCard* ESPMegaPRO::getCard(uint8_t slot) {
if (slot > 255) return nullptr;
if (!cardInstalled[slot]) return nullptr;
return cards[slot];
}
/**
* @brief Enables, Instanitates, and Initializes the internal display.
*
* @note This function can only be called if the ESPMegaIoT module is enabled.
* @note This function must be called before using the internal display.
*
* @param serial Pointer to the HardwareSerial object to use for the internal display (Serial for ESPMegaPRO R3).
*/
void ESPMegaPRO::enableInternalDisplay(HardwareSerial *serial) {
if (internalDisplayEnabled) return;
if (!iotEnabled) {
@ -130,6 +207,12 @@ void ESPMegaPRO::enableInternalDisplay(HardwareSerial *serial) {
}
/**
* @brief Dumps the contents of the internal FRAM to the serial port.
*
* @param start The starting address.
* @param end The ending address.
*/
void ESPMegaPRO::dumpFRAMtoSerial(uint16_t start, uint16_t end) {
for (int i = start; i <=end; i++) {
if (i % 16 == 0) {
@ -139,6 +222,12 @@ void ESPMegaPRO::dumpFRAMtoSerial(uint16_t start, uint16_t end) {
}
}
/**
* @brief Dumps the contents of the internal FRAM to the serial port in ASCII.
*
* @param start The starting address.
* @param end The ending address.
*/
void ESPMegaPRO::dumpFRAMtoSerialASCII(uint16_t start, uint16_t end) {
for (int i = 0; i < 500; i++) {
Serial.printf("%d: %c\n", i,this->fram.read8(i));