Make remote_id a component parameter (#11)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Marius Muja 2023-06-24 14:01:20 -07:00 committed by GitHub
parent 37a4b88355
commit a72143cd96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 4 deletions

View File

@ -11,6 +11,7 @@ ratgdo:
input_gdo_pin: ${uart_rx_pin} input_gdo_pin: ${uart_rx_pin}
output_gdo_pin: ${uart_tx_pin} output_gdo_pin: ${uart_tx_pin}
input_obst_pin: ${input_obst_pin} input_obst_pin: ${input_obst_pin}
remote_id: 0x539
sensor: sensor:
- platform: ratgdo - platform: ratgdo

View File

@ -22,6 +22,9 @@ DEFAULT_INPUT_GDO = (
CONF_INPUT_OBST = "input_obst_pin" CONF_INPUT_OBST = "input_obst_pin"
DEFAULT_INPUT_OBST = "D7" # D7 black obstruction sensor terminal DEFAULT_INPUT_OBST = "D7" # D7 black obstruction sensor terminal
CONF_REMOTE_ID = "remote_id"
DEFAULT_REMOTE_ID = 0x539
CONF_RATGDO_ID = "ratgdo_id" CONF_RATGDO_ID = "ratgdo_id"
CONFIG_SCHEMA = cv.Schema( CONFIG_SCHEMA = cv.Schema(
@ -36,6 +39,9 @@ CONFIG_SCHEMA = cv.Schema(
cv.Optional( cv.Optional(
CONF_INPUT_OBST, default=DEFAULT_INPUT_OBST CONF_INPUT_OBST, default=DEFAULT_INPUT_OBST
): pins.gpio_input_pin_schema, ): pins.gpio_input_pin_schema,
cv.Optional(
CONF_REMOTE_ID, default=DEFAULT_REMOTE_ID
): cv.uint64_t,
} }
).extend(cv.COMPONENT_SCHEMA) ).extend(cv.COMPONENT_SCHEMA)
@ -60,6 +66,7 @@ async def to_code(config):
cg.add(var.set_input_gdo_pin(pin)) cg.add(var.set_input_gdo_pin(pin))
pin = await cg.gpio_pin_expression(config[CONF_INPUT_OBST]) pin = await cg.gpio_pin_expression(config[CONF_INPUT_OBST])
cg.add(var.set_input_obst_pin(pin)) cg.add(var.set_input_obst_pin(pin))
cg.add(var.set_remote_id(config[CONF_REMOTE_ID]))
cg.add_library( cg.add_library(
name="secplus", name="secplus",

View File

@ -22,7 +22,6 @@ namespace ratgdo {
static const char* const TAG = "ratgdo"; static const char* const TAG = "ratgdo";
static const int STARTUP_DELAY = 2000; // delay before enabling interrupts 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; static const uint8_t MAX_CODES_WITHOUT_FLASH_WRITE = 3;
void IRAM_ATTR HOT RATGDOStore::isrObstruction(RATGDOStore* arg) 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 GDO Pin: ", this->input_gdo_pin_);
LOG_PIN(" Input Obstruction Pin: ", this->input_obst_pin_); LOG_PIN(" Input Obstruction Pin: ", this->input_obst_pin_);
ESP_LOGCONFIG(TAG, " Rolling Code Counter: %d", this->rollingCodeCounter); 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) const char* cmd_name(uint16_t cmd)
@ -141,7 +141,7 @@ namespace ratgdo {
cmd = ((fixed >> 24) & 0xf00) | (data & 0xff); cmd = ((fixed >> 24) & 0xf00) | (data & 0xff);
data &= ~0xf000; // clear parity nibble 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); ESP_LOGD(TAG, "[%ld] received mine: rolling=%07" PRIx32 " fixed=%010" PRIx64 " data=%08" PRIx32, millis(), rolling, fixed, data);
return 0; return 0;
} else { } else {
@ -205,7 +205,7 @@ namespace ratgdo {
void RATGDOComponent::getRollingCode(command::cmd command, uint32_t data, bool increment) 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); 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); ESP_LOGD(TAG, "[%ld] Encode for transmit rolling=%07" PRIx32 " fixed=%010" PRIx64 " data=%08" PRIx32, millis(), this->rollingCodeCounter, fixed, send_data);

View File

@ -148,6 +148,7 @@ namespace ratgdo {
void set_output_gdo_pin(InternalGPIOPin* pin) { this->output_gdo_pin_ = pin; }; 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_gdo_pin(InternalGPIOPin* pin) { this->input_gdo_pin_ = pin; };
void set_input_obst_pin(InternalGPIOPin* pin) { this->input_obst_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 /********************************** FUNCTION DECLARATION
* *****************************************/ * *****************************************/
@ -196,6 +197,7 @@ namespace ratgdo {
InternalGPIOPin* output_gdo_pin_; InternalGPIOPin* output_gdo_pin_;
InternalGPIOPin* input_gdo_pin_; InternalGPIOPin* input_gdo_pin_;
InternalGPIOPin* input_obst_pin_; InternalGPIOPin* input_obst_pin_;
uint64_t remote_id;
}; // RATGDOComponent }; // RATGDOComponent