各个模块已经写好了,现在开始写main.c文件
<span style="font-size:18px;">#include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <config.h> #include <draw.h> #include <encoding_manager.h> #include <fonts_manager.h> #include <disp_manager.h> #include <input_manager.h> #include <string.h> /* ./show_file [-s Size] [-f freetype_font_file] [-h HZK] <text_file> */ int main(int argc, char **argv) { int iError; unsigned int dwFontSize = 16; char acHzkFile[128]; char acFreetypeFile[128]; char acTextFile[128]; char acDisplay[128]; int bList = 0; T_InputEvent tInputEvent; acHzkFile[0] = '\0'; acFreetypeFile[0] = '\0'; acTextFile[0] = '\0'; strcpy(acDisplay, "fb"); while ((iError = getopt(argc, argv, "ls:f:h:d:")) != -1) { switch(iError) { case 'l': { bList = 1; break; } case 's': { dwFontSize = strtoul(optarg, NULL, 0); break; } case 'f': { strncpy(acFreetypeFile, optarg, 128); acFreetypeFile[127] = '\0'; break; } case 'h': { strncpy(acHzkFile, optarg, 128); acHzkFile[127] = '\0'; break; } case 'd': { strncpy(acDisplay, optarg, 128); acDisplay[127] = '\0'; break; } default: { printf("Usage: %s [-s Size] [-d display] [-f font_file] [-h HZK] <text_file>\n", argv[0]); printf("Usage: %s -l\n", argv[0]); return -1; break; } } } if (!bList && (optind >= argc)) { printf("Usage: %s [-s Size] [-d display] [-f font_file] [-h HZK] <text_file>\n", argv[0]); printf("Usage: %s -l\n", argv[0]); return -1; } iError = DisplayInit(); if (iError) { printf("DisplayInit error!\n"); return -1; } iError = FontsInit(); if (iError) { printf("FontsInit error!\n"); return -1; } iError = EncodingInit(); if (iError) { printf("EncodingInit error!\n"); return -1; } iError = InputInit(); if (iError) { printf("InputInit error!\n"); return -1; } if (bList) { printf("supported display:\n"); ShowDispOpr(); printf("supported font:\n"); ShowFontOpr(); printf("supported encoding:\n"); ShowEncodingOpr(); printf("supported input:\n"); ShowInputOpr(); return 0; } strncpy(acTextFile, argv[optind], 128); acTextFile[127] = '\0'; iError = OpenTextFile(acTextFile); if (iError) { printf("OpenTextFile error!\n"); return -1; } iError = SetTextDetail(acHzkFile, acFreetypeFile, dwFontSize); if (iError) { printf("SetTextDetail error!\n"); return -1; } DBG_PRINTF("%s %s %d\n", __FILE__, __FUNCTION__, __LINE__); iError = SelectAndInitDisplay(acDisplay); if (iError) { printf("SelectAndInitDisplay error!\n"); return -1; } iError = AllInputDevicesInit(); if (iError) { DBG_PRINTF("Error AllInputDevicesInit\n"); return -1; } DBG_PRINTF("%s %s %d\n", __FILE__, __FUNCTION__, __LINE__); iError = ShowNextPage(); DBG_PRINTF("%s %s %d\n", __FILE__, __FUNCTION__, __LINE__); if (iError) { printf("Error to show first page\n"); return -1; } printf("Enter 'n' to show next page, 'u' to show previous page, 'q' to exit: "); while (1) { if (0 == GetInputEvent(&tInputEvent)) { if (tInputEvent.iVal == INPUT_VALUE_DOWN) { ShowNextPage(); } else if (tInputEvent.iVal == INPUT_VALUE_UP) { ShowPrePage(); } else if (tInputEvent.iVal == INPUT_VALUE_EXIT) { return 0; } } } return 0; } </span>
还需要一些字体文件,这里看个人喜欢什么样的字体,这里我上传了一个simsun.ttc字体文件,下载:点击这里!最后准备一篇txt文件的小说,当这些都准备好了就可以测试了。
./show_file -s 16 -f simsun.ttc ./qinshimingyue.txt */
LCD就显示了小说文件,触摸屏向左滑动就是上一页,向右滑动就是下一页,串口终端输入n就是下一页,输入p就是上一页。
测试完毕,可以在文章中添加一个标志位,读到哪里就记下当前位置,下次接着从这里读取。