prepare for ESPMegaPRO OOP

This commit is contained in:
Siwat Sirichai 2023-12-28 01:25:35 +07:00
parent 51e9f5258a
commit fc692ef0b0
9 changed files with 266 additions and 71 deletions

View file

@ -1,8 +1,8 @@
#pragma once
#include <ESPMegaPRO.h>
#include <ExpansionCard.hpp>
#include <PCF8574.h>
class DigitalInputCard {
class DigitalInputCard : public ExpansionCard {
public:
// Instantiate the card with the specified address
DigitalInputCard(uint8_t address_a, uint8_t address_b);
@ -11,17 +11,23 @@ class DigitalInputCard {
// Initialize the card
void begin();
// Refresh and Read the input from the specified pin, always refresh the input buffers
uint8_t digitalRead(uint8_t pin);
bool digitalRead(uint8_t pin);
// Read the input from the specified pin, also refresh the input buffers if refresh is true
uint8_t digitalRead(uint8_t pin, bool refresh);
bool digitalRead(uint8_t pin, bool refresh);
// Preform a loop to refresh the input buffers
void loop();
// Get the input buffer for bank A
uint8_t getInputBufferA();
// Get the input buffer for bank B
uint8_t getInputBufferB();
// Set the debounce time for the specified pin
void setDebounceTime(uint8_t pin, uint32_t debounceTime);
// Register a callback function to be called when a pin changes
void registerCallback(void (*callback)(int, bool));
void registerCallback(void (*callback)(uint8_t, bool));
// Unregister the callback function
void unregisterCallback();
// Load a new pin map
void loadPinMap(uint8_t pinMap[16]);
private:
PCF8574 inputBankA;
PCF8574 inputBankB;
@ -29,7 +35,16 @@ class DigitalInputCard {
uint8_t address_b;
uint8_t inputBufferA;
uint8_t inputBufferB;
void (*callback)(int, bool);
uint8_t previousInputBufferA;
uint8_t previousInputBufferB;
uint32_t debounceTime[16];
uint32_t lastDebounceTime[16];
// A map of the physical pin to the virtual pin
uint8_t pinMap[16];
// A map of the virtual pin to the physical pin
uint8_t virtualPinMap[16];
void (*callback)(uint8_t, bool);
void refreshInputBankA();
void refreshInputBankB();
void handlePinChange(int pin, uint8_t& currentBuffer, uint8_t& previousBuffer);
};