completed OOP demo
This commit is contained in:
parent
9c3d4e7bab
commit
1862887d30
|
@ -7,7 +7,8 @@ void ESPMegaPRO::begin() {
|
||||||
inputs.begin();
|
inputs.begin();
|
||||||
outputs.begin();
|
outputs.begin();
|
||||||
fram.begin(FRAM_ADDRESS);
|
fram.begin(FRAM_ADDRESS);
|
||||||
|
uint8_t pinMap[16] = {0, 1, 2, 3, 4, 5, 6, 7, 15, 14, 13, 12, 11, 10, 9, 8};
|
||||||
|
inputs.loadPinMap(pinMap);
|
||||||
}
|
}
|
||||||
void ESPMegaPRO::loop() {
|
void ESPMegaPRO::loop() {
|
||||||
inputs.loop();
|
inputs.loop();
|
||||||
|
@ -22,6 +23,7 @@ void ESPMegaPRO::installCard(uint8_t slot, ExpansionCard* card) {
|
||||||
cards[slot] = card;
|
cards[slot] = card;
|
||||||
cardInstalled[slot] = true;
|
cardInstalled[slot] = true;
|
||||||
cardCount++;
|
cardCount++;
|
||||||
|
card->begin();
|
||||||
}
|
}
|
||||||
bool ESPMegaPRO::updateTimeFromNTP() {
|
bool ESPMegaPRO::updateTimeFromNTP() {
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
|
@ -63,4 +65,5 @@ void ESPMegaPRO::setTime(int hours, int minutes, int seconds, int day, int month
|
||||||
timeElement.Month = month;
|
timeElement.Month = month;
|
||||||
timeElement.Year = year - 1970;
|
timeElement.Year = year - 1970;
|
||||||
RTC.write(timeElement);
|
RTC.write(timeElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,10 +36,10 @@ class ESPMegaPRO {
|
||||||
rtctime_t getTime();
|
rtctime_t getTime();
|
||||||
void setTime(int hours, int minutes, int seconds, int day, int month, int year);
|
void setTime(int hours, int minutes, int seconds, int day, int month, int year);
|
||||||
FRAM fram;
|
FRAM fram;
|
||||||
|
DigitalInputCard inputs = DigitalInputCard(INPUT_BANK_A_ADDRESS, INPUT_BANK_B_ADDRESS);
|
||||||
|
DigitalOutputCard outputs = DigitalOutputCard(PWM_BANK_ADDRESS);
|
||||||
private:
|
private:
|
||||||
ExpansionCard* cards[255];
|
ExpansionCard* cards[255];
|
||||||
bool cardInstalled[255];
|
bool cardInstalled[255];
|
||||||
uint8_t cardCount = 0;
|
uint8_t cardCount = 0;
|
||||||
DigitalInputCard inputs = DigitalInputCard(INPUT_BANK_A_ADDRESS, INPUT_BANK_B_ADDRESS);
|
|
||||||
DigitalOutputCard outputs = DigitalOutputCard(PWM_BANK_ADDRESS);
|
|
||||||
};
|
};
|
|
@ -1,14 +1,13 @@
|
||||||
#include <ESPMegaPRO.h>
|
#include <ESPMegaPRO_OOP.hpp>
|
||||||
#include <DigitalInputCard.hpp>
|
#include <DigitalInputCard.hpp>
|
||||||
#include <DigitalOutputCard.hpp>
|
#include <DigitalOutputCard.hpp>
|
||||||
#include <AnalogCard.hpp>
|
#include <AnalogCard.hpp>
|
||||||
|
|
||||||
// This code demonstrates how to use the cards
|
// This code demonstrates how to use the cards
|
||||||
|
|
||||||
uint8_t pinMap[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15, 14, 13, 12};
|
|
||||||
|
|
||||||
DigitalInputCard icard = DigitalInputCard(0x21, 0x22);
|
ESPMegaPRO espmega = ESPMegaPRO();
|
||||||
DigitalOutputCard ocard = DigitalOutputCard(0x5F);
|
AnalogCard analogCard = AnalogCard();
|
||||||
|
|
||||||
void inputCallback(uint8_t pin, bool state) {
|
void inputCallback(uint8_t pin, bool state) {
|
||||||
Serial.print("Input ");
|
Serial.print("Input ");
|
||||||
|
@ -22,40 +21,30 @@ void printInputs() {
|
||||||
Serial.print("Input ");
|
Serial.print("Input ");
|
||||||
Serial.print(i);
|
Serial.print(i);
|
||||||
Serial.print(": ");
|
Serial.print(": ");
|
||||||
Serial.print(icard.digitalRead(i));
|
Serial.print(espmega.inputs.digitalRead(i));
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Wire.begin(14, 33);
|
// Instantiate ESPMega
|
||||||
// Instantiate Input Card
|
espmega.begin();
|
||||||
Serial.println("Initializing Input Card");
|
|
||||||
icard.begin();
|
|
||||||
Serial.println("Initialized Input Card");
|
|
||||||
// Instantiate Output Card
|
|
||||||
Serial.println("Initializing Output Card");
|
|
||||||
ocard.begin();
|
|
||||||
Serial.println("Initialized Output Card");
|
|
||||||
|
|
||||||
icard.loadPinMap(pinMap);
|
|
||||||
|
|
||||||
// Read all the inputs and print them
|
// Read all the inputs and print them
|
||||||
printInputs();
|
printInputs();
|
||||||
|
|
||||||
// Turn on all the outputs
|
// Turn on all the outputs
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
ocard.digitalWrite(i, true);
|
espmega.outputs.digitalWrite(i, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the debounce time for all inputs to 200ms
|
// Set the debounce time for all inputs to 200ms
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
icard.setDebounceTime(i, 200);
|
espmega.inputs.setDebounceTime(i, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register the callback function
|
// Register the callback function
|
||||||
icard.registerCallback(inputCallback);
|
espmega.inputs.registerCallback(inputCallback);
|
||||||
|
|
||||||
|
// Install the analog card
|
||||||
|
espmega.installCard(0, &analogCard);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long previousMillis = 0;
|
unsigned long previousMillis = 0;
|
||||||
|
@ -68,6 +57,6 @@ void loop() {
|
||||||
previousMillis = currentMillis;
|
previousMillis = currentMillis;
|
||||||
printInputs();
|
printInputs();
|
||||||
}
|
}
|
||||||
icard.loop();
|
espmega.loop();
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue