📄 lcm.c
字号:
temp[10-i] = '.';
continue;
}
temp[10-i] = tmpSum % 10 + '0';
tmpSum /= 10;
if (tmpSum == 0)
{
if ((dots == 0) || (i > dots))
{
break;
}
}
}
temp[11] = 0;
for (i=0; i<10; i++)
{
if ((temp[i] != ' ') || ((10 - i) < len))
{
break;
}
}
if (flag == 1)
{
str[0] = '-';
memcpy(&str[1], &temp[i], 12-i);
return 12-i;
}
else
{
memcpy(str, &temp[i], 12-i);
return 11-i;
}
}
/******************************************************************************
* Describe:Translate bar code to string
* Input : bar code
* Output: void
* Return: void
******************************************************************************/
void Str_BarCode(byte *str, const byte *Bcode)
{
byte i;
byte temp[20];
byte j;
memset(temp, ' ', 20);
j = 13;
for (i=0; i<BAR_BUFF_LEN; i++)
{
temp[j] = (Bcode[i] & 0x0f) + '0';
if (temp[j] > '9')
temp[j] += 7;
j--;
temp[j] = ((Bcode[i] >> 4) & 0x0f) + '0';
if (temp[j] > '9')
temp[j] += 7;
j--;
}
temp[14] = 0;
memcpy(str, &temp[1], 14);
}
/******************************************************************************
* Describe:去掉字符串后端的空格,设置"\0",
* Input :
* Output: void
* Return: void
******************************************************************************/
void Str_MoveSpace(byte *obj, const byte *src, byte maxlen)
{
byte i;
for (i=maxlen; i>0; i--)
{
if ((src[i-1] != ' ') && (src[i-1] != 0))
{
break;
}
}
memcpy(obj, src, i);
obj[i] = 0;
}
// Translate Date to string.
void Str_DateTo(byte *str, byte year, byte month, byte day, byte format)
{
byte temp[20];
// ** 0: American format (MM-DD-YY)
// ** 1: English format (DD-MM-YY)
// ** 2: China format (YY-MM-DD)
if (format > 2)
{
format = 2;
}
if (format == 0)
{
temp[0] = month/10 + 0x30;
temp[1] = month%10 + 0x30;
temp[2] = '-';
temp[3] = day/10 + 0x30;
temp[4] = day%10 + 0x30;
temp[5] = '-';
temp[6] = '2';
temp[7] = '0';
temp[8] = year/10 + 0x30;
temp[9] = year%10 + 0x30;
}
else if (format == 1)
{
temp[0] = day/10 + 0x30;
temp[1] = day%10 + 0x30;
temp[2] = '-';
temp[3] = month/10 + 0x30;
temp[4] = month%10 + 0x30;
temp[5] = '-';
temp[6] = '2';
temp[7] = '0';
temp[8] = year/10 + 0x30;
temp[9] = year%10 + 0x30;
}
else if (format == 2)
{
temp[0] = '2';
temp[1] = '0';
temp[2] = year/10 + 0x30;
temp[3] = year%10 + 0x30;
temp[4] = '-';
temp[5] = month/10 + 0x30;
temp[6] = month%10 + 0x30;
temp[7] = '-';
temp[8] = day/10 + 0x30;
temp[9] = day%10 + 0x30;
}
temp[10] = 0;
memcpy(str, temp, 10+1);
}
// Translate Time to String.
void Str_TimeTo(byte *str, byte hour, byte minute, byte second, byte format)
{
byte temp[20];
temp[0] = hour/10 + 0x30;
temp[1] = hour%10 + 0x30;
temp[2] = ':';
temp[3] = minute/10 + 0x30;
temp[4] = minute%10 + 0x30;
temp[5] = ':';
temp[6] = second/10 + 0x30;
temp[7] = second%10 + 0x30;
temp[8] = 0;
if (format == 0)
{
temp[5] = 0;
memcpy(str, temp, 5+1);
}
else
{
memcpy(str, temp, 8+1);
}
}
// 指定位置,指定格式显示时间.
// format --- 0 "时:分" 格式.
// --- 1 "时:分:秒" 格式.
void Lcm_DispTime(byte posX, byte posY, byte hour, byte minute, byte second, byte format, byte font, byte pop)
{
byte temp[20];
byte len = 8;;
Str_TimeTo(temp, hour, minute, second, format);
if (format == 0)
{
len = 5;
}
Lcm_Disp(temp, posX, posY, len, font, FALSE, pop);
}
/*
消息窗口,只用于显示某些信息,如错误提示,操作提示,当前状态,等等.
根据不同类型作不同处理.
可以指定消息框的大小位置,也可以不指定而采用默认值. (暂只支持默认值).
type -- 0 警告信息, 喇叭响.
-- 1 提示信息, 按键后恢复原显示.
-- 2 提示信息, 等待按键,但不读取按键,恢复原显示.
-- 10 提示信息, 按键后不恢复原显示.(用于紧接取消弹出窗口操作)
-- 20 提示信息, 不等待按键,不恢复原显示,用于紧接显示其它信息.
-- 30 提示信息, CLEAR键退出.按键后恢复原显示.
*/
void Message(byte type, ...)
{
byte lcmCursorBk = lcmCursor;
byte posX, posY, stDot, stLine;
byte height;
byte disp[6][MAX_CHAR57+1];
byte dispFont[6];
byte lines = 0; // 最大显示行,不超过6行.
byte cnt = 0;
byte maxLen = 0, tmpLen;
byte i;
va_list argp; // 定义保存函数参数的结构.
byte *para1; // 存放取出的字符串参数.
byte para2;
// 从参数中读取需要显示的字符串.
memset(disp[0], 0, 6 * (MAX_CHAR57+1));
va_start(argp, type); // argp指向传入的第一个可选参数,type是最后一个确定的参数.
while (1)
{
para1 = va_arg(argp, byte *); // 取出当前的参数,类型为byte *.
if (strcmp(para1, "\0") == 0)
{
break;
}
para2 = va_arg(argp, byte); // 取出当前的参数,类型为byte.
tmpLen = strlen(para1);
if (tmpLen > MAX_CHAR57)
{
tmpLen = MAX_CHAR57; // 超出部分,自动截去.
}
memcpy(disp[cnt], para1, tmpLen);
dispFont[cnt] = para2;
if (para2 == FONT_16)
{
lines += 2; // 16*8字体,占两行显示.
tmpLen *= 8;
if (tmpLen > 15 * 8)
{
disp[cnt][15] = 0; // 若显示超出长度,自动截去.
tmpLen = 15 * 8;
}
if ((tmpLen % 6) != 0)
{
tmpLen = tmpLen / 6 + 1;
}
else
{
tmpLen /= 6;
}
if (maxLen < tmpLen)
{
maxLen = tmpLen;
}
}
else if (para2 == FONT_5)
{
lines++;
if (maxLen < tmpLen)
{
maxLen = tmpLen;
}
}
cnt++;
if (lines >= 6)
{
break;
}
}
va_end(argp); // 将argp置为NULL.
// 关闭光标.
lcmCursor = 0;
// 首先,保存当前显示画面. 以及光标设置.
memcpy(Lcm_mirrorMessage[0], Lcm_mirror[0], LCMLIMIT*LCM_MAX_LINE);
// 弹出消息框,根据字符长度不同,自动以合适的格式显示.
Lcm_ClrLine(0, 8, 0);
stDot = (MAX_CHAR57 - maxLen) / 2 + 1;
stLine = (LCM_MAX_LINE - 2 - lines) / 2 + 1;
posY = stDot * 6;
posX = stLine;
if (lines < 3)
{
lines += 2;
stLine -= 1;
//posX = stLine;
}
if (maxLen < 15)
{
stDot = (MAX_CHAR57 - 15) / 2 + 1;
maxLen = 15;
}
Lcm_PopFrame(stLine*8, stDot*6, lines*8, maxLen*6, 0, TRUE);
for (i=0,lines=0; i < cnt; i++)
{
if (dispFont[i] == 0)
{
posY = stDot * 6 + (maxLen * 6 - strlen(disp[i]) * 6) / 2;
Lcm_Disp(disp[i], (posX+lines)*8, posY, 0, dispFont[i], FALSE, FALSE);
lines++;
}
else
{
posY = stDot * 6 + (maxLen * 6 - strlen(disp[i]) * 8) / 2;
Lcm_Disp(disp[i], (posX+lines)*8, posY, 0, dispFont[i], FALSE, FALSE);
lines += 2;
}
}
// 根据不同类型加以提示.
if (type == 0) // Error Message
{
bellcnt = 100;
GetKey();
}
else if ((type == 1) || (type == 10)) // Prompt Message
{
GetKey();
}
else if (type == 2)
{
while (!Key_Poll_Chk());
}
else if (type == 30)
{
while (GetKey() != KD_CLEAR);
}
// 指定按键退出,恢复原画面.
if ((type != 10) && (type != 20))
{
memcpy(Lcm_mirror[0], Lcm_mirrorMessage[0], LCMLIMIT * LCM_MAX_LINE);
Lcm_Flush(Lcm_mirror[0]);
lcmCursor = lcmCursorBk;
}
}
/********************************************************************************
* 函数说明: 计算字符串(中英文混合)的字符数 (一个中文算一个).
* 输入参数: *str, maxLen -- 待检查字符串的长度.
* 输出参数: void
* 返回值: 字符数.
********************************************************************************/
//byte Lib_SizeofStr(const byte *str, byte maxLen)
byte Lib_SizeofStr(const byte *str)
{
byte maxLen = MAX_DISP_LEN;
byte len = 0;
while (TRUE)
{
if (*str == 0)
{
return len;
}
else if (*str < 0xa1)
{
len++;
str++;
}
else
{
len++;
str += 2;
}
if (len >= maxLen) // 为防止错误发生时无法返回.
{
return len;
}
}
return 0;
}
#if 0
/********************************************************************************
* 函数说明: User Press key "SET".
* 输入参数: void
* 返回值: 0 , cmd
********************************************************************************/
byte SelectOperate(const byte **title, const byte *idx, const byte *modeDesc)
{
char tmpCnt, temp;
byte flag = 0;
byte funcNum;
byte i, j;
void *str;
word key;
byte input = 0;
funcNum = 0;
i = 0;
while (idx[i++] != 0xff)
funcNum++;
tmpCnt = 0;
Lcm_ClrLineCn(0, 4, 0);
while (1)
{
if (funcNum <= 3)
{
temp = '1';
str = title[0];
// Lcm_Disp(&temp, 0*8, 0*8, 1, FONT_16, ((tmpCnt + '1') == temp) ? 1 : 0, 0);
Lcm_DispCn(str,0,0,MAX_DISP_LEN-2,((tmpCnt + '1') == temp));
// Lcm_Disp(str, 0*8, 0*8, Lib_SizeofStr(str), FONT_16, ((tmpCnt + '1') == temp) ? 1 : 0, 0);
Lcm_Disp(modeDesc, 0*8, (MAX_CHAR16 - strlen(modeDesc))*8, 0, FONT_16, 0, 0);
if (funcNum > 1)
{
temp = '2';
str = title[1];
// Lcm_Disp(&temp, 2*8, 0*8, 1, FONT_16, ((tmpCnt + '1') == temp) ? 1 : 0, 0);
Lcm_DispCn(str,1,0,MAX_DISP_LEN-2,((tmpCnt + '1') == temp));
// Lcm_Disp(str, 2*8, 0*8, Lib_SizeofStr(str), FONT_16, ((tmpCnt + '1') == temp) ? 1 : 0, 0);
}
if (funcNum > 2)
{
temp = '3';
str = title[2];
// Lcm_Disp(&temp, 4*8, 0*8, 1, FONT_16, ((tmpCnt + '1') == temp) ? 1 : 0, 0);
Lcm_DispCn(str,2,0,MAX_DISP_LEN-2,((tmpCnt + '1') == temp));
// Lcm_Disp(str, 4*8, 0*8, Lib_SizeofStr(str), FONT_16, ((tmpCnt + '1') == temp) ? 1 : 0, 0);
}
}
else
{
temp = "1234567890"[tmpCnt];
temp = '1';
// Lcm_Disp(&temp, 0*8, 0*8, 1, FONT_16, 1, 0);
str = title[tmpCnt];
Lcm_DispCn(str,0,0,MAX_DISP_LEN-2,1);
//Lcm_Disp(str, 0*8, 0*8, Lib_SizeofStr(str), FONT_16, 1, 0);
Lcm_Disp(modeDesc, 0*8, (MAX_CHAR16 - strlen(modeDesc))*8, 0, FONT_16, 0, 0);
temp = "1234567890"[(tmpCnt + 1) % funcNum];
temp = '2';
// Lcm_Disp(&temp, 2*8, 0*8, 1, FONT_16, 0, 0);
str = title[(tmpCnt + 1) % funcNum];
Lcm_DispCn(str,1,0,MAX_DISP_LEN-2,0);
//Lcm_Disp(str, 2*8, 0*8, Lib_SizeofStr(str), FONT_16, 0, 0);
temp = "1234567890"[(tmpCnt + 2) % funcNum];
temp = '3';
// Lcm_Disp(&temp, 4*8, 0*8, 1, FONT_16, 0, 0);
str = title[(tmpCnt + 2) % funcNum];
Lcm_DispCn(str,2,0,MAX_DISP_LEN-2,0);
//Lcm_Disp(str, 4*8, 0*8, Lib_SizeofStr(str), FONT_16, 0, 0);
temp = "1234567890"[(tmpCnt + 3) % funcNum];
temp = '4';
// Lcm_Disp(&temp, 6*8, 0*8, 1, FONT_16, 0, 0);
str = title[(tmpCnt + 3) % funcNum];
//Lcm_Disp(str, 6*8, 0*8, Lib_SizeofStr(str), FONT_16, 0, 0);
Lcm_DispCn(str,3,0,MAX_DISP_LEN-2,0);
// Lcm_Disp(str, 6*8, 0*8, MAX_CHAR16-4, FONT_16, 0, 0);
{
byte temp[10];
sprintf(temp, " %3d", input);
Lcm_Disp(temp, 6*8, (MAX_CHAR16 - 4)*8, 4, FONT_16, 0, 0);
}
}
switch (key = GetKey())
{
// case KD_1: flag = 1; tmpCnt = 0; break;
// case KD_2: flag = 1; tmpCnt = 1; break;
// case KD_3: flag = 1; tmpCnt = 2; break;
// case KD_4: flag = 1; tmpCnt = 3; break;
// case KD_5: flag = 1; tmpCnt = 4; break;
// case KD_6: flag = 1; tmpCnt = 5; break;
// case KD_7: flag = 1; tmpCnt = 6; break;
// case KD_8: flag = 1; tmpCnt = 7; break;
// case KD_9: flag = 1; tmpCnt = 8; break;
// case KD_0: flag = 1; tmpCnt = 9; break;
// case KD_1: flag = 1; tmpCnt += 0; break;
// case KD_2: flag = 1; tmpCnt += 1; break;
// case KD_3: flag = 1; tmpCnt += 2; break;
// case KD_4: flag = 1; tmpCnt += 3; break;
case KD_1:
case KD_2:
case KD_3:
case KD_4:
case KD_5:
case KD_6:
case KD_7:
case KD_8:
case KD_9:
case KD_0:
{
const byte num_kd[10] = {KD_0, KD_1, KD_2, KD_3, KD_4,
KD_5, KD_6, KD_7, KD_8, KD_9};
byte i;
word tmpInput;
for (i=0; i<10; i++)
{
if (key == num_kd[i])
break;
}
tmpInput = input * 10 + i;
if (tmpInput < 255)
input = tmpInput;
}
break;
case KD_CLEAR:
input = 0;
break;
case KD_TNSFER://display
case KD_CHARGE://Display
case KD_SUBTTL:
case KD_CREDIT://print
if (input != 0)
{
byte i;
for (i=0; i<funcNum; i++)
{
if (idx[i] == input)
break;
}
if (i >= funcNum)
continue;
tmpCnt = i;
}
flag = 1;
if((key == KD_TNSFER)||(key == KD_CHARGE))
InCmd = KD_DISPLAY;
else
InCmd = key;
break;
case KD_LEFT:
if (tmpCnt == 0) tmpCnt = funcNum - 1;
else tmpCnt--;
input = 0;
break;
case KD_RIGHT:
case KD_SUSPEND:
tmpCnt++;
tmpCnt %= funcNum;
input = 0;
break;
case KD_PGUP:
{
byte k;
for (k=0; k<4; k++)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -