📄 menu.c
字号:
#include "main.h"
#include "port.h"
#include "DisplayDir.h"
#include "SysTick.h"
#include "key.h"
#include "Menu.h"
#include "RTC.h"
#define MAX_MENU_ITEM 1
void (code *FuncPtr)(void);
typedef struct {
uint8_t Current_Index;
uint8_t Set_Index;
uint8_t Enter_Index;
uint8_t Right_Index;
uint8_t Up_Index;
void (code *Current_Operation)(void);
}Key_Table;
static uint8_t Index = 0;
static UserChoose = 0; //用户所选菜单项
// 时间变量
static uint8_t hour_temp, minute_temp;
// 函数列表
static void NopFunc(void);
static void MainMenuItem(void);
static void Exit_MainMenuItem(void);
static void AdjHourSelect(void);
static void AdjMinuteSelect(void);
static void AdjTime_Hour(void);
static void AdjTime_Minute(void);
static void SetTime_Enter(void);
Key_Table code table[] = {
// |----------------- Current_Index
// | |-------------- Set_Index
// | | |----------- Enter_Index
// | | | |------ Right_Index
// | | | | |- Up_Index
// | | | | |
{0, 1, 0, 0, 0, (*NopFunc)}, // 主菜单
{1, 4, 5, 255, 255, (*MainMenuItem)}, // SEL.0, 调时
{2, 4, 255, 255, 255, (*MainMenuItem)}, // SEL.1, 设闹铃
{3, 4, 255, 255, 255, (*MainMenuItem)}, // SEL.2, 删除闹铃
{4, 4, 255, 255, 255, (*Exit_MainMenuItem)},// 退出菜单
// SEL.0, 调时
{5, 1, 9, 6, 7, (*AdjHourSelect)}, // 调时选择
{6, 1, 9, 5, 8, (*AdjMinuteSelect)}, // 调分选择
{7, 1, 9, 6, 7, (*AdjTime_Hour)}, // 调时
{8, 1, 9, 5, 8, (*AdjTime_Minute)}, // 调分
{9, 0, 0, 0, 0, (*SetTime_Enter)}, // ok
// SEL.1, 设闹铃
};
void Menu_Change(uint8_t KeyNum)
{
uint8_t Index_Backup;
Index_Backup = Index; // Index备份
switch(KeyNum)
{
case K_Set: Index = table[Index].Set_Index; break;
case K_Right: Index = table[Index].Right_Index; break;
case K_Up: Index = table[Index].Up_Index; break;
case K_Enter: Index = table[Index].Enter_Index; break;
default: /* --------------------------- */ break;
}
if (255 == Index)
{
Index = Index_Backup; // 无效键
}
else
{
FuncPtr = table[Index].Current_Operation;
(*FuncPtr)();
}
}
void NopFunc(void)
{
// 空函数,作用不小啊!!
}
// 主菜单item
void MainMenuItem(void)
{
LedChangeFlag = 0x00;
LedChangeFlag |= (1 << DOT3) | (1 << BIT4);
bUpdateDisplayEn = 0;
hour_temp = Rtc.hour; // 读时间
minute_temp = Rtc.min;
if (UserChoose >= MAX_MENU_ITEM)
{
UserChoose = 0;
}
DisplayBuffer[0] = _S;
DisplayBuffer[1] = _E;
DisplayBuffer[2] = _L;
DisplayBuffer[3] = UserChoose++;
}
// 不保存退也菜单
void Exit_MainMenuItem(void)
{
LedChangeFlag = 0x00;
LedChangeFlag |= (1 << DOT2); // 只有时钟的时个位点可以闪烁
bUpdateDisplayEn = 1;
Index = 0;
UserChoose = 0;
}
// 调时位选择
void AdjHourSelect(void)
{
LedChangeFlag = 0x00;
bUpdateDisplayEn = 0;
LedChangeFlag |= (1 << BIT1) | (1 << BIT2); // 调时选择
UpdateDisplayBuffer(hour_temp, minute_temp);
}
// 调分位选择
void AdjMinuteSelect(void)
{
LedChangeFlag = 0x00;
bUpdateDisplayEn = 0;
LedChangeFlag |= (1 << BIT3) | (1 << BIT4); // 调分选择
UpdateDisplayBuffer(hour_temp, minute_temp);
}
// 调时
void AdjTime_Hour(void)
{
bUpdateDisplayEn = 0;
hour_temp++;
if (hour_temp >= 24)
hour_temp = 0;
DisplayBuffer[0] = hour_temp / 10;
DisplayBuffer[1] = hour_temp % 10;
}
// 调分
void AdjTime_Minute(void)
{
bUpdateDisplayEn = 0;
minute_temp++;
if (minute_temp >= 60)
minute_temp = 0;
DisplayBuffer[2] = minute_temp / 10;
DisplayBuffer[3] = minute_temp % 10;
}
// 调时OK
void SetTime_Enter(void)
{
Rtc.hour = hour_temp; // 时间
Rtc.min = minute_temp;
Rtc.sec = 0;
ClockReviseTemp = 0; // 复位校正计时器
ClockReviseTemp1 = 0;
Exit_MainMenuItem();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -