Advertisement
Guest User

dalitest

a guest
May 17th, 2015
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sys
  4. sys.path.insert(0, "/srv/hacksense/lib")
  5.  
  6. import hacksense
  7. import logging
  8. import time
  9.  
  10. units = range(0, 18)
  11.  
  12. logging.basicConfig()
  13. logging.getLogger().setLevel(logging.INFO)
  14.  
  15. conn = hacksense.AMQPTopic()
  16.  
  17. def msg(data):
  18.     body = "".join(map(lambda x: "%02x" % (x), data))
  19. #    print body
  20.     conn.publish("dali.command", {}, body)
  21.  
  22. def simple_count():
  23.     msg([0xfe, 0x01])
  24.     time.sleep(1)
  25.     for unit in units:
  26.         msg([unit<<1, 254])
  27.         time.sleep(0.5)
  28.         msg([unit<<1, 1])
  29.     time.sleep(1)
  30.     msg([0xfe, 254])
  31.  
  32. def chase(t=0.25):
  33.     while True:
  34.         for i in range(0, len(units)):
  35.             a = units[i]
  36.             b = units[i % len(units)-1]
  37.             msg([a << 1, 254, b << 1, 1])
  38.             time.sleep(t)
  39.  
  40. def row_chase(t=0.5):
  41.     rows = [
  42.         [0, 1, 2, 9, 10, 11],
  43.         [3, 4, 5, 12, 13, 14],
  44.         [6, 7, 8, 15, 16, 17]
  45.         ]
  46.     while True:
  47.         for row in range(0, len(rows)):
  48.             #print "row", row, rows[row]
  49.             output = []
  50.             for unit in rows[row]:
  51.                 #print " unit", unit
  52.                 output.append(unit << 1)
  53.                 output.append(254)
  54.             for unit in rows[(row-1) % len(rows)]:
  55.                 #print " prev", unit
  56.                 output.append(unit << 1)
  57.                 output.append(1)
  58.             msg(output)
  59.             time.sleep(t)
  60.  
  61. def setlamp(unit, value):
  62.     msg([unit << 1, value])
  63.  
  64. try:
  65.     #simple_count()
  66.     row_chase()
  67. except KeyboardInterrupt:
  68.     msg([0xfe, 254])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement