@@ -170,12 +170,21 @@ char getmorsecode(uint8_t len,uint8_t code)
|
||||
button B1;//创建一个按钮
|
||||
encoder E1;//创建一个编码器
|
||||
int mode=0;
|
||||
uint32_t run_tick=0;
|
||||
uint32_t run_tick=0,jump_tick=0;
|
||||
char str[16];
|
||||
uint16_t fps=0,fps_=0;
|
||||
char sys_lan=0;
|
||||
|
||||
int encode_c=0;
|
||||
|
||||
menu menu_main=
|
||||
{
|
||||
"Back\nInput\nBuzzer\nOLED\nAuto\nType\nLanguage\nAbout",
|
||||
"返回\n",
|
||||
|
||||
0,0
|
||||
};
|
||||
|
||||
void mymain()
|
||||
{
|
||||
//按钮定义接口
|
||||
@@ -213,9 +222,23 @@ void mymain()
|
||||
fps_++;
|
||||
sprintf(str,"FPS:%d",fps);
|
||||
OLED_Str(0,56,8,str,1);
|
||||
|
||||
if(B1.code==255)
|
||||
{
|
||||
mode=2;
|
||||
jump_tick=HAL_GetTick()+10000;
|
||||
}
|
||||
|
||||
break;
|
||||
case 2:
|
||||
//菜单界面
|
||||
switch(SHOW_MENU(&menu_main,GET_ENCODE(&E1),B1.code,sys_lan))
|
||||
{
|
||||
case 0:
|
||||
mode=1;
|
||||
break;
|
||||
}
|
||||
if(HAL_GetTick()>jump_tick){mode=1;}
|
||||
break;
|
||||
|
||||
}
|
||||
@@ -259,6 +282,6 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
||||
default:
|
||||
break;
|
||||
|
||||
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
|
||||
//__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
|
||||
}
|
||||
}
|
||||
@@ -1105,3 +1105,92 @@ void OLED_square(int Start_x, int Start_y, int End_x, int End_y, char type)
|
||||
}
|
||||
}
|
||||
|
||||
int SHOW_MENU(menu *m,int encoder,char button,char lan)
|
||||
{
|
||||
int return_code=-1;
|
||||
char str[32];
|
||||
const char *list;
|
||||
uint16_t list_len=0;
|
||||
uint16_t a=0;
|
||||
uint16_t b=0;
|
||||
uint16_t c=0;
|
||||
uint16_t d=0;
|
||||
|
||||
//get list
|
||||
switch(lan)
|
||||
{
|
||||
case 0:
|
||||
list=m->list_en;
|
||||
break;
|
||||
case 1:
|
||||
list=m->list_ch;
|
||||
break;
|
||||
default :
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//check how many list
|
||||
while(list[a]!='\0')
|
||||
{
|
||||
if(list[a]=='\n'){list_len++;}
|
||||
a++;
|
||||
}
|
||||
|
||||
m->sele+=encoder;
|
||||
|
||||
if(m->sele<0){m->sele=0;}
|
||||
if(m->sele>list_len){m->sele=list_len;}
|
||||
|
||||
if(m->sele<m->list_dis_top+3){m->list_dis_top--;}
|
||||
if(m->sele>m->list_dis_top){if((m->list_dis_top+3)<list_len){m->list_dis_top++;}}
|
||||
|
||||
m->list_dis_top=((list_len+1>4)?(m->list_dis_top):0);
|
||||
|
||||
//display list
|
||||
for(d=0;d<m->list_dis_top;d++)
|
||||
{
|
||||
while((*list!='\0')&&(*list!='\n'))
|
||||
{
|
||||
list++;
|
||||
}
|
||||
list++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
for(b=0;b<(list_len+1>4?4:list_len+1);b++)
|
||||
{
|
||||
if((m->list_dis_top+b)==m->sele)
|
||||
{
|
||||
str[c]='>';
|
||||
|
||||
}else
|
||||
{
|
||||
str[c]=' ';
|
||||
}
|
||||
c++;
|
||||
while((*list!='\0')&&(*list!='\n'))
|
||||
{
|
||||
str[c]=*list;
|
||||
c++;
|
||||
list++;
|
||||
}
|
||||
str[c]='\0';
|
||||
OLED_Str(0, 16*b, 16, str, 1);
|
||||
c=0;
|
||||
list++;
|
||||
|
||||
}
|
||||
|
||||
if(button==1)
|
||||
{
|
||||
return_code=m->sele;
|
||||
}
|
||||
|
||||
return return_code;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,13 @@
|
||||
#define Y_WIDTH_ 8
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const char *list_en;
|
||||
const char *list_ch;
|
||||
int sele;
|
||||
int list_dis_top;
|
||||
}menu;
|
||||
|
||||
|
||||
|
||||
@@ -34,4 +41,7 @@ void OLED_Str(unsigned char x,unsigned char y,unsigned char size,char *str,unsig
|
||||
void OLED_AL(int sx,int sy,int ex,int ey,unsigned char dot_type);
|
||||
|
||||
void OLED_square(int Start_x, int Start_y, int End_x, int End_y, char type);
|
||||
|
||||
int SHOW_MENU(menu *m,int encoder,char button,char lan);
|
||||
|
||||
#endif /* OLED_H_ */
|
||||
|
||||
Reference in New Issue
Block a user