Browse Source

Added "identify" command

The GUI will have a button to identify a particular PD Buddy Sink, in
case several are connected to the computer at once.  The button will
cause the LED to blink quickly for a couple seconds, then go back to
normal.  To allow this, I added a new LED blink mode (FAST_BLINK_SLOW)
that causes 8 fast blinks, then returns to SLOW_BLINK mode.  A new
"identify" command triggers this LED mode.
Clara Hobbs 7 years ago
parent
commit
efec067df9
3 changed files with 30 additions and 2 deletions
  1. 14
    1
      src/led.c
  2. 1
    0
      src/led.h
  3. 15
    1
      src/shell.c

+ 14
- 1
src/led.c View File

@@ -27,8 +27,9 @@
27 27
 #define LED_MEDIUM MS2ST(250)
28 28
 #define LED_SLOW MS2ST(500)
29 29
 
30
-/* Number of blinks for medium blink off mode */
30
+/* Number of blinks for temporary modes */
31 31
 #define LED_MEDIUM_BLINKS 3
32
+#define LED_FAST_BLINKS 8
32 33
 
33 34
 
34 35
 thread_t *pdb_led_thread;
@@ -100,6 +101,18 @@ static THD_FUNCTION(LED, arg) {
100 101
                     palToggleLine(LINE_LED);
101 102
                 }
102 103
                 break;
104
+            case PDB_EVT_LED_FAST_BLINK_SLOW:
105
+                timeout = LED_FAST;
106
+                if (i == 0) {
107
+                    palSetLine(LINE_LED);
108
+                } else if (i < (LED_FAST_BLINKS * 2)) {
109
+                    palToggleLine(LINE_LED);
110
+                } else {
111
+                    palClearLine(LINE_LED);
112
+                    timeout = TIME_INFINITE;
113
+                    chEvtSignal(pdb_led_thread, PDB_EVT_LED_SLOW_BLINK);
114
+                }
115
+                break;
103 116
             default:
104 117
                 break;
105 118
         }

+ 1
- 0
src/led.h View File

@@ -28,6 +28,7 @@
28 28
 #define PDB_EVT_LED_FAST_BLINK EVENT_MASK(2)
29 29
 #define PDB_EVT_LED_MEDIUM_BLINK_OFF EVENT_MASK(3)
30 30
 #define PDB_EVT_LED_SLOW_BLINK EVENT_MASK(4)
31
+#define PDB_EVT_LED_FAST_BLINK_SLOW EVENT_MASK(5)
31 32
 
32 33
 /* The LED thread object */
33 34
 extern thread_t *pdb_led_thread;

+ 15
- 1
src/shell.c View File

@@ -43,6 +43,7 @@
43 43
 
44 44
 #include "usbcfg.h"
45 45
 #include "storage.h"
46
+#include "led.h"
46 47
 
47 48
 
48 49
 /* Buffer for unwritten configuration */
@@ -131,7 +132,7 @@ static void cmd_get_tmpcfg(BaseSequentialStream *chp, int argc, char *argv[])
131 132
 {
132 133
     (void) argv;
133 134
     if (argc > 0) {
134
-        chprintf(chp, "Usage: get_tmpcfg [index]\r\n");
135
+        chprintf(chp, "Usage: get_tmpcfg\r\n");
135 136
         return;
136 137
     }
137 138
 
@@ -178,6 +179,18 @@ static void cmd_set_i(BaseSequentialStream *chp, int argc, char *argv[])
178 179
     }
179 180
 }
180 181
 
182
+static void cmd_identify(BaseSequentialStream *chp, int argc, char *argv[])
183
+{
184
+    (void) chp;
185
+    (void) argv;
186
+    if (argc > 0) {
187
+        chprintf(chp, "Usage: identify\r\n");
188
+        return;
189
+    }
190
+
191
+    chEvtSignal(pdb_led_thread, PDB_EVT_LED_FAST_BLINK_SLOW);
192
+}
193
+
181 194
 static const struct pdb_shell_cmd commands[] = {
182 195
     {"erase", cmd_erase, "Erase all stored configuration"},
183 196
     {"write", cmd_write, "Write the changes to flash"},
@@ -189,6 +202,7 @@ static const struct pdb_shell_cmd commands[] = {
189 202
     {"set_v", cmd_set_v, "Set the voltage in millivolts"},
190 203
     {"set_i", cmd_set_i, "Set the current in milliamps"},
191 204
     /* TODO {"set_v_range", cmd_set_v_range, "Set the minimum and maximum voltage in millivolts"},*/
205
+    {"identify", cmd_identify, "Blink the LED to identify the device"},
192 206
     {NULL, NULL, NULL}
193 207
 };
194 208
 

Loading…
Cancel
Save