382 lines
9.1 KiB
C
382 lines
9.1 KiB
C
|
|
|
|||
|
|
#define __IN_BUTTONS_C
|
|||
|
|
#include "buttons.h"
|
|||
|
|
#include "trigger.h"
|
|||
|
|
//----------------------------------------------------------------------------------------------------------------
|
|||
|
|
|
|||
|
|
#define KEY_SCAN_NUM 2 // <20><><EFBFBD><EFBFBD>ȥ<EFBFBD><C8A5>, <20><>Ϊ<EFBFBD><CEAA><EFBFBD>ȶ<EFBFBD><C8B6><EFBFBD>ƽ(100ms)
|
|||
|
|
#define KEY_LONG_DOWN_NUM 50 // <20><><EFBFBD><EFBFBD>500ms<6D><73><EFBFBD>Ӱ<EFBFBD><D3B0><EFBFBD>, <20><>Ϊ<EFBFBD>dz<EFBFBD>ʱ<EFBFBD>䰴<EFBFBD><E4B0B4>
|
|||
|
|
#define KEY_TASK_DISABLE 50 // 500ms<6D><73>û<EFBFBD><C3BB><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>, <20><>ô<EFBFBD><C3B4>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч
|
|||
|
|
|
|||
|
|
//--------------------------------------------------------
|
|||
|
|
|
|||
|
|
|
|||
|
|
//--------------------------------------------------------
|
|||
|
|
#ifndef MAX_BUTTONS_NUM
|
|||
|
|
#define MAX_BUTTONS_NUM 10 // <20><><EFBFBD><EFBFBD>֧<EFBFBD>ְ<EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD>
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
typedef struct
|
|||
|
|
{
|
|||
|
|
ScanFunc scanfunc; // <20><><EFBFBD>⺯<EFBFBD><E2BAAF>
|
|||
|
|
u8 checkState; // <20><><EFBFBD><EFBFBD>״̬
|
|||
|
|
|
|||
|
|
TaskFunc ldtaskFunc; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
TaskFunc dtaskFunc; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
TaskFunc ctaskFunc; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
TaskFunc dQuktaskFunc; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
}ButtonScan;
|
|||
|
|
|
|||
|
|
|
|||
|
|
typedef struct
|
|||
|
|
{
|
|||
|
|
ButtonScan buttonsList[MAX_BUTTONS_NUM];
|
|||
|
|
int buttonsNumber; // ע<><D7A2><EFBFBD>İ<EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD>
|
|||
|
|
int buttonTask; // <20><>ť<EFBFBD><C5A5>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD> -1:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD> 0: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 3:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
int scanIndex; // <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8>/<2F>ȴ<EFBFBD>ִ<EFBFBD>еİ<D0B5>ť
|
|||
|
|
|
|||
|
|
u16 buttonCount; // <20><>ťɨ<C5A5><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
u16 taskCount; // <20><>ť<EFBFBD><C5A5>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
u8 shakeSta[KEY_SCAN_NUM]; // <20><><EFBFBD><EFBFBD>ȥ<EFBFBD><C8A5><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
|
|||
|
|
u8 shakeIdx; // <20><><EFBFBD><EFBFBD>ȥ<EFBFBD><C8A5><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>ָ<EFBFBD><D6B8>
|
|||
|
|
|
|||
|
|
DelayRun delay;
|
|||
|
|
|
|||
|
|
int execing; // <20><><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>־
|
|||
|
|
}ButtonCtrl;
|
|||
|
|
|
|||
|
|
|
|||
|
|
ButtonCtrl g_buttonCtrl;
|
|||
|
|
|
|||
|
|
//----------------------------------------------------------------------------------------------------------------
|
|||
|
|
|
|||
|
|
//--------------------------------------------------------
|
|||
|
|
|
|||
|
|
void InitButtonCtrl(void)
|
|||
|
|
{
|
|||
|
|
int i;
|
|||
|
|
|
|||
|
|
g_buttonCtrl.buttonsNumber = 0; // ע<><D7A2><EFBFBD>İ<EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD>
|
|||
|
|
g_buttonCtrl.buttonTask = 0; // <20><>ť<EFBFBD><C5A5>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>
|
|||
|
|
g_buttonCtrl.scanIndex = -1; // û<><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD>İ<EFBFBD>ť
|
|||
|
|
|
|||
|
|
memset(g_buttonCtrl.buttonsList, 0, sizeof(ButtonScan)*MAX_BUTTONS_NUM);
|
|||
|
|
for (i = 0; i < MAX_BUTTONS_NUM; i++)
|
|||
|
|
{
|
|||
|
|
g_buttonCtrl.buttonsList[i].scanfunc = NULL;
|
|||
|
|
}
|
|||
|
|
g_buttonCtrl.delay = NULL;
|
|||
|
|
|
|||
|
|
AddTriggerToList(10, ScanButtons, NULL); // 10ms
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//--------------------------------------------------------
|
|||
|
|
// <20><><EFBFBD><EFBFBD>Botton<6F><6E>ɨ<EFBFBD><C9A8><EFBFBD>б<EFBFBD>
|
|||
|
|
|
|||
|
|
int AddButtonToList(ScanFunc fp, u8 sta, TaskFunc ldtsk, TaskFunc ctsk, TaskFunc dtsk, TaskFunc dqtsk)
|
|||
|
|
{
|
|||
|
|
if ((fp != NULL) &&
|
|||
|
|
((ldtsk != NULL) || (ctsk != NULL) || (dtsk != NULL) || (dqtsk != NULL)) &&
|
|||
|
|
(g_buttonCtrl.buttonsNumber < MAX_BUTTONS_NUM) &&
|
|||
|
|
1 )
|
|||
|
|
{
|
|||
|
|
memset(&(g_buttonCtrl.buttonsList[g_buttonCtrl.buttonsNumber]), 0, sizeof(ButtonScan));
|
|||
|
|
g_buttonCtrl.buttonsList[g_buttonCtrl.buttonsNumber].scanfunc = fp;
|
|||
|
|
g_buttonCtrl.buttonsList[g_buttonCtrl.buttonsNumber].checkState = sta;
|
|||
|
|
g_buttonCtrl.buttonsList[g_buttonCtrl.buttonsNumber].ldtaskFunc = ldtsk;
|
|||
|
|
g_buttonCtrl.buttonsList[g_buttonCtrl.buttonsNumber].ctaskFunc = ctsk;
|
|||
|
|
g_buttonCtrl.buttonsList[g_buttonCtrl.buttonsNumber].dtaskFunc = dtsk;
|
|||
|
|
g_buttonCtrl.buttonsList[g_buttonCtrl.buttonsNumber].dQuktaskFunc = dqtsk;
|
|||
|
|
g_buttonCtrl.buttonsNumber++;
|
|||
|
|
|
|||
|
|
// printf("add a new button to %d\r\n", g_buttonCtrl.buttonsNumber);
|
|||
|
|
|
|||
|
|
return g_buttonCtrl.buttonsNumber;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
printf("add button more than enable\r\n");
|
|||
|
|
return -1;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//--------------------------------------------------------
|
|||
|
|
// ÿ10msɨ<73><C9A8>һ<EFBFBD><D2BB>
|
|||
|
|
|
|||
|
|
void ScanButtons(void)
|
|||
|
|
{
|
|||
|
|
u8 sta,staOk;
|
|||
|
|
int i;
|
|||
|
|
ButtonScan * pScan;
|
|||
|
|
|
|||
|
|
if (g_buttonCtrl.scanIndex == -1)
|
|||
|
|
{// û<><C3BB>ȷ<EFBFBD><C8B7>Ŀ<EFBFBD>갴ť
|
|||
|
|
for (i = 0; i < g_buttonCtrl.buttonsNumber; i++)
|
|||
|
|
{
|
|||
|
|
pScan = (&(g_buttonCtrl.buttonsList[i]));
|
|||
|
|
if (pScan->scanfunc == NULL)
|
|||
|
|
{
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
sta = pScan->scanfunc();
|
|||
|
|
if (sta == pScan->checkState) // <20>а<EFBFBD><D0B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڰ<EFBFBD><DAB0><EFBFBD>״̬
|
|||
|
|
{
|
|||
|
|
g_buttonCtrl.scanIndex = i; // <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8>/<2F>ȴ<EFBFBD>ִ<EFBFBD>еİ<D0B5>ť
|
|||
|
|
g_buttonCtrl.shakeIdx = 0; // <20><><EFBFBD><EFBFBD>ȥ<EFBFBD><C8A5><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>ָ<EFBFBD><D6B8>
|
|||
|
|
g_buttonCtrl.taskCount = 0; // <20><>ť<EFBFBD><C5A5>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
g_buttonCtrl.buttonCount = 0; // <20><>ťɨ<C5A5><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
memset(g_buttonCtrl.shakeSta, (~pScan->checkState), KEY_SCAN_NUM); // ȥ<><C8A5><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else if (g_buttonCtrl.scanIndex < g_buttonCtrl.buttonsNumber)
|
|||
|
|
{// <20>жϰ<D0B6>ť״̬
|
|||
|
|
pScan = (&(g_buttonCtrl.buttonsList[g_buttonCtrl.scanIndex]));
|
|||
|
|
if (pScan->scanfunc != NULL)
|
|||
|
|
{
|
|||
|
|
sta = pScan->scanfunc(); // <20><><EFBFBD><EFBFBD>ֵ
|
|||
|
|
staOk = 1; // <20>˲<EFBFBD><CBB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬʱΪ1,<2C><><EFBFBD><EFBFBD>Ϊ0
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>ȥ<EFBFBD><C8A5>
|
|||
|
|
if (KEY_SCAN_NUM > 1)
|
|||
|
|
{
|
|||
|
|
g_buttonCtrl.shakeSta[g_buttonCtrl.shakeIdx++] = sta;
|
|||
|
|
g_buttonCtrl.shakeIdx %= KEY_SCAN_NUM;
|
|||
|
|
|
|||
|
|
for (i = 0; i < KEY_SCAN_NUM-1; i++)
|
|||
|
|
{
|
|||
|
|
if (g_buttonCtrl.shakeSta[i] != g_buttonCtrl.shakeSta[i+1])
|
|||
|
|
{
|
|||
|
|
staOk = 0;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>ж<EFBFBD>
|
|||
|
|
if (g_buttonCtrl.buttonCount == 0)
|
|||
|
|
{// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч
|
|||
|
|
if ((sta == pScan->checkState) && (staOk == 1))
|
|||
|
|
{// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч
|
|||
|
|
g_buttonCtrl.buttonCount = 1;
|
|||
|
|
if (pScan->dQuktaskFunc != NULL)
|
|||
|
|
{// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>
|
|||
|
|
pScan->dQuktaskFunc();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (pScan->dtaskFunc != NULL)
|
|||
|
|
{// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
g_buttonCtrl.buttonTask = 1; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD> -1:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD> 0: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 3:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
g_buttonCtrl.taskCount = KEY_TASK_DISABLE; // <20><>ť<EFBFBD><C5A5>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else if (g_buttonCtrl.buttonTask != 3)
|
|||
|
|
{// <20><><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>Ч<EFBFBD><EFBFBD><F3B2BBBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (sta == pScan->checkState)
|
|||
|
|
{// <20><>ť<EFBFBD><C5A5>ס
|
|||
|
|
if (g_buttonCtrl.buttonCount < KEY_LONG_DOWN_NUM)
|
|||
|
|
{
|
|||
|
|
g_buttonCtrl.buttonCount++;
|
|||
|
|
}
|
|||
|
|
else if (g_buttonCtrl.buttonCount == KEY_LONG_DOWN_NUM)
|
|||
|
|
{// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (pScan->ldtaskFunc != NULL)
|
|||
|
|
{
|
|||
|
|
g_buttonCtrl.taskCount = KEY_TASK_DISABLE; // <20><>ť<EFBFBD><C5A5>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
g_buttonCtrl.buttonTask = 2; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD> -1:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD> 0: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 3:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
}
|
|||
|
|
g_buttonCtrl.buttonCount++;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{// <20><>ţ̌<C5A5><CCA7>
|
|||
|
|
if (staOk == 1) // <20><>ţ̌<C5A5><CCA7><EFBFBD>˲<EFBFBD>
|
|||
|
|
{// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (pScan->ctaskFunc != NULL)
|
|||
|
|
{
|
|||
|
|
g_buttonCtrl.taskCount = KEY_TASK_DISABLE; // <20><>ť<EFBFBD><C5A5>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
g_buttonCtrl.buttonTask = 3; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD> -1:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD> 0: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 3:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
if (((pScan->dtaskFunc == NULL) && (pScan->ldtaskFunc == NULL) && (pScan->ctaskFunc == NULL)) || // ֻע<D6BB><D7A2><EFBFBD>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>
|
|||
|
|
(g_buttonCtrl.buttonTask == -1) || // <20><><EFBFBD>»<C2BB><F2B3A4B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ
|
|||
|
|
0 )
|
|||
|
|
{
|
|||
|
|
g_buttonCtrl.buttonTask = 0;
|
|||
|
|
g_buttonCtrl.scanIndex = -1; // <20>ް<EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD>
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><>ť<EFBFBD><C5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ж<EFBFBD>
|
|||
|
|
if ((g_buttonCtrl.buttonTask > 0) && // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫִ<D2AA><D6B4>
|
|||
|
|
(g_buttonCtrl.taskCount != 0) && // δ<><CEB4>ʱ
|
|||
|
|
1 )
|
|||
|
|
{
|
|||
|
|
if (--g_buttonCtrl.taskCount == 0)
|
|||
|
|
{
|
|||
|
|
if (g_buttonCtrl.buttonTask == 3)
|
|||
|
|
{
|
|||
|
|
g_buttonCtrl.scanIndex = -1; // <20>ް<EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD>
|
|||
|
|
}
|
|||
|
|
g_buttonCtrl.buttonTask = -1;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//--------------------------------------------------------
|
|||
|
|
|
|||
|
|
int WaitAllButtonUp(void)
|
|||
|
|
{
|
|||
|
|
int i, j;
|
|||
|
|
int rslt;
|
|||
|
|
u32 startTime,loopTime; //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> <20><>λ:s
|
|||
|
|
ButtonScan * pScan;
|
|||
|
|
|
|||
|
|
rslt = 0;
|
|||
|
|
startTime = GetMsSoftTimer();
|
|||
|
|
do
|
|||
|
|
{
|
|||
|
|
j = 0;
|
|||
|
|
for (i = 0; i < g_buttonCtrl.buttonsNumber; i++)
|
|||
|
|
{
|
|||
|
|
pScan = (&(g_buttonCtrl.buttonsList[i]));
|
|||
|
|
if (pScan->scanfunc == NULL)
|
|||
|
|
{
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
if (pScan->scanfunc() != pScan->checkState)
|
|||
|
|
{
|
|||
|
|
j++;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (g_buttonCtrl.buttonsNumber == j)
|
|||
|
|
{
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ScanButtons(); // ɨ<>谴<EFBFBD><E8B0B4> // <20>а<EFBFBD>ťδ̧<CEB4><CCA7>,ִ<>а<EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
if (g_buttonCtrl.delay != NULL)
|
|||
|
|
{
|
|||
|
|
g_buttonCtrl.delay(1);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
loopTime = GetMsSoftTimer();
|
|||
|
|
if ((loopTime - startTime) > 5000) // <20><><EFBFBD><EFBFBD>ֻ<EFBFBD>ȴ<EFBFBD>5sʱ<73><CAB1>
|
|||
|
|
{
|
|||
|
|
rslt = -1;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}while(1);
|
|||
|
|
|
|||
|
|
g_buttonCtrl.buttonTask = 0;
|
|||
|
|
g_buttonCtrl.scanIndex = -1; // <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8>/<2F>ȴ<EFBFBD>ִ<EFBFBD>еİ<D0B5>ť
|
|||
|
|
|
|||
|
|
return rslt;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void RegDelayFun(DelayRun delay)
|
|||
|
|
{
|
|||
|
|
g_buttonCtrl.delay = delay;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void CleanButtonTask(void)
|
|||
|
|
{
|
|||
|
|
g_buttonCtrl.buttonTask = 0; // <20><>ť<EFBFBD><C5A5>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD> -1:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD> 0: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 3:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
g_buttonCtrl.scanIndex = -1; // <20><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8>/<2F>ȴ<EFBFBD>ִ<EFBFBD>еİ<D0B5>ť
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void ButtonsTask()
|
|||
|
|
{
|
|||
|
|
int i, rslt;
|
|||
|
|
u8 sta;
|
|||
|
|
ButtonScan * pScan;
|
|||
|
|
|
|||
|
|
if (g_buttonCtrl.execing != 0) // ֻ<><D6BB><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4>һ<EFBFBD>ΰ<EFBFBD><CEB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD>Ƕ<EFBFBD><EFBFBD><D7B5><EFBFBD>
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
g_buttonCtrl.execing++;
|
|||
|
|
|
|||
|
|
if ((g_buttonCtrl.buttonTask > 0) &&
|
|||
|
|
(g_buttonCtrl.scanIndex >= 0) &&
|
|||
|
|
1 )
|
|||
|
|
{
|
|||
|
|
rslt = 0;
|
|||
|
|
for (i = 0; i < g_buttonCtrl.buttonsNumber; i++)
|
|||
|
|
{// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϰ<EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD>ʱ,<2C><><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
|
|||
|
|
pScan = (&(g_buttonCtrl.buttonsList[i]));
|
|||
|
|
if (pScan->scanfunc == NULL)
|
|||
|
|
{
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
sta = pScan->scanfunc();
|
|||
|
|
if (sta == pScan->checkState)
|
|||
|
|
{
|
|||
|
|
if (i == g_buttonCtrl.scanIndex)
|
|||
|
|
{// ָ<><D6B8><EFBFBD><EFBFBD>ť
|
|||
|
|
rslt++;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{// <20>쳣<EFBFBD><ECB3A3>ť
|
|||
|
|
rslt--;
|
|||
|
|
printf("button%d state error\r\n", g_buttonCtrl.scanIndex);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (((g_buttonCtrl.buttonTask != 3) && (rslt == 1)) ||
|
|||
|
|
((g_buttonCtrl.buttonTask == 3) && (rslt == 0)) ||
|
|||
|
|
0 )
|
|||
|
|
{// ֻ<><D6BB>һ<EFBFBD><D2BB><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD>ʱ,ִ<><D6B4><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
pScan = (&(g_buttonCtrl.buttonsList[g_buttonCtrl.scanIndex]));
|
|||
|
|
if (pScan != NULL)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
if (g_buttonCtrl.buttonTask == 1)
|
|||
|
|
{// 1:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (pScan->dtaskFunc != NULL)
|
|||
|
|
{
|
|||
|
|
rslt = pScan->dtaskFunc();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else if (g_buttonCtrl.buttonTask == 2)
|
|||
|
|
{// 2:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (pScan->ldtaskFunc != NULL)
|
|||
|
|
{
|
|||
|
|
rslt = pScan->ldtaskFunc();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else if (g_buttonCtrl.buttonTask == 3)
|
|||
|
|
{// 3:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (pScan->ctaskFunc != NULL)
|
|||
|
|
{
|
|||
|
|
rslt = pScan->ctaskFunc();
|
|||
|
|
CleanButtonTask(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ť<EFBFBD><C5A5><EFBFBD><EFBFBD>
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
g_buttonCtrl.buttonTask = -1; // ִ<><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
g_buttonCtrl.execing = 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|