Browse Source

Don't give up on transmitting the code

Before, we'd give up on transmitting the RC5 power signal if a different
NEC signal was received.  This resulted in some cases where the green
LED would get stuck on with no code being transmitted.

Now that doesn't happen anymore because we just wait until no more NEC
codes are received, then send the RC5 power signal.  That is, the power
signal only needs to be seen once, then once the channel is clear we
transmit.
Clara Hobbs 6 years ago
parent
commit
9b02a5011b
1 changed files with 6 additions and 7 deletions
  1. 6
    7
      src/main.c

+ 6
- 7
src/main.c View File

@@ -248,16 +248,17 @@ int main(void)
248 248
     gptStart(&GPTD4, &gpt4cfg);
249 249
 
250 250
     while (true) {
251
+        /* Wait for a signal */
252
+        chEvtWaitAny(ALL_EVENTS);
253
+
251 254
         /* If an NEC power signal was received */
252 255
         if (nec_addr == 0x80 && nec_data == 0x18) {
253 256
             /* Turn on the LED */
254 257
             palClearPad(GPIOC, GPIOC_LED);
255 258
 
256
-            /* Wait to see if another code arrives */
257
-            if (chEvtWaitAnyTimeout(ALL_EVENTS, MS2ST(200))) {
258
-                /* If one does, keep waiting so as not to interfere */
259
-                continue;
260
-            }
259
+            /* Wait until further codes stop arriving to avoid interfering */
260
+            while (chEvtWaitAnyTimeout(ALL_EVENTS, MS2ST(200)))
261
+                ;
261 262
 
262 263
             /* Send the RC5 power signal */
263 264
             for (int i = 0; i < 3; i++) {
@@ -268,7 +269,5 @@ int main(void)
268 269
             /* Turn off the LED */
269 270
             palSetPad(GPIOC, GPIOC_LED);
270 271
         }
271
-        /* Wait for a signal */
272
-        chEvtWaitAny(ALL_EVENTS);
273 272
     }
274 273
 }

Loading…
Cancel
Save