Patch display, pinmap
This commit is contained in:
parent
d608fdbf9a
commit
23af3d5aed
|
@ -439,7 +439,6 @@ ESPMegaDisplay::ESPMegaDisplay(HardwareSerial *displayAdapter)
|
||||||
*/
|
*/
|
||||||
void ESPMegaDisplay::begin()
|
void ESPMegaDisplay::begin()
|
||||||
{
|
{
|
||||||
this->displayAdapter->begin(115200);
|
|
||||||
this->displayAdapter->setTimeout(100);
|
this->displayAdapter->setTimeout(100);
|
||||||
this->displayAdapter->flush();
|
this->displayAdapter->flush();
|
||||||
this->reset();
|
this->reset();
|
||||||
|
|
|
@ -84,6 +84,10 @@ void ESPMega_analogWrite(int id, int value)
|
||||||
|
|
||||||
void ESPMega_digitalWrite(int id, bool value)
|
void ESPMega_digitalWrite(int id, bool value)
|
||||||
{
|
{
|
||||||
|
if (id >= 0 && id <= 7)
|
||||||
|
id += 8;
|
||||||
|
else if (id >= 8 && id <= 15)
|
||||||
|
id -= 8;
|
||||||
if (value)
|
if (value)
|
||||||
pwmBank.setPin(id, 4095);
|
pwmBank.setPin(id, 4095);
|
||||||
else
|
else
|
||||||
|
|
|
@ -6,83 +6,97 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create a new ESPMegaPRO object
|
* @brief Create a new ESPMegaPRO object
|
||||||
*
|
*
|
||||||
* @warning Only one ESPMegaPRO object can be created, creating more than one will result in undefined behavior
|
* @warning Only one ESPMegaPRO object can be created, creating more than one will result in undefined behavior
|
||||||
*/
|
*/
|
||||||
ESPMegaPRO::ESPMegaPRO() {
|
ESPMegaPRO::ESPMegaPRO()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initializes the ESPMegaPRO object.
|
* @brief Initializes the ESPMegaPRO object.
|
||||||
*
|
*
|
||||||
* This function initializes the ESPMegaPRO object and all of its components.
|
* This function initializes the ESPMegaPRO object and all of its components.
|
||||||
* It also initializes the built-in Digital Input and Digital Output cards.
|
* It also initializes the built-in Digital Input and Digital Output cards.
|
||||||
*
|
*
|
||||||
* @return True if the initialization is successful, false otherwise.
|
* @return True if the initialization is successful, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool ESPMegaPRO::begin() {
|
bool ESPMegaPRO::begin()
|
||||||
|
{
|
||||||
Wire.begin(14, 33);
|
Wire.begin(14, 33);
|
||||||
fram.begin(FRAM_ADDRESS);
|
fram.begin(FRAM_ADDRESS);
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
this->installCard(1, &outputs);
|
this->installCard(1, &outputs);
|
||||||
outputs.bindFRAM(&fram,0);
|
outputs.bindFRAM(&fram, 0);
|
||||||
outputs.loadFromFRAM();
|
outputs.loadFromFRAM();
|
||||||
outputs.setAutoSaveToFRAM(true);
|
outputs.setAutoSaveToFRAM(true);
|
||||||
if(!this->installCard(0, &inputs)) {
|
if (!this->installCard(0, &inputs))
|
||||||
|
{
|
||||||
ESP_LOGE("ESPMegaPRO", "Failed to initialize inputs");
|
ESP_LOGE("ESPMegaPRO", "Failed to initialize inputs");
|
||||||
ESP_LOGE("ESPMegaPRO", "Is this an ESPMegaPRO device?");
|
ESP_LOGE("ESPMegaPRO", "Is this an ESPMegaPRO device?");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
uint8_t pinMap[16] = {0, 1, 2, 3, 4, 5, 6, 7, 15, 14, 13, 12, 11, 10, 9, 8};
|
uint8_t inputPinMap[16] = {0, 1, 2, 3, 4, 5, 6, 7, 15, 14, 13, 12, 11, 10, 9, 8};
|
||||||
inputs.loadPinMap(pinMap);
|
inputs.loadPinMap(inputPinMap);
|
||||||
|
uint8_t outputPinMap[16] = {8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7};
|
||||||
|
outputs.loadPinMap(outputPinMap);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The main loop for the ESPMegaPRO object.
|
* @brief The main loop for the ESPMegaPRO object.
|
||||||
*
|
*
|
||||||
* @note This function must be called in the main loop of the program.
|
* @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.
|
* It will call the loop() function of all installed expansion cards, the ESPMegaIoT module, and the internal display.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void ESPMegaPRO::loop() {
|
void ESPMegaPRO::loop()
|
||||||
|
{
|
||||||
inputs.loop();
|
inputs.loop();
|
||||||
outputs.loop();
|
outputs.loop();
|
||||||
for (int i = 0; i < 255; i++) {
|
for (int i = 0; i < 255; i++)
|
||||||
if (cardInstalled[i]) {
|
{
|
||||||
|
if (cardInstalled[i])
|
||||||
|
{
|
||||||
cards[i]->loop();
|
cards[i]->loop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(iotEnabled) {
|
if (iotEnabled)
|
||||||
|
{
|
||||||
iot->loop();
|
iot->loop();
|
||||||
}
|
}
|
||||||
if(internalDisplayEnabled) {
|
if (internalDisplayEnabled)
|
||||||
|
{
|
||||||
display->loop();
|
display->loop();
|
||||||
}
|
}
|
||||||
if(webServerEnabled) {
|
if (webServerEnabled)
|
||||||
|
{
|
||||||
webServer->loop();
|
webServer->loop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Installs an expansion card to the specified slot.
|
* @brief Installs an expansion card to the specified slot.
|
||||||
*
|
*
|
||||||
* @note This function automatically initializes the expansion card.
|
* @note This function automatically initializes the expansion card.
|
||||||
*
|
*
|
||||||
* @param slot The slot to install the card to.
|
* @param slot The slot to install the card to.
|
||||||
* @param card Pointer to the ExpansionCard object.
|
* @param card Pointer to the ExpansionCard object.
|
||||||
*
|
*
|
||||||
* @return True if the installation is successful, false otherwise.
|
* @return True if the installation is successful, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool ESPMegaPRO::installCard(uint8_t slot, ExpansionCard* card) {
|
bool ESPMegaPRO::installCard(uint8_t slot, ExpansionCard *card)
|
||||||
if (slot > 255) return false;
|
{
|
||||||
if (cardInstalled[slot]) {
|
if (slot > 255)
|
||||||
|
return false;
|
||||||
|
if (cardInstalled[slot])
|
||||||
|
{
|
||||||
ESP_LOGE("ESPMegaPRO", "Card already installed at slot %d", slot);
|
ESP_LOGE("ESPMegaPRO", "Card already installed at slot %d", slot);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!card->begin()) {
|
if (!card->begin())
|
||||||
|
{
|
||||||
ESP_LOGE("ESPMegaPRO", "Failed to initialize card at slot %d", slot);
|
ESP_LOGE("ESPMegaPRO", "Failed to initialize card at slot %d", slot);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -94,12 +108,13 @@ bool ESPMegaPRO::installCard(uint8_t slot, ExpansionCard* card) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Updates the internal RTC from NTP.
|
* @brief Updates the internal RTC from NTP.
|
||||||
*
|
*
|
||||||
* @note Network must be connected before calling this function (see ESPMegaPRO.ESPMegaIoT::connectNetwork()).
|
* @note Network must be connected before calling this function (see ESPMegaPRO.ESPMegaIoT::connectNetwork()).
|
||||||
*
|
*
|
||||||
* @return True if the update is successful, false otherwise.
|
* @return True if the update is successful, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool ESPMegaPRO::updateTimeFromNTP() {
|
bool ESPMegaPRO::updateTimeFromNTP()
|
||||||
|
{
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
if (getLocalTime(&timeinfo))
|
if (getLocalTime(&timeinfo))
|
||||||
{
|
{
|
||||||
|
@ -109,8 +124,7 @@ bool ESPMegaPRO::updateTimeFromNTP() {
|
||||||
rtctime.month != timeinfo.tm_mon + 1 || rtctime.year != timeinfo.tm_year + 1900)
|
rtctime.month != timeinfo.tm_mon + 1 || rtctime.year != timeinfo.tm_year + 1900)
|
||||||
{
|
{
|
||||||
this->setTime(timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec,
|
this->setTime(timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec,
|
||||||
timeinfo.tm_mday, timeinfo.tm_mon + 1, timeinfo.tm_year + 1900);
|
timeinfo.tm_mday, timeinfo.tm_mon + 1, timeinfo.tm_year + 1900);
|
||||||
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -119,10 +133,11 @@ bool ESPMegaPRO::updateTimeFromNTP() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gets the current time from the internal RTC.
|
* @brief Gets the current time from the internal RTC.
|
||||||
*
|
*
|
||||||
* @return The current time as a rtctime_t struct.
|
* @return The current time as a rtctime_t struct.
|
||||||
*/
|
*/
|
||||||
rtctime_t ESPMegaPRO::getTime() {
|
rtctime_t ESPMegaPRO::getTime()
|
||||||
|
{
|
||||||
tmElements_t timeElement;
|
tmElements_t timeElement;
|
||||||
RTC.read(timeElement);
|
RTC.read(timeElement);
|
||||||
rtctime_t time;
|
rtctime_t time;
|
||||||
|
@ -137,7 +152,7 @@ rtctime_t ESPMegaPRO::getTime() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the current time of the internal RTC.
|
* @brief Sets the current time of the internal RTC.
|
||||||
*
|
*
|
||||||
* @param hours The hours.
|
* @param hours The hours.
|
||||||
* @param minutes The minutes.
|
* @param minutes The minutes.
|
||||||
* @param seconds The seconds.
|
* @param seconds The seconds.
|
||||||
|
@ -159,11 +174,13 @@ void ESPMegaPRO::setTime(int hours, int minutes, int seconds, int day, int month
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Enables, Instanitates, and Initializes the ESPMegaIoT module.
|
* @brief Enables, Instanitates, and Initializes the ESPMegaIoT module.
|
||||||
*
|
*
|
||||||
* @note This function must be called before using the ESPMegaIoT module.
|
* @note This function must be called before using the ESPMegaIoT module.
|
||||||
*/
|
*/
|
||||||
void ESPMegaPRO::enableIotModule() {
|
void ESPMegaPRO::enableIotModule()
|
||||||
if (iotEnabled) return;
|
{
|
||||||
|
if (iotEnabled)
|
||||||
|
return;
|
||||||
this->iot = new ESPMegaIoT();
|
this->iot = new ESPMegaIoT();
|
||||||
this->iot->bindFRAM(&fram);
|
this->iot->bindFRAM(&fram);
|
||||||
this->iot->intr_begin(cards);
|
this->iot->intr_begin(cards);
|
||||||
|
@ -172,29 +189,35 @@ void ESPMegaPRO::enableIotModule() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gets the expansion card installed at the specified slot.
|
* @brief Gets the expansion card installed at the specified slot.
|
||||||
*
|
*
|
||||||
* @param slot The slot to get the card from.
|
* @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.
|
* @return Pointer to the ExpansionCard object, or nullptr if no card is installed at the specified slot.
|
||||||
*/
|
*/
|
||||||
ExpansionCard* ESPMegaPRO::getCard(uint8_t slot) {
|
ExpansionCard *ESPMegaPRO::getCard(uint8_t slot)
|
||||||
if (slot > 255) return nullptr;
|
{
|
||||||
if (!cardInstalled[slot]) return nullptr;
|
if (slot > 255)
|
||||||
|
return nullptr;
|
||||||
|
if (!cardInstalled[slot])
|
||||||
|
return nullptr;
|
||||||
return cards[slot];
|
return cards[slot];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Enables, Instanitates, and Initializes the internal display.
|
* @brief Enables, Instanitates, and Initializes the internal display.
|
||||||
*
|
*
|
||||||
* @note &Serial is used for the internal display on ESPMegaPRO R3.
|
* @note &Serial is used for the internal display on ESPMegaPRO R3.
|
||||||
* @note This function can only be called if the ESPMegaIoT module is enabled.
|
* @note This function can only be called if the ESPMegaIoT module is enabled.
|
||||||
* @note This function must be called before using the internal display.
|
* @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).
|
* @param serial Pointer to the HardwareSerial object to use for the internal display (Serial for ESPMegaPRO R3).
|
||||||
*/
|
*/
|
||||||
void ESPMegaPRO::enableInternalDisplay(HardwareSerial *serial) {
|
void ESPMegaPRO::enableInternalDisplay(HardwareSerial *serial)
|
||||||
if (internalDisplayEnabled) return;
|
{
|
||||||
if (!iotEnabled) {
|
if (internalDisplayEnabled)
|
||||||
|
return;
|
||||||
|
if (!iotEnabled)
|
||||||
|
{
|
||||||
ESP_LOGE("ESPMegaPRO", "Cannot enable internal display without IoT module enabled");
|
ESP_LOGE("ESPMegaPRO", "Cannot enable internal display without IoT module enabled");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -205,21 +228,23 @@ void ESPMegaPRO::enableInternalDisplay(HardwareSerial *serial) {
|
||||||
ESP_LOGD("ESPMegaPRO", "Binding Internal Display to Input/Output Cards");
|
ESP_LOGD("ESPMegaPRO", "Binding Internal Display to Input/Output Cards");
|
||||||
display->bindInputCard(&inputs);
|
display->bindInputCard(&inputs);
|
||||||
display->bindOutputCard(&outputs);
|
display->bindOutputCard(&outputs);
|
||||||
display->begin(this->iot,bindedGetTime);
|
display->begin(this->iot, bindedGetTime);
|
||||||
internalDisplayEnabled = true;
|
internalDisplayEnabled = true;
|
||||||
ESP_LOGD("ESPMegaPRO", "Internal Display Enabled");
|
ESP_LOGD("ESPMegaPRO", "Internal Display Enabled");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Dumps the contents of the internal FRAM to the serial port.
|
* @brief Dumps the contents of the internal FRAM to the serial port.
|
||||||
*
|
*
|
||||||
* @param start The starting address.
|
* @param start The starting address.
|
||||||
* @param end The ending address.
|
* @param end The ending address.
|
||||||
*/
|
*/
|
||||||
void ESPMegaPRO::dumpFRAMtoSerial(uint16_t start, uint16_t end) {
|
void ESPMegaPRO::dumpFRAMtoSerial(uint16_t start, uint16_t end)
|
||||||
for (int i = start; i <=end; i++) {
|
{
|
||||||
if (i % 16 == 0) {
|
for (int i = start; i <= end; i++)
|
||||||
|
{
|
||||||
|
if (i % 16 == 0)
|
||||||
|
{
|
||||||
Serial.printf("\n%03d: ", i);
|
Serial.printf("\n%03d: ", i);
|
||||||
}
|
}
|
||||||
Serial.printf("%03d ", this->fram.read8(i));
|
Serial.printf("%03d ", this->fram.read8(i));
|
||||||
|
@ -228,30 +253,35 @@ void ESPMegaPRO::dumpFRAMtoSerial(uint16_t start, uint16_t end) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Dumps the contents of the internal FRAM to the serial port in ASCII.
|
* @brief Dumps the contents of the internal FRAM to the serial port in ASCII.
|
||||||
*
|
*
|
||||||
* @param start The starting address.
|
* @param start The starting address.
|
||||||
* @param end The ending address.
|
* @param end The ending address.
|
||||||
*/
|
*/
|
||||||
void ESPMegaPRO::dumpFRAMtoSerialASCII(uint16_t start, uint16_t end) {
|
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));
|
for (int i = 0; i < 500; i++)
|
||||||
|
{
|
||||||
|
Serial.printf("%d: %c\n", i, this->fram.read8(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Enables the internal web server.
|
* @brief Enables the internal web server.
|
||||||
*
|
*
|
||||||
* @note This function can only be called if the ESPMegaIoT module is enabled.
|
* @note This function can only be called if the ESPMegaIoT module is enabled.
|
||||||
* @note This function can only be called once.
|
* @note This function can only be called once.
|
||||||
*
|
*
|
||||||
* @param port The port to use for the web server.
|
* @param port The port to use for the web server.
|
||||||
*/
|
*/
|
||||||
void ESPMegaPRO::enableWebServer(uint16_t port) {
|
void ESPMegaPRO::enableWebServer(uint16_t port)
|
||||||
if (!iotEnabled) {
|
{
|
||||||
|
if (!iotEnabled)
|
||||||
|
{
|
||||||
ESP_LOGE("ESPMegaPRO", "Cannot enable web server without IoT module enabled");
|
ESP_LOGE("ESPMegaPRO", "Cannot enable web server without IoT module enabled");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (webServerEnabled) {
|
if (webServerEnabled)
|
||||||
|
{
|
||||||
ESP_LOGE("ESPMegaPRO", "Web server already enabled");
|
ESP_LOGE("ESPMegaPRO", "Web server already enabled");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,13 +81,15 @@ void InternalDisplay::handlePwmStateChange(uint8_t pin, bool state, uint16_t val
|
||||||
{
|
{
|
||||||
// If the output card is binded to the display and the current page is the output page
|
// If the output card is binded to the display and the current page is the output page
|
||||||
// then update the respective output component
|
// then update the respective output component
|
||||||
if (this->outputCard != nullptr || this->currentPage != INTERNAL_DISPLAY_OUTPUT_PAGE)
|
if (this->outputCard != nullptr)
|
||||||
return;
|
return;
|
||||||
|
if(this->currentPage == INTERNAL_DISPLAY_OUTPUT_PAGE) {
|
||||||
// Update the output state
|
// Update the output state
|
||||||
this->setOutputBar(pin, value);
|
this->setOutputBar(pin, value);
|
||||||
this->setOutputStateColor(pin, state);
|
this->setOutputStateColor(pin, state);
|
||||||
|
}
|
||||||
// Refresh the PWM Adjustment page if the current page is the PWM Adjustment page and the pin is the same
|
// Refresh the PWM Adjustment page if the current page is the PWM Adjustment page and the pin is the same
|
||||||
if (this->currentPage == INTERNAL_DISPLAY_PWM_ADJUSTMENT_PAGE && this->pmwAdjustmentPin == pin)
|
else if (this->currentPage == INTERNAL_DISPLAY_PWM_ADJUSTMENT_PAGE && this->pmwAdjustmentPin == pin)
|
||||||
{
|
{
|
||||||
this->refreshPWMAdjustment();
|
this->refreshPWMAdjustment();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue