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

+ 3
- 0
src/device_policy_manager.h View File

24
 #include "messages.h"
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
 /* Whether the DPM sets the LED to indicate the PD status */
30
 /* Whether the DPM sets the LED to indicate the PD status */
28
 extern bool pdb_dpm_led_pd_status;
31
 extern bool pdb_dpm_led_pd_status;
29
 
32
 

+ 1
- 0
src/main.c View File

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

+ 29
- 0
src/shell.c View File

42
 #include "usbcfg.h"
42
 #include "usbcfg.h"
43
 #include "storage.h"
43
 #include "storage.h"
44
 #include "led.h"
44
 #include "led.h"
45
+#include "device_policy_manager.h"
45
 #include "policy_engine.h"
46
 #include "policy_engine.h"
46
 #include "pd.h"
47
 #include "pd.h"
47
 
48
 
244
     chEvtSignal(pdb_led_thread, PDB_EVT_LED_IDENTIFY);
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
  * List of shell commands
276
  * List of shell commands
249
  */
277
  */
261
     {"set_i", cmd_set_i, "Set the current in milliamps"},
289
     {"set_i", cmd_set_i, "Set the current in milliamps"},
262
     /* TODO {"set_v_range", cmd_set_v_range, "Set the minimum and maximum voltage in millivolts"},*/
290
     /* TODO {"set_v_range", cmd_set_v_range, "Set the minimum and maximum voltage in millivolts"},*/
263
     {"identify", cmd_identify, "Blink the LED to identify the device"},
291
     {"identify", cmd_identify, "Blink the LED to identify the device"},
292
+    {"output", cmd_output, "Get or set the output status"},
264
     {NULL, NULL, NULL}
293
     {NULL, NULL, NULL}
265
 };
294
 };
266
 
295
 

Loading…
Cancel
Save