From 733fa1325d52801aa2f1c0a1f3e2a96da6c21443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Weigert?= Date: Thu, 14 Mar 2019 10:10:14 +0100 Subject: [PATCH] added ants and blink mode. And --mode-help to document animations. --- README.md | 34 +++++++++++++++++---------- led-badge-11x44.py | 57 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 69 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 956fb5d..9f6ed78 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,10 @@ shows a bicycle crossing the display in left-to-right and right-to-left (as a se ![LED Mini Board](photos/bicycle.gif) + sudo python3. /led-badge-11-x44.py -b0,1 -s1 -m5 " :heart2: :HEART2:" " :HEART2:" + +shows a simple animation of a slowly beating heart on the first message, and a blinking heart on the second message. + python3 ./led-badge-11x44.py --list-names prints the list of builtin icon names, including :happy: :happy2: :heart: :HEART: :heart2: :HEART2: :fablab: :bicycle: :bicycle_r: :owncloud: :: @@ -60,12 +64,13 @@ prints the list of builtin icon names, including :happy: :happy2: :heart: :HEART prints some condensed help:
-Usage: led-badge-11x44.py [-h] [-s SPEED] [-m MODE] [-p FILE] [-l]
+usage: led-badge-11x44.py [-h] [-s SPEED] [-m MODE] [-b BLINK] [-a ANTS]
+                          [-p FILE] [-l]
                           MESSAGE [MESSAGE ...]
 
-Upload messages or graphics to a 44x11 led badge via USB HID. Version 0.5 from
-https://github.com/jnweiger/led-badge-44x11 -- see there for more examples and
-for updates.
+Upload messages or graphics to a 44x11 led badge via USB HID.
+Version 0.6 from https://github.com/jnweiger/led-badge-44x11
+ -- see there for more examples and for updates.
 
 positional arguments:
   MESSAGE               Up to 8 message texts with embedded builtin icons or
@@ -75,15 +80,20 @@ positional arguments:
 optional arguments:
   -h, --help            show this help message and exit
   -s SPEED, --speed SPEED
-                        Scroll speed. Up to 8 comma-seperated values (range
-                        1..8)
+                        Scroll speed (Range 1..8). Up to 8 comma-seperated
+                        values
   -m MODE, --mode MODE  Up to 8 mode values: Scroll-left(0) -right(1) -up(2)
-                        -down(3); still-centered(4) -left(5); drop-down(6);
-                        curtain(7); laser(8)
-  -l, --list, --list-names, --listnames
-                        list named icons to be embedded in messages and exit
-
-Example combining image and text: sudo ./led-badge-11x44.py "I:HEART2:you"
+                        -down(3); still-centered(4); animation(5); drop-
+                        down(6); curtain(7); laser(8); See '--mode-help' for
+                        more details.
+  -b BLINK, --blink BLINK
+                        1: blinking, 0: normal. Up to 8 comma-seperated values
+  -a ANTS, --ants ANTS  1: animated border, 0: normal. Up to 8 comma-seperated
+                        values
+  -l, --list-names      list named icons to be embedded in messages and exit
+
+Example combining image and text:
+ sudo ./led-badge-11x44.py "I:HEART2:you"
 
diff --git a/led-badge-11x44.py b/led-badge-11x44.py index a524bcd..6e80ca2 100755 --- a/led-badge-11x44.py +++ b/led-badge-11x44.py @@ -18,12 +18,14 @@ # v0.4, 2019-03-08, jw Warning about unused images added. Examples added to the README. # v0.5, jw Deprecated -p and CTRL-characters. We now use embedding within colons(:) # Added builtin icons and -l to list them. +# v0.6, 2019-03-14, jw Added --mode-help with hints and example for making animations. +# Options -b --blink, -a --ants added. Removed -p from usage. import sys, os, re, time, argparse from array import array import usb.core -__version = "0.5" +__version = "0.6" font_11x44 = ( # 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' @@ -272,31 +274,66 @@ proto_header = ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ) -def header(lengths, speeds, modes): +def header(lengths, speeds, modes, blink, ants): """ lengths[0] is the number of chars of the first text + + Speeds come in as 1..8, but are needed 0..7 here. """ + a = [int(x) for x in re.split(r'[\s,]+', ants)] + a = a + [a[-1]]*(8-len(a)) # repeat last element - s = [int(x) for x in re.split(r'[\s,]+', speeds)] - s = s + [s[-1]]*(8-len(s)) + b = [int(x) for x in re.split(r'[\s,]+', blink)] + b = b + [b[-1]]*(8-len(b)) # repeat last element + + s = [int(x)-1 for x in re.split(r'[\s,]+', speeds)] + s = s + [s[-1]]*(8-len(s)) # repeat last element m = [int(x) for x in re.split(r'[\s,]+', modes)] - m = m + [m[-1]]*(8-len(m)) + m = m + [m[-1]]*(8-len(m)) # repeat last element h = list(proto_header) + for i in range(8): + h[6] += b[i]<