diff --git a/base.yaml b/base.yaml index 79d0de0..a864835 100644 --- a/base.yaml +++ b/base.yaml @@ -11,6 +11,7 @@ ratgdo: input_gdo_pin: ${uart_rx_pin} output_gdo_pin: ${uart_tx_pin} input_obst_pin: ${input_obst_pin} + remote_id: 0x539 sensor: - platform: ratgdo @@ -167,4 +168,4 @@ button: type: query entity_category: diagnostic ratgdo_id: ${id_prefix} - name: "Query" + name: "Query" \ No newline at end of file diff --git a/components/ratgdo/__init__.py b/components/ratgdo/__init__.py index afa1c75..f59ebcb 100644 --- a/components/ratgdo/__init__.py +++ b/components/ratgdo/__init__.py @@ -22,6 +22,9 @@ DEFAULT_INPUT_GDO = ( CONF_INPUT_OBST = "input_obst_pin" DEFAULT_INPUT_OBST = "D7" # D7 black obstruction sensor terminal +CONF_REMOTE_ID = "remote_id" +DEFAULT_REMOTE_ID = 0x539 + CONF_RATGDO_ID = "ratgdo_id" CONFIG_SCHEMA = cv.Schema( @@ -36,6 +39,9 @@ CONFIG_SCHEMA = cv.Schema( cv.Optional( CONF_INPUT_OBST, default=DEFAULT_INPUT_OBST ): pins.gpio_input_pin_schema, + cv.Optional( + CONF_REMOTE_ID, default=DEFAULT_REMOTE_ID + ): cv.uint64_t, } ).extend(cv.COMPONENT_SCHEMA) @@ -60,6 +66,7 @@ async def to_code(config): cg.add(var.set_input_gdo_pin(pin)) pin = await cg.gpio_pin_expression(config[CONF_INPUT_OBST]) cg.add(var.set_input_obst_pin(pin)) + cg.add(var.set_remote_id(config[CONF_REMOTE_ID])) cg.add_library( name="secplus", diff --git a/components/ratgdo/ratgdo.cpp b/components/ratgdo/ratgdo.cpp index 22b5dbb..92d66ef 100644 --- a/components/ratgdo/ratgdo.cpp +++ b/components/ratgdo/ratgdo.cpp @@ -22,7 +22,6 @@ namespace ratgdo { static const char* const TAG = "ratgdo"; static const int STARTUP_DELAY = 2000; // delay before enabling interrupts - static const uint64_t REMOTE_ID = 0x539; static const uint8_t MAX_CODES_WITHOUT_FLASH_WRITE = 3; void IRAM_ATTR HOT RATGDOStore::isrObstruction(RATGDOStore* arg) @@ -73,6 +72,7 @@ namespace ratgdo { LOG_PIN(" Input GDO Pin: ", this->input_gdo_pin_); LOG_PIN(" Input Obstruction Pin: ", this->input_obst_pin_); ESP_LOGCONFIG(TAG, " Rolling Code Counter: %d", this->rollingCodeCounter); + ESP_LOGCONFIG(TAG, " Remote ID: %d", this->remote_id); } const char* cmd_name(uint16_t cmd) @@ -141,7 +141,7 @@ namespace ratgdo { cmd = ((fixed >> 24) & 0xf00) | (data & 0xff); data &= ~0xf000; // clear parity nibble - if ((fixed & 0xfff) == REMOTE_ID) { // my commands + if ((fixed & 0xfff) == this->remote_id) { // my commands ESP_LOGD(TAG, "[%ld] received mine: rolling=%07" PRIx32 " fixed=%010" PRIx64 " data=%08" PRIx32, millis(), rolling, fixed, data); return 0; } else { @@ -205,7 +205,7 @@ namespace ratgdo { void RATGDOComponent::getRollingCode(command::cmd command, uint32_t data, bool increment) { - uint64_t fixed = ((command & ~0xff) << 24) | REMOTE_ID; + uint64_t fixed = ((command & ~0xff) << 24) | this->remote_id; uint32_t send_data = (data << 8) | (command & 0xff); ESP_LOGD(TAG, "[%ld] Encode for transmit rolling=%07" PRIx32 " fixed=%010" PRIx64 " data=%08" PRIx32, millis(), this->rollingCodeCounter, fixed, send_data); diff --git a/components/ratgdo/ratgdo.h b/components/ratgdo/ratgdo.h index 9520eba..2c37874 100644 --- a/components/ratgdo/ratgdo.h +++ b/components/ratgdo/ratgdo.h @@ -148,6 +148,7 @@ namespace ratgdo { void set_output_gdo_pin(InternalGPIOPin* pin) { this->output_gdo_pin_ = pin; }; void set_input_gdo_pin(InternalGPIOPin* pin) { this->input_gdo_pin_ = pin; }; void set_input_obst_pin(InternalGPIOPin* pin) { this->input_obst_pin_ = pin; }; + void set_remote_id(uint64_t remote_id) { this->remote_id = remote_id & 0xffffff; }; // not sure how large remote_id can be, assuming not more than 24 bits /********************************** FUNCTION DECLARATION * *****************************************/ @@ -196,6 +197,7 @@ namespace ratgdo { InternalGPIOPin* output_gdo_pin_; InternalGPIOPin* input_gdo_pin_; InternalGPIOPin* input_obst_pin_; + uint64_t remote_id; }; // RATGDOComponent