我有个旋转编码器,可以通过这个旋钮左右旋转,进行画面上控件里面变量的加减操作,但是不能实现OK键的功能,也就是GUI_KEY_ENTER 这个键的功能 。外部的OK键按下以后,进入中断,执行了GUI_StoreKeyMsg(GUI_KEY_ENTER, 1); 但是怎么样才能进入到回调函数里面的 case GUI_KEY_ENTER: ,求指点
代码如下:
/********************************************
* QEI 中断处理函数
********************************************/
void QEI_IRQHandler(void)
{
uint32_t regVal;
int Position;
int DIR;
regVal = LPC_QEI->QEIINTSTAT; /*读取中断寄存器的值*/
DIR=LPC_QEI->QEISTAT; /*读取方向位的值*/
if (regVal & 0x1==1) /*如果是索引中断*/
{
GUI_StoreKeyMsg(GUI_KEY_ENTER, 1); /*OK*/
}
if ((DIR&0x1)==1) /*反向旋转*/
{
if ( (regVal>>6) & 0x1==1)
{
GUI_StoreKeyMsg(GUI_KEY_DOWN, 1);
}
}
if((DIR&0x1)==0) /*正向旋转*/
{
if ( (regVal>>6) & 0x1==1) /*如果是当前位置=位置0的中断*/
{
GUI_StoreKeyMsg(GUI_KEY_UP, 1);
}
}
QEI_IRQCLR(); /*清中断*/
}
回调函数:
static void _cbDialog_B(WM_MESSAGE * pMsg) {
int NCode,i,Id, IdEdit;
WM_HWIN hDlg,ahButton[5],hItem,hEdit,hButton;
hDlg = pMsg->hWin;
/* Get focussed edit widget */
hEdit = WM_GetFocussedWindow();
IdEdit = WM_GetId(hEdit);
if ((IdEdit < GUI_ID_EDIT0) || (IdEdit > GUI_ID_EDIT14))
hEdit = 0;
switch (pMsg->MsgId) {
case WM_PAINT:
/* Owner drawn background of dialog */
GUI_SetBkColor(GUI_LIGHTGREEN);
GUI_Clear();
GUI_SetColor(GUI_RED);
GUI_SetFont(&GUI_Font10_ASCII);
GUI_DispStringAt("K11",20,25);
GUI_DispStringAt("K12",90,25);
GUI_DispStringAt("K13",160,25);
GUI_DispStringAt("K14",20,55);
GUI_DispStringAt("K15",90,55);
GUI_DispStringAt("K16",160,55);
GUI_DispStringAt("K17",20,85);
GUI_DispStringAt("K18",90,85);
GUI_DispStringAt("K19",160,85);
GUI_DispStringAt("B",25,125);
GUI_DispStringAt("C",95,125);
GUI_DispStringAt("D",165,125);
GUI_DispStringAt("R1",25,155);
GUI_DispStringAt("R2",95,155);
GUI_DispStringAt("R3",165,155);
break;
case WM_INIT_DIALOG:
/* Create the buttons */
ahButton[0] = BUTTON_CreateEx(250, 120, 50, 20, //Send
hDlg, WM_CF_SHOW , 0, GUI_ID_SENDMESSAGE);
BUTTON_SetFont(ahButton[0], &GUI_FontHZ12);
BUTTON_SetText(ahButton[0],"Send");
BUTTON_SetFocussable(ahButton[0], 0);
ahButton[1] = BUTTON_CreateEx(240, 170, 30, 20, //OK
hDlg, WM_CF_SHOW , 0, GUI_KEY_ENTER);
BUTTON_SetFont(ahButton[1], &GUI_FontHZ12);
BUTTON_SetText(ahButton[1],"OK");
BUTTON_SetFocussable(ahButton[1], 0);
ahButton[2] = BUTTON_CreateEx(270, 170, 30, 20, //Del
hDlg, WM_CF_SHOW , 0, GUI_KEY_DELETE);
BUTTON_SetFont(ahButton[2], &GUI_FontHZ12);
BUTTON_SetText(ahButton[2],"Del");
BUTTON_SetFocussable(ahButton[2], 0);
ahButton[3] = BUTTON_CreateEx(230, 150, 40, 20, //UP
hDlg, WM_CF_SHOW , 0, GUI_KEY_TAB);
BUTTON_SetFont(ahButton[3], &GUI_FontHZ12);
BUTTON_SetText(ahButton[3],"Up");
BUTTON_SetFocussable(ahButton[3], 0);
ahButton[4] = BUTTON_CreateEx(270, 150, 40, 20, //DOWN
hDlg, WM_CF_SHOW , 0, GUI_KEY_BACKTAB);
BUTTON_SetFont(ahButton[4], &GUI_FontHZ12);
BUTTON_SetText(ahButton[4],"Down");
BUTTON_SetFocussable(ahButton[4], 0);
/* Set buttons to not focussable state 清除按钮焦点*/
for (i = '0'; i <= '9'; i++)
{
hButton = WM_GetDialogItem(hDlg, i);
BUTTON_SetFocussable(hButton, 0);
}
hButton = WM_GetDialogItem(hDlg, GUI_KEY_DELETE);
BUTTON_SetFocussable(hButton, 0);
hButton = WM_GetDialogItem(hDlg, GUI_KEY_ENTER);
BUTTON_SetFocussable(hButton, 0);
hButton = WM_GetDialogItem(hDlg, GUI_KEY_TAB);
BUTTON_SetFocussable(hButton, 0);
hButton = WM_GetDialogItem(hDlg, GUI_KEY_BACKTAB);
BUTTON_SetFocussable(hButton, 0);
/* Init edit widgets */
for (i=0; i<10; i++)
{
hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT0+i);
EDIT_SetDecMode(hItem, B_Value, 0, 9999, 1, 0); /*启用十进制编辑模式设置小数点后1位*/
/*如此EDIT_GetValue(hItem);此函数才有效*/
}
hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT10);
EDIT_SetDecMode(hItem, B_Value[10], 0, 9999, 2, 0);
hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT11);
EDIT_SetDecMode(hItem, B_Value[11], 0, 9999, 2, 0);
hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT12);
EDIT_SetDecMode(hItem, B_Value[12], 0, 9999, 2, 0);
hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT13);
EDIT_SetDecMode(hItem, B_Value[13], 0, 9999, 2, 0);
hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT14);
EDIT_SetDecMode(hItem, B_Value[14], 0, 9999, 2, 0);
hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT15);
EDIT_SetDecMode(hItem, B_Value[15], 0, 9999, 2, 0);
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v; /* Notification code */
switch (NCode) {
case WM_NOTIFICATION_VALUE_CHANGED: /* Value has changed */
Id = WM_GetId(pMsg->hWinSrc); /* Id of widget */
break;
case WM_NOTIFICATION_RELEASED: /* React only if released */
switch (Id)
{
case GUI_KEY_ENTER: // Save "Edit" boxes values to "Current" values.
for (i=0; i<10; i++)
{
hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT0 + i);
B_Value = EDIT_GetValue(hItem);
}
hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT10);
B_Value[10] = EDIT_GetValue(hItem);
hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT11);
B_Value[11] = EDIT_GetValue(hItem);
hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT12);
B_Value[12] = EDIT_GetValue(hItem);
hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT13);
B_Value[13] = EDIT_GetValue(hItem);
hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT14);
B_Value[14] = EDIT_GetValue(hItem);
// Invalidate window to make sure value will be shown
WM_InvalidateWindow(hDlg);
break;
case GUI_KEY_DELETE: //delete
hEdit = WM_GetFocussedWindow();
EDIT_SetText(hEdit, "");
break;
case GUI_KEY_TAB:
break;
case GUI_KEY_BACKTAB:
break;
case '0':
if (IdEdit)
EDIT_AddKey(hEdit, '0');
break;
case '1':
if (IdEdit)
EDIT_AddKey(hEdit, '1');
break;
case '2':
if (IdEdit)
EDIT_AddKey(hEdit, '2');
break;
case '3':
if (IdEdit)
EDIT_AddKey(hEdit, '3');
break;
case '4':
if (IdEdit)
EDIT_AddKey(hEdit, '4');
break;
case '5':
if (IdEdit)
EDIT_AddKey(hEdit, '5');
break;
case '6':
if (IdEdit)
EDIT_AddKey(hEdit, '6');
break;
case '7':
if (IdEdit)
EDIT_AddKey(hEdit, '7');
break;
case '8':
if (IdEdit)
EDIT_AddKey(hEdit, '8');
break;
case '9':
if (IdEdit)
EDIT_AddKey(hEdit, '9');
break;
case '.':
if (IdEdit)
EDIT_AddKey(hEdit, '.');
break;
//default:
// break;
}
if (hEdit)
WM_SetFocus(hEdit);
}
break;
default:
WM_DefaultProc(pMsg);
}
}
|