ESPMegaPRO-v3-SDK/Template Project/lib/ESPMegaPRO/DigitalInputCard.hpp

50 lines
2.1 KiB
C++
Raw Normal View History

2023-12-27 16:15:11 +00:00
#pragma once
2023-12-27 18:25:35 +00:00
#include <ExpansionCard.hpp>
2023-12-27 16:15:11 +00:00
#include <PCF8574.h>
2023-12-27 18:25:35 +00:00
class DigitalInputCard : public ExpansionCard {
2023-12-27 16:15:11 +00:00
public:
// Instantiate the card with the specified address
DigitalInputCard(uint8_t address_a, uint8_t address_b);
// Instantiate the card with the specified position on the dip switch
DigitalInputCard(bool bit0, bool bit1, bool bit2, bool bit3, bool bit4, bool bit5);
// Initialize the card
2023-12-27 19:18:21 +00:00
bool begin();
2023-12-27 16:15:11 +00:00
// Refresh and Read the input from the specified pin, always refresh the input buffers
2023-12-27 18:25:35 +00:00
bool digitalRead(uint8_t pin);
2023-12-27 16:15:11 +00:00
// Read the input from the specified pin, also refresh the input buffers if refresh is true
2023-12-27 18:25:35 +00:00
bool digitalRead(uint8_t pin, bool refresh);
2023-12-27 16:15:11 +00:00
// 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();
2023-12-27 18:25:35 +00:00
// Set the debounce time for the specified pin
void setDebounceTime(uint8_t pin, uint32_t debounceTime);
2023-12-27 16:15:11 +00:00
// Register a callback function to be called when a pin changes
2023-12-27 18:25:35 +00:00
void registerCallback(void (*callback)(uint8_t, bool));
// Unregister the callback function
void unregisterCallback();
// Load a new pin map
void loadPinMap(uint8_t pinMap[16]);
2023-12-27 16:15:11 +00:00
private:
PCF8574 inputBankA;
PCF8574 inputBankB;
uint8_t address_a;
uint8_t address_b;
uint8_t inputBufferA;
uint8_t inputBufferB;
2023-12-27 18:25:35 +00:00
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);
2023-12-27 16:15:11 +00:00
void refreshInputBankA();
void refreshInputBankB();
2023-12-27 18:25:35 +00:00
void handlePinChange(int pin, uint8_t& currentBuffer, uint8_t& previousBuffer);
2023-12-27 16:15:11 +00:00
};