?? descinput.c
字號:
* desc_len: 允許輸入的最大字符長度.
* 注意, 當 mode == YES 時, 字符串的最后一個字節用作是否整行Bold的標志
* mode: 2 --- 按鍵名稱的輸入
* 1 --- 允許在輸入描述符同時設定字符的格式(是否為雙寬).
* 0 --- 在輸入描述符同時不能選擇字符格式的設定.
* 當前暫時只支持一種輸入方式, 即直接輸入描述符, 沒有代碼選擇方式.
* 輸入的同時,也會顯示輸入結果,
*----------------------------------------------------------------------------*/
byte Get_Desc(byte *desc_str, byte desc_len, byte mode)
{
byte bak_str[MAX_DESC_EX_LEN]; /* Can support the max description length */
byte caps_flag = 0; /* The capital letter input flag:
1: Small letter input mode (Default)
0: Capital letter input mode
*/
byte Symbole_flag = 0; /*1-Symbole / 0-normal*/
byte cch1,cch2; // 當前輸入的最近的描述符. 主要考慮到控制字符的干擾
word key; // 當前按鍵的邏輯代碼輸入
byte count; // 當前輸入的字符個數.
byte BOLD; //設置是否需要支持整行雙寬
byte DB_Mode; //設置當前字體是否為雙寬
byte idx = 0;
BOOL loop = TRUE;
//顯示當前的操作界面
Bak_Ts_Key_Tab = Ts_Key_Tab;
Bak_Ts_Key_Table_Size = Ts_Key_Table_Size;
Ts_Key_Tab = Desc_Input_KeyTab;
Ts_Key_Table_Size = Desc_Input_Key_Size;
Lcd_Desc_Input_Layout(mode, 0);
memset(bak_str, 0, MAX_DESC_EX_LEN);
cch1 = 0;
cch2 = 0;
key = KD_NULL;
count=0;
BOLD = NRM_FONT;
DB_Mode = 0;
if(mode == 2)//保留最后一個字節作為BOLD 的存放空間
desc_len -=1;
while(Key_Poll_Chk() != TRUE);//等待第一個按鍵按下
while (loop)
{
// if(count == 0)
// progflag = 0;
// else
// progflag = 1;
//顯示輸入的字符串
Lcd_Disp_Text_btn(BUF_ID_TL_INPUT, bak_str,count,MAX_TEXT, BTN_DFT_FONT, ALIGN_RIGHT);
if(mode == 2)//需要顯示按鍵效果
{
memset(Input_Btn.desc, 0x20, MAX_BTN_DESC_LEN+1);
memcpy(Input_Btn.desc, bak_str,count);
Input_Btn.desc[MAX_BTN_DESC_LEN] = BOLD;
Lcd_Draw_Button(Input_Btn);
}
key = GetKey();
GetMainMode();//檢測控制鎖的位置
if(GetMainMode() != CurrMode)
{
loop = FALSE;
break;
}
switch( key )
{
case DS_CHAR://符號鍵輸入
key = Check_Key(Ts_Key.curr_logi,RIGHT);//取當前代碼的邏輯輸入值
if(key >= MAX_LAYOUT_KEY)
continue;
cch2 = cch1;
cch1 = code[key + (Symbole_flag*2+caps_flag)*MAX_LAYOUT_KEY];
if(cch1 == 0xff)
{
cch1 = cch2;
continue;
}
if(count + DB_Mode < desc_len)
{
if(DB_Mode)
bak_str[count++] = DB_BOLD_FONT;
bak_str[count++] = cch1;
}
break;
case KD_CAP_SHIFT:
caps_flag = (caps_flag+1)%2;
Lcd_Desc_Input_Layout(mode, Symbole_flag*2+caps_flag+1);
break;
case KD_SYMBOLE:
Symbole_flag = (Symbole_flag+1)%2;
Lcd_Desc_Input_Layout(mode, Symbole_flag*2+caps_flag+1);
break;
case KD_BACK_SPACE:
if(count > 0)
{
count--;
if((count > 0)&&(bak_str[count-1] == DB_BOLD_FONT))
count--;
}
break;
case KD_CANCEL:
if(count > 0)
count = 0;
else
{
Lcd_Res_Pop_Text();
InCmd = KD_ENTER;
progflag = 0;
return NG;
}
break;
case KD_DB_WIDTH:
DB_Mode = (DB_Mode+1)%2;
break;
case KD_LARGE_FONT:
if(mode == 0)
break;
BOLD = (BOLD +1)%2;
break;
case KD_ENTER:
if(count >0)
{
if(mode != 1)
{
memset(desc_str, 0x20, desc_len);
memcpy(desc_str, bak_str, count);
if(mode != 0)
desc_str[desc_len] = BOLD_FONT;
}
else//mode == 1
{
byte tmp_i;
for(tmp_i = 0; tmp_i < count; tmp_i++)
{
if(bak_str[tmp_i] <0x20)//有控制字符輸入
{
// if(BOLD)
// desc_str[2*tmp_i] = DB_HTWDT_PRN;
// else
desc_str[2*tmp_i] = DB_WIDTH_PRN;
desc_str[2*tmp_i+1] = bak_str[tmp_i+1];
tmp_i++;
desc_str[2*tmp_i] = DB_WIDTH_PRN;
desc_str[2*tmp_i+1] = DB_WIDTH_PRN;
}
else
{
// if(BOLD)
// desc_str[2*tmp_i] = DB_HEIGT_PRN;
// else
desc_str[2*tmp_i] = NM_FONT_PRN;
desc_str[2*tmp_i+1] = bak_str[tmp_i];
}
}
}
}
Lcd_Res_Pop_Text();
InCmd = KD_ENTER;
// progflag = 1;
return OK;
#ifdef SCANNER /* Support the scanner function */
case SPLU:
#endif /* End SCANNER */
case KD_PAGE_UP:
case KD_PAGE_DOWN:
case KD_UP:
case KD_DOWN:
loop = FALSE;
break;
default:
break;
}
} // End while
Lcd_Res_Pop_Text();
progflag = 0;
InCmd = KD_NULL;
return NG;
}
/*------------------------------------------------------------------*
* Calculate the description length
*------------------------------------------------------------------*/
byte Get_Desc_Len(byte *disp_str, byte disp_len)
{
byte i;
i = disp_len;
disp_str += disp_len-1;
while((*disp_str == ' ') || (*disp_str == DB_WIDTH_PRN))
{
disp_str --;
i --;
if (i == 0)
break;
}
return (i);
}
#define PRN_DBWD_FREE_BYTE 0xff // 雙寬屬性后續字節為空.
/************************************************************
The next sentences is create by Jiang WangMing
************************************************************/
// Note: In this funciton not consider of the disp_len is 0
byte Get_Desc_Len_Ex(byte *disp_str, byte disp_len, byte mode)
{
byte i;
byte db_wid_flag; /* Double width flag */
if (mode == NO)
{
return (Get_Desc_Len(disp_str, disp_len));
}
else
{
i = disp_len;
disp_str += 2*disp_len - 1;
db_wid_flag = 0;
while(TRUE)
{
if((*disp_str == PRN_DBWD_FREE_BYTE) && (!db_wid_flag)) /* The double width */
{
db_wid_flag = 1;
disp_str -= 2;
}
else if(*disp_str == ' ')
{
if(db_wid_flag)
i -= 2;
else
i -= 1;
db_wid_flag = 0;
disp_str -= 2;
if(i == 0)
break;
}
else
{
break;
}
}
return (i);
}
}
/***********************************************************/
/*-----------------------------------------------------------------------------*
* Display the description to the screen, *
* only display the number to the VFD. *
* Note: This function is especial for the description's format is sepecial *
* The description's format has no end tag, the description is append *
* with '0'. *
*-----------------------------------------------------------------------------*/
void Disp_Desc_Len(byte *disp_str, byte disp_len, byte mode)
{
byte len;
byte i;
if(mode == NO)
{
len = Get_Desc_Len_Ex(disp_str, disp_len, mode);
if(len > MAX_LCD_NUM-3) // 保留三個空間作為代碼輸入時候的顯示
len = MAX_LCD_NUM-3;
for(i = 0; i < len; i ++)
{
Insert_Char(disp_str[i], i);
}
}
else
{
len = Get_Desc_Len_Ex(disp_str, disp_len, mode);
disp_Char_Str(Disp_Desc_Length, 0);
Insert_Num(len/10, 14);
Insert_Num(len%10, 15);
}
}
///////////////////////////////////////////////////////////////////////////////
// Descript: 計算字符串的打印寬度,以普通字體為單位,此字符串符合打印的標準格式.
// In Param: *str, maxLen -- 字符串的最大長度(注: 不包含格式字符的長度).
// Out Param: void
// Return: 字符串的打印寬度.
///////////////////////////////////////////////////////////////////////////////
byte Prn_CalcuWidth(const byte *str, byte maxLen)
{
byte width = 0;
byte i;
for (i=0; i<maxLen; i++)
{
switch (*str++)
{
case NM_FONT_PRN: if (*str++ == 0) return width; width++; break;
case DB_HEIGT_PRN: if (*str++ == 0) return width; width++; break;
case DB_WIDTH_PRN: if (*str++ == 0) return width; width+=2; break;
case DB_HTWDT_PRN: if (*str++ == 0) return width; width+=2; break;
case PRN_DBWD_FREE_BYTE: str++; break;
default: return width;
}
}
return width;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -