Browse Source

Added output command

Just as specified last night.  This represents the completion of a big
part of the new interactive Power Delivery features of the shell.
Next up: printing the source's advertised PDOs.
Clara Hobbs 7 years ago
parent
commit
2eebf02f91
4 changed files with 36 additions and 1 deletions
  1. 3
    1
      src/device_policy_manager.c
  2. 3
    0
      src/device_policy_manager.h
  3. 1
    0
      src/main.c
  4. 29
    0
      src/shell.c

+ 3
- 1
src/device_policy_manager.c View File

@@ -28,6 +28,8 @@
28 28
 #include "fusb302b.h"
29 29
 
30 30
 
31
+bool pdb_dpm_output_enabled = true;
32
+
31 33
 bool pdb_dpm_led_pd_status = true;
32 34
 
33 35
 bool pdb_dpm_usb_comms = false;
@@ -229,7 +231,7 @@ void pdb_dpm_output_set(bool state)
229 231
     dpm_present_voltage = dpm_requested_voltage;
230 232
 
231 233
     /* Set the power output */
232
-    if (state) {
234
+    if (state && pdb_dpm_output_enabled) {
233 235
         /* Turn the output on */
234 236
         if (pdb_dpm_led_pd_status) {
235 237
             chEvtSignal(pdb_led_thread, PDB_EVT_LED_OUTPUT_ON);

+ 3
- 0
src/device_policy_manager.h View File

@@ -24,6 +24,9 @@
24 24
 #include "messages.h"
25 25
 
26 26
 
27
+/* Whether the DPM is able to turn on the output */
28
+extern bool pdb_dpm_output_enabled;
29
+
27 30
 /* Whether the DPM sets the LED to indicate the PD status */
28 31
 extern bool pdb_dpm_led_pd_status;
29 32
 

+ 1
- 0
src/main.c View File

@@ -91,6 +91,7 @@ static void start_pd(void)
91 91
 static void setup(void)
92 92
 {
93 93
     /* Configure the DPM to play nice with the shell */
94
+    pdb_dpm_output_enabled = false;
94 95
     pdb_dpm_led_pd_status = false;
95 96
     pdb_dpm_usb_comms = true;
96 97
 

+ 29
- 0
src/shell.c View File

@@ -42,6 +42,7 @@
42 42
 #include "usbcfg.h"
43 43
 #include "storage.h"
44 44
 #include "led.h"
45
+#include "device_policy_manager.h"
45 46
 #include "policy_engine.h"
46 47
 #include "pd.h"
47 48
 
@@ -244,6 +245,33 @@ static void cmd_identify(BaseSequentialStream *chp, int argc, char *argv[])
244 245
     chEvtSignal(pdb_led_thread, PDB_EVT_LED_IDENTIFY);
245 246
 }
246 247
 
248
+static void cmd_output(BaseSequentialStream *chp, int argc, char *argv[])
249
+{
250
+    if (argc == 0) {
251
+        /* With no arguments, print the output status */
252
+        if (pdb_dpm_output_enabled) {
253
+            chprintf(chp, "enabled\r\n");
254
+        } else {
255
+            chprintf(chp, "disabled\r\n");
256
+        }
257
+    } else if (argc == 1) {
258
+        /* Set the output status and re-negotiate power */
259
+        if (strcmp(argv[0], "enable") == 0) {
260
+            pdb_dpm_output_enabled = true;
261
+            chEvtSignal(pdb_pe_thread, PDB_EVT_PE_GET_SOURCE_CAP);
262
+        } else if (strcmp(argv[0], "disable") == 0) {
263
+            pdb_dpm_output_enabled = false;
264
+            chEvtSignal(pdb_pe_thread, PDB_EVT_PE_GET_SOURCE_CAP);
265
+        } else {
266
+            /* Or, if the argument was invalid, print a usage message */
267
+            chprintf(chp, "Usage: output [enable|disable]\r\n");
268
+        }
269
+    } else {
270
+        /* If there are too many arguments, print a usage message */
271
+        chprintf(chp, "Usage: output [enable|disable]\r\n");
272
+    }
273
+}
274
+
247 275
 /*
248 276
  * List of shell commands
249 277
  */
@@ -261,6 +289,7 @@ static const struct pdb_shell_cmd commands[] = {
261 289
     {"set_i", cmd_set_i, "Set the current in milliamps"},
262 290
     /* TODO {"set_v_range", cmd_set_v_range, "Set the minimum and maximum voltage in millivolts"},*/
263 291
     {"identify", cmd_identify, "Blink the LED to identify the device"},
292
+    {"output", cmd_output, "Get or set the output status"},
264 293
     {NULL, NULL, NULL}
265 294
 };
266 295
 

Loading…
Cancel
Save