ESPMegaPRO-v3-SDK/ESPMegaPRO-firmware/lib/ESPMegaPRO/ESPMegaPRO_OOP.hpp

92 lines
3.7 KiB
C++
Raw Normal View History

2023-12-27 18:25:35 +00:00
#pragma once
#include <ExpansionCard.hpp>
#include <DigitalInputCard.hpp>
#include <DigitalOutputCard.hpp>
2023-12-30 07:52:54 +00:00
#include <ClimateCard.hpp>
#include <AnalogCard.hpp>
2023-12-28 06:14:18 +00:00
#include <ESPMegaIoT.hpp>
2023-12-27 18:25:35 +00:00
#include <Arduino.h>
#include <Wire.h>
#include <FRAM.h>
#include <TimeLib.h>
#include <DS1307RTC.h>
#include <time.h>
2023-12-29 16:43:12 +00:00
#include <TimeStructure.hpp>
2023-12-30 06:49:37 +00:00
#include <ESPMegaDisplay.hpp>
#include <InternalDisplay.hpp>
2023-12-31 08:53:39 +00:00
#include <ESPMegaWebServer.hpp>
2023-12-27 18:25:35 +00:00
2023-12-31 18:56:49 +00:00
// ESPMega Pro R3 Board Address
2023-12-27 18:25:35 +00:00
#define FRAM_ADDRESS 0x56
#define INPUT_BANK_A_ADDRESS 0x21
#define INPUT_BANK_B_ADDRESS 0x22
#define PWM_BANK_ADDRESS 0x5F
#define RTC_ADDRESS 0x68
2023-12-31 18:56:49 +00:00
/**
* @brief The ESPMegaPRO class is the main class for the ESPMegaPRO library.
*
* This class provides functions for managing the ESPMegaPRO board, such as installing expansion cards, managing the internal RTC, and managing the internal FRAM.
* This class also provides functions for managing the ESPMegaIoT module and the internal display.
*
* This class provide a Object Oriented Programming (OOP) interface for the ESPMegaPRO board.
* If you are looking for a more simple and a more procedural interface, please use the ESPMegaPRO class in ESPMegaPRO.hpp.
* But note that the ESPMegaPRO class only interfaces with the built-in Digital Input and Digital Output cards and other onboard components.
* It does not provide an interface for expansion cards, the ESPMegaIoT module, and the internal display.
*
* @warning Only one ESPMegaPRO object can be created, creating more than one will result in undefined behavior.
*/
2023-12-27 18:25:35 +00:00
class ESPMegaPRO {
public:
ESPMegaPRO();
2023-12-27 19:18:21 +00:00
bool begin();
2023-12-27 18:25:35 +00:00
void loop();
2023-12-27 19:18:21 +00:00
bool installCard(uint8_t slot, ExpansionCard* card);
2023-12-27 18:25:35 +00:00
bool updateTimeFromNTP();
2023-12-28 07:52:52 +00:00
void enableIotModule();
void enableInternalDisplay(HardwareSerial *serial);
2024-01-01 06:28:15 +00:00
void enableWebServer(uint16_t port);
2023-12-27 18:25:35 +00:00
rtctime_t getTime();
2023-12-30 19:59:25 +00:00
void dumpFRAMtoSerial(uint16_t start, uint16_t end);
void dumpFRAMtoSerialASCII(uint16_t start, uint16_t end);
2023-12-27 18:33:37 +00:00
void setTime(int hours, int minutes, int seconds, int day, int month, int year);
2023-12-29 17:49:09 +00:00
ExpansionCard* getCard(uint8_t slot);
2023-12-27 18:25:35 +00:00
FRAM fram;
2023-12-31 19:44:01 +00:00
/**
* @brief The Digital Input Card Built-in to the ESPMegaPRO board.
* @typedef DigitalInputCard
* @note This card is installed by default at slot 0 on the ESPMegaPRO R3 board.
*/
2023-12-27 18:44:15 +00:00
DigitalInputCard inputs = DigitalInputCard(INPUT_BANK_A_ADDRESS, INPUT_BANK_B_ADDRESS);
2023-12-31 19:44:01 +00:00
/**
* @brief The Digital Output Card Built-in to the ESPMegaPRO board.
* @typedef DigitalOutputCard
* @note This card is installed by default at slot 1 on the ESPMegaPRO R3 board.
*/
2023-12-27 18:44:15 +00:00
DigitalOutputCard outputs = DigitalOutputCard(PWM_BANK_ADDRESS);
/**
* @brief The Display Built-in to the ESPMegaPRO board.
* @typedef InternalDisplay
* @note SKU EMG-PRO-R3-XXX-(F)-(12/24)V does not have a built-in display.
*/
InternalDisplay *display;
2024-01-01 04:16:27 +00:00
/**
* @brief This component is used to connect the ESPMegaPRO board to the internet and communicate with it through MQTT.
* @typedef ESPMegaIoT
* @note You must call enableIotModule() before using this component.
*/
ESPMegaIoT *iot;
2024-01-01 06:28:15 +00:00
/**
* @brief This component is used to create a web server on the ESPMegaPRO board.
* @typedef ESPMegaWebServer
* @note You must call enableWebServer() before using this component.
*/
ESPMegaWebServer *webServer;
2023-12-27 18:25:35 +00:00
private:
bool iotEnabled = false;
bool internalDisplayEnabled = false;
2024-01-01 06:28:15 +00:00
bool webServerEnabled = false;
2023-12-27 18:25:35 +00:00
ExpansionCard* cards[255];
2023-12-27 18:33:37 +00:00
bool cardInstalled[255];
2023-12-27 18:25:35 +00:00
uint8_t cardCount = 0;
};