📄 eng_io.c
字号:
/*
* Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
* All rights reserved.
*
* This software is copyrighted by and is the sole property of
* VIA Networking Technologies, Inc. This software may only be used
* in accordance with the corresponding license agreement. Any unauthorized
* use, duplication, transmission, distribution, or disclosure of this
* software is expressly forbidden.
*
* This software is provided by VIA Networking Technologies, Inc. "as is"
* and any express or implied warranties, including, but not limited to, the
* implied warranties of merchantability and fitness for a particular purpose
* are disclaimed. In no event shall VIA Networking Technologies, Inc.
* be liable for any direct, indirect, incidental, special, exemplary, or
* consequential damages.
*
*
* File: eng_io.c
*
* Purpose: UI engine module to support I/O related operations
*
* Author: Jenda Jao
*
* Date: Jan 08, 2002
*
* Functions:
*
* Revision History:
*
*/
#if !defined(__ASCII_H__)
#include "ascii.h"
#endif
#if !defined(__KEY_H__)
#include "key.h"
#endif
#if !defined(__STR_H__)
#include "str.h"
#endif
#if !defined(__UART_H__)
#include "uart.h"
#endif
#include "tty.h"
#if !defined(__SWSRAM_H__)
#include "swsram.h"
#endif
#include "allpages.h"
#include "engine.h"
#include "eng_io.h"
#include "eng_act.h"
/*--------------------- Static Functions --------------------------*/
/*--------------------- Export Functions --------------------------*/
////////////////////
//// input functions
// Get a string (include space) / password / dec_num / hex_num
void ENGvInputItem(SItem* pSItem)
{
UINT8 byInLen, byStrLen;
char* strBuf;
char strNum[MAX_ITEM_DEC_LEN+1]; // num string buffer
if (! STR_bIsPrint(g_byCurKey))
{
g_byCurKey = 0;
return;
}
if (pSItem->f4DataType == ITEM_STRING)
{
byStrLen = ((SItemString*)(pSItem->pvItem))->byMaxLen;
strBuf = (char*)(((SItemString*)(pSItem->pvItem))->strString+g_wCurLineID*(byStrLen+1));
}
else if (pSItem->f4DataType == ITEM_PASSWORD)
{
strBuf = ((SItemPasswd*)(pSItem->pvItem))->strPassword;
byStrLen = ((SItemPasswd*)(pSItem->pvItem))->byMaxLen;
}
else
{
if (( (pSItem->f4DataType == ITEM_HEXNUM) && ! STR_bIsXDigit(g_byCurKey) ) ||
( (pSItem->f4DataType == ITEM_DECNUM) && ! STR_bIsDigit(g_byCurKey) ) )
{
g_byCurKey = 0;
return;
}
strBuf = strNum;
byStrLen = ((SItemNum*)(pSItem->pvItem))->f5MaxLen;
}
// backspace N char
UART_vPutChar(MC_ESCAPE);
UART_vPutChar('[');
TTY_vPutDec(byStrLen);
UART_vPutChar('D');
TTY_vRevChar();
for (byInLen=0; byInLen<byStrLen; byInLen++)
UART_vPutChar(' ');
UART_vPutChar(MC_ESCAPE);
UART_vPutChar('[');
TTY_vPutDec(byStrLen);
UART_vPutChar('D');
// output the first char
strBuf[0] = g_byCurKey;
byInLen = 1;
if (pSItem->f4DataType == ITEM_PASSWORD)
UART_vPutChar('*');
else
UART_vPutChar(g_byCurKey);
while (1) {
g_byCurKey = TTY_cGetChar();
if (g_byCurKey == MK_BACKSPACE)
{
if (byInLen > 0)
{
byInLen--;
TTY_vBackspace();
}
}
else if (! STR_bIsPrint(g_byCurKey))
{
strBuf[byInLen] = 0;
break;
}
else if ((byInLen < byStrLen) &&
( ( (pSItem->f4DataType == ITEM_STRING) && STR_bIsPrint(g_byCurKey) ) ||
( (pSItem->f4DataType == ITEM_PASSWORD) && STR_bIsPrint(g_byCurKey) ) ||
( (pSItem->f4DataType == ITEM_HEXNUM) && STR_bIsXDigit(g_byCurKey) ) ||
( (pSItem->f4DataType == ITEM_DECNUM) && STR_bIsDigit(g_byCurKey) ) ) )
{
strBuf[byInLen] = g_byCurKey;
if (pSItem->f4DataType == ITEM_PASSWORD)
UART_vPutChar('*');
else
UART_vPutChar(g_byCurKey);
byInLen++;
}
}
if ((pSItem->f4DataType == ITEM_HEXNUM)||(pSItem->f4DataType == ITEM_DECNUM))
{
UINT8 byValue=0;
UINT16 wValue=0;
UINT32 dwValue=0;
// convert string to num value
for (byInLen=0; strBuf[byInLen] != '\0'/*byInLen<STR_iStrlen(strBuf)*/; byInLen++) {
if (((SItemNum*)(pSItem->pvItem))->f3ByteNum == 2) //UINT16
wValue = wValue*((pSItem->f4DataType == ITEM_DECNUM) ? 10 : 16) + STR_cToInt(strBuf[byInLen]);
else if (((SItemNum*)(pSItem->pvItem))->f3ByteNum == 4) //UINT32
dwValue = dwValue*((pSItem->f4DataType == ITEM_DECNUM) ? 10 : 16) + STR_cToInt(strBuf[byInLen]);
else //UINT8
byValue = byValue*((pSItem->f4DataType == ITEM_DECNUM) ? 10 : 16) + STR_cToInt(strBuf[byInLen]);
}
if (((SItemNum*)(pSItem->pvItem))->f3ByteNum == 2) //UINT16
(*((UINT16*)(((SItemNum*)(pSItem->pvItem))->pbyNum + ((SItemNum*)(pSItem->pvItem))->byVarByteOffset * g_wCurLineID))) = wValue;
else if (((SItemNum*)(pSItem->pvItem))->f3ByteNum == 4) //UINT32
(*((UINT32*)(((SItemNum*)(pSItem->pvItem))->pbyNum + ((SItemNum*)(pSItem->pvItem))->byVarByteOffset * g_wCurLineID))) = dwValue;
else //UINT8
(*(((SItemNum*)(pSItem->pvItem))->pbyNum + ((SItemNum*)(pSItem->pvItem))->byVarByteOffset * g_wCurLineID)) = byValue;
}
}
/////////////////////
//// output functions
// print whole page
void ENGvPrintPage(void)
{
UINT8 ui;
TTY_vRstChar();
TTY_vClearScrn();
// print fix label
for (ui=0; ui<g_pSCurPage->byFixLabelNum; ui++)
{
if (g_pSCurPage->aSFixLabel[ui].byDrawLineLen)
TTY_vDrawLine(g_pSCurPage->aSFixLabel[ui].SPos.byRow,
g_pSCurPage->aSFixLabel[ui].SPos.byCol,
g_pSCurPage->aSFixLabel[ui].strLabel[0],
g_pSCurPage->aSFixLabel[ui].byDrawLineLen);
else
TTY_vPutStrOnPos(g_pSCurPage->aSFixLabel[ui].SPos.byRow,
g_pSCurPage->aSFixLabel[ui].SPos.byCol,
g_pSCurPage->aSFixLabel[ui].strLabel);
}
ENGvPrintVarPage();
if (g_aSCurActionList)
ENGvPrintActionbar();
}
// print variable part of a page, only print items with different values
void ENGvPrintVarPage(void)
{
UINT16 wItemID;
UINT16 wLineID;
UINT8 byLineNumPerPage;
// print var label
for (wItemID=0; wItemID<g_pSCurPage->byVarLabelNum; wItemID++)
{
switch (g_pSCurPage->aSVarLabel[wItemID].f2RepeatType)
{
case REPEAT_TYPE_NONE:
ENGvPrintItem(0, wItemID, PRINT_VAR_LABEL);
break;
case REPEAT_TYPE_RECT_SINGLE:
case REPEAT_TYPE_RECT_MULTI: {
if (g_wTotalLineNum == 0)
break;
byLineNumPerPage = ((80/g_pSCurPage->aSVarLabel[wItemID].byPosColOffset) + ((80%g_pSCurPage->aSVarLabel[wItemID].byPosColOffset) ? 1 : 0)) * g_pSCurPage->aSVarLabel[wItemID].byLineNumPerColumn;
for (wLineID=0; wLineID<byLineNumPerPage; wLineID++) {
if (wLineID >= g_wTotalLineNum)
break;
ENGvPrintItem(wLineID, wItemID, PRINT_VAR_LABEL);
}
}break;
}
}
// print var item
for (wItemID=0; wItemID<g_pSCurPage->wVarItemNum; wItemID++)
{
if ((g_wTotalLineNum == 0)&&(REPEAT_TYPE_NONE != g_aSCurItemList[wItemID].f2RepeatType))
continue;
switch (g_aSCurItemList[wItemID].f2RepeatType)
{
case REPEAT_TYPE_NONE:
ENGvPrintItem(0, wItemID, PRINT_ITEM_NORMAL);
break;
case REPEAT_TYPE_RECT_SINGLE:
case REPEAT_TYPE_RECT_MULTI: {
byLineNumPerPage = ((80/g_pSCurPage->aSVarItem[wItemID].byPosColOffset) + ((80%g_pSCurPage->aSVarItem[wItemID].byPosColOffset) ? 1 : 0)) * g_pSCurPage->aSVarItem[wItemID].byLineNumPerColumn;
for (wLineID=0; wLineID<byLineNumPerPage; wLineID++) {
if (wLineID >= g_wTotalLineNum)
break;
ENGvPrintItem(wLineID, wItemID, PRINT_ITEM_NORMAL);
}
}break;
}
}
}
// add space after strBuf in order to satisfy byMaxLen, for ENGvPrintItem() only
static void s_vAddSpace(char* strBuf, UINT8 byMaxLen)
{
UINT8 len;
for (len = STR_iStrlen(strBuf); len < byMaxLen; len++)
strBuf[len] = ' ';
strBuf[byMaxLen] = 0;
// if (len < byMaxLen)
// {
// STR_pvMemset(strBuf+len, ' ', byMaxLen-len);
// strBuf[byMaxLen+1] = 0;
// }
}
// print a item for all types, and append space to user defined length
void ENGvPrintItem(UINT16 wLineID, UINT16 wItemID, UINT8 byType)
{
SItem* pSItem;
UINT8 byLineNumPerPage;
if (byType == PRINT_VAR_LABEL) // print var label or item
pSItem = g_pSCurPage->aSVarLabel + wItemID;
else
pSItem = g_aSCurItemList + wItemID;
if ((byType == PRINT_ITEM_HIGHLIGHT)
&& (g_aSCurItemList[wItemID].strDescription) )
ENGcPrintMessage(g_aSCurItemList[wItemID].strDescription, PRINT_THEN_RETURN);
// set current position of cursor
switch (pSItem->f2RepeatType) {
case REPEAT_TYPE_NONE:
wLineID = 0;
TTY_vSetCurPos(pSItem->SPos.byRow, pSItem->SPos.byCol);
break;
case REPEAT_TYPE_RECT_SINGLE: {
TTY_vSetCurPos(pSItem->SPos.byRow + (wLineID%pSItem->byLineNumPerColumn),
pSItem->SPos.byCol + (wLineID/pSItem->byLineNumPerColumn) * pSItem->byPosColOffset);
if ((pSItem->f4DataType == ITEM_DECNUM) || (pSItem->f4DataType == ITEM_STRING)) {
byLineNumPerPage = ((80/pSItem->byPosColOffset) + ((80%pSItem->byPosColOffset) ? 1 : 0)) * pSItem->byLineNumPerColumn;
wLineID += (g_byMultiPageNo*byLineNumPerPage);
}
}break;
case REPEAT_TYPE_RECT_MULTI:
TTY_vSetCurPos(pSItem->SPos.byRow + (wLineID%pSItem->byLineNumPerColumn),
pSItem->SPos.byCol + (wLineID/pSItem->byLineNumPerColumn) * pSItem->byPosColOffset);
break;
}
if (byType == PRINT_ITEM_HIGHLIGHT) // highlight item
TTY_vRevChar();
switch (pSItem->f4DataType) { // for every item type
case ITEM_MENU_PAGESEL: {
/*
if (wItemID+1 == g_pSCurPage->wVarItemNum)
UART_vPutChar('0');
*/
/* Henry add, when NOLOGOUT MainMenu show item"8" not "0"*/
if ((wItemID+1 == g_pSCurPage->wVarItemNum) &&
(g_byCurPageID!= PAGE_MAIN_MENU_NOLOGOUT))
UART_vPutChar('0');
else
{
if (wItemID >= 9)
UART_vPutChar('A'+(wItemID-9));
else
UART_vPutChar('1'+wItemID);
}
TTY_vPutStr(". ");
TTY_vPutStr(((SItemPageSel*)(pSItem->pvItem))->strPageSel);
} break;
case ITEM_DECNUM:
case ITEM_HEXNUM: {
SItemNum* pSItemNum = (SItemNum*)(pSItem->pvItem);
char strBuf[MAX_ITEM_STR_LEN];
STR_pvMemset(strBuf, 0 , MAX_ITEM_STR_LEN);
if (pSItem->f4DataType == ITEM_DECNUM)
{
if (pSItemNum->f3ByteNum == 2) // value is UINT16
STR_iU32ToStrDec(strBuf, *((UINT16*)(pSItemNum->pbyNum + pSItemNum->byVarByteOffset * wLineID)));
else if (pSItemNum->f3ByteNum == 4) //UINT32
STR_iU32ToStrDec(strBuf, *((UINT32*)(pSItemNum->pbyNum + pSItemNum->byVarByteOffset * wLineID)));
else //UINT8
STR_iU32ToStrDec(strBuf, *(pSItemNum->pbyNum + pSItemNum->byVarByteOffset * wLineID));
}
else
{
if (pSItemNum->f3ByteNum == 2) // value is UINT16
STR_iU32ToStrHex(strBuf, *((UINT16*)(pSItemNum->pbyNum + pSItemNum->byVarByteOffset * wLineID)));
else if (pSItemNum->f3ByteNum == 4) // UINT32
STR_iU32ToStrHex(strBuf, *((UINT32*)(pSItemNum->pbyNum + pSItemNum->byVarByteOffset * wLineID)));
else //UINT8
STR_iU32ToStrHex(strBuf, *(pSItemNum->pbyNum + pSItemNum->byVarByteOffset * wLineID));
}
s_vAddSpace(strBuf, pSItemNum->f5MaxLen);
TTY_vPutStr(strBuf);
} break;
case ITEM_LISTBOX: {
SItemListbox *pSIListbox = (SItemListbox*)(pSItem->pvItem);
UINT8 byValue, byStartBit, byEndBit;
byStartBit = pSIListbox->byStartBit;
byEndBit = pSIListbox->byEndBit;
SWSRAM_vExtractBitsByByte(pSIListbox->pbyIndex + (pSIListbox->byVarBitOffset >> 3) * wLineID,
byStartBit + (pSIListbox->byVarBitOffset & 0x07) * wLineID,
byEndBit + (pSIListbox->byVarBitOffset & 0x07) * wLineID,
&byValue);
TTY_vPutStr(pSIListbox->astrListbox[byValue]);
} break;
case ITEM_VAR_LISTBOX: {
SItemVarListbox *pSIListbox = (SItemVarListbox*)(pSItem->pvItem);
UINT8 byValue, byStartBit, byEndBit;
byStartBit = pSIListbox->byStartBit;
byEndBit = pSIListbox->byEndBit;
// The ITEM_VAR_LISTBOX item does not support repeat-type in this smart version
SWSRAM_vExtractBitsByByte(pSIListbox->pbyIndex,
byStartBit,
byEndBit,
&byValue);
TTY_vPutStr(pSIListbox->astrListbox[ (pSIListbox->pSStrTblMap->abyListIndex)[byValue] ]);
} break;
case ITEM_STRING: {
char strBuf[MAX_ITEM_STR_LEN];
UINT8 byMaxLen = 0;
byMaxLen = ((SItemString*)(pSItem->pvItem))->byMaxLen;
STR_pszStrcpy(strBuf, (char*)(((SItemString*)(pSItem->pvItem))->strString+wLineID*(byMaxLen+1)));
s_vAddSpace(strBuf, byMaxLen);
TTY_vPutStr(strBuf);
} break;
case ITEM_PASSWORD: {
TTY_vDrawLine(pSItem->SPos.byRow, pSItem->SPos.byCol,
'*', ((SItemPasswd*)(pSItem->pvItem))->byMaxLen);
} break;
default:
TTY_vPutStr("Panic !");
TTY_cGetChar();
}
TTY_vRstChar();
}
char ENGcPrintMessage(PSTR str, BOOL bPause)
{
if (STR_iStrlen(str) == 0)
return '\0';
TTY_vRevChar();
TTY_vDrawLine(23, 2, ' ', 77);
TTY_vSetCurPos(23, (80 - STR_iStrlen(str)) / 2);
TTY_vPutStr(str);
TTY_vRstChar();
if (bPause)
return TTY_cGetChar();
else
return '\0';
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -