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

40 lines
1.2 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_ADS1X15.h>
#include <MCP4725.h>
2023-12-28 04:41:20 +00:00
#define CARD_TYPE_ANALOG 0x02
2023-12-27 16:15:11 +00:00
#define ANALOG_INPUT_BANK_A_ADDRESS 0x48
#define ANALOG_INPUT_BANK_B_ADDRESS 0x49
#define DAC0_ADDRESS 0x60
#define DAC1_ADDRESS 0x61
#define DAC2_ADDRESS 0x62
#define DAC3_ADDRESS 0x63
2023-12-27 18:25:35 +00:00
class AnalogCard : public ExpansionCard {
2023-12-27 16:15:11 +00:00
public:
AnalogCard();
void dacWrite(uint8_t pin, uint16_t value);
2023-12-28 17:39:11 +00:00
void sendDataToDAC(uint8_t pin, uint16_t value);
2023-12-27 16:15:11 +00:00
uint16_t analogRead(uint8_t pin);
2023-12-27 19:18:21 +00:00
bool begin();
void loop();
2023-12-28 17:39:11 +00:00
bool getDACState(uint8_t pin);
uint16_t getDACValue(uint8_t pin);
void setDACState(uint8_t pin, bool state);
void setDACValue(uint8_t pin, uint16_t value);
void registerDACChangeCallback(std::function<void(uint8_t, bool, uint16_t)> callback);
void deregisterDACChangeCallback();
2023-12-28 04:41:20 +00:00
uint8_t getType();
2023-12-27 16:15:11 +00:00
private:
2023-12-28 17:39:11 +00:00
std::function<void(uint8_t, bool, uint16_t)> dac_change_callback;
bool dac_state[4];
uint16_t dac_value[4];
2023-12-27 16:15:11 +00:00
MCP4725 dac0;
MCP4725 dac1;
MCP4725 dac2;
MCP4725 dac3;
Adafruit_ADS1115 analogInputBankA;
Adafruit_ADS1115 analogInputBankB;
};