I have ssd1306 OLED display with GT20L16S1Y spi font chip,since micropython officially don’t support GT20L16S1Y 。so I begin to wite driver for font chip 。Accroding to GT20L16S1Y data sheet,GT20L16S1Y is a spi chip。Chinese gb2312 encoded data store in it。
gb2312 = text.encode('gb2312')
# add this line
print("len(gb2312):",len(gb2312))
on pc the rusult is:
"len(gb2312):",2
on micropython the rusult is:
"len(gb2312):",3
Is it a bug of micropython?How can i fix it?Thank you for your help
#############################################
following guide:
https://github.com/pengfexue2/printPlay ... intPlay.py
code run perfect on pc
Code: Select all
def printPlay(textStr,line,background):
for text in textStr:
# get chinese gb2312 encode,each chinese gb2312 character contains 2 bytes
gb2312 = text.encode('gb2312')
# add this line
print("len(gb2312):",len(gb2312))
"len(gb2312):",2
#############################################
then modified code and run on ESP32 micropython 1.12 version 20200206 ,
Code: Select all
def getAddr2(self,chn_str):
global Address
#encoding chines in 'gb2312'
print("input is:",text)
gb2312 = text.encode('gb2312')
print("gb2312:",gb2312)
print("len(gb2312)",len(gb2312))
###on micropython the rusult is:
####"len(gb2312):",3
#get hex of gb2312
hex_str = ubinascii.hexlify(gb2312)
print("hex_str:",hex_str)
print("len(hex_str)",len(hex_str))
# get area
+---+---+---+---+---+---+
| P | y | t | h | o | n |
+---+---+---+---+---+---+
0 1 2 3 4 5 6
-6 -5 -4 -3 -2 -1 0
k= hex_str[:2]
kkk=str(k,'utf8')
l=hex_str[2:]
lll=str(l,'utf8')
print("kkk: ",kkk)
print("lll: ",lll)
hb = eval('0x' + bytes.decode(hex_str[:2])) - 0xA0
#get index
lb = eval('0x' + bytes.decode(hex_str[2:])) - 0xA0
print("HB:")
print(hb)
print("LB:")
print(lb)
#predefined,or it go wrong
Address = 0x00
if (hb > 0xA0 and lb > 0xA0): ##is GB2312
BaseAdd = 0
#/*chines standard(GB2312)15x16 in font IC ,to calculate Address of each character ,
#following this formula:*/
#/*Address = ((MSB - 0xa1) * 94 + (LSB - 0xA1))*32+ BaseAdd BaseAdd=0*/
#/*8bit mcu overlap,so in 3 step*/
if (hb == 0xA9 and lb >= 0xA1):
Address = (282 + (lb - 0xA1 )) ##8 bit chip run whith error,so in 3 step and work well
Address = Address * 32
Address += BaseAdd
elif (hb >= 0xA1 and hb <= 0xA3 and lb >= 0xA1):
Address = ((hb - 0xA1) * 94 + (lb - 0xA1))
Address = Address * 32
Address += BaseAdd
#16~87 (0xb0~0xf7) :chinese characters
elif (hb >= 0xB0 and hb <= 0xF7 and lb >= 0xA1):
Address = ((hb - 0xB0) * 94 + (lb - 0xA1) + 846)
Address = Address * 32
Address += BaseAdd
#01~09 :symbol、numers
else: ##is ASCII
BaseAdd = 0x03b7c0
if (lb >= 0x20 and lb <= 0x7E):
Address = (lb - 0x20 ) * 16 + BaseAdd
print("Address is:",Address)
return Address
#########################
"len(gb2312):",3