Hello.
I have a simple GUI Window with a button on it.
my problem is that when I remove (release) my finger (pressure) from the (any) widget on analog touch screen, the WM_NOTIFICATION_RELEASED is not fired in Dialog callback routine(_cbDialog) and Cursor is also jumped to other position which is different from last coordinate of my finger.(the values of x and y coordinates are right in pressed state).
--------------------------------------------------------------------------------------------------------------------------------------
Used Components : LPC1788 as Micro and XPT2046 IC to read analog touch screen by SPI.
Used Software : KEIL
Method description:
1-I call GUI_TOUCH_Exec from OS timer regularly.(there is no problem here).
2-I have defined a Variable named IsPressed which is used to store the active low PENIRQ pin on XPT2046 .
static uint32_t IsPressed;
void CheckTouch()
{
IsPressed=GPIO_PinRead(TOUCH_INTERRUPT_PIN.Portnum,TOUCH_INTERRUPT_PIN.Pinnum);//IsPressed=0 so we have a //press, IsPressed=1 so the Touch panel is released.
}
3-I have defined GUI_TOUCH_X_ActivateX , GUI_TOUCH_X_ActivateY , GUI_TOUCH_X_MeasureX , GUI_TOUCH_X_MeasureY as follows:(I use KEIL SPI middleware to read/write from/to XPT2046 IC)
void GUI_TOUCH_X_ActivateX(void) {
CheckTouch();//I use this Function to check whether PENIRQ pin on XPT2046 is LOW(Tuch Panel is Pressed)
if (IsPressed==0)//Touch Panel Is Pressed, so I send Command to XPT2046 to initiate ADC conversion
{
ARM_DRIVER_SPI* SPI_Drv=&Driver_SPI0;
SPI_Drv->Control(ARM_SPI_CONTROL_SS,ARM_SPI_SS_ACTIVE);
SPI_Drv->Send(&X_Active_Y_Out,sizeof(X_Active_Y_Out));
}
}
void GUI_TOUCH_X_ActivateY(void) {
if (IsPressed==0)//Touch Panel Is Pressed, so I send Command to XPT2046 to initiate ADC conversion
{
ARM_DRIVER_SPI* SPI_Drv=&Driver_SPI0;
SPI_Drv->Control(ARM_SPI_CONTROL_SS,ARM_SPI_SS_ACTIVE);
SPI_Drv->Send(&Y_Active_X_Out,sizeof(Y_Active_X_Out));
}
}
int GUI_TOUCH_X_MeasureX(void) {
uint16_t result=-1;
if (IsPressed==0)//Touch Panel Is Pressed, so I send Command to XPT2046 to get back X
{
ARM_DRIVER_SPI* SPI_Drv=&Driver_SPI0;
DelayUS(2);
SPI_Drv->Control(ARM_SPI_CONTROL_SS,ARM_SPI_SS_ACTIVE);
SPI_Drv->Receive(X_Out,sizeof(X_Out));
result=(X_Out[0]<<8) | X_Out[1];
result>>=3;
result&=0x0FFF;
SPI_Drv->Control(ARM_SPI_CONTROL_SS,ARM_SPI_SS_INACTIVE);
return result;
}
return -1;//return -1 if there is no press to indicate an unpressed state.(I think so...)}
int GUI_TOUCH_X_MeasureY(void) {
uint16_t result=-1;
if (IsPressed==0)//Touch Panel Is Pressed, so I send Command to XPT2046 to get back X
{
ARM_DRIVER_SPI* SPI_Drv=&Driver_SPI0;
SPI_Drv->Control(ARM_SPI_CONTROL_SS,ARM_SPI_SS_ACTIVE);
SPI_Drv->Receive(Y_Out,sizeof(Y_Out));
result=(Y_Out[0]<<8) | Y_Out[1];
result>>=3;
result&=0x0FFF;
SPI_Drv->Control(ARM_SPI_CONTROL_SS,ARM_SPI_SS_INACTIVE);
return result;
}
return -1;//return -1 if there is no press to indicate an unpressed state.(I think so...)
}
4-Above function all work properly and GUI_TOUCH_GetState() function return true X and Y position, but as I said before the WM_NOTIFICATION_RELEASED message is not fired in Dialog callback routine(_cbDialog) when I remove my finger from any widgets on touch screen.
5-my dialog source:
#include "DIALOG.h"
#define ID_WINDOW_0 (GUI_ID_USER + 0x00)
#define ID_BUTTON_0 (GUI_ID_USER + 0x01)
/*********************************************************************
*
* _aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 800, 480, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Button", ID_BUTTON_0, 15, 14, 407, 138, 0, 0x0, 0 },
// USER START (Optionally insert additional widgets)
// USER END
};
// USER START (Optionally insert additional static code)
//a Test Callback method for BUTTON to see whether created butten react to WM_NOTIFICATION_RELEASED (the result is NO)
static void _cbButton(WM_MESSAGE * pMsg) {
int NCode;
int Id;
WM_HWIN hParentWin;
GUI_PID_STATE *pid_State;
// USER START (Optionally insert additional variables)
// USER END
switch (pMsg->MsgId) {
case WM_TOUCH:
pid_State=(GUI_PID_STATE*)pMsg->Data.p;
if (pid_State->Pressed==1)
{
BUTTON_SetText(pMsg->hWin,"Pressed");//Yes this message works.
}
else
{
BUTTON_SetText(pMsg->hWin,"Not Pressed");//I can get here
}
break;
case WM_NOTIFICATION_RELEASED:
BUTTON_SetText(pMsg->hWin,"Realese From Button");//but I can not get WM_NOTIFICATION_RELEASED
break;
default:
BUTTON_Callback(pMsg);
break;
}
}
// USER END
/*********************************************************************
*
* _cbDialog
*/
static void _cbDialog(WM_MESSAGE * pMsg) {
int NCode;
int Id;
WM_HWIN hItem;
// USER START (Optionally insert additional variables)
// USER END
switch (pMsg->MsgId) {
case WM_INIT_DIALOG:
hItem=WM_GetDialogItem(pMsg->hWin,ID_BUTTON_0);
WM_SetCallback(hItem,_cbButton);
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch(Id) {
case ID_BUTTON_0: // Notifications sent by 'Button'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
BUTTON_SetText(pMsg->hWinSrc,"Rel");// The Code never reach here
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
// USER START (Optionally insert additional code for further Ids)
// USER END
}
break;
// USER START (Optionally insert additional message handling)
// USER END
default:
WM_DefaultProc(pMsg);
break;
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* CreateWindow
*/
WM_HWIN CreateWindow(void);
WM_HWIN CreateWindow(void) {
WM_HWIN hWin;
hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
return hWin;
}
/*************************** End of file ****************************/
Somewhere in the forum I read that one should enable "release event for EMwin" , but I don't know what is that and What should I do to enable WM_NOTIFICATION_RELEASED for my widgets?
Thank you.
I have a simple GUI Window with a button on it.
my problem is that when I remove (release) my finger (pressure) from the (any) widget on analog touch screen, the WM_NOTIFICATION_RELEASED is not fired in Dialog callback routine(_cbDialog) and Cursor is also jumped to other position which is different from last coordinate of my finger.(the values of x and y coordinates are right in pressed state).
--------------------------------------------------------------------------------------------------------------------------------------
Used Components : LPC1788 as Micro and XPT2046 IC to read analog touch screen by SPI.
Used Software : KEIL
Method description:
1-I call GUI_TOUCH_Exec from OS timer regularly.(there is no problem here).
2-I have defined a Variable named IsPressed which is used to store the active low PENIRQ pin on XPT2046 .
static uint32_t IsPressed;
void CheckTouch()
{
IsPressed=GPIO_PinRead(TOUCH_INTERRUPT_PIN.Portnum,TOUCH_INTERRUPT_PIN.Pinnum);//IsPressed=0 so we have a //press, IsPressed=1 so the Touch panel is released.
}
3-I have defined GUI_TOUCH_X_ActivateX , GUI_TOUCH_X_ActivateY , GUI_TOUCH_X_MeasureX , GUI_TOUCH_X_MeasureY as follows:(I use KEIL SPI middleware to read/write from/to XPT2046 IC)
void GUI_TOUCH_X_ActivateX(void) {
CheckTouch();//I use this Function to check whether PENIRQ pin on XPT2046 is LOW(Tuch Panel is Pressed)
if (IsPressed==0)//Touch Panel Is Pressed, so I send Command to XPT2046 to initiate ADC conversion
{
ARM_DRIVER_SPI* SPI_Drv=&Driver_SPI0;
SPI_Drv->Control(ARM_SPI_CONTROL_SS,ARM_SPI_SS_ACTIVE);
SPI_Drv->Send(&X_Active_Y_Out,sizeof(X_Active_Y_Out));
}
}
void GUI_TOUCH_X_ActivateY(void) {
if (IsPressed==0)//Touch Panel Is Pressed, so I send Command to XPT2046 to initiate ADC conversion
{
ARM_DRIVER_SPI* SPI_Drv=&Driver_SPI0;
SPI_Drv->Control(ARM_SPI_CONTROL_SS,ARM_SPI_SS_ACTIVE);
SPI_Drv->Send(&Y_Active_X_Out,sizeof(Y_Active_X_Out));
}
}
int GUI_TOUCH_X_MeasureX(void) {
uint16_t result=-1;
if (IsPressed==0)//Touch Panel Is Pressed, so I send Command to XPT2046 to get back X
{
ARM_DRIVER_SPI* SPI_Drv=&Driver_SPI0;
DelayUS(2);
SPI_Drv->Control(ARM_SPI_CONTROL_SS,ARM_SPI_SS_ACTIVE);
SPI_Drv->Receive(X_Out,sizeof(X_Out));
result=(X_Out[0]<<8) | X_Out[1];
result>>=3;
result&=0x0FFF;
SPI_Drv->Control(ARM_SPI_CONTROL_SS,ARM_SPI_SS_INACTIVE);
return result;
}
return -1;//return -1 if there is no press to indicate an unpressed state.(I think so...)}
int GUI_TOUCH_X_MeasureY(void) {
uint16_t result=-1;
if (IsPressed==0)//Touch Panel Is Pressed, so I send Command to XPT2046 to get back X
{
ARM_DRIVER_SPI* SPI_Drv=&Driver_SPI0;
SPI_Drv->Control(ARM_SPI_CONTROL_SS,ARM_SPI_SS_ACTIVE);
SPI_Drv->Receive(Y_Out,sizeof(Y_Out));
result=(Y_Out[0]<<8) | Y_Out[1];
result>>=3;
result&=0x0FFF;
SPI_Drv->Control(ARM_SPI_CONTROL_SS,ARM_SPI_SS_INACTIVE);
return result;
}
return -1;//return -1 if there is no press to indicate an unpressed state.(I think so...)
}
4-Above function all work properly and GUI_TOUCH_GetState() function return true X and Y position, but as I said before the WM_NOTIFICATION_RELEASED message is not fired in Dialog callback routine(_cbDialog) when I remove my finger from any widgets on touch screen.
5-my dialog source:
#include "DIALOG.h"
#define ID_WINDOW_0 (GUI_ID_USER + 0x00)
#define ID_BUTTON_0 (GUI_ID_USER + 0x01)
/*********************************************************************
*
* _aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 800, 480, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Button", ID_BUTTON_0, 15, 14, 407, 138, 0, 0x0, 0 },
// USER START (Optionally insert additional widgets)
// USER END
};
// USER START (Optionally insert additional static code)
//a Test Callback method for BUTTON to see whether created butten react to WM_NOTIFICATION_RELEASED (the result is NO)
static void _cbButton(WM_MESSAGE * pMsg) {
int NCode;
int Id;
WM_HWIN hParentWin;
GUI_PID_STATE *pid_State;
// USER START (Optionally insert additional variables)
// USER END
switch (pMsg->MsgId) {
case WM_TOUCH:
pid_State=(GUI_PID_STATE*)pMsg->Data.p;
if (pid_State->Pressed==1)
{
BUTTON_SetText(pMsg->hWin,"Pressed");//Yes this message works.
}
else
{
BUTTON_SetText(pMsg->hWin,"Not Pressed");//I can get here
}
break;
case WM_NOTIFICATION_RELEASED:
BUTTON_SetText(pMsg->hWin,"Realese From Button");//but I can not get WM_NOTIFICATION_RELEASED
break;
default:
BUTTON_Callback(pMsg);
break;
}
}
// USER END
/*********************************************************************
*
* _cbDialog
*/
static void _cbDialog(WM_MESSAGE * pMsg) {
int NCode;
int Id;
WM_HWIN hItem;
// USER START (Optionally insert additional variables)
// USER END
switch (pMsg->MsgId) {
case WM_INIT_DIALOG:
hItem=WM_GetDialogItem(pMsg->hWin,ID_BUTTON_0);
WM_SetCallback(hItem,_cbButton);
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch(Id) {
case ID_BUTTON_0: // Notifications sent by 'Button'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
BUTTON_SetText(pMsg->hWinSrc,"Rel");// The Code never reach here
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
// USER START (Optionally insert additional code for further Ids)
// USER END
}
break;
// USER START (Optionally insert additional message handling)
// USER END
default:
WM_DefaultProc(pMsg);
break;
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* CreateWindow
*/
WM_HWIN CreateWindow(void);
WM_HWIN CreateWindow(void) {
WM_HWIN hWin;
hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
return hWin;
}
/*************************** End of file ****************************/
Somewhere in the forum I read that one should enable "release event for EMwin" , but I don't know what is that and What should I do to enable WM_NOTIFICATION_RELEASED for my widgets?
Thank you.