@@ -39,44 +39,46 @@ class IRDriver : public Node {
3939
4040 void readPins () {
4141 moduleIO->read ([&](ModuleState& state) {
42+ pinInfrared = UINT8_MAX;
4243 for (JsonObject pinObject : state.data [" pins" ].as <JsonArray>()) {
4344 uint8_t usage = pinObject[" usage" ];
4445 if (usage == pin_Infrared) {
45- pinInfrared = pinObject[" GPIO" ]. as < uint8_t >() ;
46+ pinInfrared = pinObject[" GPIO" ];
4647 EXT_LOGD (ML_TAG, " pin_Infrared found %d" , pinInfrared);
48+ }
49+ }
50+ if (pinInfrared != UINT8_MAX) {
51+ EXT_LOGI (IR_DRIVER_TAG, " Changing to pin #%d" , pinInfrared);
52+
53+ if (rx_channel) {
54+ EXT_LOGI (IR_DRIVER_TAG, " Removing callback" );
55+ ESP_ERROR_CHECK (rmt_rx_register_event_callbacks (rx_channel, &cbs_empty, receive_queue));
56+ EXT_LOGI (IR_DRIVER_TAG, " Stopping RMT reception" );
57+ ESP_ERROR_CHECK (rmt_disable (rx_channel));
58+ EXT_LOGI (IR_DRIVER_TAG, " Deleting old RX channel" );
59+ ESP_ERROR_CHECK (rmt_del_channel (rx_channel));
60+ rx_channel = NULL ;
61+ }
4762
48- EXT_LOGI (IR_DRIVER_TAG, " Changing to pin #%d" , pinInfrared);
49-
50- if (rx_channel) {
51- EXT_LOGI (IR_DRIVER_TAG, " Removing callback" );
52- ESP_ERROR_CHECK (rmt_rx_register_event_callbacks (rx_channel, &cbs_empty, receive_queue));
53- EXT_LOGI (IR_DRIVER_TAG, " Stopping RMT reception" );
54- ESP_ERROR_CHECK (rmt_disable (rx_channel));
55- EXT_LOGI (IR_DRIVER_TAG, " Deleting old RX channel" );
56- ESP_ERROR_CHECK (rmt_del_channel (rx_channel));
57- rx_channel = NULL ;
58- }
59-
60- if (receive_queue) {
61- vQueueDelete (receive_queue);
62- receive_queue = NULL ;
63- }
64-
65- rx_channel_cfg.gpio_num = (gpio_num_t )pinInfrared;
66- EXT_LOGI (IR_DRIVER_TAG, " create RMT RX channel" );
67- ESP_ERROR_CHECK (rmt_new_rx_channel (&rx_channel_cfg, &rx_channel));
68-
69- EXT_LOGI (IR_DRIVER_TAG, " Enable RMT RX channel" );
70- ESP_ERROR_CHECK (rmt_enable (rx_channel));
71-
72- EXT_LOGI (IR_DRIVER_TAG, " Register RX done callback" );
73- receive_queue = xQueueCreate (1 , sizeof (rmt_rx_done_event_data_t ));
74- assert (receive_queue);
75- ESP_ERROR_CHECK (rmt_rx_register_event_callbacks (rx_channel, &cbs, receive_queue));
76-
77- EXT_LOGI (IR_DRIVER_TAG, " Arm receive" );
78- ESP_ERROR_CHECK (rmt_receive (rx_channel, raw_symbols, sizeof (raw_symbols), &receive_config));
63+ if (receive_queue) {
64+ vQueueDelete (receive_queue);
65+ receive_queue = NULL ;
7966 }
67+
68+ rx_channel_cfg.gpio_num = (gpio_num_t )pinInfrared;
69+ EXT_LOGI (IR_DRIVER_TAG, " create RMT RX channel" );
70+ ESP_ERROR_CHECK (rmt_new_rx_channel (&rx_channel_cfg, &rx_channel));
71+
72+ EXT_LOGI (IR_DRIVER_TAG, " Enable RMT RX channel" );
73+ ESP_ERROR_CHECK (rmt_enable (rx_channel));
74+
75+ EXT_LOGI (IR_DRIVER_TAG, " Register RX done callback" );
76+ receive_queue = xQueueCreate (1 , sizeof (rmt_rx_done_event_data_t ));
77+ assert (receive_queue);
78+ ESP_ERROR_CHECK (rmt_rx_register_event_callbacks (rx_channel, &cbs, receive_queue));
79+
80+ EXT_LOGI (IR_DRIVER_TAG, " Arm receive" );
81+ ESP_ERROR_CHECK (rmt_receive (rx_channel, raw_symbols, sizeof (raw_symbols), &receive_config));
8082 }
8183 // for (int i = 0; i < sizeof(pins); i++) EXT_LOGD(ML_TAG, "pin %d = %d", i, pins[i]);
8284 });
@@ -405,7 +407,7 @@ class IRDriver : public Node {
405407 void loop () override {
406408 if (receive_queue) {
407409 if (xQueueReceive (receive_queue, &rx_data, 0 ) == pdPASS) {
408- if (rx_data.num_symbols != 1 ) EXT_LOGD (IR_DRIVER_TAG, " Received symbols: #%d" , rx_data.num_symbols ); // will not be processed (only 34 and 2)
410+ if (rx_data.num_symbols != 1 ) EXT_LOGD (IR_DRIVER_TAG, " Received symbols: #%d" , rx_data.num_symbols ); // will not be processed (only 34 and 2)
409411 // parse the receive symbols and print the result
410412 parse_nec_frame (rx_data.received_symbols , rx_data.num_symbols );
411413 // start receive again
0 commit comments