0

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

  • 2
    sources is array of pointers to arrays so uint16_t* sources[] = {sourceCD, sourceAUX, sourceCDR};. array variable is a pointer to first member location – Juraj Mar 18 at 19:10
  • That doesn't quite fix it. I still get this error 3 times: warning: invalid conversion from 'const uint16_t* {aka const unsigned int*}' to 'uint16_t* {aka unsigned int*}' [-fpermissive] I also tried uint16_t *sources[] = {sourceCD, sourceAUX, sourceCDR}. Any other ideas? – Aaron Ciuffo Mar 18 at 19:37
  • I didn't notice that your first array is const and others are not. make all const. the position of * is not important. you should read the error/warning messages. – Juraj Mar 19 at 5:37
  • @Juraj I noticed that too, but I'm not sure what in the warnings would have indicated that was the problem. Can you help me understand the warning message? – Aaron Ciuffo Mar 19 at 20:21
  • 1
    I think the error messages in your Question are not for the code with Question. the first error message would have const mentioned. the messages say that you try to use uint16_t* where uint16_t is expected – Juraj Mar 20 at 8:09
3

You have two options.

  1. 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])
  1. 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.