Skip to content

Instantly share code, notes, and snippets.

@alessaba
Last active December 14, 2020 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alessaba/e9b5c7304d641dbd20ed807d8c528675 to your computer and use it in GitHub Desktop.
Save alessaba/e9b5c7304d641dbd20ed807d8c528675 to your computer and use it in GitHub Desktop.
Interacts with the DCSD Alex Cable's Status LEDs. This can be adapted to any use case you want.
#!/usr/bin/python3
try:
import pylibftdi
except ImportError:
import os
os.system("brew install libftdi libusb; brew link libusb; pip3 install pylibftdi")
print("Dependencies installed.\n")
# Device Config
pylibftdi.USB_PID_LIST.append(0x8a88) # PID
pylibftdi.USB_VID_LIST.append(0x0403) # VID
bitmode_cbus = 0x20
i = 0
d = pylibftdi.BitBangDevice("AH022NWG") # Device Serial for the Status LED FTDI.
if d.device_id: print(f"Found FTDI chip with requested Serial Number: {d.device_id}")
'''
Value Map
0xF0: All Lights Off (0,0,0)
0xF1: Red Light On (0,0,1)
0xF2: Green Light On (1,0,0)
0xF3: Red + Green Lights On (1,0,1)
0xF8: Yellow Light On (0,1,0)
0xF9: Red + Yellow Lights On (0,1,1)
0xFA: Yellow + Green Lights On (1,1,0)
0xFB: All Lights On (1,1,1)
'''
def dcsd_lights_set(green, yellow, red):
lights_map = {
(0,0,0): 0xF0,
(0,0,1): 0xF1,
(1,0,0): 0xF2,
(1,0,1): 0xF3,
(0,1,0): 0xF8,
(0,1,1): 0xF9,
(1,1,0): 0xFA,
(1,1,1): 0xFB
}
tuple_key = tuple([green,yellow,red])
d.ftdi_fn.ftdi_set_bitmode(lights_map[tuple_key], bitmode_cbus)
def blinkenlights():
from time import sleep
i = 0
command = [(0,0,0),(1,0,0),(1,1,0),(1,1,1),(0,1,1),(0,0,1)]
try:
while 1:
dcsd_lights_set(*(command[i])) # With *() possiamo direttamente passare una tupla alla funzione
i+=1
if i == 6:
i = 0
sleep(.3)
except KeyboardInterrupt:
dcsd_lights_set(1,1,1) # Sets all lights on
print("\r\rDone!")
def randlights():
from random import randint
from time import sleep
while 1:
a, b, c = randint(0, 1), randint(0, 1), randint(0, 1)
dcsd_lights_set(a,b,c)
sleep(.3)
d.open()
blinkenlights()
d.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment