wearable_sign_06.py
の編集
./?wearable_sign_06.py
[
トップ
] [
編集
|
差分
|
履歴
|
添付
|
リロード
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
-- 雛形とするページ --
adkArduino.ino
AutoTicketLinkName
basic
BracketName
ex0
ex1
ex2
ex3
ex4
FormattingRules
FrontPage
Help
Installing-Android-Application
InterWiki
InterWikiName
InterWikiSandBox
ladyMadonna
Menu
MenuBar
music
musicTest
musicTest0
NetDraw
pen
pen-ex1
PHP
Physical-Connection-1
pi_i2c_pico_neomatrix_ex01.ino
pi_i2c_pico_neomatrix_ex02.ino
PukiWiki
PukiWiki/1.4
PukiWiki/1.4/Manual
PukiWiki/1.4/Manual/Plugin
PukiWiki/1.4/Manual/Plugin/A-D
PukiWiki/1.4/Manual/Plugin/E-G
PukiWiki/1.4/Manual/Plugin/H-K
PukiWiki/1.4/Manual/Plugin/L-N
PukiWiki/1.4/Manual/Plugin/O-R
PukiWiki/1.4/Manual/Plugin/S-U
PukiWiki/1.4/Manual/Plugin/V-Z
Required-Hardware
Required-Software-and-Data
SandBox
simple example
tcp_server_ex1.py
Test-1
wearable_sign_01.py
wearable_sign_02.py
wearable_sign_03.py
wearable_sign_05.py
wearable_sign_06.py
WikiEngines
WikiName
WikiWikiWeb
wiki_bot_ex07.py
wiki_bot_ex08.py
wiki_bot_ex09.py
wiki_page_gps_ex01
Writing-Arduino-Firmware
YukiWiki
[[Required-Software-and-Data]] #code(Python){{ # -*- coding: utf-8 -*- # # wearable_sign_06.py # takashi yamanoue, 2025 7/21 # # # +---------+ +--------------+ # Wiki <->| fwb4pi |<---->|tcp_server_ex1| # +---------+ +--------------+ # ^ # | # v # +------------------+ # |RemoteCommandReder| # | | | # | v | # | handler | # | | | # | v | # | parser | # | | | # +----|-------------+ # | # | put # v # +------------------+ # |TeleportDresser | # | | | # | v | # | handler | # +------------------+ # import smbus import time import traceback import struct import threading import copy import socket import os import sys import netifaces class RemoteCommandReader: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) HOST = 'localhost' PORT = 9998 def __init__(self): print("start RemoteCommandReader.__init__") self.client_start() #self.teleport_dress=Teleport_Dress() self.ss=Show_String() #print(self.teleport_dress) #self.teleport_dress.setRemoteCommandReader(self) self.ss.set_RemoteCommandReader(self) while True: try: time.sleep(0.01) except: print("error") def python2fwbln(self,py2x_message): msg=py2x_message+'\n' self.sock.sendall(msg.encode('utf-8')) def python2fwb(self,py2x_message): msg=py2x_message self.sock.sendall(msg.encode('utf-8')) def rb(self,in_str): while True: if in_str.startswith(' '): in_str=in_str[1:] else: break return in_str def parse_key(self,key,inx,rest): #print("parse_key-"+key) keylen=len(key) inlen=len(inx) if inx.startswith(key): rest[0]=inx[keylen:] return True rest[0]=inx return False def parse_String_Constant(self,inx,strc,rest): rx=[""] xstr="" if self.parse_key('"',inx,rx): #print("parse_String_Constant") inx=rx[0] fx=inx[0] xlen=len(inx) while fx!='"': if xlen==0: return False if fx=='\\': inx=inx[1:xlen] else: xstr=xstr+fx xlen=len(inx) inx=inx[1:xlen] fx=inx[0] if self.parse_key('"',inx,rx): strc[0]=xstr rest[0]=rx[0] return True return False def parse(self,line): self.python2fwb(">"+line) #words=line.split() #print('parse line='+line) if line.startswith('show '): line=line[len('show '):] #print(line) line=self.rb(line) #print('line='+line) text=[''] rest=[''] if self.parse_String_Constant(line,text,rest): self.ss.set_string(text[0]) elif line.startswith('clear'): self.ss.set_string('') elif line.startswith('ls'): self.returnFileList() elif line.startswith('address'): self.show_address() elif line.startswith('shutdown'): self.shutdown() def returnFileList(self): cpath=os.getcwd() os.chdir("/home/pi/Pictures") filenames = [f.name for f in os.scandir()] filenames.sort() for fn in filenames: self.python2fwbln(fn) os.chdir(cpath) def shutdown(self): os.system("sudo shutdown -h now") def show_address(self): ifs=netifaces.interfaces() #print("show address ifs=",end="") #print(ifs) for i in ifs: rtn=i+':' ifps=netifaces.ifaddresses(i) #print("ifps=",end="") #print(ifps) try: rtn=rtn+ifps[2][0]['addr'] except Exception as e: print(e) print(rtn) self.python2fwbln(rtn) def client_start(self): """クライアントのスタート""" self.sock.connect((self.HOST, self.PORT)) handle_thread = threading.Thread(target=self.handler, args=(self.sock,), daemon=True) handle_thread.start() def handler(self,sock): """サーバからメッセージを受信し、表示する""" fx=sock.makefile('r') while True: try: l=fx.readline() #print('l='+l) except socket.error: # socketにエラーが発生したとき print("socket error. exit") sock.close() # socketをclose except: import traceback traceback.print_exc() print("server_handler receive error.") self.parse(l) class Binary_file_reader: binary_data=None def read_file(self,path): self.binary_data=None try: with open(path,'rb') as file: while True: chunk = file.read(1024) if not chunk: break if not self.binary_data: self.binary_data=chunk else: self.binary_data=self.binary_data+chunk file.close() except Exception as e: print(traceback.format_exc()) def get_binary(self): return self.binary_data def dump_binary(self,frm, length): if not self.binary_data: print("no binary.") adr=frm s="" c="" size=len(self.binary_data) cs=[' '] if size<length: length=size eadr=adr+length while adr<eadr: a=adr if a<size: s='{:08x}'.format(a) else: s=' ' print(s,end='') sline='' cline='' for i in range(16): if a<size: d=self.binary_data[a] & 0xff sline=sline+'{:02x}'.format(d)+' ' if d<0x20 or d>0xde or (d>0x73 and d<0xa1): d=0x2e cs=chr(d); cline=cline+cs+' ' else: s=' ' c=' ' a=a+1 print(' '+sline+' '+cline) adr=a def dump_binary_all(self): self.dump_binary(0,len(self.binary_data)) #b_reader=Binary_file_reader() #b_reader.read_file('ShinonomeMin_16.pdb') #b_reader.dump_binary(0,1024) class Font_accessor: font_array=[] base=0 one_font_size=16 font_width_byte=2 asciicode=[ 0x2121, 0x2121,0x2121,0x2121, #//0x00, 0x01, 0x02, 0x03, 0x2121, 0x2121,0x2121,0x2121, #//0x04, 0x05, 0x06, 0x07, 0x2121, 0x2121,0x2121,0x2121, #//0x08, 0x09, 0x0A, 0x0B, 0x2121, 0x2121,0x2121,0x2121, #//0x0C, 0x0D, 0x0E, 0x0F, 0x2121, 0x2121,0x2121,0x2121, #//0x10, 0x11, 0x12, 0x13, 0x2121, 0x2121,0x2121,0x2121, #//0x14, 0x15, 0x16, 0x17, 0x2121, 0x2121,0x2121,0x2121, #//0x18, 0x19, 0x1A, 0x1B, 0x2121, 0x2121,0x2121,0x2121, #//0x1C, 0x1D, 0x1E, 0x1F, 0x2121, 0x212A,0x2148,0x2174, #//0x20, 0x21, 0x22, 0x23, ' ', '!', '"', '#', 0x2170, 0x2173,0x2175,0x212D, #//0x24, 0x25, 0x26, 0x27, '$', '%', '&', ''', 0x214A, 0x214B,0x2176,0x215C, #//0x28, 0x29, 0x2A, 0x2B, '(', ')', '*', '+', 0x2124, 0x215D,0x2125,0x213F, #//0x2C, 0x2D, 0x2E, 0x2F, ',', '-', '.', '/', 0x2330, 0x2331,0x2332,0x2333, #//0x30, 0x31, 0x32, 0x33, '0', '1', '2', '3', 0x2334, 0x2335,0x2336,0x2337, #//0x34, 0x35, 0x36, 0x37, '4', '5', '6', '7', 0x2338, 0x2339,0x2127,0x2128, #//0x38, 0x39, 0x3A, 0x3B, '8', '9', ':', ';', 0x2163, 0x2161,0x2164,0x2129, #//0x3C, 0x3D, 0x3E, 0x3F, '<', '=', '>', '?', 0x2177, 0x2341,0x2342,0x2343, #//0x40, 0x41, 0x42, 0x43, '@', 'A', 'B', 'C', 0x2344, 0x2345,0x2346,0x2347, #//0x44, 0x45, 0x46, 0x47, 'D', 'E', 'F', 'G', 0x2348, 0x2349,0x234A,0x234B, #//0x48, 0x49, 0x4A, 0x4B, 'H', 'I', 'J', 'K', 0x234C, 0x234D,0x234E,0x234F, #//0x4C, 0x4D, 0x4E, 0x4F, 'L', 'M', 'N', 'O', 0x2350, 0x2351,0x2352,0x2353, #//0x50, 0x51, 0x52, 0x53, 'P', 'Q', 'R', 'S', 0x2354, 0x2355,0x2356,0x2357, #//0x54, 0x55, 0x56, 0x57, 'T', 'U', 'V', 'W', 0x2358, 0x2359,0x235A,0x214E, #//0x58, 0x59, 0x5A, 0x5B, 'X', 'Y', 'Z', '[', 0x2140, 0x214F,0x2130,0x2132, #//0x5C, 0x5D, 0x5E, 0x5F, '\', ']', '^', '_', 0x212D, 0x2361,0x2362,0x2363, #//0x60, 0x61, 0x62, 0x63, '`', 'a', 'b', 'c', 0x2364, 0x2365,0x2366,0x2367, #//0x64, 0x65, 0x66, 0x67, 'd', 'e', 'f', 'g', 0x2368, 0x2369,0x236A,0x236B, #//0x68, 0x69, 0x6A, 0x6B, 'h', 'i', 'j', 'k', 0x236C, 0x236D,0x236E,0x236F, #//0x6C, 0x6D, 0x6E, 0x6F, 'l', 'm', 'n', 'o', 0x2370, 0x2371,0x2372,0x2373, #//0x70, 0x71, 0x72, 0x73, 'p', 'q', 'r', 's', 0x2374, 0x2375,0x2376,0x2377, #//0x74, 0x65, 0x76, 0x77, 't', 'u', 'v', 'w', 0x2378, 0x2379,0x237A,0x2150, #//0x78, 0x69, 0x7A, 0x7B, 'x', 'y', 'z', '{', 0x2143, 0x2151,0x2141,0x2121 # //0x7C, 0x6D, 0x7E, 0x7F, '|', '}', '~', ' ', ] ascii_font=[0 for x in range(256*8)] ascii_font_data=[ #// #// use https://github.com/alexmac/alcextra/blob/master/aalib-1.4.0/src/font8.c #// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, #//0x00 null 0x7e, 0x81, 0xa5, 0x81, 0xbd, 0x99, 0x81, 0x7e, 0x7e, 0xff, 0xdb, 0xff, 0xc3, 0xe7, 0xff, 0x7e, 0x6c, 0xfe, 0xfe, 0xfe, 0x7c, 0x38, 0x10, 0x00, 0x10, 0x38, 0x7c, 0xfe, 0x7c, 0x38, 0x10, 0x00, 0x38, 0x7c, 0x38, 0xfe, 0xfe, 0x92, 0x10, 0x7c, 0x00, 0x10, 0x38, 0x7c, 0xfe, 0x7c, 0x38, 0x7c, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00, 0x00, 0xff, 0xff, 0xe7, 0xc3, 0xc3, 0xe7, 0xff, 0xff, 0x00, 0x3c, 0x66, 0x42, 0x42, 0x66, 0x3c, 0x00, 0xff, 0xc3, 0x99, 0xbd, 0xbd, 0x99, 0xc3, 0xff, 0x0f, 0x07, 0x0f, 0x7d, 0xcc, 0xcc, 0xcc, 0x78, 0x3c, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x18, 0x3f, 0x33, 0x3f, 0x30, 0x30, 0x70, 0xf0, 0xe0, 0x7f, 0x63, 0x7f, 0x63, 0x63, 0x67, 0xe6, 0xc0, 0x99, 0x5a, 0x3c, 0xe7, 0xe7, 0x3c, 0x5a, 0x99, 0x80, 0xe0, 0xf8, 0xfe, 0xf8, 0xe0, 0x80, 0x00, #//0x10 0x02, 0x0e, 0x3e, 0xfe, 0x3e, 0x0e, 0x02, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x00, 0x7f, 0xdb, 0xdb, 0x7b, 0x1b, 0x1b, 0x1b, 0x00, 0x3e, 0x63, 0x38, 0x6c, 0x6c, 0x38, 0x86, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x7e, 0x3c, 0x18, 0xff, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x00, 0x00, 0x18, 0x0c, 0xfe, 0x0c, 0x18, 0x00, 0x00, 0x00, 0x30, 0x60, 0xfe, 0x60, 0x30, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xfe, 0x00, 0x00, 0x00, 0x24, 0x66, 0xff, 0x66, 0x24, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7e, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, #//0x20 space 0x18, 0x3c, 0x3c, 0x18, 0x18, 0x00, 0x18, 0x00, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c, 0xfe, 0x6c, 0xfe, 0x6c, 0x6c, 0x00, 0x18, 0x7e, 0xc0, 0x7c, 0x06, 0xfc, 0x18, 0x00, 0x00, 0xc6, 0xcc, 0x18, 0x30, 0x66, 0xc6, 0x00, 0x38, 0x6c, 0x38, 0x76, 0xdc, 0xcc, 0x76, 0x00, 0x30, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x30, 0x60, 0x60, 0x60, 0x30, 0x18, 0x00, 0x60, 0x30, 0x18, 0x18, 0x18, 0x30, 0x60, 0x00, 0x00, 0x66, 0x3c, 0xff, 0x3c, 0x66, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x80, 0x00, 0x7c, 0xce, 0xde, 0xf6, 0xe6, 0xc6, 0x7c, 0x00, #//0x30 0 0x30, 0x70, 0x30, 0x30, 0x30, 0x30, 0xfc, 0x00, #// 1 0x78, 0xcc, 0x0c, 0x38, 0x60, 0xcc, 0xfc, 0x00, #// 2 0x78, 0xcc, 0x0c, 0x38, 0x0c, 0xcc, 0x78, 0x00, #// 3 0x1c, 0x3c, 0x6c, 0xcc, 0xfe, 0x0c, 0x1e, 0x00, #// 4 0xfc, 0xc0, 0xf8, 0x0c, 0x0c, 0xcc, 0x78, 0x00, #// 5 0x38, 0x60, 0xc0, 0xf8, 0xcc, 0xcc, 0x78, 0x00, #// 6 0xfc, 0xcc, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x00, #// 7 0x78, 0xcc, 0xcc, 0x78, 0xcc, 0xcc, 0x78, 0x00, #// 8 0x78, 0xcc, 0xcc, 0x7c, 0x0c, 0x18, 0x70, 0x00, #// 9 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x30, 0x18, 0x30, 0x60, 0xc0, 0x60, 0x30, 0x18, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x0c, 0x18, 0x30, 0x60, 0x00, 0x3c, 0x66, 0x0c, 0x18, 0x18, 0x00, 0x18, 0x00, 0x7c, 0xc6, 0xde, 0xde, 0xdc, 0xc0, 0x7c, 0x00, #//0x40 @ 0x30, 0x78, 0xcc, 0xcc, 0xfc, 0xcc, 0xcc, 0x00, #// A 0xfc, 0x66, 0x66, 0x7c, 0x66, 0x66, 0xfc, 0x00, #// B 0x3c, 0x66, 0xc0, 0xc0, 0xc0, 0x66, 0x3c, 0x00, #// C 0xf8, 0x6c, 0x66, 0x66, 0x66, 0x6c, 0xf8, 0x00, #// D 0xfe, 0x62, 0x68, 0x78, 0x68, 0x62, 0xfe, 0x00, #// E 0xfe, 0x62, 0x68, 0x78, 0x68, 0x60, 0xf0, 0x00, #// F 0x3c, 0x66, 0xc0, 0xc0, 0xce, 0x66, 0x3a, 0x00, #// G 0xcc, 0xcc, 0xcc, 0xfc, 0xcc, 0xcc, 0xcc, 0x00, #// H 0x78, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, #// I 0x1e, 0x0c, 0x0c, 0x0c, 0xcc, 0xcc, 0x78, 0x00, #// J 0xe6, 0x66, 0x6c, 0x78, 0x6c, 0x66, 0xe6, 0x00, #// K 0xf0, 0x60, 0x60, 0x60, 0x62, 0x66, 0xfe, 0x00, #// L 0xc6, 0xee, 0xfe, 0xfe, 0xd6, 0xc6, 0xc6, 0x00, #// M 0xc6, 0xe6, 0xf6, 0xde, 0xce, 0xc6, 0xc6, 0x00, #// N 0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x00, #// O 0xfc, 0x66, 0x66, 0x7c, 0x60, 0x60, 0xf0, 0x00, #// 0x50 P 0x7c, 0xc6, 0xc6, 0xc6, 0xd6, 0x7c, 0x0e, 0x00, #// Q 0xfc, 0x66, 0x66, 0x7c, 0x6c, 0x66, 0xe6, 0x00, #// R 0x7c, 0xc6, 0xe0, 0x78, 0x0e, 0xc6, 0x7c, 0x00, #// S 0xfc, 0xb4, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, #// T 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xfc, 0x00, #// U 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x78, 0x30, 0x00, #// V 0xc6, 0xc6, 0xc6, 0xc6, 0xd6, 0xfe, 0x6c, 0x00, #// W 0xc6, 0xc6, 0x6c, 0x38, 0x6c, 0xc6, 0xc6, 0x00, #// X 0xcc, 0xcc, 0xcc, 0x78, 0x30, 0x30, 0x78, 0x00, #// Y 0xfe, 0xc6, 0x8c, 0x18, 0x32, 0x66, 0xfe, 0x00, #// Z 0x78, 0x60, 0x60, 0x60, 0x60, 0x60, 0x78, 0x00, 0xc0, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x02, 0x00, 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, #// 0x60 0x00, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00, #// 0x61 a 0xe0, 0x60, 0x60, 0x7c, 0x66, 0x66, 0xdc, 0x00, #// b 0x00, 0x00, 0x78, 0xcc, 0xc0, 0xcc, 0x78, 0x00, #// c 0x1c, 0x0c, 0x0c, 0x7c, 0xcc, 0xcc, 0x76, 0x00, #// d 0x00, 0x00, 0x78, 0xcc, 0xfc, 0xc0, 0x78, 0x00, #// e 0x38, 0x6c, 0x64, 0xf0, 0x60, 0x60, 0xf0, 0x00, #// f 0x00, 0x00, 0x76, 0xcc, 0xcc, 0x7c, 0x0c, 0xf8, #// g 0xe0, 0x60, 0x6c, 0x76, 0x66, 0x66, 0xe6, 0x00, #// h 0x30, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, #// i 0x0c, 0x00, 0x1c, 0x0c, 0x0c, 0xcc, 0xcc, 0x78, #// j 0xe0, 0x60, 0x66, 0x6c, 0x78, 0x6c, 0xe6, 0x00, #// k 0x70, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, #// l 0x00, 0x00, 0xcc, 0xfe, 0xfe, 0xd6, 0xd6, 0x00, #// m 0x00, 0x00, 0xb8, 0xcc, 0xcc, 0xcc, 0xcc, 0x00, #// n 0x00, 0x00, 0x78, 0xcc, 0xcc, 0xcc, 0x78, 0x00, #// o 0x00, 0x00, 0xdc, 0x66, 0x66, 0x7c, 0x60, 0xf0, #// 0x70 p 0x00, 0x00, 0x76, 0xcc, 0xcc, 0x7c, 0x0c, 0x1e, #// q 0x00, 0x00, 0xdc, 0x76, 0x62, 0x60, 0xf0, 0x00, #// r 0x00, 0x00, 0x7c, 0xc0, 0x70, 0x1c, 0xf8, 0x00, #// s 0x10, 0x30, 0xfc, 0x30, 0x30, 0x34, 0x18, 0x00, #// t 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, #// u 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0x78, 0x30, 0x00, #// v 0x00, 0x00, 0xc6, 0xc6, 0xd6, 0xfe, 0x6c, 0x00, #// w 0x00, 0x00, 0xc6, 0x6c, 0x38, 0x6c, 0xc6, 0x00, #// z 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0x7c, 0x0c, 0xf8, 0x00, 0x00, 0xfc, 0x98, 0x30, 0x64, 0xfc, 0x00, 0x1c, 0x30, 0x30, 0xe0, 0x30, 0x30, 0x1c, 0x00, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00, 0xe0, 0x30, 0x30, 0x1c, 0x30, 0x30, 0xe0, 0x00, 0x76, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0x00, 0x7c, 0xc6, 0xc0, 0xc6, 0x7c, 0x0c, 0x06, 0x7c, 0x00, 0xcc, 0x00, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x1c, 0x00, 0x78, 0xcc, 0xfc, 0xc0, 0x78, 0x00, #//0x80 0x7e, 0x81, 0x3c, 0x06, 0x3e, 0x66, 0x3b, 0x00, 0xcc, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00, 0xe0, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00, 0x30, 0x30, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0, 0x78, 0x0c, 0x38, 0x7e, 0x81, 0x3c, 0x66, 0x7e, 0x60, 0x3c, 0x00, 0xcc, 0x00, 0x78, 0xcc, 0xfc, 0xc0, 0x78, 0x00, 0xe0, 0x00, 0x78, 0xcc, 0xfc, 0xc0, 0x78, 0x00, 0xcc, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, 0x7c, 0x82, 0x38, 0x18, 0x18, 0x18, 0x3c, 0x00, 0xe0, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, 0xc6, 0x10, 0x7c, 0xc6, 0xfe, 0xc6, 0xc6, 0x00, 0x30, 0x30, 0x00, 0x78, 0xcc, 0xfc, 0xcc, 0x00, 0x1c, 0x00, 0xfc, 0x60, 0x78, 0x60, 0xfc, 0x00, 0x00, 0x00, 0x7f, 0x0c, 0x7f, 0xcc, 0x7f, 0x00, 0x3e, 0x6c, 0xcc, 0xfe, 0xcc, 0xcc, 0xce, 0x00, #//0x90 0x78, 0x84, 0x00, 0x78, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0xcc, 0x00, 0x78, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0xe0, 0x00, 0x78, 0xcc, 0xcc, 0x78, 0x00, 0x78, 0x84, 0x00, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0xe0, 0x00, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0xcc, 0x00, 0xcc, 0xcc, 0x7c, 0x0c, 0xf8, 0xc3, 0x18, 0x3c, 0x66, 0x66, 0x3c, 0x18, 0x00, 0xcc, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0x78, 0x00, 0x18, 0x18, 0x7e, 0xc0, 0xc0, 0x7e, 0x18, 0x18, 0x38, 0x6c, 0x64, 0xf0, 0x60, 0xe6, 0xfc, 0x00, 0xcc, 0xcc, 0x78, 0x30, 0xfc, 0x30, 0xfc, 0x30, 0xf8, 0xcc, 0xcc, 0xfa, 0xc6, 0xcf, 0xc6, 0xc3, 0x0e, 0x1b, 0x18, 0x3c, 0x18, 0x18, 0xd8, 0x70, 0x1c, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00, 0x38, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, 0x00, 0x1c, 0x00, 0x78, 0xcc, 0xcc, 0x78, 0x00, #//0xA0 0x00, 0x1c, 0x00, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0xf8, 0x00, 0xb8, 0xcc, 0xcc, 0xcc, 0x00, 0xfc, 0x00, 0xcc, 0xec, 0xfc, 0xdc, 0xcc, 0x00, 0x3c, 0x6c, 0x6c, 0x3e, 0x00, 0x7e, 0x00, 0x00, 0x38, 0x6c, 0x6c, 0x38, 0x00, 0x7c, 0x00, 0x00, 0x18, 0x00, 0x18, 0x18, 0x30, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0c, 0x00, 0x00, 0xc6, 0xcc, 0xd8, 0x36, 0x6b, 0xc2, 0x84, 0x0f, 0xc3, 0xc6, 0xcc, 0xdb, 0x37, 0x6d, 0xcf, 0x03, 0x18, 0x00, 0x18, 0x18, 0x3c, 0x3c, 0x18, 0x00, 0x00, 0x33, 0x66, 0xcc, 0x66, 0x33, 0x00, 0x00, 0x00, 0xcc, 0x66, 0x33, 0x66, 0xcc, 0x00, 0x00, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0xdb, 0xf6, 0xdb, 0x6f, 0xdb, 0x7e, 0xd7, 0xed, #//0xB0 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36, 0xf6, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x36, 0x36, 0x36, 0x00, 0x00, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x36, 0x36, 0xf6, 0x06, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0xfe, 0x06, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0xf6, 0x06, 0xfe, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0xfe, 0x00, 0x00, 0x00, 0x18, 0x18, 0xf8, 0x18, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x18, 0x18, 0x18, #//0xC0 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36, 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x30, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x30, 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0xf7, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xf7, 0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x30, 0x37, 0x36, 0x36, 0x36, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x36, 0x36, 0xf7, 0x00, 0xf7, 0x36, 0x36, 0x36, 0x18, 0x18, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0xff, 0x36, 0x36, 0x36, #//0xD0 0x36, 0x36, 0x36, 0x36, 0x3f, 0x00, 0x00, 0x00, 0x18, 0x18, 0x1f, 0x18, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xff, 0x36, 0x36, 0x36, 0x18, 0x18, 0xff, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x18, 0x18, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0xc8, 0xdc, 0x76, 0x00, 0x00, 0x78, 0xcc, 0xf8, 0xcc, 0xf8, 0xc0, 0xc0, 0x00, 0xfc, 0xcc, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, #// 0xE0 0x00, 0x00, 0xfe, 0x6c, 0x6c, 0x6c, 0x6c, 0x00, 0xfc, 0xcc, 0x60, 0x30, 0x60, 0xcc, 0xfc, 0x00, 0x00, 0x00, 0x7e, 0xd8, 0xd8, 0xd8, 0x70, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x7c, 0x60, 0xc0, 0x00, 0x76, 0xdc, 0x18, 0x18, 0x18, 0x18, 0x00, 0xfc, 0x30, 0x78, 0xcc, 0xcc, 0x78, 0x30, 0xfc, 0x38, 0x6c, 0xc6, 0xfe, 0xc6, 0x6c, 0x38, 0x00, 0x38, 0x6c, 0xc6, 0xc6, 0x6c, 0x6c, 0xee, 0x00, 0x1c, 0x30, 0x18, 0x7c, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00, 0x7e, 0xdb, 0xdb, 0x7e, 0x00, 0x00, 0x06, 0x0c, 0x7e, 0xdb, 0xdb, 0x7e, 0x60, 0xc0, 0x38, 0x60, 0xc0, 0xf8, 0xc0, 0x60, 0x38, 0x00, 0x78, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x00, 0x00, 0x7e, 0x00, 0x7e, 0x00, 0x7e, 0x00, 0x00, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x7e, 0x00, 0x60, 0x30, 0x18, 0x30, 0x60, 0x00, 0xfc, 0x00, #// 0xF0 0x18, 0x30, 0x60, 0x30, 0x18, 0x00, 0xfc, 0x00, 0x0e, 0x1b, 0x1b, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xd8, 0xd8, 0x70, 0x18, 0x18, 0x00, 0x7e, 0x00, 0x18, 0x18, 0x00, 0x00, 0x76, 0xdc, 0x00, 0x76, 0xdc, 0x00, 0x00, 0x38, 0x6c, 0x6c, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x0f, 0x0c, 0x0c, 0x0c, 0xec, 0x6c, 0x3c, 0x1c, 0x58, 0x6c, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x70, 0x98, 0x30, 0x60, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x3c, 0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] def __init__(self,font_data, font_size, base): self.font_array=font_data self.one_font_size=font_size self.base=base self.font_width_byte=int((self.one_font_size+7)/8) for i in range(len(self.ascii_font)): self.ascii_font[i]=self.ascii_font_data[i] def utf_8_str_to_jis_barray(self,x): #print('utf_8_str_to_jis_barray x='+x) rtn=[] lx=len(x) for i in range(lx): c=x[i] #print('c='+c) j=self.utf_8_to_jis_char(c) #print('j={:x}'.format(j)) rtn.append(j) return rtn def utf_8_to_jis_char(self,x): #print('utf_8_to_jis_char x='+x) w=x.encode('shift_jis') jw=self.sjis_to_jis(w) return jw def sjis_to_jis_string(self,x): xlen=len(x) rtn='' for i in range(xlen): w=self.sjis_to_jis(x[i]) rtn=rtn+w return rtn def sjis_to_jis(self, x): #print('sjis_to_jis x=',end='') #print(x) if len(x)==2: wx=struct.unpack('BB',x) c1=wx[0] c2=wx[1] else: wx=struct.unpack('B',x) c1=0 c2=wx[0] #print(wx) ##c1=(x >> 8) &0x00ff ##c2=x & 0x00ff #print('c1={:x}'.format(c1)) #print('c2={:x}'.format(c2)) if c1==0: c2=c2 else: if c1 >=0xe0: c1=c1-0x40 if c2 >=0x80: c2=c2-1 if c2 >=0x9e: c1=(c1-0x70)*2 c2=c2-0x7d else: c1=((c1-0x70)*2)-1 c2=c2-0x1f rtn=(c1<<8)|c2 #print('rtn=',end='') #print(rtn) return rtn def get_JIS_string(self,x): tmp=self.get_SJIS_string(x) if tmp==None: return None rtn=[' ' for i in range(len(tmp))] bl=len(tmp) for i in range(bl): #print('tmp[i]='+tmp[i]) #print('tmp[i]={:0x}'.format(ord(tmp[i]))) cx=ord(tmp[i]) & 0x0000ffff if cx>0x2100: rtn[i]=self.sjis_to_jis(tmp[i]) else: rtn[i]=tmp[i] return rtn def get_font_jis(self,code): hb=(0xff00 & code)>>8 lb=0x00ff & code if code <0x2100: return self.get_ascii_font(code) fn=((hb-0x21)*(0x7f-0x21))+lb-0x21 pos=self.base+(fn*self.one_font_size*self.font_width_byte) return self.get_font_raw(pos) def get_ascii_font(self,c): # Standard ASCII 5x7 font # Draw a character rtn=[0 for i in range(16)] offset=6 #print('get_ascii_font c={:x}'.format(c)) for i in range(8): rtn[offset+i]=self.ascii_font[8*c+i] #print(rtn) return rtn def get_font_raw(self,pos): if self.font_array==None: return None rtn=[0 for i in range(self.one_font_size*self.font_width_byte)] if pos+self.one_font_size*self.font_width_byte > len(self.font_array): print("exceeded the max font range.") return None for i in range(self.one_font_size*self.font_width_byte): rtn[i]=self.font_array[pos+i] return rtn def print_font(self,f): if f==None: return w=int(self.one_font_size/8) fsize=len(f) if fsize<=16: w=1 for i in range(self.one_font_size): for j in range(w): l=f[i*w+j] mask=0x0080 for k in range(8): if (mask & l)!=0: print('*',end='') else: print(' ',end='') mask=mask>>1 print('') print('') class Bitmap_to_Display: # # command: # clear... 0x00 # show ... 0x01 # set1 ix,iy,r,g,b # ... 0x02 *,*, *,*,* # setn ix,iy,n, r0,g0,b0, ..r(n-1),g(n-1),b(n-1) n<=8 # ... 0x03 *,*, *, *,*,*, ..., *,*,* # pixels_ex01= [ \ [ ' ',' ',' ',' ',' ',' ',' ',' '],\ [ ' ','r','r',' ',' ','r','r',' '],\ [ 'r',' ',' ','r','r',' ',' ','r'],\ [ 'r',' ',' ',' ',' ',' ',' ','r'],\ [ 'r',' ',' ',' ',' ',' ',' ','r'],\ [ 'r',' ',' ',' ',' ',' ',' ','r'],\ [ ' ','r',' ',' ',' ',' ','r',' '],\ [ ' ','r',' ',' ',' ',' ','r',' '],\ [ ' ',' ','r',' ',' ','r',' ',' '],\ [ ' ',' ',' ','r','r',' ',' ',' '],\ [ ' ',' ',' ',' ',' ',' ',' ',' '],\ [ ' ','g','g','g','g','g','g','g'],\ [ ' ',' ','g','y','y','y','g',' '],\ [ ' ',' ',' ','g','y','g',' ',' '],\ [ ' ',' ',' ','g','y','g',' ',' '],\ [ ' ',' ',' ',' ','g',' ',' ',' '] ] r_comp={' ':0x00, 'r':0xff, 'g':0x00, 'b':0x00, 'y':0xff, 'w':0xff} g_comp={' ':0x00, 'r':0x00, 'g':0xff, 'b':0x00, 'y':0xff, 'w':0xff} b_comp={' ':0x00, 'r':0x00, 'g':0x00, 'b':0xff, 'y':0x00, 'w':0xff} def __init__(self,fa): self.i2c = smbus.SMBus(1) self.addrs = 0x3f self.fourpix=[0x00, 0x00, 0x04, 0,0,0, 0,0,0, 0,0,0, 0,0,0] self.v_bitmap=[[] for i in range(16)] self.v_lp=0 self.v_rp=0 self.d_bitmap=[[[0]*3 for i in range(32)] for j in range(16)] self.current_r=0xff self.current_g=0x00 self.current_b=0x00 self.font_accessor=fa self.update_display=True def init_v_bitmap(self): self.v_bitmap=[[] for i in range(16)] self.v_lp=0 self.v_rp=0 def start_display_thread(self): self.thread=threading.Thread(target=self.display_thread) self.thread.start() def display_thread(self): while True: if self.update_display: if self.v_rp>=(len(self.v_bitmap[0])): self.v_rp=0 if self.v_lp>=(len(self.v_bitmap[0])): self.v_lp=0 #print('len(v_bitmap[0]={:d})'.format(len(self.v_bitmap[0]))) #print('v_lp='+str(self.v_lp)+' v_rp='+str(self.v_rp)) if self.v_lp==self.v_rp: self.clear_bitmap(self.d_bitmap) elif self.v_lp<self.v_rp: self.set_bitmap(self.v_bitmap,0,self.v_lp,16,32, self.d_bitmap,0,0) else: self.set_bitmap(self.v_bitmap,0,self.v_lp,16, len(self.v_bitmap[0])-self.v_lp, self.d_bitmap,0,0) self.set_bitmap(self.v_bitmap,0,0,16,self.v_rp, self.d_bitmap,0,len(self.v_bitmap[0])-self.v_lp+1) self.v_lp=self.v_lp+1 self.v_rp=self.v_rp+1 self.show_bitmap(self.d_bitmap,0,0,16,32) time.sleep(0.01) def put_font(self,font): #print(font) if(len(font)>16): w=16 else: w=8 f_bitmap=[[[0,0,0] for i in range(w)] for j in range(16)] self.set_font(self.font_accessor,font,f_bitmap,0,0) self.append_font(f_bitmap) def append_font(self,font): #print('append_font w={:d}'.format(len(font[0]))) #self.print_bitmap(font) if len(font)!=len(self.v_bitmap): print('font size unmatch') return for i in range(len(self.d_bitmap)): l=copy.copy(font[i]) #print('l=',end='') #print(l) #print('l len={:d}'.format(len(l))) #print('b v_bitmap[{:d}'.format(i)+']=',end='') #print(self.v_bitmap[i]) (self.v_bitmap[i]).extend(l) #print('a v_bitmap[{:d}'.format(i)+']=',end='') #print(self.v_bitmap[i]) #print('len={:d}'.format(len(self.v_bitmap[i]))) self.v_lp=0 if len(self.v_bitmap[0])<31: self.v_rp=len(self.v_bitmap[0]) else: self.v_rp=31 #print('-print_bitmap v_lp={:d}'.format(self.v_lp)+' v_rp={:d}'.format(self.v_rp)) #for i in range(16): #print('v_bitmap[{:d}'.format(i)+'] w={:d}'.format(len(self.v_bitmap[i]))) def set_color(self,r,g,b): self.current_r=r self.current_g=g self.current_b=b def clear_bitmap(self,bitmap): h_max=len(bitmap) w_max=len(bitmap[0]) for i in range(h_max): for j in range(w_max): for k in range(3): bitmap[i][j][k]=0 def set_example_01(self,pixels_ex01,i,j,h,w,destination): for ip in range(h): for jp in range(w): p=pixels_ex01[i+ip][j+jp] for color in ['r','g','b']: if color == 'r': destination[ip][jp][0]=self.r_comp[p] elif color == 'g': destination[ip][jp][1]=self.g_comp[p] elif color == 'b': destination[ip][jp][2]=self.b_comp[p] def set_bitmap(self,source,i,j,h,w, destination,k,l): #print('set_bitmap i={:d}'.format(i)+' j={:d}'.format(j)+ # ' h={:d}'.format(h)+' w={:d}'.format(w)+ # ' k={:d}'.format(k)+' l={:d}'.format(k)) #self.print_bitmap(source) for ip in range(h): for jp in range(w): for cp in range(3): #print(' i+ip={:d}'.format(i+ip)+' j+jp={:d}'.format(j+jp)) cx=source[i+ip][j+jp][cp] destination[k+ip][l+jp][cp]=cx def set_font(self,fa,f, destination,d_i,d_j): if f==None: return w=int(fa.one_font_size/8) fsize=len(f) if fsize<=16: w=1 for i in range(fa.one_font_size): for j in range(w): l=f[i*w+j] mask=0x0080 for k in range(8): if (mask & l)!=0: #print('*',end='') destination[d_i+i][d_j+j*8+k][0]=self.current_r destination[d_i+i][d_j+j*8+k][1]=self.current_g destination[d_i+i][d_j+j*8+k][2]=self.current_b else: destination[d_i+i][d_j+j*8+k][0]=0 destination[d_i+i][d_j+j*8+k][1]=0 destination[d_i+i][d_j+j*8+k][2]=0 #print(' ',end='') mask=mask>>1 #print('') #print('') def show_bitmap(self, pixels, #bitmap data i,j, #i,j: left, top position from the bitmap h,w #h:hight, w:width of the showing ): self.i2c.write_byte(self.addrs,0x00) four_bitmap=[[0]*3 for i in range(4)] for ip in range(h): for jp in range(int(w/4)): for kp in range(4): for cp in range(3): four_bitmap[kp][cp]=pixels[i+ip][j+jp*4+kp][cp] self.send_4_pixel(i+ip,j+jp*4,four_bitmap) self.i2c.write_byte(self.addrs,0x01) def send_4_pixel(self, i,j,four_bitmap): #self.i2c.write_byte(self.addrs,0x00) self.fourpix[0]=i self.fourpix[1]=j for k in range(4): for l in range(3): p=four_bitmap[k][l] self.fourpix[3+3*k+l]=p #print('self.fourpix=',end='') #print(self.fourpix) self.i2c.write_i2c_block_data(self.addrs,0x03,self.fourpix) #i2c.write_byte(addrs,0x01) def print_bitmap(self,bitmap): h_max=len(bitmap) w_max=len(bitmap[0]) for ip in range(h_max): for jp in range(w_max): cc=0 for cp in range(3): cx=bitmap[ip][jp][cp] cc=cc<<8|cx print('{:6x}'.format(cc),end='') print() def test_01(self): self.clear_bitmap(self.d_bitmap) self.print_bitmap(self.d_bitmap) self.set_example_01(self.pixels_ex01,0,0,16,8,self.d_bitmap) self.print_bitmap(self.d_bitmap) self.show_bitmap(self.d_bitmap,0,0,16,8) self.print_bitmap(self.d_bitmap) class Show_String: def __init__(self): b_reader=Binary_file_reader() b_reader.read_file('ShinonomeMin_16.pdb') self.fa=Font_accessor(b_reader.get_binary(),16,0x00F0) self.b2d=Bitmap_to_Display(self.fa) self.b2d.start_display_thread() def set_RemoteCommandReader(self,rcr): self.rcr=rcr def clear(self): self.b2d.update_display=False self.b2d.i2c.write_byte(self.b2d.addrs,0x00) self.b2d.i2c.write_byte(self.b2d.addrs,0x01) time.sleep(0.01) self.b2d.i2c.write_byte(self.b2d.addrs,0x00) self.b2d.i2c.write_byte(self.b2d.addrs,0x01) self.b2d.init_v_bitmap() self.b2d.update_display=True def set_string(self,s): self.clear() self.b2d.update_display=False sx="" while True: print('s='+s+' sx='+sx) if s.startswith('(red)'): self.put_string(sx) sx="" self.b2d.current_r=0xff self.b2d.current_g=0x00 self.b2d.current_b=0x00 s=s[len('(red)'):] if s.startswith('(green)'): self.put_string(sx) sx="" self.b2d.current_r=0x00 self.b2d.current_g=0xff self.b2d.current_b=0x00 s=s[len('(green)'):] if s.startswith('(blue)'): self.put_string(sx) sx="" self.b2d.current_r=0x00 self.b2d.current_g=0x00 self.b2d.current_b=0xff s=s[len('(blue)'):] if s.startswith('(yellow)'): self.put_string(sx) sx="" self.b2d.current_r=0xff self.b2d.current_g=0xff self.b2d.current_b=0x00 s=s[len('(yellow)'):] if s.startswith('(magenta)'): self.put_string(sx) sx="" self.b2d.current_r=0xff self.b2d.current_g=0x00 self.b2d.current_b=0xff s=s[len('(magenta)'):] if s.startswith('(cyan)'): self.put_string(sx) sx="" self.b2d.current_r=0x00 self.b2d.current_g=0xff self.b2d.current_b=0xff s=s[len('(cyan)'):] if s.startswith('(white)'): self.put_string(sx) sx="" self.b2d.current_r=0xc0 self.b2d.current_g=0xc0 self.b2d.current_b=0xc0 s=s[len('(white)'):] if s.startswith('(pink)'): self.put_string(sx) sx="" self.b2d.current_r=0xc0 self.b2d.current_g=0x30 self.b2d.current_b=0x30 s=s[len('(pink)'):] if s.startswith('(orange)'): self.put_string(sx) sx="" self.b2d.current_r=233 self.b2d.current_g=163 self.b2d.current_b=0 s=s[len('(orange)'):] if s.startswith('(brown)'): self.put_string(sx) sx="" self.b2d.current_r=100 self.b2d.current_g=77 self.b2d.current_b=55 s=s[len('(orange)'):] if s.startswith('(purple)'): self.put_string(sx) sx="" self.b2d.current_r=128 self.b2d.current_g=0 self.b2d.current_b=128 s=s[len('(purple)'):] if len(s)>0: sx=sx+s[0] s=s[1:] if len(s)<=0: self.put_string(sx) if(self.b2d.v_rp<15): self.put_string(' ') if(self.b2d.v_rp<23): self.put_string(' ') if(self.b2d.v_rp<31): self.put_string(' ') self.b2d.update_display=True return def put_string(self,s): if s=="": return #print('r={:d}'.format(self.b2d.current_r)+ # ' g={:d}'.format(self.b2d.current_g)+ # ' b={:d}'.format(self.b2d.current_b)) #print('put_string '+s) s_jis=self.fa.utf_8_str_to_jis_barray(s) self.b2d.clear_bitmap(self.b2d.d_bitmap) for i in range(len(s_jis)): c=s_jis[i] fx=self.b2d.font_accessor.get_font_jis(c) #self.b2d.font_accessor.print_font(fx) self.b2d.put_font(fx) def main(): #ss=Show_String() #brightness=[40] #ss.b2d.i2c.write_i2c_block_data(ss.b2d.addrs,0x06,brightness) #ss.set_string("(green)福山(red)薔薇(blue)祭(white)!") RemoteCommandReader() if __name__ == "__main__": main() }} ---- #counter
タイムスタンプを変更しない
[[Required-Software-and-Data]] #code(Python){{ # -*- coding: utf-8 -*- # # wearable_sign_06.py # takashi yamanoue, 2025 7/21 # # # +---------+ +--------------+ # Wiki <->| fwb4pi |<---->|tcp_server_ex1| # +---------+ +--------------+ # ^ # | # v # +------------------+ # |RemoteCommandReder| # | | | # | v | # | handler | # | | | # | v | # | parser | # | | | # +----|-------------+ # | # | put # v # +------------------+ # |TeleportDresser | # | | | # | v | # | handler | # +------------------+ # import smbus import time import traceback import struct import threading import copy import socket import os import sys import netifaces class RemoteCommandReader: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) HOST = 'localhost' PORT = 9998 def __init__(self): print("start RemoteCommandReader.__init__") self.client_start() #self.teleport_dress=Teleport_Dress() self.ss=Show_String() #print(self.teleport_dress) #self.teleport_dress.setRemoteCommandReader(self) self.ss.set_RemoteCommandReader(self) while True: try: time.sleep(0.01) except: print("error") def python2fwbln(self,py2x_message): msg=py2x_message+'\n' self.sock.sendall(msg.encode('utf-8')) def python2fwb(self,py2x_message): msg=py2x_message self.sock.sendall(msg.encode('utf-8')) def rb(self,in_str): while True: if in_str.startswith(' '): in_str=in_str[1:] else: break return in_str def parse_key(self,key,inx,rest): #print("parse_key-"+key) keylen=len(key) inlen=len(inx) if inx.startswith(key): rest[0]=inx[keylen:] return True rest[0]=inx return False def parse_String_Constant(self,inx,strc,rest): rx=[""] xstr="" if self.parse_key('"',inx,rx): #print("parse_String_Constant") inx=rx[0] fx=inx[0] xlen=len(inx) while fx!='"': if xlen==0: return False if fx=='\\': inx=inx[1:xlen] else: xstr=xstr+fx xlen=len(inx) inx=inx[1:xlen] fx=inx[0] if self.parse_key('"',inx,rx): strc[0]=xstr rest[0]=rx[0] return True return False def parse(self,line): self.python2fwb(">"+line) #words=line.split() #print('parse line='+line) if line.startswith('show '): line=line[len('show '):] #print(line) line=self.rb(line) #print('line='+line) text=[''] rest=[''] if self.parse_String_Constant(line,text,rest): self.ss.set_string(text[0]) elif line.startswith('clear'): self.ss.set_string('') elif line.startswith('ls'): self.returnFileList() elif line.startswith('address'): self.show_address() elif line.startswith('shutdown'): self.shutdown() def returnFileList(self): cpath=os.getcwd() os.chdir("/home/pi/Pictures") filenames = [f.name for f in os.scandir()] filenames.sort() for fn in filenames: self.python2fwbln(fn) os.chdir(cpath) def shutdown(self): os.system("sudo shutdown -h now") def show_address(self): ifs=netifaces.interfaces() #print("show address ifs=",end="") #print(ifs) for i in ifs: rtn=i+':' ifps=netifaces.ifaddresses(i) #print("ifps=",end="") #print(ifps) try: rtn=rtn+ifps[2][0]['addr'] except Exception as e: print(e) print(rtn) self.python2fwbln(rtn) def client_start(self): """クライアントのスタート""" self.sock.connect((self.HOST, self.PORT)) handle_thread = threading.Thread(target=self.handler, args=(self.sock,), daemon=True) handle_thread.start() def handler(self,sock): """サーバからメッセージを受信し、表示する""" fx=sock.makefile('r') while True: try: l=fx.readline() #print('l='+l) except socket.error: # socketにエラーが発生したとき print("socket error. exit") sock.close() # socketをclose except: import traceback traceback.print_exc() print("server_handler receive error.") self.parse(l) class Binary_file_reader: binary_data=None def read_file(self,path): self.binary_data=None try: with open(path,'rb') as file: while True: chunk = file.read(1024) if not chunk: break if not self.binary_data: self.binary_data=chunk else: self.binary_data=self.binary_data+chunk file.close() except Exception as e: print(traceback.format_exc()) def get_binary(self): return self.binary_data def dump_binary(self,frm, length): if not self.binary_data: print("no binary.") adr=frm s="" c="" size=len(self.binary_data) cs=[' '] if size<length: length=size eadr=adr+length while adr<eadr: a=adr if a<size: s='{:08x}'.format(a) else: s=' ' print(s,end='') sline='' cline='' for i in range(16): if a<size: d=self.binary_data[a] & 0xff sline=sline+'{:02x}'.format(d)+' ' if d<0x20 or d>0xde or (d>0x73 and d<0xa1): d=0x2e cs=chr(d); cline=cline+cs+' ' else: s=' ' c=' ' a=a+1 print(' '+sline+' '+cline) adr=a def dump_binary_all(self): self.dump_binary(0,len(self.binary_data)) #b_reader=Binary_file_reader() #b_reader.read_file('ShinonomeMin_16.pdb') #b_reader.dump_binary(0,1024) class Font_accessor: font_array=[] base=0 one_font_size=16 font_width_byte=2 asciicode=[ 0x2121, 0x2121,0x2121,0x2121, #//0x00, 0x01, 0x02, 0x03, 0x2121, 0x2121,0x2121,0x2121, #//0x04, 0x05, 0x06, 0x07, 0x2121, 0x2121,0x2121,0x2121, #//0x08, 0x09, 0x0A, 0x0B, 0x2121, 0x2121,0x2121,0x2121, #//0x0C, 0x0D, 0x0E, 0x0F, 0x2121, 0x2121,0x2121,0x2121, #//0x10, 0x11, 0x12, 0x13, 0x2121, 0x2121,0x2121,0x2121, #//0x14, 0x15, 0x16, 0x17, 0x2121, 0x2121,0x2121,0x2121, #//0x18, 0x19, 0x1A, 0x1B, 0x2121, 0x2121,0x2121,0x2121, #//0x1C, 0x1D, 0x1E, 0x1F, 0x2121, 0x212A,0x2148,0x2174, #//0x20, 0x21, 0x22, 0x23, ' ', '!', '"', '#', 0x2170, 0x2173,0x2175,0x212D, #//0x24, 0x25, 0x26, 0x27, '$', '%', '&', ''', 0x214A, 0x214B,0x2176,0x215C, #//0x28, 0x29, 0x2A, 0x2B, '(', ')', '*', '+', 0x2124, 0x215D,0x2125,0x213F, #//0x2C, 0x2D, 0x2E, 0x2F, ',', '-', '.', '/', 0x2330, 0x2331,0x2332,0x2333, #//0x30, 0x31, 0x32, 0x33, '0', '1', '2', '3', 0x2334, 0x2335,0x2336,0x2337, #//0x34, 0x35, 0x36, 0x37, '4', '5', '6', '7', 0x2338, 0x2339,0x2127,0x2128, #//0x38, 0x39, 0x3A, 0x3B, '8', '9', ':', ';', 0x2163, 0x2161,0x2164,0x2129, #//0x3C, 0x3D, 0x3E, 0x3F, '<', '=', '>', '?', 0x2177, 0x2341,0x2342,0x2343, #//0x40, 0x41, 0x42, 0x43, '@', 'A', 'B', 'C', 0x2344, 0x2345,0x2346,0x2347, #//0x44, 0x45, 0x46, 0x47, 'D', 'E', 'F', 'G', 0x2348, 0x2349,0x234A,0x234B, #//0x48, 0x49, 0x4A, 0x4B, 'H', 'I', 'J', 'K', 0x234C, 0x234D,0x234E,0x234F, #//0x4C, 0x4D, 0x4E, 0x4F, 'L', 'M', 'N', 'O', 0x2350, 0x2351,0x2352,0x2353, #//0x50, 0x51, 0x52, 0x53, 'P', 'Q', 'R', 'S', 0x2354, 0x2355,0x2356,0x2357, #//0x54, 0x55, 0x56, 0x57, 'T', 'U', 'V', 'W', 0x2358, 0x2359,0x235A,0x214E, #//0x58, 0x59, 0x5A, 0x5B, 'X', 'Y', 'Z', '[', 0x2140, 0x214F,0x2130,0x2132, #//0x5C, 0x5D, 0x5E, 0x5F, '\', ']', '^', '_', 0x212D, 0x2361,0x2362,0x2363, #//0x60, 0x61, 0x62, 0x63, '`', 'a', 'b', 'c', 0x2364, 0x2365,0x2366,0x2367, #//0x64, 0x65, 0x66, 0x67, 'd', 'e', 'f', 'g', 0x2368, 0x2369,0x236A,0x236B, #//0x68, 0x69, 0x6A, 0x6B, 'h', 'i', 'j', 'k', 0x236C, 0x236D,0x236E,0x236F, #//0x6C, 0x6D, 0x6E, 0x6F, 'l', 'm', 'n', 'o', 0x2370, 0x2371,0x2372,0x2373, #//0x70, 0x71, 0x72, 0x73, 'p', 'q', 'r', 's', 0x2374, 0x2375,0x2376,0x2377, #//0x74, 0x65, 0x76, 0x77, 't', 'u', 'v', 'w', 0x2378, 0x2379,0x237A,0x2150, #//0x78, 0x69, 0x7A, 0x7B, 'x', 'y', 'z', '{', 0x2143, 0x2151,0x2141,0x2121 # //0x7C, 0x6D, 0x7E, 0x7F, '|', '}', '~', ' ', ] ascii_font=[0 for x in range(256*8)] ascii_font_data=[ #// #// use https://github.com/alexmac/alcextra/blob/master/aalib-1.4.0/src/font8.c #// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, #//0x00 null 0x7e, 0x81, 0xa5, 0x81, 0xbd, 0x99, 0x81, 0x7e, 0x7e, 0xff, 0xdb, 0xff, 0xc3, 0xe7, 0xff, 0x7e, 0x6c, 0xfe, 0xfe, 0xfe, 0x7c, 0x38, 0x10, 0x00, 0x10, 0x38, 0x7c, 0xfe, 0x7c, 0x38, 0x10, 0x00, 0x38, 0x7c, 0x38, 0xfe, 0xfe, 0x92, 0x10, 0x7c, 0x00, 0x10, 0x38, 0x7c, 0xfe, 0x7c, 0x38, 0x7c, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00, 0x00, 0xff, 0xff, 0xe7, 0xc3, 0xc3, 0xe7, 0xff, 0xff, 0x00, 0x3c, 0x66, 0x42, 0x42, 0x66, 0x3c, 0x00, 0xff, 0xc3, 0x99, 0xbd, 0xbd, 0x99, 0xc3, 0xff, 0x0f, 0x07, 0x0f, 0x7d, 0xcc, 0xcc, 0xcc, 0x78, 0x3c, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x18, 0x3f, 0x33, 0x3f, 0x30, 0x30, 0x70, 0xf0, 0xe0, 0x7f, 0x63, 0x7f, 0x63, 0x63, 0x67, 0xe6, 0xc0, 0x99, 0x5a, 0x3c, 0xe7, 0xe7, 0x3c, 0x5a, 0x99, 0x80, 0xe0, 0xf8, 0xfe, 0xf8, 0xe0, 0x80, 0x00, #//0x10 0x02, 0x0e, 0x3e, 0xfe, 0x3e, 0x0e, 0x02, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x00, 0x7f, 0xdb, 0xdb, 0x7b, 0x1b, 0x1b, 0x1b, 0x00, 0x3e, 0x63, 0x38, 0x6c, 0x6c, 0x38, 0x86, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x7e, 0x3c, 0x18, 0xff, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x00, 0x00, 0x18, 0x0c, 0xfe, 0x0c, 0x18, 0x00, 0x00, 0x00, 0x30, 0x60, 0xfe, 0x60, 0x30, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xfe, 0x00, 0x00, 0x00, 0x24, 0x66, 0xff, 0x66, 0x24, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7e, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, #//0x20 space 0x18, 0x3c, 0x3c, 0x18, 0x18, 0x00, 0x18, 0x00, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c, 0xfe, 0x6c, 0xfe, 0x6c, 0x6c, 0x00, 0x18, 0x7e, 0xc0, 0x7c, 0x06, 0xfc, 0x18, 0x00, 0x00, 0xc6, 0xcc, 0x18, 0x30, 0x66, 0xc6, 0x00, 0x38, 0x6c, 0x38, 0x76, 0xdc, 0xcc, 0x76, 0x00, 0x30, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x30, 0x60, 0x60, 0x60, 0x30, 0x18, 0x00, 0x60, 0x30, 0x18, 0x18, 0x18, 0x30, 0x60, 0x00, 0x00, 0x66, 0x3c, 0xff, 0x3c, 0x66, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x80, 0x00, 0x7c, 0xce, 0xde, 0xf6, 0xe6, 0xc6, 0x7c, 0x00, #//0x30 0 0x30, 0x70, 0x30, 0x30, 0x30, 0x30, 0xfc, 0x00, #// 1 0x78, 0xcc, 0x0c, 0x38, 0x60, 0xcc, 0xfc, 0x00, #// 2 0x78, 0xcc, 0x0c, 0x38, 0x0c, 0xcc, 0x78, 0x00, #// 3 0x1c, 0x3c, 0x6c, 0xcc, 0xfe, 0x0c, 0x1e, 0x00, #// 4 0xfc, 0xc0, 0xf8, 0x0c, 0x0c, 0xcc, 0x78, 0x00, #// 5 0x38, 0x60, 0xc0, 0xf8, 0xcc, 0xcc, 0x78, 0x00, #// 6 0xfc, 0xcc, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x00, #// 7 0x78, 0xcc, 0xcc, 0x78, 0xcc, 0xcc, 0x78, 0x00, #// 8 0x78, 0xcc, 0xcc, 0x7c, 0x0c, 0x18, 0x70, 0x00, #// 9 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x30, 0x18, 0x30, 0x60, 0xc0, 0x60, 0x30, 0x18, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x0c, 0x18, 0x30, 0x60, 0x00, 0x3c, 0x66, 0x0c, 0x18, 0x18, 0x00, 0x18, 0x00, 0x7c, 0xc6, 0xde, 0xde, 0xdc, 0xc0, 0x7c, 0x00, #//0x40 @ 0x30, 0x78, 0xcc, 0xcc, 0xfc, 0xcc, 0xcc, 0x00, #// A 0xfc, 0x66, 0x66, 0x7c, 0x66, 0x66, 0xfc, 0x00, #// B 0x3c, 0x66, 0xc0, 0xc0, 0xc0, 0x66, 0x3c, 0x00, #// C 0xf8, 0x6c, 0x66, 0x66, 0x66, 0x6c, 0xf8, 0x00, #// D 0xfe, 0x62, 0x68, 0x78, 0x68, 0x62, 0xfe, 0x00, #// E 0xfe, 0x62, 0x68, 0x78, 0x68, 0x60, 0xf0, 0x00, #// F 0x3c, 0x66, 0xc0, 0xc0, 0xce, 0x66, 0x3a, 0x00, #// G 0xcc, 0xcc, 0xcc, 0xfc, 0xcc, 0xcc, 0xcc, 0x00, #// H 0x78, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, #// I 0x1e, 0x0c, 0x0c, 0x0c, 0xcc, 0xcc, 0x78, 0x00, #// J 0xe6, 0x66, 0x6c, 0x78, 0x6c, 0x66, 0xe6, 0x00, #// K 0xf0, 0x60, 0x60, 0x60, 0x62, 0x66, 0xfe, 0x00, #// L 0xc6, 0xee, 0xfe, 0xfe, 0xd6, 0xc6, 0xc6, 0x00, #// M 0xc6, 0xe6, 0xf6, 0xde, 0xce, 0xc6, 0xc6, 0x00, #// N 0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x00, #// O 0xfc, 0x66, 0x66, 0x7c, 0x60, 0x60, 0xf0, 0x00, #// 0x50 P 0x7c, 0xc6, 0xc6, 0xc6, 0xd6, 0x7c, 0x0e, 0x00, #// Q 0xfc, 0x66, 0x66, 0x7c, 0x6c, 0x66, 0xe6, 0x00, #// R 0x7c, 0xc6, 0xe0, 0x78, 0x0e, 0xc6, 0x7c, 0x00, #// S 0xfc, 0xb4, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, #// T 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xfc, 0x00, #// U 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x78, 0x30, 0x00, #// V 0xc6, 0xc6, 0xc6, 0xc6, 0xd6, 0xfe, 0x6c, 0x00, #// W 0xc6, 0xc6, 0x6c, 0x38, 0x6c, 0xc6, 0xc6, 0x00, #// X 0xcc, 0xcc, 0xcc, 0x78, 0x30, 0x30, 0x78, 0x00, #// Y 0xfe, 0xc6, 0x8c, 0x18, 0x32, 0x66, 0xfe, 0x00, #// Z 0x78, 0x60, 0x60, 0x60, 0x60, 0x60, 0x78, 0x00, 0xc0, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x02, 0x00, 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, #// 0x60 0x00, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00, #// 0x61 a 0xe0, 0x60, 0x60, 0x7c, 0x66, 0x66, 0xdc, 0x00, #// b 0x00, 0x00, 0x78, 0xcc, 0xc0, 0xcc, 0x78, 0x00, #// c 0x1c, 0x0c, 0x0c, 0x7c, 0xcc, 0xcc, 0x76, 0x00, #// d 0x00, 0x00, 0x78, 0xcc, 0xfc, 0xc0, 0x78, 0x00, #// e 0x38, 0x6c, 0x64, 0xf0, 0x60, 0x60, 0xf0, 0x00, #// f 0x00, 0x00, 0x76, 0xcc, 0xcc, 0x7c, 0x0c, 0xf8, #// g 0xe0, 0x60, 0x6c, 0x76, 0x66, 0x66, 0xe6, 0x00, #// h 0x30, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, #// i 0x0c, 0x00, 0x1c, 0x0c, 0x0c, 0xcc, 0xcc, 0x78, #// j 0xe0, 0x60, 0x66, 0x6c, 0x78, 0x6c, 0xe6, 0x00, #// k 0x70, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, #// l 0x00, 0x00, 0xcc, 0xfe, 0xfe, 0xd6, 0xd6, 0x00, #// m 0x00, 0x00, 0xb8, 0xcc, 0xcc, 0xcc, 0xcc, 0x00, #// n 0x00, 0x00, 0x78, 0xcc, 0xcc, 0xcc, 0x78, 0x00, #// o 0x00, 0x00, 0xdc, 0x66, 0x66, 0x7c, 0x60, 0xf0, #// 0x70 p 0x00, 0x00, 0x76, 0xcc, 0xcc, 0x7c, 0x0c, 0x1e, #// q 0x00, 0x00, 0xdc, 0x76, 0x62, 0x60, 0xf0, 0x00, #// r 0x00, 0x00, 0x7c, 0xc0, 0x70, 0x1c, 0xf8, 0x00, #// s 0x10, 0x30, 0xfc, 0x30, 0x30, 0x34, 0x18, 0x00, #// t 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, #// u 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0x78, 0x30, 0x00, #// v 0x00, 0x00, 0xc6, 0xc6, 0xd6, 0xfe, 0x6c, 0x00, #// w 0x00, 0x00, 0xc6, 0x6c, 0x38, 0x6c, 0xc6, 0x00, #// z 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0x7c, 0x0c, 0xf8, 0x00, 0x00, 0xfc, 0x98, 0x30, 0x64, 0xfc, 0x00, 0x1c, 0x30, 0x30, 0xe0, 0x30, 0x30, 0x1c, 0x00, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00, 0xe0, 0x30, 0x30, 0x1c, 0x30, 0x30, 0xe0, 0x00, 0x76, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0x00, 0x7c, 0xc6, 0xc0, 0xc6, 0x7c, 0x0c, 0x06, 0x7c, 0x00, 0xcc, 0x00, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x1c, 0x00, 0x78, 0xcc, 0xfc, 0xc0, 0x78, 0x00, #//0x80 0x7e, 0x81, 0x3c, 0x06, 0x3e, 0x66, 0x3b, 0x00, 0xcc, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00, 0xe0, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00, 0x30, 0x30, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0, 0x78, 0x0c, 0x38, 0x7e, 0x81, 0x3c, 0x66, 0x7e, 0x60, 0x3c, 0x00, 0xcc, 0x00, 0x78, 0xcc, 0xfc, 0xc0, 0x78, 0x00, 0xe0, 0x00, 0x78, 0xcc, 0xfc, 0xc0, 0x78, 0x00, 0xcc, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, 0x7c, 0x82, 0x38, 0x18, 0x18, 0x18, 0x3c, 0x00, 0xe0, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, 0xc6, 0x10, 0x7c, 0xc6, 0xfe, 0xc6, 0xc6, 0x00, 0x30, 0x30, 0x00, 0x78, 0xcc, 0xfc, 0xcc, 0x00, 0x1c, 0x00, 0xfc, 0x60, 0x78, 0x60, 0xfc, 0x00, 0x00, 0x00, 0x7f, 0x0c, 0x7f, 0xcc, 0x7f, 0x00, 0x3e, 0x6c, 0xcc, 0xfe, 0xcc, 0xcc, 0xce, 0x00, #//0x90 0x78, 0x84, 0x00, 0x78, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0xcc, 0x00, 0x78, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0xe0, 0x00, 0x78, 0xcc, 0xcc, 0x78, 0x00, 0x78, 0x84, 0x00, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0xe0, 0x00, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0xcc, 0x00, 0xcc, 0xcc, 0x7c, 0x0c, 0xf8, 0xc3, 0x18, 0x3c, 0x66, 0x66, 0x3c, 0x18, 0x00, 0xcc, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0x78, 0x00, 0x18, 0x18, 0x7e, 0xc0, 0xc0, 0x7e, 0x18, 0x18, 0x38, 0x6c, 0x64, 0xf0, 0x60, 0xe6, 0xfc, 0x00, 0xcc, 0xcc, 0x78, 0x30, 0xfc, 0x30, 0xfc, 0x30, 0xf8, 0xcc, 0xcc, 0xfa, 0xc6, 0xcf, 0xc6, 0xc3, 0x0e, 0x1b, 0x18, 0x3c, 0x18, 0x18, 0xd8, 0x70, 0x1c, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0x76, 0x00, 0x38, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, 0x00, 0x1c, 0x00, 0x78, 0xcc, 0xcc, 0x78, 0x00, #//0xA0 0x00, 0x1c, 0x00, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0xf8, 0x00, 0xb8, 0xcc, 0xcc, 0xcc, 0x00, 0xfc, 0x00, 0xcc, 0xec, 0xfc, 0xdc, 0xcc, 0x00, 0x3c, 0x6c, 0x6c, 0x3e, 0x00, 0x7e, 0x00, 0x00, 0x38, 0x6c, 0x6c, 0x38, 0x00, 0x7c, 0x00, 0x00, 0x18, 0x00, 0x18, 0x18, 0x30, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0c, 0x0c, 0x00, 0x00, 0xc6, 0xcc, 0xd8, 0x36, 0x6b, 0xc2, 0x84, 0x0f, 0xc3, 0xc6, 0xcc, 0xdb, 0x37, 0x6d, 0xcf, 0x03, 0x18, 0x00, 0x18, 0x18, 0x3c, 0x3c, 0x18, 0x00, 0x00, 0x33, 0x66, 0xcc, 0x66, 0x33, 0x00, 0x00, 0x00, 0xcc, 0x66, 0x33, 0x66, 0xcc, 0x00, 0x00, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0xdb, 0xf6, 0xdb, 0x6f, 0xdb, 0x7e, 0xd7, 0xed, #//0xB0 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36, 0xf6, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x36, 0x36, 0x36, 0x00, 0x00, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x36, 0x36, 0xf6, 0x06, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0xfe, 0x06, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0xf6, 0x06, 0xfe, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0xfe, 0x00, 0x00, 0x00, 0x18, 0x18, 0xf8, 0x18, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x18, 0x18, 0x18, #//0xC0 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36, 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x30, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x30, 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0xf7, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xf7, 0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x30, 0x37, 0x36, 0x36, 0x36, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x36, 0x36, 0xf7, 0x00, 0xf7, 0x36, 0x36, 0x36, 0x18, 0x18, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0xff, 0x36, 0x36, 0x36, #//0xD0 0x36, 0x36, 0x36, 0x36, 0x3f, 0x00, 0x00, 0x00, 0x18, 0x18, 0x1f, 0x18, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xff, 0x36, 0x36, 0x36, 0x18, 0x18, 0xff, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x18, 0x18, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0xc8, 0xdc, 0x76, 0x00, 0x00, 0x78, 0xcc, 0xf8, 0xcc, 0xf8, 0xc0, 0xc0, 0x00, 0xfc, 0xcc, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, #// 0xE0 0x00, 0x00, 0xfe, 0x6c, 0x6c, 0x6c, 0x6c, 0x00, 0xfc, 0xcc, 0x60, 0x30, 0x60, 0xcc, 0xfc, 0x00, 0x00, 0x00, 0x7e, 0xd8, 0xd8, 0xd8, 0x70, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x7c, 0x60, 0xc0, 0x00, 0x76, 0xdc, 0x18, 0x18, 0x18, 0x18, 0x00, 0xfc, 0x30, 0x78, 0xcc, 0xcc, 0x78, 0x30, 0xfc, 0x38, 0x6c, 0xc6, 0xfe, 0xc6, 0x6c, 0x38, 0x00, 0x38, 0x6c, 0xc6, 0xc6, 0x6c, 0x6c, 0xee, 0x00, 0x1c, 0x30, 0x18, 0x7c, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00, 0x7e, 0xdb, 0xdb, 0x7e, 0x00, 0x00, 0x06, 0x0c, 0x7e, 0xdb, 0xdb, 0x7e, 0x60, 0xc0, 0x38, 0x60, 0xc0, 0xf8, 0xc0, 0x60, 0x38, 0x00, 0x78, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x00, 0x00, 0x7e, 0x00, 0x7e, 0x00, 0x7e, 0x00, 0x00, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x7e, 0x00, 0x60, 0x30, 0x18, 0x30, 0x60, 0x00, 0xfc, 0x00, #// 0xF0 0x18, 0x30, 0x60, 0x30, 0x18, 0x00, 0xfc, 0x00, 0x0e, 0x1b, 0x1b, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xd8, 0xd8, 0x70, 0x18, 0x18, 0x00, 0x7e, 0x00, 0x18, 0x18, 0x00, 0x00, 0x76, 0xdc, 0x00, 0x76, 0xdc, 0x00, 0x00, 0x38, 0x6c, 0x6c, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x0f, 0x0c, 0x0c, 0x0c, 0xec, 0x6c, 0x3c, 0x1c, 0x58, 0x6c, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x70, 0x98, 0x30, 0x60, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x3c, 0x3c, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ] def __init__(self,font_data, font_size, base): self.font_array=font_data self.one_font_size=font_size self.base=base self.font_width_byte=int((self.one_font_size+7)/8) for i in range(len(self.ascii_font)): self.ascii_font[i]=self.ascii_font_data[i] def utf_8_str_to_jis_barray(self,x): #print('utf_8_str_to_jis_barray x='+x) rtn=[] lx=len(x) for i in range(lx): c=x[i] #print('c='+c) j=self.utf_8_to_jis_char(c) #print('j={:x}'.format(j)) rtn.append(j) return rtn def utf_8_to_jis_char(self,x): #print('utf_8_to_jis_char x='+x) w=x.encode('shift_jis') jw=self.sjis_to_jis(w) return jw def sjis_to_jis_string(self,x): xlen=len(x) rtn='' for i in range(xlen): w=self.sjis_to_jis(x[i]) rtn=rtn+w return rtn def sjis_to_jis(self, x): #print('sjis_to_jis x=',end='') #print(x) if len(x)==2: wx=struct.unpack('BB',x) c1=wx[0] c2=wx[1] else: wx=struct.unpack('B',x) c1=0 c2=wx[0] #print(wx) ##c1=(x >> 8) &0x00ff ##c2=x & 0x00ff #print('c1={:x}'.format(c1)) #print('c2={:x}'.format(c2)) if c1==0: c2=c2 else: if c1 >=0xe0: c1=c1-0x40 if c2 >=0x80: c2=c2-1 if c2 >=0x9e: c1=(c1-0x70)*2 c2=c2-0x7d else: c1=((c1-0x70)*2)-1 c2=c2-0x1f rtn=(c1<<8)|c2 #print('rtn=',end='') #print(rtn) return rtn def get_JIS_string(self,x): tmp=self.get_SJIS_string(x) if tmp==None: return None rtn=[' ' for i in range(len(tmp))] bl=len(tmp) for i in range(bl): #print('tmp[i]='+tmp[i]) #print('tmp[i]={:0x}'.format(ord(tmp[i]))) cx=ord(tmp[i]) & 0x0000ffff if cx>0x2100: rtn[i]=self.sjis_to_jis(tmp[i]) else: rtn[i]=tmp[i] return rtn def get_font_jis(self,code): hb=(0xff00 & code)>>8 lb=0x00ff & code if code <0x2100: return self.get_ascii_font(code) fn=((hb-0x21)*(0x7f-0x21))+lb-0x21 pos=self.base+(fn*self.one_font_size*self.font_width_byte) return self.get_font_raw(pos) def get_ascii_font(self,c): # Standard ASCII 5x7 font # Draw a character rtn=[0 for i in range(16)] offset=6 #print('get_ascii_font c={:x}'.format(c)) for i in range(8): rtn[offset+i]=self.ascii_font[8*c+i] #print(rtn) return rtn def get_font_raw(self,pos): if self.font_array==None: return None rtn=[0 for i in range(self.one_font_size*self.font_width_byte)] if pos+self.one_font_size*self.font_width_byte > len(self.font_array): print("exceeded the max font range.") return None for i in range(self.one_font_size*self.font_width_byte): rtn[i]=self.font_array[pos+i] return rtn def print_font(self,f): if f==None: return w=int(self.one_font_size/8) fsize=len(f) if fsize<=16: w=1 for i in range(self.one_font_size): for j in range(w): l=f[i*w+j] mask=0x0080 for k in range(8): if (mask & l)!=0: print('*',end='') else: print(' ',end='') mask=mask>>1 print('') print('') class Bitmap_to_Display: # # command: # clear... 0x00 # show ... 0x01 # set1 ix,iy,r,g,b # ... 0x02 *,*, *,*,* # setn ix,iy,n, r0,g0,b0, ..r(n-1),g(n-1),b(n-1) n<=8 # ... 0x03 *,*, *, *,*,*, ..., *,*,* # pixels_ex01= [ \ [ ' ',' ',' ',' ',' ',' ',' ',' '],\ [ ' ','r','r',' ',' ','r','r',' '],\ [ 'r',' ',' ','r','r',' ',' ','r'],\ [ 'r',' ',' ',' ',' ',' ',' ','r'],\ [ 'r',' ',' ',' ',' ',' ',' ','r'],\ [ 'r',' ',' ',' ',' ',' ',' ','r'],\ [ ' ','r',' ',' ',' ',' ','r',' '],\ [ ' ','r',' ',' ',' ',' ','r',' '],\ [ ' ',' ','r',' ',' ','r',' ',' '],\ [ ' ',' ',' ','r','r',' ',' ',' '],\ [ ' ',' ',' ',' ',' ',' ',' ',' '],\ [ ' ','g','g','g','g','g','g','g'],\ [ ' ',' ','g','y','y','y','g',' '],\ [ ' ',' ',' ','g','y','g',' ',' '],\ [ ' ',' ',' ','g','y','g',' ',' '],\ [ ' ',' ',' ',' ','g',' ',' ',' '] ] r_comp={' ':0x00, 'r':0xff, 'g':0x00, 'b':0x00, 'y':0xff, 'w':0xff} g_comp={' ':0x00, 'r':0x00, 'g':0xff, 'b':0x00, 'y':0xff, 'w':0xff} b_comp={' ':0x00, 'r':0x00, 'g':0x00, 'b':0xff, 'y':0x00, 'w':0xff} def __init__(self,fa): self.i2c = smbus.SMBus(1) self.addrs = 0x3f self.fourpix=[0x00, 0x00, 0x04, 0,0,0, 0,0,0, 0,0,0, 0,0,0] self.v_bitmap=[[] for i in range(16)] self.v_lp=0 self.v_rp=0 self.d_bitmap=[[[0]*3 for i in range(32)] for j in range(16)] self.current_r=0xff self.current_g=0x00 self.current_b=0x00 self.font_accessor=fa self.update_display=True def init_v_bitmap(self): self.v_bitmap=[[] for i in range(16)] self.v_lp=0 self.v_rp=0 def start_display_thread(self): self.thread=threading.Thread(target=self.display_thread) self.thread.start() def display_thread(self): while True: if self.update_display: if self.v_rp>=(len(self.v_bitmap[0])): self.v_rp=0 if self.v_lp>=(len(self.v_bitmap[0])): self.v_lp=0 #print('len(v_bitmap[0]={:d})'.format(len(self.v_bitmap[0]))) #print('v_lp='+str(self.v_lp)+' v_rp='+str(self.v_rp)) if self.v_lp==self.v_rp: self.clear_bitmap(self.d_bitmap) elif self.v_lp<self.v_rp: self.set_bitmap(self.v_bitmap,0,self.v_lp,16,32, self.d_bitmap,0,0) else: self.set_bitmap(self.v_bitmap,0,self.v_lp,16, len(self.v_bitmap[0])-self.v_lp, self.d_bitmap,0,0) self.set_bitmap(self.v_bitmap,0,0,16,self.v_rp, self.d_bitmap,0,len(self.v_bitmap[0])-self.v_lp+1) self.v_lp=self.v_lp+1 self.v_rp=self.v_rp+1 self.show_bitmap(self.d_bitmap,0,0,16,32) time.sleep(0.01) def put_font(self,font): #print(font) if(len(font)>16): w=16 else: w=8 f_bitmap=[[[0,0,0] for i in range(w)] for j in range(16)] self.set_font(self.font_accessor,font,f_bitmap,0,0) self.append_font(f_bitmap) def append_font(self,font): #print('append_font w={:d}'.format(len(font[0]))) #self.print_bitmap(font) if len(font)!=len(self.v_bitmap): print('font size unmatch') return for i in range(len(self.d_bitmap)): l=copy.copy(font[i]) #print('l=',end='') #print(l) #print('l len={:d}'.format(len(l))) #print('b v_bitmap[{:d}'.format(i)+']=',end='') #print(self.v_bitmap[i]) (self.v_bitmap[i]).extend(l) #print('a v_bitmap[{:d}'.format(i)+']=',end='') #print(self.v_bitmap[i]) #print('len={:d}'.format(len(self.v_bitmap[i]))) self.v_lp=0 if len(self.v_bitmap[0])<31: self.v_rp=len(self.v_bitmap[0]) else: self.v_rp=31 #print('-print_bitmap v_lp={:d}'.format(self.v_lp)+' v_rp={:d}'.format(self.v_rp)) #for i in range(16): #print('v_bitmap[{:d}'.format(i)+'] w={:d}'.format(len(self.v_bitmap[i]))) def set_color(self,r,g,b): self.current_r=r self.current_g=g self.current_b=b def clear_bitmap(self,bitmap): h_max=len(bitmap) w_max=len(bitmap[0]) for i in range(h_max): for j in range(w_max): for k in range(3): bitmap[i][j][k]=0 def set_example_01(self,pixels_ex01,i,j,h,w,destination): for ip in range(h): for jp in range(w): p=pixels_ex01[i+ip][j+jp] for color in ['r','g','b']: if color == 'r': destination[ip][jp][0]=self.r_comp[p] elif color == 'g': destination[ip][jp][1]=self.g_comp[p] elif color == 'b': destination[ip][jp][2]=self.b_comp[p] def set_bitmap(self,source,i,j,h,w, destination,k,l): #print('set_bitmap i={:d}'.format(i)+' j={:d}'.format(j)+ # ' h={:d}'.format(h)+' w={:d}'.format(w)+ # ' k={:d}'.format(k)+' l={:d}'.format(k)) #self.print_bitmap(source) for ip in range(h): for jp in range(w): for cp in range(3): #print(' i+ip={:d}'.format(i+ip)+' j+jp={:d}'.format(j+jp)) cx=source[i+ip][j+jp][cp] destination[k+ip][l+jp][cp]=cx def set_font(self,fa,f, destination,d_i,d_j): if f==None: return w=int(fa.one_font_size/8) fsize=len(f) if fsize<=16: w=1 for i in range(fa.one_font_size): for j in range(w): l=f[i*w+j] mask=0x0080 for k in range(8): if (mask & l)!=0: #print('*',end='') destination[d_i+i][d_j+j*8+k][0]=self.current_r destination[d_i+i][d_j+j*8+k][1]=self.current_g destination[d_i+i][d_j+j*8+k][2]=self.current_b else: destination[d_i+i][d_j+j*8+k][0]=0 destination[d_i+i][d_j+j*8+k][1]=0 destination[d_i+i][d_j+j*8+k][2]=0 #print(' ',end='') mask=mask>>1 #print('') #print('') def show_bitmap(self, pixels, #bitmap data i,j, #i,j: left, top position from the bitmap h,w #h:hight, w:width of the showing ): self.i2c.write_byte(self.addrs,0x00) four_bitmap=[[0]*3 for i in range(4)] for ip in range(h): for jp in range(int(w/4)): for kp in range(4): for cp in range(3): four_bitmap[kp][cp]=pixels[i+ip][j+jp*4+kp][cp] self.send_4_pixel(i+ip,j+jp*4,four_bitmap) self.i2c.write_byte(self.addrs,0x01) def send_4_pixel(self, i,j,four_bitmap): #self.i2c.write_byte(self.addrs,0x00) self.fourpix[0]=i self.fourpix[1]=j for k in range(4): for l in range(3): p=four_bitmap[k][l] self.fourpix[3+3*k+l]=p #print('self.fourpix=',end='') #print(self.fourpix) self.i2c.write_i2c_block_data(self.addrs,0x03,self.fourpix) #i2c.write_byte(addrs,0x01) def print_bitmap(self,bitmap): h_max=len(bitmap) w_max=len(bitmap[0]) for ip in range(h_max): for jp in range(w_max): cc=0 for cp in range(3): cx=bitmap[ip][jp][cp] cc=cc<<8|cx print('{:6x}'.format(cc),end='') print() def test_01(self): self.clear_bitmap(self.d_bitmap) self.print_bitmap(self.d_bitmap) self.set_example_01(self.pixels_ex01,0,0,16,8,self.d_bitmap) self.print_bitmap(self.d_bitmap) self.show_bitmap(self.d_bitmap,0,0,16,8) self.print_bitmap(self.d_bitmap) class Show_String: def __init__(self): b_reader=Binary_file_reader() b_reader.read_file('ShinonomeMin_16.pdb') self.fa=Font_accessor(b_reader.get_binary(),16,0x00F0) self.b2d=Bitmap_to_Display(self.fa) self.b2d.start_display_thread() def set_RemoteCommandReader(self,rcr): self.rcr=rcr def clear(self): self.b2d.update_display=False self.b2d.i2c.write_byte(self.b2d.addrs,0x00) self.b2d.i2c.write_byte(self.b2d.addrs,0x01) time.sleep(0.01) self.b2d.i2c.write_byte(self.b2d.addrs,0x00) self.b2d.i2c.write_byte(self.b2d.addrs,0x01) self.b2d.init_v_bitmap() self.b2d.update_display=True def set_string(self,s): self.clear() self.b2d.update_display=False sx="" while True: print('s='+s+' sx='+sx) if s.startswith('(red)'): self.put_string(sx) sx="" self.b2d.current_r=0xff self.b2d.current_g=0x00 self.b2d.current_b=0x00 s=s[len('(red)'):] if s.startswith('(green)'): self.put_string(sx) sx="" self.b2d.current_r=0x00 self.b2d.current_g=0xff self.b2d.current_b=0x00 s=s[len('(green)'):] if s.startswith('(blue)'): self.put_string(sx) sx="" self.b2d.current_r=0x00 self.b2d.current_g=0x00 self.b2d.current_b=0xff s=s[len('(blue)'):] if s.startswith('(yellow)'): self.put_string(sx) sx="" self.b2d.current_r=0xff self.b2d.current_g=0xff self.b2d.current_b=0x00 s=s[len('(yellow)'):] if s.startswith('(magenta)'): self.put_string(sx) sx="" self.b2d.current_r=0xff self.b2d.current_g=0x00 self.b2d.current_b=0xff s=s[len('(magenta)'):] if s.startswith('(cyan)'): self.put_string(sx) sx="" self.b2d.current_r=0x00 self.b2d.current_g=0xff self.b2d.current_b=0xff s=s[len('(cyan)'):] if s.startswith('(white)'): self.put_string(sx) sx="" self.b2d.current_r=0xc0 self.b2d.current_g=0xc0 self.b2d.current_b=0xc0 s=s[len('(white)'):] if s.startswith('(pink)'): self.put_string(sx) sx="" self.b2d.current_r=0xc0 self.b2d.current_g=0x30 self.b2d.current_b=0x30 s=s[len('(pink)'):] if s.startswith('(orange)'): self.put_string(sx) sx="" self.b2d.current_r=233 self.b2d.current_g=163 self.b2d.current_b=0 s=s[len('(orange)'):] if s.startswith('(brown)'): self.put_string(sx) sx="" self.b2d.current_r=100 self.b2d.current_g=77 self.b2d.current_b=55 s=s[len('(orange)'):] if s.startswith('(purple)'): self.put_string(sx) sx="" self.b2d.current_r=128 self.b2d.current_g=0 self.b2d.current_b=128 s=s[len('(purple)'):] if len(s)>0: sx=sx+s[0] s=s[1:] if len(s)<=0: self.put_string(sx) if(self.b2d.v_rp<15): self.put_string(' ') if(self.b2d.v_rp<23): self.put_string(' ') if(self.b2d.v_rp<31): self.put_string(' ') self.b2d.update_display=True return def put_string(self,s): if s=="": return #print('r={:d}'.format(self.b2d.current_r)+ # ' g={:d}'.format(self.b2d.current_g)+ # ' b={:d}'.format(self.b2d.current_b)) #print('put_string '+s) s_jis=self.fa.utf_8_str_to_jis_barray(s) self.b2d.clear_bitmap(self.b2d.d_bitmap) for i in range(len(s_jis)): c=s_jis[i] fx=self.b2d.font_accessor.get_font_jis(c) #self.b2d.font_accessor.print_font(fx) self.b2d.put_font(fx) def main(): #ss=Show_String() #brightness=[40] #ss.b2d.i2c.write_i2c_block_data(ss.b2d.addrs,0x06,brightness) #ss.set_string("(green)福山(red)薔薇(blue)祭(white)!") RemoteCommandReader() if __name__ == "__main__": main() }} ---- #counter
テキスト整形のルールを表示する