uCosiii队列API应用笔记

版权声明:本文为博主原创文章,转载请注明出处 https://blog.csdn.net/jickjiang/article/details/79970887

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;
		}
	}

}




阅读更多

没有更多推荐了,返回首页