add master broacast time

This commit is contained in:
King Kévin 2022-10-13 16:27:33 +02:00
parent 9696a136f2
commit 9b16b17628
1 changed files with 14 additions and 8 deletions

22
main.c
View File

@ -47,8 +47,10 @@ static volatile uint32_t time_count = 0;
// time after last shake to go to sleep, in seconds
#define REST_TIME (5 * 60U)
// period to send our color code, in seconds
// period to share our color code, in seconds
#define SHARE_TIME (1U)
// period to enforce our color code, in seconds
#define MASTER_TIME (1U)
// time counts per us (1/(16E6/(3+1)) * 1000*1000 = 0.25 us)
#define NEC_TICKS_PER_US 4UL
@ -467,13 +469,8 @@ void main(void)
nec_flag = false; // clear flag
action = true; // redo loop
}
if (0 == time_count % (488UL * SHARE_TIME)) {
uint32_t code; // code to send
if (master) {
code = 0x02000000;
} else {
code = 0x01000000;
}
if (!master && 0 == time_count % (488UL * SHARE_TIME)) {
uint32_t code = 0x01000000; // code to send
code |= ((uint32_t)rgb[0] << 8);
code |= ((uint32_t)rgb[1] << 16);
code |= ((uint32_t)rgb[2] << 24);
@ -482,6 +479,15 @@ void main(void)
putc('t');
action = true; // redo main loop
}
if (master && 0 == time_count % (488UL * MASTER_TIME)) {
uint32_t code = 0x02000000; // code to send
code |= ((uint32_t)rgb[0] << 8);
code |= ((uint32_t)rgb[1] << 16);
code |= ((uint32_t)rgb[2] << 24);
nec_transmit(code);
putc('m');
action = true; // redo main loop
}
if (time_count > 488UL * REST_TIME && !master) {
puts("rest\r\n");
time_count = 0; // reset counter