// Testing the memcmp_P() function.
#define PATTERN_SIZE 30
#define LIST_SIZE 9
const PROGMEM uint16_t pat11[] = {1, 2, 2, 25, 3, 1, 4, 14, 1, 4, 2, 20, 3, 2, 4, 14, 1, 4, 2, 20, 3, 2, 4, 100, 13, 0, 0, 0, 0, 0};
const PROGMEM uint16_t pat12[] = {1, 2, 2, 85, 3, 2, 4, 15, 1, 3, 2, 17, 3, 1, 4, 100, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
const PROGMEM uint16_t pat13[] = {1, 3, 2, 69, 3, 1, 4, 23, 1, 1, 2, 24, 3, 1, 4, 16, 1, 1, 2, 28, 3, 1, 4, 100, 13, 0, 0, 0, 0, 0};
const PROGMEM uint16_t pat14[] = {1, 2, 2, 23, 3, 1, 4, 20, 1, 1, 2, 72, 3, 1, 4, 20, 1, 1, 2, 20, 3, 1, 4, 100, 13, 0, 0, 0, 0, 0};
const PROGMEM uint16_t pat15[] = {1, 29, 2, 100, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
const PROGMEM uint16_t pat16[] = {1, 1, 2, 100, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
const PROGMEM uint16_t pat17[] = {1, 4, 2, 15, 3, 2, 4, 21, 1, 1, 2, 100, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
const PROGMEM uint16_t pat18[] = {1, 3, 2, 20, 3, 1, 4, 17, 1, 1, 2, 17, 3, 1, 4, 26, 1, 2, 2, 100, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0};
const PROGMEM uint16_t pat19[] = {1, 2, 2, 25, 3, 1, 4, 100, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
const uint16_t *const pattern_table[LIST_SIZE] PROGMEM = {
pat11,
pat12,
pat13,
pat14,
pat15,
pat16,
pat17,
pat18,
pat19,
};
unsigned int mycode[30] = {1, 29, 2, 100, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
void setup() {
Serial.begin(115200);
Serial.println("begin");
Serial.println("model array");
printFormattedArray(mycode); // the array in ram
Serial.println(); // println without parameter will print \r\n
for (int i = 0; i < LIST_SIZE; i++) {
const unsigned int *pPattern = pgm_read_word(&(pattern_table[i]));
printFormattedArray_P(pPattern);
if (memcmp_P(mycode, pPattern, sizeof(mycode)) == 0) { // returns zero if equal
Serial.println("match=yes");
}
else {
Serial.println("match=no");
}
}
}
void loop() {
}
void printFormattedArray(const unsigned int arrayA[]) {
// print array elements up to the end or the first 0
Serial.print("{");
int i = 0;
while (i < 30) {
Serial.print(arrayA[i]);
i++;
if (i == 30)
Serial.println("}");
else
Serial.print(",");
}
}
void printFormattedArray_P(const unsigned int *p) {
// print array elements up to the end or the first 0
Serial.print("{");
int i = 0;
while (i < 30) {
Serial.print(pgm_read_word_near(p + i));
i++;
if (i == 30)
Serial.println("}");
else
Serial.print(",");
}
}