Thanks for the suggests. Here is specifically what I am trying to do. I have some arrays defined as such:
const uint8_t keyshort5[] = { 0,0,21,0,8,80,4,65,76,4,0,1,0 };
const uint8_t keyshort6[] = { 0,0,21,0,8,80,4,65,65,4,9,2,0 };
const uint8_t keyshort7[] = { 0,0,21,0,8,80,4,65,65,4,0,3,0 };
const uint8_t keyshort8[] = { 0,0,21,0,8,80,4,65,194,4,1,4,0 };
const uint8_t keylong5[] = { 0,0,21,0,8,80,3,65,76,4,0,1,0 };
const uint8_t keylong6[] = { 0,0,21,0,8,80,3,65,65,4,9,2,0 };
const uint8_t keylong7[] = { 0,0,21,0,8,80,3,65,65,4,0,3,0 };
const uint8_t keylong8[] = { 0,0,21,0,8,80,3,65,194,4,1,4,0 };
const uint8_t keynext[] = { 0,0,21,0,8,80,0,65,65,1,0,0,0 };
const uint8_t keyshortam[] = { 0,0,21,0,8,80,4,192,131,0,94,0,0 };
const uint8_t keylongam[] = { 0,0,21,0,8,80,3,192,131,0,94,0,0 };
const uint8_t keyprev[] = { 0,0,21,0,8,80,0,65,65,2,0,0,0 };
const uint8_t keyholdnext[] = { 0,0,21,0,8,80,5,65,65,1,0,0,0 };
const uint8_t keyholdprev[] = { 0,0,21,0,8,80,5,65,65,2,0,0,0 };
const uint8_t keyfm[] = { 0,0,21,0,8,80,2,65,192,3,0,0,0 };
const uint8_t keyauto[] = { 0,0,21,0,8,80,2,65,65,6,0,0,0 };
Then later in the program, a received packet has to be checked to see if it matches any of those:
int checkWhichButton() {
if ( comparearrays (incoming, keyshort5, 12) == 1 ) { lastRadioRead = 0; return 5; } else {
if ( comparearrays (incoming, keyshort6, 12) == 1 ) { lastRadioRead = 0; return 6; } else {
if ( comparearrays (incoming, keyshort7, 12) == 1 ) { lastRadioRead = 0; return 7; } else {
if ( comparearrays (incoming, keyshort8, 12) == 1 ) { lastRadioRead = 0; return 8; } else {
if ( comparearrays (incoming, keylong5, 12) == 1 ) { lastRadioRead = 0; return 15; } else {
if ( comparearrays (incoming, keylong6, 12) == 1 ) { lastRadioRead = 0; return 16; } else {
if ( comparearrays (incoming, keylong7, 12) == 1 ) { lastRadioRead = 0; return 17; } else {
if ( comparearrays (incoming, keylong8, 12) == 1 ) { lastRadioRead = 0; return 18; } else {
if ( comparearrays (incoming, keynext, 12) == 1 ) { lastRadioRead = 0; return 40; } else {
if ( comparearrays (incoming, keyprev, 12) == 1 ) { lastRadioRead = 0; return 30; } else {
if ( comparearrays (incoming, keyshortam, 12) == 1 ) { lastRadioRead = 0; return 10; } else {
if ( comparearrays (incoming, keyholdnext, 12) == 1 ) { lastRadioRead = 0; return 41; } else {
if ( comparearrays (incoming, keyholdprev, 12) == 1 ) { lastRadioRead = 0; return 31; } else {
if ( comparearrays (incoming, keylongam, 12) == 1 ) { lastRadioRead = 0; return 110; } else {
if ( comparearrays (incoming, keyfm, 12) == 1 ) { lastRadioRead = 0; return 20; } else {
if ( comparearrays (incoming, keyauto, 12) == 1 ) { lastRadioRead = 0; return 9; }}}}}}}}}}}}}}}}
// if no matches, then return a 0
return 0;
}
The comparearrays routine is as follows:
int comparearrays(int* a1, const uint8_t* a2, int positions) {
for ( int tmp = 0; tmp<positions; tmp++ ) {
if ( a1[tmp] != a2[tmp] ) { return 0; }
}
return 1;
}
I'm having a little difficulty getting PROGMEM to work as I need it to but thought I would ask this question first, in case there is an even better way to do this. I would love something along the lines of:
if ( comparearrays (incoming, [0,0,21,0,8,80,3,65,76,4,0,1,0], 12) == 1 ) { lastRadioRead = 0; return 15; } else {
but have not been able to provide on-the-fly integer arrays for this type of comparison. I was able to do a similar thing with char arrays somewhere else in my code by putting the array info in quotes, but it seems an integer array is either different syntax or not supported.
Any suggestions from you coding veterans?