Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

starting to think about threads; optimize bitmap compilation

  • Loading branch information...
commit 920767c9a7de9bead13f5341677ac5cabdbc9b55 1 parent 20eb2ae
@phooky phooky authored
Showing with 24 additions and 11 deletions.
  1. +16 −9 hexaservice/led_panel.py
  2. +8 −2 hexaservice/service.py
View
25 hexaservice/led_panel.py
@@ -11,6 +11,18 @@
CC_UART = 0xA5
CC_RELAY = 0xA6
+def compile_image(img, x=0, y=0):
+ bitmap = ''
+ width = min(img.size[0]-x,120)
+ height = min(7,img.size[1]-y)
+ for i in range(width):
+ b = 0
+ for j in range(height):
+ if img.getpixel(( i+x, j+y )):
+ b |= 1 << (7-j)
+ bitmap = bitmap + struct.pack("B",b)
+ return bitmap
+
class Panel:
def __init__(self):
self.serialPort = None
@@ -50,15 +62,10 @@ def setMessage(self, message, x =0, y =0):
self.command(CC_TEXT,cmd,0)
def setImage(self, img, x =0, y =0):
- bitmap = ''
- width = min(img.size[0]-x,120)
- height = min(7,img.size[1]-y)
- for i in range(width):
- b = 0
- for j in range(height):
- if img.getpixel(( i+x, j+y )):
- b |= 1 << (7-j)
- bitmap = bitmap + struct.pack("B",b)
+ self.command(CC_BITMAP,compile_image(img,x,y),0)
+
+
+ def setCompiledImage(self, bitmap):
self.command(CC_BITMAP,bitmap,0)
def getID(self):
View
10 hexaservice/service.py
@@ -1,11 +1,16 @@
#!/usr/bin/python
import led_panel
-from led_panel import panels
+from led_panel import panels, compile_image
from fontutil import base_font
from PIL import Image
import time
import signal
import sys
+import threading
+
+class PanelThread(threading.Thread):
+ def __init__(self, panel):
+ pass
class ServiceThread:
pass
@@ -26,7 +31,8 @@ def sigint_handler(signal,frame):
img = Image.new("1",(120,7))
img.paste(txtimg,(15,0))
img.paste(txtimg,(75,0))
- panels[j].setImage(img,0,0)
+ bitmap = compile_image(img,0,0)
+ panels[j].setCompiledImage(bitmap)
time.sleep(0.1)
panels[0].setRelay(False)
Please sign in to comment.
Something went wrong with that request. Please try again.