📄 vfd_tool.c
字号:
}
}
if (i == (VFD_CHAR_NO-1))
{
fprintf(out_c, "}\n");
}
else
{
fprintf(out_c, "},\n\n");
}
}
fprintf(out_c, "};\n");
}
/************************************************************************
Function :
Description :
Parameter :
Return :
************************************************************************/
void VfdDebugNum(FILE *out_c, FILE *out_h)
{
BYTE i, bPos;
BYTE bMaxLen;
fprintf(out_c, "#define CHAR_NUM_ARRAY_SZ %d\n\n", CHAR_NUM_ARRAY_SZ);
/* geerate number array for every char */
for (bPos=4;bPos<=5;bPos++)
{
/* reset shadow RAM */
vResetShadow();
/* set all numbers */
for (i=0;i<CHAR_NUM_ARRAY_SZ-1;i++)
{
VfdSetChar((WORD *)(&(prVfdCharSegments[bPos])), pwNumberList[i], i);
}
/* the last one is CHAR_clear */
VfdClearChar((WORD *)(&(prVfdCharSegments[bPos])), pwNumberList[i], i);
/* get list */
for (i=0;i<CHAR_NUM_ARRAY_SZ;i++)
{
VfdGetList(i);
}
bMaxLen = bVfdGetListLenMax(CHAR_NUM_ARRAY_SZ);
/* write list */
fprintf(out_c, "code BYTE pbVfdCharNo%d[CHAR_NUM_ARRAY_SZ][%d] = {\n", bPos, LIST_ITEM2LEN(bMaxLen));
VfdWriteAllList(out_c, CHAR_NUM_ARRAY_SZ, bMaxLen);
fprintf(out_c, "};\n\n");
}
fprintf(out_c, "code BYTE code * ppbVfdCharNum[2][CHAR_NUM_ARRAY_SZ] = {\n");
for (i=4;i<=5;i++)
{
fprintf(out_c, " { ", i);
for (bPos=0;bPos<CHAR_NUM_ARRAY_SZ;bPos++)
{
fprintf(out_c, "pbVfdCharNo%d[%d]", i, bPos);
if (bPos == (CHAR_NUM_ARRAY_SZ-1))
{
fprintf(out_c, " ");
}
else
{
fprintf(out_c, ", ");
}
if (bPos == ((int)(CHAR_NUM_ARRAY_SZ/2)))
{
fprintf(out_c, "\n ");
}
}
if (i == 5)
{
fprintf(out_c, "}\n");
}
else
{
fprintf(out_c, "},\n\n");
}
}
fprintf(out_c, "};\n");
}
/************************************************************************
Function :
Description :
Parameter :
Return :
************************************************************************/
void VfdSimp(FILE *out_h)
{
BYTE i, bMaxLen;
BYTE *pbIndex;
fprintf(out_h, "\n/************************************************************************\n");
fprintf(out_h, " Auto Generated Macros\n");
fprintf(out_h, "************************************************************************/\n\n");
fprintf(out_h, "#define VFD_REFRESH_MAX %d\n\n", VFD_REFRESH_TBL_SZ-1);
/* get list for '0' */
vResetShadow();
VfdSetChar((WORD *)(&(prVfdCharSegments[VFD_SECOND + 1])), pwNumberList[0], 0);
VfdGetList(0);
bMaxLen = bVfdGetListLenMax(1);
/* write list for '0' */
fprintf(out_h, "#define VfdSend0() \\\n{ \\\n");
pbIndex = (prShadow[0]).pbList;
for (i=0;i<bMaxLen;i++)
{
fprintf(out_h, " VfdUpdateByte(0x%02X, 0x%02X); \\\n", *pbIndex, *(pbIndex+1));
}
fprintf(out_h, "}\n\n");
/* get list for '1' */
vResetShadow();
VfdSetChar((WORD *)(&(prVfdCharSegments[VFD_SECOND + 1])), pwNumberList[1], 0);
VfdGetList(0);
bMaxLen = bVfdGetListLenMax(1);
/* write list for '1' */
fprintf(out_h, "#define VfdSend1() \\\n{ \\\n");
pbIndex = (prShadow[0]).pbList;
for (i=0;i<bMaxLen;i++)
{
fprintf(out_h, " VfdUpdateByte(0x%02X, 0x%02X); \\\n", *pbIndex, *(pbIndex+1));
}
fprintf(out_h, "}\n\n");
}
/************************************************************************
Function :
Description :
Parameter :
Return :
************************************************************************/
void vWriteArray(FILE *out, WORD wNum, BYTE bCol, BYTE *pbArray)
{
WORD i;
for (i=0;i<wNum;i++)
{
if ((i%bCol) == 0)
{
fprintf(out, " ");
}
fprintf(out, "0x%02x, ", pbArray[i]);
if ((i%bCol) == (bCol-1))
{
fprintf(out, "\n");
}
}
if ((wNum%bCol) != 0)
{
fprintf(out, "\n");
}
}
/************************************************************************
Function :
Description :
Parameter :
Return :
************************************************************************/
void VfdRefresh(FILE *out_c, FILE *out_h)
{
BYTE i;
fprintf(out_c, "#define VFD_SHADOW_LEN %d\n", VFD_REFRESH_TBL_SZ);
fprintf(out_c, "#define VFD_KEY_LEN %d\n", VFD_KEY_LEN);
fprintf(out_c, "\ncode BYTE _pbVfdRefresh[] = {\n");
vWriteArray(out_c, VFD_REFRESH_TBL_SZ, 3, pbVfdRefresh);
fprintf(out_c, "};\n\n");
}
/************************************************************************
Function :
Description :
Parameter :
Return :
************************************************************************/
#define ICON_MACRO_MAX 256
void VfdIcon(FILE *out_c, FILE *out_h)
{
WORD i, j;
WORD wCurrOffset;
WORD wOffsetTbl[ICON_MACRO_MAX];
BYTE bMaxLen;
assert(VFD_ICON_MACRO_NO <= ICON_MACRO_MAX);
/* first one is null */
pbVfdBinary[0] = VFD_LIST_END;
wCurrOffset = 1;
for (i = 0; i < VFD_ICON_MACRO_NO; i++)
{
vResetShadow();
for (j = 0; j < VFD_MACRO_LENGTH; j++)
{
if ((prVfdIconMacro[i].pwOn[j] != 0) && (!IS_NODE_EMPTY(prVfdIconMacro[i].pwOn[j])))
{
VfdSetIcon((strucVfdIcon *)(&(prVfdIconMacro[i].pwOn[j])), 1, 0);
}
if ((prVfdIconMacro[i].pwOff[j] != 0) && (!IS_NODE_EMPTY(prVfdIconMacro[i].pwOff[j])))
{
VfdSetIcon((strucVfdIcon *)(&(prVfdIconMacro[i].pwOff[j])), 0, 0);
}
}
VfdGetList(0);
bMaxLen = bVfdGetListLenMax(1);
/* check if ICON macro is trivial */
if (bMaxLen == 0)
{
wOffsetTbl[i] = 0;
}
else
{
/* check if buffer is full */
if ((wCurrOffset + LIST_ITEM2LEN(bMaxLen)) >= VFD_BINARY_MAX)
{
printf("Binary space is not enough!\n");
return;
}
else
{
/* copy list to buffer */
memcpy(pbVfdBinary+wCurrOffset, (prShadow[0]).pbList, LIST_ITEM2LEN(bMaxLen)-1);
*(pbVfdBinary+wCurrOffset+LIST_ITEM2LEN(bMaxLen)-1) = VFD_LIST_END;
wOffsetTbl[i] = wCurrOffset;
wCurrOffset += LIST_ITEM2LEN(bMaxLen);
}
}
}
fprintf(out_c, "code BYTE _pbVfdIconMacro[%d] = {\n", wCurrOffset);
vWriteArray(out_c, wCurrOffset, 10, pbVfdBinary);
fprintf(out_c, "};\n");
for (i = 0; i < VFD_ICON_MACRO_NO; i++)
{
fprintf(out_h, "#define VFDICON_%s %d\n", prVfdIconMacro[i].pcName, wOffsetTbl[i]);
}
}
/************************************************************************
Function :
Description :
Parameter :
Return :
************************************************************************/
void VfdCalendar(FILE *out_c, FILE *out_h)
{
fprintf(out_c, "#define VFD_CALENDAR_SZ 0\n");
}
/************************************************************************
Function :
Description :
Parameter :
Return :
************************************************************************/
void vAddSeperator(FILE *out_c, FILE *out_h, const char *str)
{
fprintf(out_c, "\n/************************************************************************\n");
fprintf(out_c, " The following data is for %s.\n", str);
fprintf(out_c, "************************************************************************/\n\n");
fprintf(out_h, "\n/************************************************************************\n");
fprintf(out_h, " The following data is for %s.\n", str);
fprintf(out_h, "************************************************************************/\n\n");
}
/************************************************************************
Function :
Description :
Parameter :
Return :
************************************************************************/
int main(int argc, char** argv)
{
FILE *out_c_file, *out_h_file;
out_c_file = fopen("vfd_data.c","w");
out_h_file = fopen("vfd_data.h","w");
if ((out_c_file == NULL) || (out_h_file == NULL))
{
printf("Open output file error!\n");
exit(1);
}
/* write refresh table */
vAddSeperator(out_c_file, out_h_file, "control mode");
fprintf(out_c_file, "#define VFD_MODE %d\n", VFD_MODE);
/* write refresh table */
vAddSeperator(out_c_file, out_h_file, "refresh table");
VfdRefresh(out_c_file, out_h_file);
/* write VFD_DEBUG option */
fprintf(out_c_file, "#ifndef VFD_DEBUG /* normal data */\n");
/* write wheel table */
vAddSeperator(out_c_file, out_h_file, "wheel table");
VfdWheel(out_c_file, out_h_file);
/* write message table */
vAddSeperator(out_c_file, out_h_file, "message table");
VfdMsg(out_c_file, out_h_file);
/* write number char table */
vAddSeperator(out_c_file, out_h_file, "number character table");
VfdNum(out_c_file, out_h_file);
/* write icon table */
vAddSeperator(out_c_file, out_h_file, "icon macro table");
VfdIcon(out_c_file, out_h_file);
/* write calendar table */
vAddSeperator(out_c_file, out_h_file, "calendar table");
VfdCalendar(out_c_file, out_h_file);
/* write VFD_DEBUG option */
fprintf(out_c_file, "\n#else /* VFD_DEBUG */\n");
/* write number char table */
vAddSeperator(out_c_file, out_h_file, "VFD debug flags");
VfdDebugNum(out_c_file, out_h_file);
/* write VFD_DEBUG option end */
fprintf(out_c_file, "\n#endif /* VFD_DEBUG */\n");
fclose(out_c_file);
fclose(out_h_file);
/* for vfd_simp.h */
out_h_file = fopen("vfd_simp.h","w");
if (out_h_file == NULL)
{
printf("Open output file error!\n");
exit(1);
}
VfdSimp(out_h_file);
fclose(out_h_file);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -