@@ -14,6 +14,9 @@
|
||||
#define morse_play_hz 1000
|
||||
|
||||
|
||||
char config_buzzer_for_button_pass=1;
|
||||
char config_buzzer_for_button_longpass=1;
|
||||
char config_buzzer_for_sele_change=1;
|
||||
|
||||
|
||||
|
||||
@@ -44,13 +47,116 @@ menu menu_main=
|
||||
menu buzzer_setting=
|
||||
{
|
||||
0,0,
|
||||
"Back\nInput",
|
||||
"返回\n输入",
|
||||
"no\noff"
|
||||
"Back\nClick\nPress\nSele change",
|
||||
"返回\n点击\n长按\n选择切换",
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
word turnon=
|
||||
{
|
||||
"ON",
|
||||
"开"
|
||||
};
|
||||
|
||||
word turnoff=
|
||||
{
|
||||
"OF",
|
||||
"关"
|
||||
};
|
||||
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void di()
|
||||
{
|
||||
BUZZER_PLAY_NOTES(morse_play_hz,morse_play_t1,50);
|
||||
@@ -79,17 +185,47 @@ void mymain()
|
||||
MUTE(0);
|
||||
|
||||
BUZZER_PLAY_NOTES(1000,1000,50);
|
||||
BUZZER_PLAY_NOTES(0,1000,50);
|
||||
|
||||
B1.config_longtimes=1;//启用B1按钮的长按检测
|
||||
|
||||
while(1)
|
||||
{
|
||||
GEI_BUTTON_CODE(&B1,en_c());//循环更新按钮
|
||||
encode_c=GET_ENCODE(&E1);
|
||||
encode_c=GET_ENCODE(&E1); //更新编码器
|
||||
|
||||
//蜂鸣器控制
|
||||
if(B1.code>0)
|
||||
{
|
||||
if(B1.code<255)//1-254
|
||||
{
|
||||
if(config_buzzer_for_button_pass==1)
|
||||
{
|
||||
BUZZER_PLAY_NOTES(1000,100,50);
|
||||
BUZZER_PLAY_NOTES(0,0,0);
|
||||
}
|
||||
}else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(encode_c!=0)
|
||||
{
|
||||
jump_tick=HAL_GetTick()+10000;
|
||||
|
||||
if(mode==2)
|
||||
{
|
||||
if(config_buzzer_for_sele_change==1)
|
||||
{
|
||||
BUZZER_PLAY_NOTES(1000,50,50);
|
||||
BUZZER_PLAY_NOTES(0,0,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
case 0:
|
||||
@@ -119,6 +255,13 @@ void mymain()
|
||||
|
||||
if(B1.code==255)
|
||||
{
|
||||
|
||||
if(config_buzzer_for_button_longpass==1)
|
||||
{
|
||||
BUZZER_PLAY_NOTES(1000,100,50);
|
||||
BUZZER_PLAY_NOTES(0,0,0);
|
||||
}
|
||||
|
||||
mode=2;
|
||||
jump_tick=HAL_GetTick()+10000;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,21 @@
|
||||
#include "hread_interface.h"
|
||||
#include "morsr.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int sele;
|
||||
int list_dis_top;
|
||||
const char *list_en;
|
||||
const char *list_ch;
|
||||
char *r_sw_list;
|
||||
|
||||
}menu;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const char *list_en;
|
||||
const char *list_ch;
|
||||
}word;
|
||||
|
||||
|
||||
extern TIM_HandleTypeDef htim3;
|
||||
|
||||
@@ -1105,92 +1105,3 @@ 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,15 +18,6 @@
|
||||
#define Y_WIDTH_ 8
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int sele;
|
||||
int list_dis_top;
|
||||
const char *list_en;
|
||||
const char *list_ch;
|
||||
char *r_list;
|
||||
|
||||
}menu;
|
||||
|
||||
|
||||
|
||||
@@ -44,6 +35,5 @@ 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