Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add arris dcx3200 + fixes for newer versions of ESP-IDF #8

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
3 changes: 2 additions & 1 deletion src/IR32.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ typedef struct {
{"NEC", 38000, 33, 32, 0, 9000, 4500, 560, 1690, 560, 560, 560},
{"samsung", 38000, 33, 32, 0, 4500, 4450, 560, 1600, 560, 560, 8950},
{"LG", 38000, 33, 28, 0, 8500, 4250, 560, 1600, 560, 560, 800},
{"LG32", 38000, 33, 32, 0, 4500, 4500, 500, 1750, 500, 560, 8950}
{"LG32", 38000, 33, 32, 0, 4500, 4500, 500, 1750, 500, 560, 8950},
{"ARRIS", 38000, 33, 16, 0, 9000, 4500, 550, 2250, 550, 4500, 5000} // arris dcx3200 cable set top box from spectrum
};
#endif // _IR32_H_
33 changes: 22 additions & 11 deletions src/IRRecv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ IRRecv::IRRecv(rmt_channel_t channel)

bool IRRecv::start(gpio_num_t rx_pin)
{
rmt_config_t rmt_rx;
rmt_rx.channel = _channel;
rmt_rx.gpio_num = rx_pin;
rmt_config_t rmt_rx = RMT_DEFAULT_CONFIG_RX(rx_pin, _channel);
rmt_rx.clk_div = RMT_CLK_DIV;
rmt_rx.mem_block_num = 1;
rmt_rx.rmt_mode = RMT_MODE_RX;
Expand All @@ -46,7 +44,11 @@ int8_t IRRecv::available()
{
if (!_active) return -1;
UBaseType_t waiting;
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4,0,0) // versions 4+ added an extra arg to vRingbufferGetInfo
vRingbufferGetInfo(_rb, NULL, NULL, NULL, NULL, &waiting);
#else
vRingbufferGetInfo(_rb, NULL, NULL, NULL, &waiting);
#endif
return waiting;
}

Expand Down Expand Up @@ -91,7 +93,7 @@ uint32_t IRRecv::rx_parse_items(rmt_item32_t* item, int item_num, uint8_t timing
{
int w_len = item_num;
if(w_len < timing_groups[timing].bit_length + 2) {
log_w("Item length was only %d bit", w_len);
log_v("Item length was only %d bit", w_len);
return 0;
}
if(!rx_header_if(item++, timing)) {
Expand All @@ -115,21 +117,19 @@ uint32_t IRRecv::rx_parse_items(rmt_item32_t* item, int item_num, uint8_t timing
void dump_item(rmt_item32_t* item, size_t sz)
{
for (int x=0; x<sz; x++) {
log_v("Count: %d duration0: %d duration1: %d\n", x,item[x].duration0,item[x].duration1);
// print item times in microseconds so its easy to use this to build a new timing entry.
log_i("Count: %d duration0: %dus duration1: %dus", x,RMT_ITEM_DURATION(item[x].duration0),RMT_ITEM_DURATION(item[x].duration1));
if(item[x].duration1==0 || item[x].duration0 == 0 || item[x].duration1 > 0x7f00 || item[x].duration0 > 0x7f00) break;
}
}

uint32_t IRRecv::read(char* &timingGroup, bool preferredOnly)
{
if (!available()) return 0;

size_t rx_size = 0;
rmt_item32_t* item = (rmt_item32_t*) xRingbufferReceive(_rb, &rx_size, RMT_RX_BUF_WAIT);
if (!item) return 0;
//after parsing the data, clear space in the ringbuffer.
vRingbufferReturnItem(_rb, (void*) item);
//dump_item(item,rx_size);
uint32_t rx_data;
uint8_t found_timing = 0;
for (uint8_t timing : _preferred) {
Expand All @@ -139,7 +139,10 @@ uint32_t IRRecv::read(char* &timingGroup, bool preferredOnly)
break;
}
}
if (!rx_data) {
// if we did not parse the item from the prefered list then
// check the non-prefered items as well, but only if
// preferredOnly is not set.
if (!rx_data && !preferredOnly) {
uint8_t groupCount = sizeof(timing_groups)/sizeof(timing_groups[0]);
for (uint8_t timing = 0; timing < groupCount; timing++) {
if (!inPrefVector(timing)) {
Expand All @@ -153,12 +156,21 @@ uint32_t IRRecv::read(char* &timingGroup, bool preferredOnly)
}
if (found_timing) {
timingGroup = (char*) timing_groups[found_timing].tag;
} else {
log_w("read() item with length %u not parsed!", rx_size / 4);
if (_dump_unknown) {
dump_item(item,rx_size);
}
}
//after parsing the data, clear space in the ringbuffer.
vRingbufferReturnItem(_rb, (void*) item);
return rx_data;
}

void IRRecv::setMargin(uint16_t margin_us) {_margin_us = margin_us;}

void IRRecv::setDumpUnknown(bool dump) {_dump_unknown = dump;}

uint8_t timingGroupElement(const char* tag)
{
uint8_t counter = 0;
Expand Down Expand Up @@ -198,7 +210,6 @@ void IRRecv::stop()
_rx_pin = GPIO_NUM_MAX;
_timing = {};
_active = false;
vRingbufferDelete(_rb);
}

bool IRRecv::active() {return _active;}
3 changes: 3 additions & 0 deletions src/IRRecv.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "IR32.h"
#include "Arduino.h"
#include "driver/rmt.h"
#include <vector>

class IRRecv
{
Expand All @@ -16,6 +17,7 @@ class IRRecv
int8_t available();
uint32_t read(char* &timingGroup, bool preferredOnly=false);
void setMargin(uint16_t margin_us);
void setDumpUnknown(bool dump);
bool inPrefVector(uint8_t element);
int setPreferred(const char* timing_group);
int setPreferred(String timing_group);
Expand All @@ -35,5 +37,6 @@ class IRRecv
std::vector<uint8_t> _preferred;
RingbufHandle_t _rb = NULL;
bool _active = false;
bool _dump_unknown = false;
};
#endif // _IRRECV_H_
8 changes: 5 additions & 3 deletions src/IRSend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ uint8_t findGroup(const char* timingGroup)

bool IRSend::startRMT(uint8_t timing)
{
rmt_config_t rmt_tx;
rmt_tx.channel = _channel;
rmt_tx.gpio_num = _tx_pin;
rmt_config_t rmt_tx = RMT_DEFAULT_CONFIG_TX(_tx_pin, _channel);
rmt_tx.clk_div = RMT_CLK_DIV;
rmt_tx.mem_block_num = 1;
rmt_tx.rmt_mode = RMT_MODE_TX;
Expand All @@ -44,7 +42,11 @@ bool IRSend::startRMT(uint8_t timing)
rmt_tx.tx_config.idle_output_en = RMT_TX_IDLE_EN;
if (rmt_config(&rmt_tx) != ESP_OK) return false;
if (rmt_driver_install(rmt_tx.channel, 0, 0) != ESP_OK) return false;
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4,4,0) // versions after 4.3.X changed `rmt_set_pin` to `rmt_set_gpio`
if (rmt_set_gpio(_channel, RMT_MODE_TX, _tx_pin, false) != ESP_OK) return false;
#else
if (rmt_set_pin(_channel, RMT_MODE_TX, _tx_pin) != ESP_OK) return false;
#endif
_timing = timing;
return true;
}
Expand Down