Browse Source

Document the main function better

Clara Hobbs 6 years ago
parent
commit
3be4c2f183
1 changed files with 13 additions and 3 deletions
  1. 13
    3
      src/main.c

+ 13
- 3
src/main.c View File

@@ -59,9 +59,10 @@
59 59
 
60 60
 
61 61
 /*
62
- * RC5 timing macros (microseconds)
62
+ * RC5 timing macros (microseconds, unless otherwise specified)
63 63
  */
64 64
 #define RC5_PULSE_LENGTH 889
65
+#define RC5_CODE_SPACE_MS 90 /* Milliseconds */
65 66
 
66 67
 /*
67 68
  * NEC timing macros (tenths of a millisecond)
@@ -246,19 +247,28 @@ int main(void)
246 247
     /* Configure GPT */
247 248
     gptStart(&GPTD4, &gpt4cfg);
248 249
 
249
-    /* Send a continuous stream of power off signals to the TV */
250 250
     while (true) {
251
+        /* If an NEC power signal was received */
251 252
         if (nec_addr == 0x80 && nec_data == 0x18) {
253
+            /* Turn on the LED */
252 254
             palClearPad(GPIOC, GPIOC_LED);
255
+
256
+            /* Wait to see if another code arrives */
253 257
             if (chEvtWaitAnyTimeout(ALL_EVENTS, MS2ST(200))) {
258
+                /* If one does, keep waiting so as not to interfere */
254 259
                 continue;
255 260
             }
261
+
262
+            /* Send the RC5 power signal */
256 263
             for (int i = 0; i < 3; i++) {
257 264
                 rc5_frame(false, 0x00, 0x0C);
258
-                chThdSleepMilliseconds(90);
265
+                chThdSleepMilliseconds(RC5_CODE_SPACE_MS);
259 266
             }
267
+
268
+            /* Turn off the LED */
260 269
             palSetPad(GPIOC, GPIOC_LED);
261 270
         }
271
+        /* Wait for a signal */
262 272
         chEvtWaitAny(ALL_EVENTS);
263 273
     }
264 274
 }

Loading…
Cancel
Save