#!/usr/bin/env python import hid import time class VFDisplay (object): def __init__ (self, force_sync = 0, vid = 0x19c2, pid = 0x6a11): ret = hid.hid_init () if ret != hid.HID_RET_SUCCESS: print "Initializing HID failed:", ret self.hid = hid.hid_new_HIDInterface () self.cmds = [] self.force_sync = force_sync matcher = hid.HIDInterfaceMatcher () matcher.vendor_id = vid matcher.product_id = pid ret = hid.hid_force_open (self.hid, 0, matcher, 3) if ret != hid.HID_RET_SUCCESS: print "Opening VFD device failed:", ret def sync (self): while len (self.cmds) > 0: cmdstr = "" while len (self.cmds) > 0 and len (cmdstr) + len (self.cmds[0]) <= 63: cmdstr += self.cmds[0] self.cmds = self.cmds[1:] cmdstr = chr (len(cmdstr)) + cmdstr hid.hid_set_output_report (self.hid, [0xff7f0004], cmdstr) def send_async (self, cmd): assert (len (cmd) < 62) self.cmds.append ("\x1b%s" % cmd) if self.force_sync: self.sync () def send (self, cmd): self.send_async (cmd) self.sync () def set_dimming (self, level = 1): assert 0 <= level <= 2 self.send_async ("\x40%c" % level) def set_symbol (self, symbol_id, intensity = 1): assert 0 <= symbol_id <= 0x18 assert symbol_id >= 0x0a or 0 <= intensity <= 1 self.send_async ("\x30%c%c" % (symbol_id, intensity)) def sync_time (self): t = time.localtime() m = (t.tm_min / 10) * 16 + (t.tm_min % 10) h = (t.tm_hour / 10) * 16 + (t.tm_hour % 10) self.send_async ("\x00%c%c" % (m, h)) self.sync () if __name__ == '__main__': vfd = VFDisplay () vfd.send ("\xf0") vfd.send ("\x00\x00\x00") vfd.set_dimming (2) vfd.set_symbol (7, 1) vfd.set_symbol (9, 1) #vfd.set_symbol (10, 1) #vfd.set_symbol (11, 2) #vfd.set_symbol (12, 1) #vfd.set_symbol (13, 2) #vfd.set_symbol (14, 1) #vfd.set_symbol (15, 2) time.sleep (.5) vfd.send ("\xf1") time.sleep (.5) vfd.set_dimming (1) vfd.send ("\xf0") time.sleep (.5) vfd.send ("\xf1") time.sleep (.5) vfd.set_dimming (2) vfd.send ("\xf0") time.sleep (.5) vfd.send ("\xf1") time.sleep (.5) vfd.set_dimming (1) vfd.send ("\xf0") time.sleep (.5) vfd.set_dimming (1) vfd.send ("\x50") vfd.sync_time () vfd.send ("\x01\x01") vfd.sync () time.sleep (.5)