Browse Source

Support PPD APDOs

This commit adds the SourcePPSAPDO class for holding information from a
Source Programmable Power Supply APDO.  It can be read and written and
printed and all that fun stuff.
Clara Hobbs 6 years ago
parent
commit
d1da298bd5
2 changed files with 47 additions and 1 deletions
  1. 37
    1
      pdbuddy/__init__.py
  2. 10
    0
      test_pdbuddy/__init__.py

+ 37
- 1
pdbuddy/__init__.py View File

@@ -240,7 +240,7 @@ class Sink:
240 240
 
241 241
         # Set voltage range
242 242
         self.set_vrange(sc.vmin, sc.vmax)
243
-        
243
+
244 244
         if sc.idim is SinkDimension.CURRENT:
245 245
             # Set current
246 246
             self.set_i(sc.i)
@@ -483,6 +483,27 @@ class SrcFixedPDO(namedtuple("SrcFixedPDO", "dual_role_pwr usb_suspend "
483 483
         return s
484 484
 
485 485
 
486
+class SourcePPSAPDO(namedtuple("SourcePPSAPDO", "vmin vmax i")):
487
+    """A Source Programmable Power Supply APDO
488
+
489
+    ``vmin`` and ``vmax`` are the minimum and maximum voltage in millivolts,
490
+    respectively, and ``i`` is the maximum current in milliamperes.
491
+    """
492
+    __slots__ = ()
493
+
494
+    pdo_type = "pps"
495
+
496
+    def __str__(self):
497
+        """Print the SourcePPSAPDO in the manner of the configuration shell"""
498
+        s = self.pdo_type + "\n"
499
+
500
+        s += "\tvmin: {:.2f} V\n".format(self.vmin / 1000.0)
501
+        s += "\tvmax: {:.2f} V\n".format(self.vmax / 1000.0)
502
+        s += "\ti: {:.2f} A".format(self.i / 1000.0)
503
+
504
+        return s
505
+
506
+
486 507
 class TypeCVirtualPDO(namedtuple("TypeCVirtualPDO", "i")):
487 508
     """A Type-C Current Virtual PDO
488 509
 
@@ -551,6 +572,21 @@ def read_pdo(text):
551 572
                 peak_i=peak_i,
552 573
                 v=v,
553 574
                 i=i)
575
+    elif pdo_type == SourcePPSAPDO.pdo_type:
576
+        # Load a SourcePPSAPDO
577
+        for line in text[1:]:
578
+            fields = line.split(b":")
579
+            fields[0] = fields[0].strip()
580
+            fields[1] = fields[1].strip()
581
+            if fields[0] == b"vmin":
582
+                vmin = round(1000*float(fields[1].split()[0]))
583
+            if fields[0] == b"vmax":
584
+                vmax = round(1000*float(fields[1].split()[0]))
585
+            if fields[0] == b"i":
586
+                i = round(1000*float(fields[1].split()[0]))
587
+
588
+        # Make the SourcePPSAPDO
589
+        return SourcePPSAPDO(vmin=vmin, vmax=vmax, i=i)
554 590
     elif pdo_type == TypeCVirtualPDO.pdo_type:
555 591
         # Load a TypeCVirtualPDO
556 592
         for line in text[1:]:

+ 10
- 0
test_pdbuddy/__init__.py View File

@@ -397,6 +397,16 @@ class SrcFixedPDOTestCase(unittest.TestCase):
397 397
                 "fixed\n\tv: 5.00 V\n\ti: 1.50 A")
398 398
 
399 399
 
400
+class SourcePPSAPDOTestCase(unittest.TestCase):
401
+
402
+    def setUp(self):
403
+        self.obj_15v = pdbuddy.SourcePPSAPDO(3000, 16000, 3000)
404
+
405
+    def test_str_15v(self):
406
+        self.assertEqual(str(self.obj_15v), "pps\n\tvmin: 3.00 V\n"
407
+                "\tvmax: 16.00 V\n\ti: 3.00 A")
408
+
409
+
400 410
 class TypeCVirtualPDOTestCase(unittest.TestCase):
401 411
 
402 412
     def setUp(self):

Loading…
Cancel
Save