Add some more configuration options
This commit is contained in:
@@ -27,6 +27,9 @@ dmx512:
|
||||
uart_num: 1
|
||||
periodic_update: true
|
||||
force_full_frames: false
|
||||
custom_break_len: 92
|
||||
custom_mab_len: 12
|
||||
update_interval: 500
|
||||
```
|
||||
|
||||
* `id`: The ID of this DMX512 hub
|
||||
@@ -39,3 +42,6 @@ dmx512:
|
||||
configured, this should be set to 1 (default).
|
||||
* `periodic_update`: If set to false, only state changes are transmitted and the bus is silent in between - violates the specification and may cause some dimmers to turn off
|
||||
* `force_full_frames`: If set to true, the full 513-byte frame is always sent. Otherwise, only the configured channels are transmitted.
|
||||
* `custom_mab_len`: Set a custom mark-after-break length (in uS, default 12)
|
||||
* `custom_break_len`: Set a custom break length (in uS, default 92)
|
||||
* `update_interval`: Specify a custom update interval, i.e. the minimum time between resending the current values (in ms, default 500)
|
||||
@@ -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]))
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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};
|
||||
|
||||
Reference in New Issue
Block a user