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
 #define LED_MEDIUM MS2ST(250)
27
 #define LED_MEDIUM MS2ST(250)
28
 #define LED_SLOW MS2ST(500)
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
 #define LED_MEDIUM_BLINKS 3
31
 #define LED_MEDIUM_BLINKS 3
32
+#define LED_FAST_BLINKS 8
32
 
33
 
33
 
34
 
34
 thread_t *pdb_led_thread;
35
 thread_t *pdb_led_thread;
100
                     palToggleLine(LINE_LED);
101
                     palToggleLine(LINE_LED);
101
                 }
102
                 }
102
                 break;
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
             default:
116
             default:
104
                 break;
117
                 break;
105
         }
118
         }

+ 1
- 0
src/led.h View File

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

+ 15
- 1
src/shell.c View File

43
 
43
 
44
 #include "usbcfg.h"
44
 #include "usbcfg.h"
45
 #include "storage.h"
45
 #include "storage.h"
46
+#include "led.h"
46
 
47
 
47
 
48
 
48
 /* Buffer for unwritten configuration */
49
 /* Buffer for unwritten configuration */
131
 {
132
 {
132
     (void) argv;
133
     (void) argv;
133
     if (argc > 0) {
134
     if (argc > 0) {
134
-        chprintf(chp, "Usage: get_tmpcfg [index]\r\n");
135
+        chprintf(chp, "Usage: get_tmpcfg\r\n");
135
         return;
136
         return;
136
     }
137
     }
137
 
138
 
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
 static const struct pdb_shell_cmd commands[] = {
194
 static const struct pdb_shell_cmd commands[] = {
182
     {"erase", cmd_erase, "Erase all stored configuration"},
195
     {"erase", cmd_erase, "Erase all stored configuration"},
183
     {"write", cmd_write, "Write the changes to flash"},
196
     {"write", cmd_write, "Write the changes to flash"},
189
     {"set_v", cmd_set_v, "Set the voltage in millivolts"},
202
     {"set_v", cmd_set_v, "Set the voltage in millivolts"},
190
     {"set_i", cmd_set_i, "Set the current in milliamps"},
203
     {"set_i", cmd_set_i, "Set the current in milliamps"},
191
     /* TODO {"set_v_range", cmd_set_v_range, "Set the minimum and maximum voltage in millivolts"},*/
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
     {NULL, NULL, NULL}
206
     {NULL, NULL, NULL}
193
 };
207
 };
194
 
208
 

Loading…
Cancel
Save