send and receive master/slave codes

This commit is contained in:
King Kévin 2022-10-13 16:05:09 +02:00
parent 1ea913a058
commit ad3b844978
1 changed files with 26 additions and 1 deletions

27
main.c
View File

@ -448,12 +448,37 @@ void main(void)
rgb[1] = 0;
rgb[2] = 0;
}
led_rgb(rgb); // ensure [new] color is set
} else if (0x01 == nec_msg[0]) { // badge tries to influence us
for (uint8_t i = 0; i < 3; i++) {
if (nec_msg[1 + i] > rgb[i]) {
rgb[i]++;
} else if (nec_msg[1 + i] < rgb[i]) {
rgb[i]--;
}
}
led_rgb(rgb); // set new color
} else if (0x02 == nec_msg[0]) { // master sets our color
rgb[0] = nec_msg[1];
rgb[1] = nec_msg[2];
rgb[2] = nec_msg[3];
led_rgb(rgb); // set new color
}
nec_flag = false; // clear flag
action = true; // redo loop
}
if (0 == time_count % (488UL * SHARE_TIME)) {
nec_transmit(0xfb047f80);
uint32_t code; // code to send
if (master) {
code = 0x02000000;
} else {
code = 0x01000000;
}
code |= ((uint32_t)rgb[0] << 8);
code |= ((uint32_t)rgb[1] << 16);
code |= ((uint32_t)rgb[2] << 24);
nec_transmit(code);
timer_ir_in(); // go back to IR capture
putc('t');
action = true; // redo main loop
}