OS_Q消息队列传输的是指针,所以在传输过程中,需要保持指针所在变量保持。
/*
************************************************************
* 函数名称: KEY_Task
*
* 函数功能: 扫描按键是否按下,如果有按下,进行对应的处理
*
* 入口参数: void类型的参数指针
*
* 返回参数: 无
*
* 说明: 按键任务
************************************************************
*/
OS_Q KeyTaskQ;
void KEY_Task(void *pdata)
{
OS_ERR err;
uint8_t keyValue = KEYNONE;
uint8_t s_keyValue = KEYNONE; //每次循环后,keyValue的值会变,所有添加s_keyValue
OSQCreate(&KeyTaskQ,"KeyTaskQ",4,&err);
while(1)
{
OSTimeDly(10, OS_OPT_TIME_PERIODIC, &err);
Led1_Set(LED_OFF);Led2_Set(LED_OFF);
keyValue = Keyboard();
if(keyValue == KEYNONE) continue;
switch(keyValue) //扫描按键状态
{
case KEY0DOWN: //如果是key0单击事件
case KEY1DOWN:
case KEY2DOWN:
case KEY3DOWN:
s_keyValue = keyValue;
OSQPost(&KeyTaskQ,&s_keyValue,1,OS_OPT_POST_FIFO ,&err);
if(err == OS_ERR_NONE)
Led2_Set(LED_ON);
break;
case KEY0DOWNLONG:{
static bool bLight = true;
bLight = !bLight;
inf_lcd_display_set(bLight);
}break;
case KEY1DOWNLONG:
oneNetInfo.sendData = SEND_TYPE_PICTURE; //上传图片
break;
case KEY2DOWNLONG:
OneNet_PushData("6056130", "{redled}1", strlen("{redled}1"));
break;
case KEY3DOWNLONG:
OneNet_PushData("6056130", "{redled}0", strlen("{redled}0"));
break;
default:
Led1_Set(LED_ON);
break;
}
}
}