添加读取赋码仪按键ke1 ,控制ledr,ledg 的功能
This commit is contained in:
@@ -11,6 +11,8 @@ typedef struct{
|
||||
pwm_def *pwm;
|
||||
int key_old;
|
||||
int key;
|
||||
int key1_old;
|
||||
int key1;
|
||||
int sen;
|
||||
char str_buff[200];
|
||||
}mymain_def;
|
||||
@@ -42,6 +44,18 @@ void *mymain_init(void)
|
||||
HAL_GPIO_WritePin(GPIOF,GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9,GPIO_PIN_RESET);
|
||||
PERIPH_UNLOCK(GPIOF);
|
||||
|
||||
// ָʾ<D6B8><CABE>PF1(<28><>) PG15(<28><>)
|
||||
init.Pin = GPIO_PIN_1;
|
||||
PERIPH_LOCK(GPIOF);
|
||||
HAL_GPIO_Init(GPIOF, &init);
|
||||
HAL_GPIO_WritePin(GPIOF,GPIO_PIN_1,GPIO_PIN_RESET);
|
||||
PERIPH_UNLOCK(GPIOF);
|
||||
init.Pin = GPIO_PIN_15;
|
||||
PERIPH_LOCK(GPIOG);
|
||||
HAL_GPIO_Init(GPIOG, &init);
|
||||
HAL_GPIO_WritePin(GPIOG,GPIO_PIN_15,GPIO_PIN_RESET);
|
||||
PERIPH_UNLOCK(GPIOG);
|
||||
|
||||
|
||||
// <20><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
init.Mode = GPIO_MODE_INPUT;
|
||||
@@ -52,12 +66,18 @@ void *mymain_init(void)
|
||||
PERIPH_UNLOCK(GPIOI);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>
|
||||
// PG3 key2 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
|
||||
// PH7 key1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
|
||||
init.Mode = GPIO_MODE_INPUT;
|
||||
init.Pull = GPIO_NOPULL;
|
||||
init.Pin = GPIO_PIN_3;
|
||||
PERIPH_LOCK(GPIOG);
|
||||
HAL_GPIO_Init(GPIOG, &init);
|
||||
PERIPH_UNLOCK(GPIOG);
|
||||
init.Pin = GPIO_PIN_7;
|
||||
PERIPH_LOCK(GPIOH);
|
||||
HAL_GPIO_Init(GPIOH, &init);
|
||||
PERIPH_UNLOCK(GPIOH);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>
|
||||
init.Mode = GPIO_MODE_INPUT;
|
||||
@@ -91,6 +111,22 @@ void out_set(int index,int power)
|
||||
send_str_to_a7(m->str_buff);
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>ledr
|
||||
void ledr_set(int power)
|
||||
{
|
||||
PERIPH_LOCK(GPIOG);
|
||||
HAL_GPIO_WritePin(GPIOG,1<<15,power?GPIO_PIN_SET:GPIO_PIN_RESET);
|
||||
PERIPH_UNLOCK(GPIOG);
|
||||
send_str_to_a7("ledr seted");
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD>ledg
|
||||
void ledg_set(int power)
|
||||
{
|
||||
PERIPH_LOCK(GPIOF);
|
||||
HAL_GPIO_WritePin(GPIOF,1<<1,power?GPIO_PIN_SET:GPIO_PIN_RESET);
|
||||
PERIPH_UNLOCK(GPIOF);
|
||||
send_str_to_a7("ledg seted");
|
||||
}
|
||||
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@@ -176,6 +212,44 @@ static int str_ainttoi(const char *s)
|
||||
|
||||
|
||||
|
||||
int read_key(void *mymain)
|
||||
{
|
||||
mymain_def *m=mymain;
|
||||
int key=0,key2=0;
|
||||
key=HAL_GPIO_ReadPin(GPIOG,1<<3);
|
||||
if(key!=m->key_old)
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD>5<EFBFBD>Σ<EFBFBD><CEA3><EFBFBD>Ϊ<EFBFBD>෴<EFBFBD><E0B7B4>ƽʱ<C6BD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>ƽ
|
||||
for(int i=0;i<2;i++)
|
||||
{
|
||||
delay_ms(20);
|
||||
key2=HAL_GPIO_ReadPin(GPIOG,1<<3);
|
||||
if(key!=key2) return key2;
|
||||
}
|
||||
return key;
|
||||
}
|
||||
return m->key_old;
|
||||
|
||||
}
|
||||
int read_key1(void *mymain)
|
||||
{
|
||||
mymain_def *m=mymain;
|
||||
int key=0,key2=0;
|
||||
key=HAL_GPIO_ReadPin(GPIOH,1<<7);
|
||||
if(key!=m->key1_old)
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD>5<EFBFBD>Σ<EFBFBD><CEA3><EFBFBD>Ϊ<EFBFBD>෴<EFBFBD><E0B7B4>ƽʱ<C6BD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>ƽ
|
||||
for(int i=0;i<2;i++)
|
||||
{
|
||||
delay_ms(20);
|
||||
key2=HAL_GPIO_ReadPin(GPIOH,1<<7);
|
||||
if(key!=key2) return key2;
|
||||
}
|
||||
return key;
|
||||
}
|
||||
return m->key1_old;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -183,7 +257,8 @@ static int str_ainttoi(const char *s)
|
||||
void mymain_scan(void *mymain)
|
||||
{
|
||||
mymain_def *m=mymain;
|
||||
m->key=HAL_GPIO_ReadPin(GPIOG,1<<3);
|
||||
m->key=read_key(mymain);
|
||||
m->key1=read_key1(mymain);
|
||||
m->sen=HAL_GPIO_ReadPin(GPIOI,1<<6);
|
||||
if(m->key_old!=m->key){
|
||||
if(m->key==RESET)
|
||||
@@ -195,6 +270,16 @@ void mymain_scan(void *mymain)
|
||||
}
|
||||
m->key_old=m->key;
|
||||
}
|
||||
if(m->key1_old!=m->key1){
|
||||
if(m->key1==RESET)
|
||||
{
|
||||
send_str_to_a7("ke1 press");
|
||||
}else
|
||||
{
|
||||
send_str_to_a7("ke1 up");
|
||||
}
|
||||
m->key1_old=m->key1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -211,6 +296,7 @@ int read_sw(void *mymain)
|
||||
|
||||
|
||||
|
||||
|
||||
void mymain_loop(void *mymain,char *cmd_str)
|
||||
{
|
||||
mymain_def *m=mymain;
|
||||
@@ -219,7 +305,6 @@ void mymain_loop(void *mymain,char *cmd_str)
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>½<EFBFBD>
|
||||
int count=str_ainttoi(cmd_str+6);
|
||||
if(count!=0){
|
||||
send_str_to_a7(m->str_buff);
|
||||
moter_run(0,count);
|
||||
if(count>0){
|
||||
send_str_to_a7("moter down");
|
||||
@@ -252,6 +337,12 @@ void mymain_loop(void *mymain,char *cmd_str)
|
||||
else
|
||||
send_str_to_a7("key press");
|
||||
}
|
||||
else if(strncmp(cmd_str,"readke1",7)==0){
|
||||
if(m->key1)
|
||||
send_str_to_a7("ke1 up");
|
||||
else
|
||||
send_str_to_a7("ke1 press");
|
||||
}
|
||||
else if(strncmp(cmd_str,"readsen",7)==0){
|
||||
// <20><><EFBFBD><EFBFBD>
|
||||
if(m->sen)
|
||||
@@ -268,6 +359,25 @@ void mymain_loop(void *mymain,char *cmd_str)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(strncmp(cmd_str,"ledr",4)==0){
|
||||
if(strncmp(cmd_str+5,"on",2)==0){
|
||||
ledr_set(1);
|
||||
}else{
|
||||
ledr_set(0);
|
||||
}
|
||||
}
|
||||
else if(strncmp(cmd_str,"ledg",4)==0){
|
||||
if(strncmp(cmd_str+5,"on",2)==0){
|
||||
ledg_set(1);
|
||||
}else{
|
||||
ledg_set(0);
|
||||
}
|
||||
}
|
||||
else if(strncmp(cmd_str,"build",5)==0){
|
||||
send_str_to_a7("buildtime: " __DATE__ " " __TIME__);
|
||||
}else{
|
||||
send_str_to_a7("unknown cmd");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -87,3 +87,16 @@ void rt_hw_us_delay(rt_uint32_t us)
|
||||
delay_us(us);
|
||||
}
|
||||
|
||||
|
||||
void delay_ms(uint32_t ms)
|
||||
{
|
||||
for(int i=0;i<ms;i++)
|
||||
{
|
||||
delay_us(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -12,7 +12,7 @@ int delay_init(void);
|
||||
|
||||
void delay_us(uint32_t us);
|
||||
|
||||
|
||||
void delay_ms(uint32_t ms);
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user