字库开发过程中的脚本
将如下参数
18
定时开关机//Timing
时间日期//date and time
节能//energy save
温度设置//temp set
高级设置//Advanced Settings tab
周编程//programming
显示设置//display
关于本机//about
秒//sec
分钟//min
#
24
华氏度显示//Fahrenheit
待机显示设定温度//set temp
显示室外温度//outdoor
温度校准//temp calibration
语言//language
恢复出厂设置//Factory Reset
中文//chinese
英文//english
时间设置//time
日期设置//date
24小时//24hour format
熄屏时间//Screen time out
节能//energy save
制冷节能温度//cool
制热节能温度//hot
重复//repeat
开机时间//turn on
关机时间//turn off
#
28
温度设置//temp set
高级设置//Advanced Settings tab
语言//language
时间日期//date and time
亮度调节//brightness regulator
节能设置//energy save
定时开关机//Timing
周编程//programming
开关//switch
#
36
日期//date
时间//time
温度校准//temp calibration
温度设置//temp set
确定恢复出厂设置//Are you sure to restore the factory default Settings?
##
生成格式
定时开关机时间日期节能温度设置高级设置周编程显示设置关于本机秒分钟
华氏度显示待机显示设定温度显示室外温度温度校准语言恢复出厂设置中文英文时间设置日期设置24小时熄屏时间节能制冷节能温度制热节能温度重复开机时间关机时间
温度设置高级设置语言时间日期亮度调节节能设置定时开关机周编程开关
日期时间温度校准温度设置确定恢复出厂设置
u16 str0[]={0xa1a1,0xa1a2,0xa1a3,0xa1a4,0xa1a5,0xa1a6,0xa1a7,0xa1a8,0xa1a9,0xa1aa,0xa1ab,0xa1ac,0xa1ad,0xa1ae,0xa1af,0xa1b0,0xa1b1,0xa1b2,0xa1b3,0xa1b4,0xa1b5,0xa1b6,0xa1b7,0xa1b8,0xa1b9,0xa1ba,0xa1bb,0xa1bc,0xa1bd,0xa1be,0xa1bf,0xa1c0,0xa1c1};
u16 str1[]={0xa1a1,0xa1a2,0xa1a3,0xa1a4,0xa1a5,0xa1a6,0xa1a7,0xa1a8,0xa1a9,0xa1aa,0xa1ab,0xa1ac,0xa1ad,0xa1ae,0xa1af,0xa1b0,0xa1b1,0xa1b2,0xa1b3,0xa1b4,0xa1b5,0xa1b6,0xa1b7,0xa1b8,0xa1b9,0xa1ba,0xa1bb,0xa1bc,0xa1bd,0xa1be,0xa1bf,0xa1c0,0xa1c1,0xa1c2,0xa1c3,0xa1c4,0xa1c5,0xa1c6,0xa1c7,0xa1c8,0xa1c9,0xa1ca,0xa1cb,0xa1cc,0xa1cd,0xa1ce,0xa1cf,0xa1d0,0xa1d1,0xa1d2,0xa1d3,0xa1d4,0xa1d5,0xa1d6,0xa1d7,0xa1d8,0xa1d9,0xa1da,0xa1db,0xa1dc,0xa1dd,0xa1de,0xa1df,0xa1e0,0xa1e1,0xa1e2,0xa1e3,0xa1e4,0xa1e5,0xa1e6,0xa1e7,0xa1e8,0xa1e9,0xa1ea,0xa1eb};
u16 str2[]={0xa1a1,0xa1a2,0xa1a3,0xa1a4,0xa1a5,0xa1a6,0xa1a7,0xa1a8,0xa1a9,0xa1aa,0xa1ab,0xa1ac,0xa1ad,0xa1ae,0xa1af,0xa1b0,0xa1b1,0xa1b2,0xa1b3,0xa1b4,0xa1b5,0xa1b6,0xa1b7,0xa1b8,0xa1b9,0xa1ba,0xa1bb,0xa1bc,0xa1bd,0xa1be,0xa1bf,0xa1c0};
u16 str3[]={0xa1a1,0xa1a2,0xa1a3,0xa1a4,0xa1a5,0xa1a6,0xa1a7,0xa1a8,0xa1a9,0xa1aa,0xa1ab,0xa1ac,0xa1ad,0xa1ae,0xa1af,0xa1b0,0xa1b1,0xa1b2,0xa1b3,0xa1b4};
write_dgus_vp(0x6010,(u8*)&str0[0],5);//定时开关机 字节数:10
write_dgus_vp(0x6020,(u8*)&str0[5],4);//时间日期 字节数:13
write_dgus_vp(0x6030,(u8*)&str0[9],2);//节能 字节数:11
write_dgus_vp(0x6040,(u8*)&str0[11],4);//温度设置 字节数:8
write_dgus_vp(0x6050,(u8*)&str0[15],4);//高级设置 字节数:21
write_dgus_vp(0x6070,(u8*)&str0[19],3);//周编程 字节数:11
write_dgus_vp(0x6080,(u8*)&str0[22],4);//显示设置 字节数:8
write_dgus_vp(0x6090,(u8*)&str0[26],4);//关于本机 字节数:8
write_dgus_vp(0x60a0,(u8*)&str0[30],1);//秒 字节数:3
write_dgus_vp(0x60b0,(u8*)&str0[31],2);//分钟 字节数:4
write_dgus_vp(0x6410,(u8*)&str1[0],5);//华氏度显示 字节数:10
write_dgus_vp(0x6420,(u8*)&str1[5],8);//待机显示设定温度 字节数:16
write_dgus_vp(0x6430,(u8*)&str1[13],6);//显示室外温度 字节数:12
write_dgus_vp(0x6440,(u8*)&str1[19],4);//温度校准 字节数:16
write_dgus_vp(0x6450,(u8*)&str1[23],2);//语言 字节数:8
write_dgus_vp(0x6460,(u8*)&str1[25],6);//恢复出厂设置 字节数:13
write_dgus_vp(0x6470,(u8*)&str1[31],2);//中文 字节数:7
write_dgus_vp(0x6480,(u8*)&str1[33],2);//英文 字节数:7
write_dgus_vp(0x6490,(u8*)&str1[35],4);//时间设置 字节数:8
write_dgus_vp(0x64a0,(u8*)&str1[39],4);//日期设置 字节数:8
write_dgus_vp(0x64b0,(u8*)&str1[43],4);//24小时 字节数:13
write_dgus_vp(0x64c0,(u8*)&str1[47],4);//熄屏时间 字节数:15
write_dgus_vp(0x64d0,(u8*)&str1[51],2);//节能 字节数:11
write_dgus_vp(0x64e0,(u8*)&str1[53],6);//制冷节能温度 字节数:12
write_dgus_vp(0x64f0,(u8*)&str1[59],6);//制热节能温度 字节数:12
write_dgus_vp(0x6500,(u8*)&str1[65],2);//重复 字节数:6
write_dgus_vp(0x6510,(u8*)&str1[67],4);//开机时间 字节数:8
write_dgus_vp(0x6520,(u8*)&str1[71],4);//关机时间 字节数:8
write_dgus_vp(0x6810,(u8*)&str2[0],4);//温度设置 字节数:8
write_dgus_vp(0x6820,(u8*)&str2[4],4);//高级设置 字节数:21
write_dgus_vp(0x6840,(u8*)&str2[8],2);//语言 字节数:8
write_dgus_vp(0x6850,(u8*)&str2[10],4);//时间日期 字节数:13
write_dgus_vp(0x6860,(u8*)&str2[14],4);//亮度调节 字节数:20
write_dgus_vp(0x6880,(u8*)&str2[18],4);//节能设置 字节数:11
write_dgus_vp(0x6890,(u8*)&str2[22],5);//定时开关机 字节数:10
write_dgus_vp(0x68a0,(u8*)&str2[27],3);//周编程 字节数:11
write_dgus_vp(0x68b0,(u8*)&str2[30],2);//开关 字节数:6
write_dgus_vp(0x6c10,(u8*)&str3[0],2);//日期 字节数:4
write_dgus_vp(0x6c20,(u8*)&str3[2],2);//时间 字节数:4
write_dgus_vp(0x6c30,(u8*)&str3[4],4);//温度校准 字节数:16
write_dgus_vp(0x6c40,(u8*)&str3[8],4);//温度设置 字节数:8
write_dgus_vp(0x6c50,(u8*)&str3[12],8);//确定恢复出厂设置 字节数:53
char *str[]={
"Timing ",
"date and time",
"energy save",
"temp set",
"Advanced Settings tab",
"programming",
"display ",
"about ",
"sec",
"min ",char *str[]={
"Fahrenheit",
"set temp ",
"outdoor ",
"temp calibration",
"language",
"Factory Reset",
"chinese",
"english",
"time ",
"date ",
"24hour format",
"Screen time out",
"energy save",
"cool ",
"hot ",
"repeat",
"turn on ",
"turn off",char *str[]={
"temp set",
"Advanced Settings tab",
"language",
"date and time",
"brightness regulator",
"energy save",
"Timing ",
"programming",
"switch",char *str[]={
"date",
"time",
"temp calibration",
"temp set",
"Are you sure to restore the factory default Settings?"
};
write_dgus_vp(0x6010,(u8*)&str[0],10);
write_dgus_vp(0x6020,(u8*)&str[1],13);
write_dgus_vp(0x6030,(u8*)&str[2],11);
write_dgus_vp(0x6040,(u8*)&str[3],8);
write_dgus_vp(0x6050,(u8*)&str[4],21);
write_dgus_vp(0x6070,(u8*)&str[5],11);
write_dgus_vp(0x6080,(u8*)&str[6],8);
write_dgus_vp(0x6090,(u8*)&str[7],8);
write_dgus_vp(0x60a0,(u8*)&str[8],3);
write_dgus_vp(0x60b0,(u8*)&str[9],4);
write_dgus_vp(0x6410,(u8*)&str[10],10);
write_dgus_vp(0x6420,(u8*)&str[11],16);
write_dgus_vp(0x6430,(u8*)&str[12],12);
write_dgus_vp(0x6440,(u8*)&str[13],16);
write_dgus_vp(0x6450,(u8*)&str[14],8);
write_dgus_vp(0x6460,(u8*)&str[15],13);
write_dgus_vp(0x6470,(u8*)&str[16],7);
write_dgus_vp(0x6480,(u8*)&str[17],7);
write_dgus_vp(0x6490,(u8*)&str[18],8);
write_dgus_vp(0x64a0,(u8*)&str[19],8);
write_dgus_vp(0x64b0,(u8*)&str[20],13);
write_dgus_vp(0x64c0,(u8*)&str[21],15);
write_dgus_vp(0x64d0,(u8*)&str[22],11);
write_dgus_vp(0x64e0,(u8*)&str[23],12);
write_dgus_vp(0x64f0,(u8*)&str[24],12);
write_dgus_vp(0x6500,(u8*)&str[25],6);
write_dgus_vp(0x6510,(u8*)&str[26],8);
write_dgus_vp(0x6520,(u8*)&str[27],8);
write_dgus_vp(0x6810,(u8*)&str[28],8);
write_dgus_vp(0x6820,(u8*)&str[29],21);
write_dgus_vp(0x6840,(u8*)&str[30],8);
write_dgus_vp(0x6850,(u8*)&str[31],13);
write_dgus_vp(0x6860,(u8*)&str[32],20);
write_dgus_vp(0x6880,(u8*)&str[33],11);
write_dgus_vp(0x6890,(u8*)&str[34],10);
write_dgus_vp(0x68a0,(u8*)&str[35],11);
write_dgus_vp(0x68b0,(u8*)&str[36],6);
write_dgus_vp(0x6c10,(u8*)&str[37],4);
write_dgus_vp(0x6c20,(u8*)&str[38],4);
write_dgus_vp(0x6c30,(u8*)&str[39],16);
write_dgus_vp(0x6c40,(u8*)&str[40],8);
write_dgus_vp(0x6c50,(u8*)&str[41],53);
代码
'''
import os
#生成u16 str[]={0xA1A1,0xA1A2,0xA1A3,0xA1A4,0xA1A5};
def Code1_Generate(char_static,char_static4):
code_section1 = 'u16 str'+str(char_static4)+'[]={'
for n in range(1,char_static+1):#写入char_static个数字
code_section1=code_section1+str(hex(0xA1A0+n))+','
code_section1=code_section1.strip(',')+'};'+'\n'
return code_section1
#生成write_dgus_vp(0x6040,(u8*)&str,5);//定时开关机
def Code2_Generate(char_static2,char_static3,Charater_Chinese_Size,Charater_Chinese,char_static4,address,maxsize):
#生成write_dgus_vp
code_section2 = "write_dgus_vp("
code_section2 += str(hex(address+char_static3*16))+',(u8*)&str'+str(char_static4)+'['
code_section2 += str(char_static2)+'],'+str(Charater_Chinese_Size)+');'+'//'+ Charater_Chinese+' 字节数:'+str(maxsize)+'\n'
return code_section2
'''
不满足最大字节数,使用空格补齐
生成
char *str[]={
"Timing ",
"date and time",
"energy save",
};
'''
def Code3_Generate(Charater_English,maxsize,Charater_English_Size):
code_section10='\n\"'+Charater_English
#用空格补足与最大字节的差距
j=maxsize-Charater_English_Size
if j!=0:
for i in range(1,j+1):
code_section10+=" "
code_section10+='\",'
return code_section10
#生成write_dgus_vp(0x6000,(u8*)&str[1],10);
def Code4_Generate(char_static3,address,maxsize,char_static5):
code_section100='write_dgus_vp('+str(hex(address+char_static3*16))+',(u8*)&str['+str(char_static5-1)+'],'+str(maxsize)+');'+'\n'
return code_section100
#按小段提取出中文字符
def Magic_Start(f,foo):
char_static=0#每大段的字符总数统计
char_static2=0#统计每一段每行累加
char_static3=0#统计小段行数
char_static4=0#统计小段数量
char_static5=0#统计全部行数
code_section3=""#最终代码片段1
code_section4=""#最终代码片段2
code_section20=""#最终代码片段3
code_section200=""#最终代码片段4
address=0x6000
for line in f.readlines():
Charater_Chinese=""#每行的中文字符存储
Charater_English=""#每行的英文字符存储
line=line.strip('\n')#去掉换行符
line_size=len(line)
if line.isdigit():#行开头为数字
#进行换行和跳转操作
code_section20 += 'char *str[]={'
foo.write('\n\n')
continue
elif line=="#": #行结尾
#生成代码
code_section4+=Code1_Generate(char_static,char_static4)
char_static=0
char_static2=0
char_static3=0
char_static4+=1
address+=0x400
continue
elif line=='##':#文件结束标志
code_section4+=Code1_Generate(char_static,char_static4)
foo.write('\n')
foo.write(code_section4)
foo.write('\n')
foo.write(code_section3)
foo.write('\n')
code_section20=code_section20.strip(',')
code_section20+='\n};\n'
foo.write(code_section20)
foo.write('\n')
foo.write(code_section200)
for char in line:
if char != '/':#非英语部分
Charater_Chinese += char
char_static += 1
elif char =='/':#英语部分
#英文字符串
Charater_English=line.strip(Charater_Chinese)
Charater_English=Charater_English.strip('/')
foo.write(Charater_Chinese)
Charater_Chinese_Size=len(Charater_Chinese)
Charater_English_Size=len(Charater_English)
char_static3+=1
char_static5+=1
maxsize=(max(Charater_English_Size,(Charater_Chinese_Size*2))) #所需要的最大地址数量
code_section3+=Code2_Generate(char_static2,char_static3,Charater_Chinese_Size,
Charater_Chinese,char_static4,address,maxsize)#每次生成write_dgus_vp(0x6040,(u8*)&str,5);//定时开关机
#每次生成英文串
code_section20+=Code3_Generate(Charater_English,maxsize,Charater_English_Size)
#每次生成代码4片段
code_section200+=Code4_Generate(char_static3,address,maxsize,char_static5)
#最大地址数过大时候,调整变量间距
if maxsize>16:
char_static3+=int(maxsize/16)
char_static2+=Charater_Chinese_Size
break
if __name__ == '__main__':
with open(u'E:/Desktop/各种文件/字库相关/代码生成器--迪文/相关参数.txt', 'r') as f:
with open(u'E:/Desktop/各种文件/字库相关/代码生成器--迪文/222.txt', 'a+') as foo:
Magic_Start(f,foo)
os.system("pause")