From 1759fcebf18ad27f697ac8ba7b51d6a7862fbe09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Weigert?= Date: Fri, 8 Mar 2019 20:06:59 +0100 Subject: [PATCH] more icons --- gfx/bicycle3.png | Bin 0 -> 186 bytes gfx/fablab_logo_16x11.png | Bin 175 -> 180 bytes gfx/{smiley8.png => happy.png} | Bin gfx/happy2.png | Bin 0 -> 161 bytes gfx/owncloud_logo_24x11.png | Bin 273 -> 273 bytes led-badge-11x44.py | 63 +++++++++++++++++++++++++++------ 6 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 gfx/bicycle3.png rename gfx/{smiley8.png => happy.png} (100%) create mode 100644 gfx/happy2.png diff --git a/gfx/bicycle3.png b/gfx/bicycle3.png new file mode 100644 index 0000000000000000000000000000000000000000..95b64b0468fd019cb5fa788404fb3389de5ddaf6 GIT binary patch literal 186 zcmeAS@N?(olHy`uVBq!ia0vp^5sjzz8q-Ft)IfsCjFnGH9xvX-L30Qa9Sk>U#+m>C08>dsK~yNujgLVN03i$l#q9sTj0Y2=Q=-eM zO`(9=3EOLy)Cv^YlR8((I@p!Ed(t8L0R2z&{rc5|q@_WgqXT5NAEjfMSc8u*1?cc( cXCHI`1}()z@dhmL)c^nh07*qoM6N<$f);8s-~a#s delta 117 zcmV-*0E+*#0j~j&L2d^U2rzfiOkV&108U9nK~yNujgd7+ zq#!X!S`I+wAnAcr%5(P0pd&j;`Xk+UPi+7&rh3rTOj;O#DrWjw8$1}u8`js;?YgU7 XwMJ0ZB$B$k00000NkvXXu0mjfll(AY diff --git a/gfx/smiley8.png b/gfx/happy.png similarity index 100% rename from gfx/smiley8.png rename to gfx/happy.png diff --git a/gfx/happy2.png b/gfx/happy2.png new file mode 100644 index 0000000000000000000000000000000000000000..f34c7cbf7020569833e0bbb54688c9e57e99988b GIT binary patch literal 161 zcmeAS@N?(olHy`uVBq!ia0vp^0zk~o!2~3KHq6QcQk(@Ik;OnUVGw3ym^DWND9B#o z>Fdh=n3+R}pV3hF)EA(TgQtsQh{pNkgas^r{{Nr9fMb`;CN3YrQ#lImvW8VNJWM+{ zlO$$UM%Xqhb*yBcp5^8fEGhYs(@5xx_NF>EHa3QvO^)XnmqjfEn#JJh>gTe~DWM4f DtBfnu literal 0 HcmV?d00001 diff --git a/gfx/owncloud_logo_24x11.png b/gfx/owncloud_logo_24x11.png index 2b15f08f446752b55f9dda6897ee8c1d2afac07c..df43baef75256149b35a04ca64baa18624c9d802 100644 GIT binary patch delta 18 ZcmbQpG?8h7BL{~t8&idfm%&8O696gP1ls@r delta 18 ZcmbQpG?8h7BL};Xkh+V$vGYXF696g-1l<4t diff --git a/led-badge-11x44.py b/led-badge-11x44.py index 5e744a0..7d43e77 100755 --- a/led-badge-11x44.py +++ b/led-badge-11x44.py @@ -17,7 +17,8 @@ # v0.3 jw option -p to preload graphics for inline use in text. # v0.4, 2019-03-08, jw Warning about unused images added. Examples added to the README. -import sys, os, re, array, time, argparse +import sys, os, re, time, argparse +from array import array import usb.core __version = "0.4" @@ -152,7 +153,30 @@ for i in range(len(charmap)): char_offset[charmap[i]] = 11 * i bitmap_preloaded = [ ([],0) ] -bitmaps_unused = False +bitmaps_preloaded_unused = False + +bitmap_named = { + 'happy': (array('B', (0x00, 0x3c, 0x42, 0xa5, 0x81, 0xa5, 0x99, 0x42, 0x3c, 0x00, 0x00)), 1, '\x1d'), + 'happy2': (array('B', (0x00, 0x08, 0x14, 0x08, 0x01, 0x00, 0x00, 0x61, 0x30, 0x1c, 0x07, + 0x00, 0x20, 0x50, 0x20, 0x00, 0x80, 0x80, 0x86, 0x0c, 0x38, 0xe0)), 2, '\x1c'), + 'heart': (array('B', (0x00, 0x00, 0x6c, 0x92, 0x82, 0x82, 0x44, 0x28, 0x10, 0x00, 0x00)), 1, '\x1b'), + 'HEART': (array('B', (0x00, 0x00, 0x6c, 0xfe, 0xfe, 0xfe, 0x7c, 0x38, 0x10, 0x00, 0x00)), 1, '\x1a'), + 'heart2': (array('B', (0x00, 0x0c, 0x12, 0x21, 0x20, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, + 0x00, 0x60, 0x90, 0x08, 0x08, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00)), 2, '\x19'), + 'HEART2': (array('B', (0x00, 0x0c, 0x1e, 0x3f, 0x3f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, + 0x00, 0x60, 0xf0, 0xf8, 0xf8, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00)), 2, '\x18'), + 'fablab': (array('B', (0x07, 0x0e, 0x1b, 0x03, 0x21, 0x2c, 0x2e, 0x26, 0x14, 0x1c, 0x06, + 0x80, 0x60, 0x30, 0x80, 0x88, 0x38, 0xe8, 0xc8, 0x10, 0x30, 0xc0)), 2, '\x17'), + 'bicycle': (array('B', (0x01, 0x02, 0x00, 0x01, 0x07, 0x09, 0x12, 0x12, 0x10, 0x08, 0x07, + 0x00, 0x87, 0x81, 0x5f, 0x22, 0x94, 0x49, 0x5f, 0x49, 0x80, 0x00, + 0x00, 0x80, 0x00, 0x80, 0x70, 0xc8, 0x24, 0xe4, 0x04, 0x88, 0x70)), 3, '\x16'), + 'owncloud': (array('B', (0x00, 0x01, 0x02, 0x03, 0x06, 0x0c, 0x1a, 0x13, 0x11, 0x19, 0x0f, + 0x78, 0xcc, 0x87, 0xfc, 0x42, 0x81, 0x81, 0x81, 0x81, 0x43, 0xbd, + 0x00, 0x00, 0x00, 0x80, 0x80, 0xe0, 0x30, 0x10, 0x28, 0x28, 0xd0)), 3, '\x15'), +} +bitmap_builtin = {} +for i in bitmap_named: + bitmap_builtin[bitmap_named[i][0]] = bitmap_named[i] def bitmap_char(ch): """ Returns a tuple of 11 bytes, @@ -160,17 +184,36 @@ def bitmap_char(ch): The bits in each byte are horizontal, highest bit is left. """ if ord(ch) < 32: - global bitmaps_unused - bitmaps_unused = False + if ch in bitmap_builtin: + return bitmap_builtin[ch] + + global bitmaps_preloaded_unused + bitmaps_preloaded_unused = False return bitmap_preloaded[ord(ch)] + o = char_offset[ch] return (font_11x44[o:o+11],1) def bitmap_text(text): """ returns a tuple of (buffer, length_in_byte_columns_aka_chars) + We preprocess the text string for substitution patterns + "::" is replaced with a single ":" + ":happy:" is replaced with a reference to a builtin smiley glyph + ":heart:" is replaced with a reference to a builtin heart glyph + ":gfx/logo.png:" preloads the file gfx/logo.png and is replaced the corresponding control char. """ - buf = array.array('B') + def colonrepl(m): + name = m.group(1) + if name == '': return ':' + if '.' in name: + bitmap_preloaded.append(bitmap_img(name)) + return chr(len(bitmap_preloaded)-1) + b = bitmap_named[name] + return b[2] + + text = re.sub(r':([^:]*):', colonrepl, text) + buf = array('B') cols = 0 for c in text: (b,n) = bitmap_char(c) @@ -185,10 +228,10 @@ def bitmap_img(file): from PIL import Image im = Image.open(file) - print("preloading bitmap from file %s -> (%d x %d)" % (file, im.width, im.height)) + print("fetching bitmap from file %s -> (%d x %d)" % (file, im.width, im.height)) if im.height != 11: sys.exit("%s: image height must be 11px. Seen %d" % (file, im.height)) - buf = array.array('B') + buf = array('B') cols = int((im.width+7)/8) for col in range(cols): for row in range(11): @@ -259,16 +302,16 @@ print("using [%s %s] bus=%d dev=%d" % (dev.manufacturer, dev.product, dev.bus, d if args.preload: for file in args.preload: bitmap_preloaded.append(bitmap_img(file)) - bitmaps_unused = True + bitmaps_preloaded_unused = True msgs = [] for arg in args.message: msgs.append(bitmap(arg)) -if bitmaps_unused == True: +if bitmaps_preloaded_unused == True: print("\nWARNING:\n Your preloaded images are not used.\n Try without '-p' or embed the control character '^A' in your message.\n") -buf = array.array('B') +buf = array('B') buf.extend(header(list(map(lambda x: x[1], msgs)), args.speed, args.mode)) for msg in msgs: