Add simple auto-wiring

This commit is contained in:
Daniel Rojas 2020-05-22 14:05:36 +02:00
parent c63da45d8f
commit da258ceaa8
2 changed files with 13 additions and 4 deletions

View File

@ -34,10 +34,10 @@ W1 = wireviz.Cable("W1", colors=COLORS_I2C)
W2 = wireviz.Cable("W2", colors=COLORS_I2C)
W3 = wireviz.Cable("W3", colors=('BK','BU','OG','VT'))
W4 = wireviz.Cable("W4", colors=('BK','RD'))
W1.connect(X1,(1,2,3,4),(1,2,3,4),X2,(1,2,3,4))
W2.connect(X1,(1,2,3,4),(1,2,3,4),X3,(1,2,3,4))
W3.connect(X1,(1,5,6,7),(1,2,3,4),X4,(1,3,4,5))
W4.connect(X5,(1,2),(1,2),X4,(1,2))
W1.connect(X1,(1,2,3,4),'auto',X2,'auto')
W2.connect(X1,(1,2,3,4),'auto',X3,'auto')
W3.connect(X1,(1,5,6,7),'auto',X4,(1,3,4,5))
W4.connect(X5,'auto','auto',X4,'auto')
objects = [X1, X2, X3, X4, X5, W1, W2, W3, W4]
with open('output/output.dot','w') as f:

View File

@ -117,11 +117,20 @@ class Cable:
self.colors = self.colors + ('Shield',)
def connect(self, from_name, from_pin, via, to_name, to_pin):
if from_pin == 'auto':
from_pin = tuple(x+1 for x in range(len(self.colors)))
if via == 'auto':
via = tuple(x+1 for x in range(len(self.colors)))
if to_pin == 'auto':
to_pin = tuple(x+1 for x in range(len(self.colors)))
if len(from_pin) != len(to_pin):
raise Exception("from_pin must have the same number of elements as to_pin")
for i, x in enumerate(from_pin):
self.connections.append((from_name, from_pin[i], via[i], to_name, to_pin[i]))
def connect_all_straight(self, from_name, to_name):
self.connect(from_name, 'auto', 'auto', to_name, 'auto')
def __repr__(self):
return "{} = {} {}\n {}".format(self.name, len(self.colors), self.colors, self.connections)