📄 main.c.bak
字号:
char key;
if (pMenu) {
key = pMenu->EventArg;
onSelectMainMenu(key - '1');
DrawGraphicsMenu(pMenu);
}
return 0;
}
void onSelectSysMenu(int index)
{
char str[100] = "1234";
int len, object, level;
if (index < 0 || index >= sizeof(sysMenuItems) / sizeof(char *)) return;
clrscr();
switch (index) {
case 0:
SetCurrentDate();
break;
case 1:
SetCurrentTime();
break;
case 2:
systemConfig(0);
break;
case 3:
systemConfig(1);
break;
case 4:
showBattery();
break;
case 5:
adjustLcd();
break;
}
clrscr();
}
UINT onSysMenu_Ok(void * arg)
{
Menu * pMenu = (Menu *)arg;
if (pMenu) onSelectSysMenu(pMenu->Current);
return 0;
}
UINT onSysMenu_Cancel(void * arg)
{
Menu * pMenu = (Menu *)arg;
if (pMenu) {
CloseMenu(pMenu);
}
return 0;
}
UINT onSysMenu_OtherKey(void * arg)
{
Menu * pMenu = (Menu *)arg;
char key;
if (pMenu) {
key = pMenu->EventArg;
onSelectSysMenu(key - '1');
DrawMenu(pMenu);
}
return 0;
}
// Battery Menu
void onSelectBatteryMenu(int index)
{
if (index < 0 || index >= sizeof(batteryMenuItems) / sizeof(char *)) return;
clrscr();
switch (index) {
case 0:
CollectBatteryValues();
break;
case 1:
UploadBatteryValues();
break;
}
clrscr();
}
UINT onBatteryMenu_Ok(void * arg)
{
Menu * pMenu = (Menu *)arg;
if (pMenu) onSelectBatteryMenu(pMenu->Current);
return 0;
}
UINT onBatteryMenu_Cancel(void * arg)
{
Menu * pMenu = (Menu *)arg;
if (pMenu) {
CloseMenu(pMenu);
}
return 0;
}
UINT onBatteryMenu_OtherKey(void * arg)
{
Menu * pMenu = (Menu *)arg;
char key;
if (pMenu) {
key = pMenu->EventArg;
onSelectBatteryMenu(key - '1');
DrawMenu(pMenu);
}
return 0;
}
//端口菜单
void onSelectComMenu(int index)
{
if (index < 0 || index >= sizeof(fsMenuItems) / sizeof(char *)) return;
clrscr();
switch (index) {
case 0:
testCreateFile();
break;
case 1:
testWriteFile();
break;
case 2:
testReadFile();
break;
}
clrscr();
}
UINT onComMenu_Ok(void * arg)
{
Menu * pMenu = (Menu *)arg;
if (pMenu) onSelectComMenu(pMenu->Current);
return 0;
}
UINT onComMenu_Cancel(void * arg)
{
Menu * pMenu = (Menu *)arg;
if (pMenu) {
CloseMenu(pMenu);
}
return 0;
}
UINT onFsMenu_OtherKey(void * arg)
{
Menu * pMenu = (Menu *)arg;
char key;
if (pMenu) {
key = pMenu->EventArg;
onSelectComMenu(key - '1');
DrawMenu(pMenu);
}
return 0;
}
// ------------------------------------------------------------------
void onSelectFsMenu(int index)
{
if (index < 0 || index >= sizeof(fsMenuItems) / sizeof(char *)) return;
clrscr();
switch (index) {
case 0:
testCreateFile();
break;
case 1:
testWriteFile();
break;
case 2:
testReadFile();
break;
case 3:
testDeleteFile();
break;
case 4:
testFormatFlash();
break;
}
clrscr();
}
UINT onFsMenu_Ok(void * arg)
{
Menu * pMenu = (Menu *)arg;
if (pMenu) onSelectFsMenu(pMenu->Current);
return 0;
}
UINT onFsMenu_Cancel(void * arg)
{
Menu * pMenu = (Menu *)arg;
if (pMenu) {
CloseMenu(pMenu);
}
return 0;
}
UINT onFsMenu_OtherKey(void * arg)
{
Menu * pMenu = (Menu *)arg;
char key;
if (pMenu) {
key = pMenu->EventArg;
onSelectFsMenu(key - '1');
DrawMenu(pMenu);
}
return 0;
}
// ------------------------------------------------------------------
// COM1 SLP test
void testRs232()
{
char ch, bufr[100];
HDEV dev;
if (ShowMessage("串口测试", "请运行PC超级终端波特率9600", MB_CANCEL | MB_OK, true) == MR_CANCEL)
return;
clrscr();
dev = open(COM1, BAUD_9600);
while ((ch = inkey()) != vk_ESC) {
if (ch) {
putch(ch);
write(dev, 0, &ch, 1);
}
if (read(dev, 0, &ch, 1)) {
putch(ch);
}
}
close(dev);
}
// IRDA terminal (test with Windows 超级终端)
void testIrda()
{
char ch, bufr[100];
HDEV dev;
if (ShowMessage("红外测试", "请运行PC超级终端波特率9600", MB_CANCEL | MB_OK, true) == MR_CANCEL)
return;
clrscr();
dev = open(IRDA, BAUD_9600);
while ((ch = inkey()) != vk_ESC) {
if (ch) {
putch(ch);
write(dev, 0, &ch, 1);
}
if (read(dev, 0, &ch, 1)) {
putch(ch);
}
}
close(dev);
}
// ------------------------------------------------------------------------
// File System Test
void testFormatFlash()
{
if (ShowMessage("格式化", "所有数据将丢失!", MB_OK | MB_CANCEL, true) == MR_CANCEL)
return;
DisplayLine(0, "格式化", ALIGN_CENTER, false);
DisplayMidLine(3, "正在进行...", ALIGN_CENTER, false);
file_system_format();
clrscr();
DisplayMidLine(3, "格式化完成", ALIGN_CENTER, false);
DisplayOkCancel(MB_OK);
get_key();
}
int indexFile = 1;
void testCreateFile()
{
char buffer[300];
int handle, len;
if (ShowInputBox("输入文件名", buffer, &len, MB_OK | MB_CANCEL) == MR_CANCEL)
return;
if (len == 0)
sprintf(buffer, "DEMO%d.TXT", indexFile++);
handle = file_create(buffer);
if (handle < 0) {
clrscr();
DisplayLine(0, "创建失败", ALIGN_CENTER, false);
DisplayLine(1, buffer, ALIGN_LEFT, false);
DisplayOkCancel(MB_CANCEL);
get_key();
return;
}
clrscr();
file_close(handle);
ShowMessage("创建文件", "成功完成", MB_OK, true);
}
void testDeleteFile()
{
char buffer[300];
int ret, len;
if (ShowInputBox("输入文件名", buffer, &len, MB_OK | MB_CANCEL) == MR_CANCEL)
return;
if (len == 0)
sprintf(buffer, "DEMO%d.TXT", indexFile++);
ret = file_delete(buffer);
if (ret != 0) {
clrscr();
ShowMessage("删除文件", "文件不存在或者正在使用中", MB_OK, true);
return;
}
ShowMessage("删除文件", "成功完成", MB_OK, true);
}
void testWriteFile()
{
int handle, len;
char name[32], buffer[200];
clrscr();
if (ShowInputBox("输入文件名", name, &len, MB_OK | MB_CANCEL) == MR_CANCEL)
return;
if (len == 0)
sprintf(name, "DEMO%d.TXT", indexFile);
handle = file_open(name, WRITE_ONLY);
if (handle < 0) {
ShowMessage("打开失败", name, MB_OK, true);
return;
}
clrscr();
DisplayLine(0, "输入内容", ALIGN_CENTER, false);
gotoxy(0, 1);
if (!getabc(buffer, 100, &len)) {
file_close(handle);
return;
}
if (len == 0)
strcpy(buffer, "Hello World!");
file_seek(handle, 0, SEEK_FILE_END);
file_write(handle, buffer, strlen(buffer), &len);
clrscr();
if (len == 0) {
ShowMessage("写入错误", buffer, MB_OK, true);
} else if (len != strlen(buffer)) {
ShowMessage("写入文件", "长度错误", MB_OK, true);
} else {
ShowMessage("写入文件", "成功完成", MB_OK, true);
}
file_close(handle);
}
void testReadFile()
{
int handle, len;
char name[32], buffer[200];
clrscr();
if (ShowInputBox("输入文件名", name, &len, MB_OK | MB_CANCEL) == MR_CANCEL)
return;
if (len == 0)
sprintf(name, "DEMO%d.TXT", indexFile);
handle = file_open(name, READ_ONLY);
if (handle < 0) {
ShowMessage("打开失败", name, MB_OK, true);
return;
}
memset(buffer, 0, sizeof(buffer));
file_seek(handle, 0, SEEK_FILE_SET);
len = file_read(handle, buffer, 32);
file_close(handle);
ShowMessage("读取内容", buffer, MB_OK, true);
}
// End of test File System
// ------------------------------------------------------------------------
// Begin Battery test
typedef struct tagBatteryRecord {
unsigned short index;
unsigned short value;
} TBatteryRecord;
TBatteryRecord EofRecord = { 0x55, 0xAA };
#define BATTERY_TIME_INTERVAL 600000L
//#define BATTERY_TIME_INTERVAL 10000
void CollectBatteryValues()
{
long current = 0, origin = -BATTERY_TIME_INTERVAL;
TBatteryRecord rec = { 0, 0 };
long addr = 0;
char buf[100];
// erase a sector, use zero
if (ShowMessage("删除扇区", "文件系统将被破坏", MB_OK | MB_CANCEL, true) == MR_CANCEL)
return;
clrscr();
DisplayLine(1, "删除零扇区", ALIGN_CENTER, false);
FlashSectorErase(0);
delay(500);
// begin record
clrscr();
DisplayLine(0, "正在记录", ALIGN_CENTER, true);
//bl_on(0x7fffffff);
while (true) {
current = GetTickCount();
if (current >= origin + BATTERY_TIME_INTERVAL) {
// 10 minutes one time
rec.index++;
rec.value = battery_ind();
sprintf(buf, "已写入%d条", (int)rec.index);
DisplayLine(2, buf, ALIGN_CENTER, false);
FlashWrite(addr, (BYTE *)&rec, sizeof(rec));
addr += sizeof(rec);
origin = current;
}
/*
else {
sys_sleep();
}
*/
if (inkey() == vk_ESC) {
if (ShowMessage("确认退出", "操作还未完成!", MB_OK | MB_CANCEL, true) == MR_OK) {
//bl_off();
return;
}
else {
clrscr();
DisplayLine(0, "正在记录", ALIGN_CENTER, true);
sprintf(buf, "已写入%d条", (int)rec.index);
DisplayLine(2, buf, ALIGN_CENTER, false);
}
}
}
}
// ------------------------------------------------------------------------
void UploadBatteryValues()
{
long addr = 0;
TBatteryRecord rec = { 0, 0 };
unsigned short origin_index;
char buf[100];
open(COM1, BAUD_9600);
DisplayLine(0, "正在传输", ALIGN_CENTER, false);
while (true) {
origin_index = rec.index;
FlashRead(addr, (BYTE *)&rec, sizeof(rec));
addr += sizeof(rec);
if (rec.index != (origin_index + 1)) {
clrscr();
DisplayLine(0, "传输完成", ALIGN_CENTER, true);
sprintf(buf, "总共%d条", (int)origin_index);
DisplayLine(2, buf, ALIGN_CENTER, false);
get_key();
goto out;
}
sprintf(buf, "第%d条", (int)rec.index);
DisplayLine(2, buf, ALIGN_CENTER, false);
sprintf(buf, "%d\t%d\r\n", (int)rec.index, (int)rec.value);
write(COM1, 0, buf, strlen(buf));
}
out:
close(COM1);
}
// ------------------------------------------------------------------------
void tmain(void)
{
unsigned char b;
unsigned char ch,line,row;
unsigned short tmp;
char dest[100];
ShowComsysLogo("山东方锐");
LcdSetIcon(LCD_ICON_BATTERY, 5);
LcdSetIcon(LCD_ICON_TIME, "1256");
clrscr();
InitializeMenu(&sys_menu, title_SysMenu, sysMenuItems, sizeof(sysMenuItems) / sizeof(char *));
sys_menu.OnOk = onSysMenu_Ok;
sys_menu.OnOtherKey = onSysMenu_OtherKey;
sys_menu.OnCancel = onSysMenu_Cancel;
InitializeMenu(&fs_menu, title_FsMenu, fsMenuItems, sizeof(fsMenuItems) / sizeof(char *));
fs_menu.OnOk = onFsMenu_Ok;
fs_menu.OnOtherKey = onFsMenu_OtherKey;
fs_menu.OnCancel = onFsMenu_Cancel;
InitializeMenu(&battery_menu, title_BatteryMenu, batteryMenuItems, sizeof(batteryMenuItems) / sizeof(char *));
battery_menu.OnOk = onBatteryMenu_Ok;
battery_menu.OnOtherKey = onBatteryMenu_OtherKey;
battery_menu.OnCancel = onBatteryMenu_Cancel;
InitializeGraphicsMenu(&gmenu, ImageList, sizeof(ImageList) / sizeof(GraphicsMenuItem));
gmenu.OnOk = onMainMenu_Ok;
gmenu.OnOtherKey = onMainMenu_OtherKey;
gmenu.OnCancel = onMainMenu_Cancel;
ShowGraphicsMenu(&gmenu);
}
// ------------------------------------------------------------------------
// End of P115 DEMO
// Ken, 2003-6-16
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -