Przeglądaj źródła

Improved error handling for set_v and set_i

Now the error behavior for set_v and set_i is well-defined by the
documentation: they print nothing on success and an error message on
failure.  The range of valid values is now [0, 20000] for set_v and
[0, 5000] for set_i, matching the voltages and currents that can be
provided by USB Power Delivery.

Bumped version number to 1.0.1, reflecting this bugfix.
Clara Hobbs 7 lat temu
rodzic
commit
0706adb3f7
4 zmienionych plików z 20 dodań i 6 usunięć
  1. 5
    3
      docs/console_config.md
  2. 12
    0
      src/pd.h
  3. 2
    2
      src/shell.c
  4. 1
    1
      src/usbcfg.c

+ 5
- 3
docs/console_config.md Wyświetl plik

@@ -1,6 +1,6 @@
1 1
 # PD Buddy Sink Serial Console Configuration Interface
2 2
 
3
-Version 1.0.0, 2017-06-05
3
+Version 1.0.1, 2017-06-19
4 4
 
5 5
 The PD Buddy Sink can be put into setup mode by holding the Setup button while
6 6
 plugging it into a computer.  In this mode, the device does not perform any USB
@@ -152,7 +152,8 @@ battery.
152 152
 
153 153
 Usage: `set_v voltage_in_mV`
154 154
 
155
-Sets the voltage of the configuration buffer, in millivolts.
155
+Sets the voltage of the configuration buffer, in millivolts.  Prints no output
156
+on success, an error message on failure.
156 157
 
157 158
 Note: values are rounded down to the nearest Power Delivery voltage unit
158 159
 (50 mV).
@@ -161,7 +162,8 @@ Note: values are rounded down to the nearest Power Delivery voltage unit
161 162
 
162 163
 Usage: `set_i current_in_mA`
163 164
 
164
-Sets the current of the configuration buffer, in milliamperes.
165
+Sets the current of the configuration buffer, in milliamperes.  Prints no
166
+output on success, an error message on failure.
165 167
 
166 168
 Note: values are rounded down to the nearest Power Delivery current unit
167 169
 (10 mA).

+ 12
- 0
src/pd.h Wyświetl plik

@@ -256,5 +256,17 @@
256 256
 #define PD_PDI_A(pdv) ((pdv) / 100)
257 257
 #define PD_PDI_CA(pdv) ((pdv) % 100)
258 258
 
259
+/*
260
+ * Unit constants
261
+ */
262
+#define PD_MV_MIN 0
263
+#define PD_MV_MAX 20000
264
+#define PD_PDV_MIN PD_MV2PDV(PD_MV_MIN)
265
+#define PD_PDV_MAX PD_MV2PDV(PD_MV_MAX)
266
+#define PD_MA_MIN 0
267
+#define PD_MA_MAX 5000
268
+#define PD_PDI_MIN PD_MA2PDI(PD_MA_MIN)
269
+#define PD_PDI_MAX PD_MA2PDI(PD_MA_MAX)
270
+
259 271
 
260 272
 #endif /* PDB_PD_H */

+ 2
- 2
src/shell.c Wyświetl plik

@@ -198,7 +198,7 @@ static void cmd_set_v(BaseSequentialStream *chp, int argc, char *argv[])
198 198
 
199 199
     char *endptr;
200 200
     long i = strtol(argv[0], &endptr, 0);
201
-    if (i >= 0 && i <= UINT16_MAX && endptr > argv[0]) {
201
+    if (i >= PD_MV_MIN && i <= PD_MV_MAX && endptr > argv[0]) {
202 202
         /* Convert mV to the unit used by USB PD */
203 203
         tmpcfg.v = PD_MV2PDV(i);
204 204
     } else {
@@ -216,7 +216,7 @@ static void cmd_set_i(BaseSequentialStream *chp, int argc, char *argv[])
216 216
 
217 217
     char *endptr;
218 218
     long i = strtol(argv[0], &endptr, 0);
219
-    if (i >= 0 && i <= UINT16_MAX && endptr > argv[0]) {
219
+    if (i >= PD_MA_MIN && i <= PD_MA_MAX && endptr > argv[0]) {
220 220
         /* Convert mA to the unit used by USB PD */
221 221
         tmpcfg.i = PD_MA2PDI(i);
222 222
     } else {

+ 1
- 1
src/usbcfg.c Wyświetl plik

@@ -189,7 +189,7 @@ static const uint8_t vcom_string2[] = {
189 189
 static const uint8_t vcom_string3[] = {
190 190
     USB_DESC_BYTE(12),                    /* bLength.                         */
191 191
     USB_DESC_BYTE(USB_DESCRIPTOR_STRING), /* bDescriptorType.                 */
192
-    '1', 0, '.', 0, '0', 0, '.', 0, '0', 0
192
+    '1', 0, '.', 0, '0', 0, '.', 0, '1', 0
193 193
 };
194 194
 
195 195
 /*

Ładowanie…
Anuluj
Zapisz