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

49 lines
1.6 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 <Adafruit_PWMServoDriver.h>
2023-12-28 04:41:20 +00:00
2023-12-28 05:46:39 +00:00
// Protocol for digital output card
// Note that pin is always 2 characters long and padded with 0 if necessary
// Set pin state topic: <pin>/set/state payload: 0/1
// Set pin pwm topic: <pin>/set/value payload: 0-4095
// Publish pin state topic: <pin>/state payload: 0/1
// Publish pin pwm topic: <pin>/value payload: 0-4095
// Publish all topic: requeststate payload: N/A
// Enable/disable publish topic: publish_enable payload: 0/1
#define SET_STATE_TOPIC "/set/state"
#define SET_VALUE_TOPIC "/set/value"
#define STATE_TOPIC "/state"
#define VALUE_TOPIC "/value"
#define REQUEST_STATE_TOPIC "requeststate"
#define PUBLISH_ENABLE_TOPIC "publish_enable"
2023-12-28 04:41:20 +00:00
#define CARD_TYPE_DIGITAL_OUTPUT 0x00
2023-12-27 18:25:35 +00:00
class DigitalOutputCard : public ExpansionCard
2023-12-27 16:15:11 +00:00
{
public:
// Instantiate the card with the specified address
DigitalOutputCard(uint8_t address);
// Instantiate the card with the specified position on the dip switch
DigitalOutputCard(bool bit0, bool bit1, bool bit2, bool bit3, bool bit4);
// Initialize the card
2023-12-27 19:18:21 +00:00
bool begin();
// Dummy loop function
void loop();
2023-12-27 16:15:11 +00:00
// Set the output to the specified state
void digitalWrite(uint8_t pin, bool state);
// Set the output to the specified pwm value
void analogWrite(uint8_t pin, uint16_t value);
2023-12-28 05:46:39 +00:00
// Get the state of the specified pin
bool getState(uint8_t pin);
// Get the pwm value of the specified pin
uint16_t getValue(uint8_t pin);
2023-12-28 04:41:20 +00:00
// Get type of card
uint8_t getType();
2023-12-27 16:15:11 +00:00
private:
Adafruit_PWMServoDriver pwm;
uint8_t address;
2023-12-28 05:46:39 +00:00
bool state_buffer[16];
uint16_t value_buffer[16];
2023-12-27 16:15:11 +00:00
};