Enhance parameter support

This commit is contained in:
Daniel Rojas 2020-05-22 16:36:29 +02:00
parent 485f7af747
commit 140966f5bc
2 changed files with 16 additions and 15 deletions

View File

@ -8,9 +8,9 @@ COLORS_I2C = ('BK', 'RD', 'YE', 'GN')
PINOUT_SPI_DATAONLY = ('MISO','MOSI','SCK')
# example 1
X1 = wireviz.Node('X1', type='D-Sub DE-9', gender='female', pinout=PINOUT_SERIAL, ports_right=True)
X1 = wireviz.Node('X1', type='D-Sub', gender='female', pinout=PINOUT_SERIAL, ports_right=True)
X2 = wireviz.Node('X2', type='Molex KK 254', gender='female', num_pins=6, ports_left=True)
W1 = wireviz.Cable('W1', mm2=0.25, length=0.2, show_name=False, show_pinout=False, num_wires=3, color_code='DIN', shield=True)
W1 = wireviz.Cable('W1', mm2=0.25, length=0.2, show_name=True, show_pinout=True, num_wires=3, color_code='DIN', shield=True)
# Option 1: define wires and shield in one line
# W1.connect(X1,(5,2,3,5),(1,2,3,'s'),X2,(1,3,2,None))
# Option 2: define wires and shield separately
@ -20,7 +20,7 @@ X2.loop(5,6)
objects = [X1, X2, W1]
# example 2
# X1 = wireviz.Node('X1', pinout=(
# X1 = wireviz.Node('X1',type='Molex KK 254', gender='female', pinout=(
# 'GND',
# '+5V',
# 'SCL',
@ -30,14 +30,14 @@ objects = [X1, X2, W1]
# 'SCK',
# 'N/C'
# ), ports_right=True)
# X2 = wireviz.Node('X2', pinout=PINOUT_I2C, ports_left=True)
# X3 = wireviz.Node('X3', pinout=PINOUT_I2C, ports_left=True)
# X4 = wireviz.Node('X4', pinout=('GND','+12V')+PINOUT_SPI_DATAONLY, ports_left=True)
# X5 = wireviz.Node('X5', pinout=('GND','+12V'), ports_right=True)
# 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'))
# X2 = wireviz.Node('X2', type='Molex KK 254', gender='female', pinout=PINOUT_I2C, ports_left=True)
# X3 = wireviz.Node('X3', type='Molex KK 254', gender='female', pinout=PINOUT_I2C, ports_left=True)
# X4 = wireviz.Node('X4', type='Molex KK 254', gender='female', pinout=('GND','+12V')+PINOUT_SPI_DATAONLY, ports_left=True)
# X5 = wireviz.Node('X5', type='Molex Micro-Fit', gender='male', pinout=('GND','+12V'), ports_right=True)
# W1 = wireviz.Cable('W1', mm2=0.14, length=0.2, colors=COLORS_I2C)
# W2 = wireviz.Cable('W2', mm2=0.14, length=0.2, colors=COLORS_I2C)
# W3 = wireviz.Cable('W3', mm2=0.14, length=0.2, colors=('BK','BU','OG','VT'))
# W4 = wireviz.Cable('W4', mm2=0.5, length=0.35, colors=('BK','RD'))
# 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))

View File

@ -63,15 +63,15 @@ class Node:
if self.show_name == True:
s = s + '{name} | '.format(name=self.name)
#print parameters
s = s + '{'
l = []
if self.type is not None:
l.append('{}'.format(self.type))
if self.gender is not None:
l.append('{}'.format(self.gender))
l.append('{}-pin'.format(len(self.pinout)))
if len(l) > 0:
s = s + ', '.join(l)
s = s + '|'.join(l)
s = s + '} | '
s = s + '{'
@ -138,8 +138,6 @@ class Cable:
self.colors = colors
else:
self.colors = colors[:num_wires]
# if shield == True:
# self.colors = self.colors + ('Shield',)
def connect(self, from_name, from_pin, via, to_name, to_pin):
if from_pin == 'auto':
@ -182,10 +180,13 @@ class Cable:
#print parameters
s = s + '{'
l = []
l.append('{}x'.format(len(self.colors)))
if self.mm2 > 0:
l.append('{} mm²'.format(self.mm2))
if self.awg > 0:
l.append('{} AWG'.format(self.awg))
if self.shield == True:
l.append(' + S')
if self.length > 0:
l.append('{} m'.format(self.length))
if len(l) > 0: