Add some more configuration options

This commit is contained in:
Andreas Böhler
2022-01-11 15:08:14 +01:00
parent 3edca04bf4
commit 8eadc3ca3b
4 changed files with 28 additions and 3 deletions

View File

@@ -16,6 +16,9 @@ CONF_ENABLE_PIN = 'enable_pin'
CONF_UART_NUM = 'uart_num'
CONF_PERIODIC_UPDATE = 'periodic_update'
CONF_FORCE_FULL_FRAMES = 'force_full_frames'
CONF_CUSTOM_BREAK_LEN = 'custom_break_len'
CONF_CUSTOM_MAB_LEN = 'custom_mab_len'
CONF_UPDATE_INTERVAL = 'update_interval'
def _declare_type(value):
if CORE.is_esp32:
@@ -30,6 +33,9 @@ CONFIG_SCHEMA = cv.Schema({
cv.Optional(CONF_UART_NUM, default=1): cv.int_range(min=0, max=2),
cv.Optional(CONF_PERIODIC_UPDATE, default=True): cv.boolean,
cv.Optional(CONF_FORCE_FULL_FRAMES, default=False): cv.boolean,
cv.Optional(CONF_CUSTOM_MAB_LEN, default=12): cv.int_range(min=12,max=1000),
cv.Optional(CONF_CUSTOM_BREAK_LEN, default=92): cv.int_range(min=92, max=1000),
cv.Optional(CONF_UPDATE_INTERVAL, default=500): cv.int_range(),
}).extend(cv.COMPONENT_SCHEMA).extend(uart.UART_DEVICE_SCHEMA)
async def to_code(config):
@@ -46,3 +52,6 @@ async def to_code(config):
cg.add(var.set_uart_num(config[CONF_UART_NUM]))
cg.add(var.set_periodic_update(config[CONF_PERIODIC_UPDATE]))
cg.add(var.set_force_full_frames(config[CONF_FORCE_FULL_FRAMES]))
cg.add(var.set_mab_len(config[CONF_CUSTOM_MAB_LEN]))
cg.add(var.set_break_len(config[CONF_CUSTOM_BREAK_LEN]))
cg.add(var.set_update_interval(config[CONF_UPDATE_INTERVAL]))

View File

@@ -8,10 +8,11 @@ static const char *TAG = "dmx512";
void DMX512::loop() {
bool update = false;
if(this->update_ || ((this->last_update_ + UPDATE_INTERVAL_MS < millis()) && this->periodic_update_)) {
if(this->update_ || ((this->last_update_ + this->update_interval_ < millis()) && this->periodic_update_)) {
update = true;
}
if(update) {
ESP_LOGD(TAG, "update");
this->uart_->flush();
this->sendBreak();
this->device_values_[0] = 0;
@@ -25,9 +26,9 @@ void DMX512::sendBreak() {
pinMatrixOutDetach(this->tx_pin_, false, false);
pinMode(this->tx_pin_, OUTPUT);
digitalWrite(this->tx_pin_, LOW);
delayMicroseconds(DMX_BREAK_LEN);
delayMicroseconds(this->break_len_);
digitalWrite(this->tx_pin_, HIGH);
delayMicroseconds(DMX_MAB_LEN);
delayMicroseconds(this->mab_len_);
pinMatrixOutAttach(this->tx_pin_, this->uart_idx_, false, false);
}

View File

@@ -39,6 +39,12 @@ class DMX512 : public Component {
void set_periodic_update(bool update) { periodic_update_ = update; }
void set_mab_len(int len) { mab_len_ = len; }
void set_break_len(int len) { break_len_ = len; }
void set_update_interval(int intvl) { update_interval_ = intvl; }
void set_uart_num(int num) {
if(num == 0) {
this->uart_idx_ = U0TXD_OUT_IDX;
@@ -61,6 +67,9 @@ class DMX512 : public Component {
uint8_t device_values_[DMX_MSG_SIZE];
int uart_idx_{0};
int tx_pin_{0};
int update_interval_{UPDATE_INTERVAL_MS};
int mab_len_{DMX_MAB_LEN};
int break_len_{DMX_BREAK_LEN};
uint16_t max_chan_{0};
bool update_{true};
bool periodic_update_{true};