add Interface class
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 20 Mar 2018 16:27:53 +0000 (16:27 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 20 Mar 2018 16:27:53 +0000 (16:27 +0000)
src/interface_decl.py

index a74e812fd005a0358f9b7cf0a9f8670934db8a94..79710d41433d687a53c425c60cf23446cda086e4 100644 (file)
@@ -104,6 +104,18 @@ class Pin(object):
         res += ";"
         return res
 
+
+class Interface(object):
+
+    def __init__(self, pinspecs):
+        self.pins = []
+        for p in pinspecs:
+            self.pins.append(Pin(**p))
+
+    def __str__(self):
+        return '\n'.join(map(str, self.pins))
+
+
 # basic test
 if __name__ == '__main__':
 
@@ -125,7 +137,7 @@ if __name__ == '__main__':
         p = _pinmunge(p, " ", " ")
         return p
 
-    pwm = Pin("pwm{0}", True, True, True, True)
-    print pinmunge(str(pwm))
-    print pinmunge(pwminterface_decl)
+    pwm = Interface([{'name': "pwm{0}", 'action': True}])
+    print pwm
     assert pinmunge(str(pwm)) == pinmunge(pwminterface_decl)
+