I'd like to create an array of remote control codes provided by the raw read feature of the irlib2 library.
irlib2 provides the following uint16t arrays using the following format:
#define RAW_DATA_LEN 68
const uint16_t powerOff[RAW_DATA_LEN]={
8550, 4306, 530, 1606, 530, 566, 502, 1610,
530, 566, 502, 574, 506, 1630, 506, 566,
506, 1630, 506, 566, 502, 1610, 530, 566,
502, 1634, 506, 1606, 530, 570, 498, 1634,
506, 570, 510, 562, 506, 566, 502, 1634,
506, 1606, 530, 1610, 530, 562, 538, 538,
530, 542, 538, 1598, 538, 1570, 558, 542,
538, 538, 530, 542, 538, 1598, 530, 1578,
558, 1578, 562, 1000};
I'd like create an array of these arrays using the code below, but get the following errors.
CODE
#define RAW_DATA_LEN 68
const uint16_t powerOff[RAW_DATA_LEN]={
8550, 4306, 530, 1606, 530, 566, 502, 1610,
530, 566, 502, 574, 506, 1630, 506, 566,
506, 1630, 506, 566, 502, 1610, 530, 566,
502, 1634, 506, 1606, 530, 570, 498, 1634,
506, 570, 510, 562, 506, 566, 502, 1634,
506, 1606, 530, 1610, 530, 562, 538, 538,
530, 542, 538, 1598, 538, 1570, 558, 542,
538, 538, 530, 542, 538, 1598, 530, 1578,
558, 1578, 562, 1000};
uint16_t sourceCD[RAW_DATA_LEN]={
8546, 4310, 558, 1578, 562, 538, 498, 1638,
530, 542, 506, 570, 502, 1634, 502, 570,
498, 1638, 534, 538, 498, 1638, 530, 542,
506, 1606, 554, 1582, 558, 538, 510, 1602,
554, 546, 506, 566, 502, 570, 510, 1602,
554, 1582, 558, 538, 510, 566, 502, 1606,
554, 546, 502, 1610, 558, 1574, 554, 546,
502, 570, 510, 1602, 526, 1610, 526, 574,
506, 1602, 526, 1000};
uint16_t sourceAUX[RAW_DATA_LEN]={
8550, 4310, 526, 1634, 506, 566, 502, 1634,
506, 566, 502, 574, 506, 1626, 510, 566,
506, 1630, 506, 566, 502, 1634, 506, 566,
502, 1634, 506, 1606, 530, 566, 506, 1630,
506, 566, 502, 1634, 506, 1630, 506, 1630,
510, 1602, 526, 570, 510, 566, 502, 1634,
502, 570, 502, 570, 510, 566, 502, 570,
510, 562, 506, 1630, 506, 1630, 510, 562,
506, 1630, 510, 1000};
uint16_t sourceCDR[RAW_DATA_LEN]={
8550, 4306, 530, 1606, 534, 566, 502, 1606,
534, 566, 502, 570, 510, 1602, 526, 570,
510, 1602, 534, 566, 502, 1606, 534, 566,
506, 1602, 530, 1606, 534, 566, 502, 1610,
530, 570, 498, 574, 506, 566, 502, 570,
510, 1602, 526, 570, 510, 566, 502, 570,
510, 1602, 526, 1610, 526, 1606, 534, 1602,
534, 566, 502, 1610, 530, 1602, 534, 1602,
526, 574, 506, 1000};
//This is the problem code:
uint16_t sources[3] = {sourceCD, sourceAUX, sourceCDR};
ERRORS
warning: invalid conversion from 'uint16_t* {aka unsigned int*}' to 'uint16_t {aka unsigned int}' [-fpermissive]
uint16_t sources[3] = {sourceCD, sourceAUX, sourceCDR};
warning: invalid conversion from 'uint16_t* {aka unsigned int*}' to 'uint16_t {aka unsigned int}' [-fpermissive]
warning: invalid conversion from 'uint16_t* {aka unsigned int*}' to 'uint16_t {aka unsigned int}' [-fpermissive]
I gather this has something to do with mixing and converting invalid types, but I'm not quite sure where to go from here
1 Answer 1
You have two options.
- You can make an array of arrays like this:
const uint16_t sources[3][RAW_DATA_LEN] = {
{ 8546, 4310, 558, ... }, // CD
{ 8550, 4310, 526, ... }, // AUX
{ 8550, 4306, 530, ... } // CDR
};
But then you don't have the sourceCD
, etc. variables any more. If you
want, you could #define
aliases for them like this:
#define sourceCD (sources[0])
#define sourceAUX (sources[1])
#define sourceCDR (sources[2])
- You can make an array of pointers, as suggested in the comments:
const uint16_t sourceCD[RAW_DATA_LEN] = { 8546, 4310, 558, ... };
const uint16_t sourceAUX[RAW_DATA_LEN] = { 8550, 4310, 526, ... };
const uint16_t sourceCDR[RAW_DATA_LEN] = { 8550, 4306, 530, ... };
const uint16_t *sources[3] = { sourceCD, sourceAUX, sourceCDR };
This works because, in the last line, the array identifiers such as
sourceCD
implicitly "decay" to pointers to their first elements. Note
the const
keyword in the last line, needed for consistency with the
types of the arrays declared above.
sources
is array of pointers to arrays souint16_t* sources[] = {sourceCD, sourceAUX, sourceCDR};
. array variable is a pointer to first member locationwarning: invalid conversion from 'const uint16_t* {aka const unsigned int*}' to 'uint16_t* {aka unsigned int*}' [-fpermissive]
I also trieduint16_t *sources[] = {sourceCD, sourceAUX, sourceCDR}
. Any other ideas?const
and others are not. make allconst
. the position of * is not important. you should read the error/warning messages.