Create first draft of wireviz Python module
This commit is contained in:
parent
6b258179bc
commit
072958d1a3
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
temp/
|
||||||
|
|||||||
1
src/.gitignore
vendored
Normal file
1
src/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
__pycache__/
|
||||||
20
src/test.py
Normal file
20
src/test.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import wireviz
|
||||||
|
|
||||||
|
PINOUT_I2C = ("GND","VCC","SCL","SDA")
|
||||||
|
COLORS_WEIRD = ("infrared","ultraviolet","transparent","invisible")
|
||||||
|
|
||||||
|
X1 = wireviz.Node("X1", num_pins=4)
|
||||||
|
X2 = wireviz.Node("X2", pinout=PINOUT_I2C)
|
||||||
|
X3 = wireviz.Node("X3", pinout=PINOUT_I2C)
|
||||||
|
|
||||||
|
W1 = wireviz.Cable("W1", num_wires=4)
|
||||||
|
W2 = wireviz.Cable("W2", num_wires=4, color_code="DIN")
|
||||||
|
W3 = wireviz.Cable("W3", num_wires=3, colors=COLORS_WEIRD)
|
||||||
|
|
||||||
|
print(X1)
|
||||||
|
print(X2)
|
||||||
|
print(X3)
|
||||||
|
|
||||||
|
print(W1)
|
||||||
|
print(W2)
|
||||||
|
print(W3)
|
||||||
56
src/wireviz.py
Normal file
56
src/wireviz.py
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
|
||||||
|
COLOR_CODE_DIN = ['WH','BN','GN','YE','GY','PK','BU','RD','BK','VT']
|
||||||
|
COLOR_CODE_IEC = ['BN','RD','OG','YE','GN','BU','VT','GY','WH','BK']
|
||||||
|
|
||||||
|
class Node:
|
||||||
|
|
||||||
|
def __init__(self, name, num_pins=None, pinout=None):
|
||||||
|
self.name = name
|
||||||
|
|
||||||
|
if pinout is None:
|
||||||
|
self.pinout = ("",) * num_pins
|
||||||
|
else:
|
||||||
|
if num_pins is None:
|
||||||
|
if pinout is None:
|
||||||
|
raise Exception("Must provide num_pins or pinout")
|
||||||
|
else:
|
||||||
|
self.pinout = pinout
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "{} = {} {}".format(self.name, len(self.pinout), self.pinout)
|
||||||
|
|
||||||
|
class Cable:
|
||||||
|
|
||||||
|
def __init__(self, name, num_wires=None, colors=None, color_code=None):
|
||||||
|
self.name = name
|
||||||
|
if color_code is None and colors is None:
|
||||||
|
self.colors = ("",) * num_wires
|
||||||
|
else:
|
||||||
|
if colors is None:
|
||||||
|
if num_wires is None:
|
||||||
|
raise Exception("Unknown number of wires")
|
||||||
|
else:
|
||||||
|
# TODO: Loop through colors if num_wires > len(COLOR_CODE_XXX)
|
||||||
|
if color_code == "DIN":
|
||||||
|
self.colors = tuple(COLOR_CODE_DIN[:num_wires])
|
||||||
|
elif color_code == "IEC":
|
||||||
|
self.colors = tuple(COLOR_CODE_IEC[:num_wires])
|
||||||
|
else:
|
||||||
|
raise Exception("Unknown color code")
|
||||||
|
else:
|
||||||
|
if num_wires is None:
|
||||||
|
self.colors = colors
|
||||||
|
else:
|
||||||
|
self.colors = colors[:num_wires]
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "{} = {} {}".format(self.name, len(self.colors), self.colors)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# class ClassName(object):
|
||||||
|
# """docstring for ."""
|
||||||
|
#
|
||||||
|
# def __init__(self, arg):
|
||||||
|
# super(, self).__init__()
|
||||||
|
# self.arg = arg
|
||||||
Loading…
x
Reference in New Issue
Block a user