Browse Source

Add set_vrange command

Just as described in console_config.md.  Soon the DPM will even use the
range when making requests.
Clara Hobbs 4 years ago
parent
commit
318cac4f7d
1 changed files with 25 additions and 1 deletions
  1. 25
    1
      src/shell.c

+ 25
- 1
src/shell.c View File

@@ -337,6 +337,30 @@ static void cmd_set_v(BaseSequentialStream *chp, int argc, char *argv[])
337 337
     }
338 338
 }
339 339
 
340
+static void cmd_set_vrange(BaseSequentialStream *chp, int argc, char *argv[])
341
+{
342
+    if (argc != 2) {
343
+        chprintf(chp, "Usage: set_vrange min_voltage_in_mV max_voltage_in_mV\r\n");
344
+        return;
345
+    }
346
+
347
+    char *endptr;
348
+    long min = strtol(argv[0], &endptr, 0);
349
+    char *endptr2;
350
+    long max = strtol(argv[1], &endptr2, 0);
351
+    if (min < PD_MV_MIN || min > PD_MV_MAX || endptr <= argv[0]
352
+            || max < PD_MV_MIN || max > PD_MV_MAX || endptr2 <= argv[1]) {
353
+        chprintf(chp, "Invalid voltage\r\n");
354
+        return;
355
+    }
356
+    if (min > max) {
357
+        chprintf(chp, "Invalid range\r\n");
358
+        return;
359
+    }
360
+    tmpcfg.vmin = min;
361
+    tmpcfg.vmax = max;
362
+}
363
+
340 364
 static void cmd_set_i(BaseSequentialStream *chp, int argc, char *argv[])
341 365
 {
342 366
     if (argc != 1) {
@@ -437,7 +461,7 @@ static const struct pdbs_shell_cmd commands[] = {
437 461
     {"toggle_hv_preferred", cmd_toggle_hv_preferred, "Toggle the HV_Preferred flag"},
438 462
     /* TODO {"toggle_var_bat", cmd_toggle_var_bat, "Toggle the Var/Bat flag"},*/
439 463
     {"set_v", cmd_set_v, "Set the voltage in millivolts"},
440
-    /* TODO {"set_vrange", cmd_set_vrange, "Set the minimum and maximum voltage in millivolts"},*/
464
+    {"set_vrange", cmd_set_vrange, "Set the minimum and maximum voltage in millivolts"},
441 465
     {"set_i", cmd_set_i, "Set the current in milliamps"},
442 466
     {"output", cmd_output, "Get or set the output status"},
443 467
     {"get_source_cap", cmd_get_source_cap, "Print the capabilities of the PD source"},

Loading…
Cancel
Save