#include "includes.h" // 显示一个8段码 // pos: 氢压力为0~4(从左到右,真值表14~10),温度为5~7(真值表4~6), // 压力为8~10(真值表7~9),真空为11~13(真值表1~3) void Disp_DispChar(u8 pos, char c) { if(pos == 0) HT1621_WriteChar(c, 291, 281, 283, 294, 293, 292, 282); else if(pos == 1) HT1621_WriteChar(c, 271, 261, 263, 274, 273, 272, 262); else if(pos == 2) HT1621_WriteChar(c, 251, 241, 243, 254, 253, 252, 242); else if(pos == 3) HT1621_WriteChar(c, 231, 221, 223, 234, 233, 232, 222); else if(pos == 4) HT1621_WriteChar(c, 211, 201, 203, 214, 213, 212, 202); else if(pos == 5) HT1621_WriteChar(c, 24, 34, 32, 21, 22, 23, 33); else if(pos == 6) HT1621_WriteChar(c, 44, 54, 52, 41, 42, 43, 53); else if(pos == 7) HT1621_WriteChar(c, 64, 74, 72, 61, 62, 63, 73); else if(pos == 8) HT1621_WriteChar(c, 144, 154, 152, 141, 142, 143, 153); else if(pos == 9) HT1621_WriteChar(c, 164, 173, 171, 161, 162, 163, 172); else if(pos == 10) HT1621_WriteChar(c, 184, 194, 192, 181, 182, 183, 193); else if(pos == 11) HT1621_WriteChar(c, 84, 94, 92, 81, 82, 83, 93); else if(pos == 12) HT1621_WriteChar(c, 104, 114, 112, 101, 102, 103, 113); else if(pos == 13) HT1621_WriteChar(c, 124, 134, 132, 121, 122, 123, 133); } // 显示氢压力数据 void Disp_H2PressText(s8 *text) { u8 len = strlen(text), i = 0, c; if(len < 5) // 万位 c = ' '; else c = text[i++]; Disp_DispChar(0, c); if(len < 4) // 千位 c = ' '; else c = text[i++]; Disp_DispChar(1, c); if(len < 3) // 百位 c = ' '; else c = text[i++]; Disp_DispChar(2, c); if(len < 2) // 十位 c = ' '; else c = text[i++]; Disp_DispChar(3, c); if(len < 1) // 个位 c = ' '; else c = text[i++]; Disp_DispChar(4, c); } // 显示小数点 void Disp_H2PressPointOn(u8 pos) { if(pos < 1 || pos > 2) return; Disp_H2PressPointOff(); if(pos == 1) // 小数点1位 HT1621_WriteBuf(224, 1); else // 小数点2位 HT1621_WriteBuf(244, 1); } void Disp_H2PressPointOff() { HT1621_WriteBuf(224, 0); HT1621_WriteBuf(244, 0); } // 显示压力数据 void Disp_PresText(s8 *text) { u8 len = strlen(text), i = 0, c; if(len < 3) // 百位 c = ' '; else c = text[i++]; Disp_DispChar(8, c); if(len < 2) // 十位 c = ' '; else c = text[i++]; Disp_DispChar(9, c); if(len < 1) // 个位 c = ' '; else c = text[i++]; Disp_DispChar(10, c); } // 显示小数点 void Disp_PresPointOn() { HT1621_WriteBuf(151, 1); } void Disp_PresPointOff() { HT1621_WriteBuf(151, 0); } // 压力单位 void Disp_PresUnitOn() { HT1621_WriteBuf(191, 1); } // 压力单位 void Disp_PresUnitOff() { HT1621_WriteBuf(191, 0); } // 显示温度数据 void Disp_TempText(s8 *text) { u8 len = strlen(text), i = 0, c; // 符号位 if(len < 4) HT1621_WriteBuf(31, 0); else { HT1621_WriteBuf(31, 1); i++; } if(len < 3) // 百位 c = ' '; else c = text[i++]; Disp_DispChar(5, c); if(len < 2) // 十位 c = ' '; else c = text[i++]; Disp_DispChar(6, c); if(len < 1) // 个位 c = ' '; else c = text[i++]; Disp_DispChar(7, c); // 不显示小数点 HT1621_WriteBuf(51, 0); } // 显示小数点 void Disp_TempPointOn() { HT1621_WriteBuf(51, 1); } void Disp_TempPointOff() { HT1621_WriteBuf(51, 0); } // 温度单位 void Disp_TempUnitOn() { HT1621_WriteBuf(71, 1); } // 温度单位 void Disp_TempUnitOff() { HT1621_WriteBuf(71, 0); } // 显示真空数据 void Disp_VacuText(s8 *text) { u8 len = strlen(text), i = 0, c; if(len < 3) // 百位 c = ' '; else c = text[i++]; Disp_DispChar(11, c); if(len < 2) // 十位 c = ' '; else c = text[i++]; Disp_DispChar(12, c); if(len < 1) // 个位 c = ' '; else c = text[i++]; Disp_DispChar(13, c); } // 显示小数点 void Disp_VacuPointOn() { HT1621_WriteBuf(111, 1); } void Disp_VacuPointOff() { HT1621_WriteBuf(111, 0); } // 氢压力单位关闭 void Disp_H2PressUnitOff() { HT1621_WriteBuf(264, 0); // PSI HT1621_WriteBuf(174, 0); // M3 HT1621_WriteBuf(284, 0); // % HT1621_WriteBuf(204, 0); // MPa } // 氢压力显示切换 void Disp_SwitchH2PressUnit(TH2PressUnit unit) { Disp_H2PressUnitOff(); if(unit == UNIT_PSI) HT1621_WriteBuf(264, 1); else if(unit == UNIT_M3) HT1621_WriteBuf(174, 1); else if(unit == UNIT_PCT) HT1621_WriteBuf(284, 1); else // MPa HT1621_WriteBuf(204, 1); } void Disp_WriteNeedle(u8 val) { HT1621_WriteBuf(324, val >= 1); HT1621_WriteBuf(323, val >= 2); HT1621_WriteBuf(322, val >= 3); HT1621_WriteBuf(321, val >= 4); HT1621_WriteBuf(311, val >= 5); HT1621_WriteBuf(301, val >= 6); HT1621_WriteBuf(302, val >= 7); HT1621_WriteBuf(303, val >= 8); HT1621_WriteBuf(304, val >= 9); HT1621_WriteBuf(11, val >= 10); } // 写电量数据 void Disp_WriteBattery(u8 val) { HT1621_WriteBuf(312, val >= 1); HT1621_WriteBuf(313, val >= 2); HT1621_WriteBuf(314, val >= 3); } // 写信号强度 void Disp_WriteStrength(u8 val) { HT1621_WriteBuf(131, val >= 1); HT1621_WriteBuf(91, val >= 2); HT1621_WriteBuf(14, val >= 3); HT1621_WriteBuf(13, val >= 4); } // 写通讯状态 void Disp_WriteCommunication(u8 val) { HT1621_WriteBuf(12, val != 0); } // 清屏 void Disp_Clear() { memset(&VideoBuf, 0, sizeof(VideoBuf)); } // 设置闪烁 void Disp_SetBlinkVisible(u8 visible) { VideoBuf.blink_visible = visible; } void Disp_H2PressBlink(u8 blink) { VideoBuf.h2press_blink = blink; } void Disp_PresBlink(u8 blink) { VideoBuf.pres_blink = blink; } void Disp_TempBlink(u8 blink) { VideoBuf.temp_blink = blink; } void Disp_VacuBlink(u8 blink) { VideoBuf.vacu_blink = blink; } void Disp_BatteryBlink(u8 blink) { VideoBuf.battery_blink = blink; } // ******************************************** // 以下为窗口界面实现 // ******************************************** // 设置焦点显示 void Disp_SetCursor(u8 pos, u8 width) { VideoBuf.cursor_pos = pos; VideoBuf.cursor_width = width; } void Disp_ClearCursor() { VideoBuf.cursor_pos = 0; VideoBuf.cursor_width = 0; } // 选择框函数 // 刷新显示 void SelectBox_Refresh(TSelectBox *pBox) { u8 i; for(i = 0; i < strlen(pBox->items[pBox->idx]) && i < pBox->width; i++) Disp_DispChar(pBox->pos + i, pBox->items[pBox->idx][i]); for(; i < pBox->width; i++) Disp_DispChar(pBox->pos + i, ' '); } // 创建选择框 void SelectBox_Create(TSelectBox *pBox, u8 pos, u8 width, u8 count, const char items[][6], u8 idx) { u8 i; memset(pBox, 0, sizeof(TSelectBox)); pBox->pos = pos; pBox->width = width; pBox->count = count; for(i = 0; i < count; i++) strcpy(pBox->items[i], items[i]); pBox->idx = idx; // 刷新显示 SelectBox_Refresh(pBox); } // 设置只读属性 void SelectBox_ReadOnly(TSelectBox *pBox) { pBox->read_only = 1; } // 设置隐藏属性 void SelectBox_Hide(TSelectBox *pBox) { pBox->hide = 1; } // 选择框处理按键 u8 SelectBox_OnKey(TSelectBox *pBox, u8 key) { u8 idx = pBox->idx; if(key == KEY_FUNC) return key; // 留给上一级处理 if(key == KEY_UP) { if(!pBox->read_only) { if(pBox->idx == pBox->count - 1) pBox->idx = 0; else pBox->idx++; } } else if(key == KEY_DOWN) { if(!pBox->read_only) { if(pBox->idx == 0) pBox->idx = pBox->count - 1; else pBox->idx--; } } // 刷新显示 if(idx != pBox->idx) SelectBox_Refresh(pBox); return KEY_INVALID; // 已处理 } // 选择框获得焦点 void SelectBox_SetFocus(TSelectBox *pBox) { Disp_SetCursor(pBox->pos, pBox->width); } // 编辑框函数 // 刷新显示 void EditBox_Refresh(TEditBox *pEdit) { u8 i, j; for(i = pEdit->left_idx, j = 0; i < strlen(pEdit->text) && i < pEdit->len && j < pEdit->width; i++, j++) Disp_DispChar(pEdit->pos + j, pEdit->text[i]); for(; j < pEdit->width; j++) Disp_DispChar(pEdit->pos + j, ' '); } // 创建编辑框 void EditBox_Create(TEditBox *pEdit, u8 pos, u8 width, u8 len, char *text) { memset(pEdit, 0, sizeof(TEditBox)); pEdit->pos = pos; pEdit->width = width; pEdit->len = len; strcpy(pEdit->text, text); pEdit->left_idx = 0; pEdit->curr_idx = 0; pEdit->read_only = 0; // 刷新显示 EditBox_Refresh(pEdit); } // 设置只读属性 void EditBox_ReadOnly(TEditBox *pEdit) { pEdit->read_only = 1; } // 设置隐藏属性 void EditBox_Hide(TEditBox *pEdit) { pEdit->hide = 1; } // 编辑框处理按键 u8 EditBox_OnKey(TEditBox *pEdit, u8 key) { u8 idx = pEdit->curr_idx; u8 c = pEdit->text[idx]; if(key == KEY_FUNC) return key; // 跳出EditBox,留给上一级处理 if(key == KEY_UP) { if(!pEdit->read_only) { if(pEdit->curr_idx == 0 && (pEdit->text[pEdit->curr_idx] == '+' || pEdit->text[pEdit->curr_idx] == '-')) { if(pEdit->text[pEdit->curr_idx] == '+') pEdit->text[pEdit->curr_idx] = '-'; else pEdit->text[pEdit->curr_idx] = '+'; } else if(pEdit->text[pEdit->curr_idx] == '9' || !isdigit(pEdit->text[pEdit->curr_idx])) pEdit->text[pEdit->curr_idx] = '0'; else pEdit->text[pEdit->curr_idx]++; } } else if(key == KEY_DOWN) { if(!pEdit->read_only) { if(pEdit->curr_idx == 0 && (pEdit->text[pEdit->curr_idx] == '+' || pEdit->text[pEdit->curr_idx] == '-')) { if(pEdit->text[pEdit->curr_idx] == '+') pEdit->text[pEdit->curr_idx] = '-'; else pEdit->text[pEdit->curr_idx] = '+'; } else if(pEdit->text[pEdit->curr_idx] == '0' || !isdigit(pEdit->text[pEdit->curr_idx])) pEdit->text[pEdit->curr_idx] = '9'; else pEdit->text[pEdit->curr_idx]--; } } else if(key == KEY_SET) { // 光标移动 if(pEdit->curr_idx == pEdit->len - 1) { pEdit->curr_idx = 0; pEdit->left_idx = 0; } else { pEdit->curr_idx++; // 处理滚动 if(pEdit->curr_idx >= pEdit->left_idx + pEdit->width) pEdit->left_idx++; } // 设置光标 Disp_SetCursor(pEdit->pos + (pEdit->curr_idx - pEdit->left_idx), 1); } // 刷新显示 if(idx != pEdit->curr_idx || c != pEdit->text[pEdit->curr_idx]) EditBox_Refresh(pEdit); return KEY_INVALID; // 已处理 } // 编辑框获得焦点 void EditBox_SetFocus(TEditBox *pEdit) { pEdit->left_idx = 0; pEdit->curr_idx = 0; Disp_SetCursor(pEdit->pos, 1); } // 按钮函数 // 刷新显示 void Button_Refresh(TButton *pButton) { u8 i; for(i = 0; i < strlen(pButton->caption) && i < pButton->width; i++) Disp_DispChar(pButton->pos + i, pButton->caption[i]); for(; i < pButton->width; i++) Disp_DispChar(pButton->pos + i, ' '); } // 创建按钮 void Button_Create(TButton *pButton, u8 pos, u8 width, char *caption) { memset(pButton, 0, sizeof(TButton)); pButton->pos = pos; pButton->width = width; strcpy(pButton->caption, caption); } // 设置隐藏属性 void Button_Hide(TButton *pButton) { pButton->hide = 1; } // 按钮处理按键 u8 Button_OnKey(TButton *pButton, u8 key) { if(key == KEY_FUNC) return key; // 跳出EditBox,留给上一级处理 if(key == KEY_SET) return key; // 执行,留给上一级处理 return KEY_INVALID; // 已处理 } // 按钮获得焦点 void Button_SetFocus(TButton *pButton) { Disp_SetCursor(pButton->pos, pButton->width); }