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

Loading…
Cancel
Save