From 3bd849ea92babcb95cd3b2bafd45744a49378395 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Tue, 20 Mar 2018 16:27:53 +0000 Subject: [PATCH] add Interface class --- src/interface_decl.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/interface_decl.py b/src/interface_decl.py index a74e812..79710d4 100644 --- a/src/interface_decl.py +++ b/src/interface_decl.py @@ -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) + -- 2.30.2