Jump to content

Test routine "PushButton". Need help...


Recommended Posts

Posted

Good day to all!!

I am continuing my study of uGFX very slowly. Next stuff - widgets...

To understand the work, I took an example from \ugfx_2.9\demos\modules\gwin\button. I added the missing, in my opinion, function calls: ginputCalibrateMouse(),  geventAttachSource(); Now the code looks like this:

#include "gfx.h"
#include <stdio.h>
#include <string.h>
#include <stm32f10x.h>

#include "uGFX/gdriver/gdriver.h"
#include "uGFX/ginput/ginput_driver_mouse.h"

static GListener gl;
static GHandle   ghButton1;
 
static void createWidgets(void) {
	GWidgetInit	wi;
 
	// Apply some default values for GWIN
	gwinWidgetClearInit(&wi);
	wi.g.show = TRUE;
 
	// Apply the button parameters	
	wi.g.width = 100;
	wi.g.height = 30;
	wi.g.y = 100;
	wi.g.x = 100;
	wi.text = "Push Button";
 
	// Create the actual button
	ghButton1 = gwinButtonCreate(NULL, &wi);
}


int main(void) {
	GEvent* pe;
        GMouse *			m;
        GSourceHandle			gs;
// =========== Timer setup block ==================
  SystemCoreClockUpdate();
  SysTick_Config(SystemCoreClock /1000);
//=================================================
	// Initialize the display
	gfxInit();
 
        m = (GMouse *)gdriverGetInstance(GDRIVER_TYPE_MOUSE, 0);
  // === Added by me ======
       		 ginputCalibrateMouse(0);
  // ======================
        gs = ginputGetMouse(0);

        // Set the widget defaults
	gwinSetDefaultFont(gdispOpenFont("UI2"));
	gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE);
	gdispClear(White);

	// create the widget
	createWidgets();
	
 
	// We want to listen for widget events
	geventListenerInit(&gl);
   // === Added by me ======
        geventAttachSource(&gl, gs, GLISTEN_MOUSEMETA | GLISTEN_TOUCHMETA);
   // ======================
	gwinAttachListener(&gl);
 
	while(1) {
		// Get an Event
		pe = geventEventWait(&gl, TIME_INFINITE);
 
		switch(pe->type) {
			case GEVENT_GWIN_BUTTON:
				if (((GEventGWinButton*)pe)->gwin == ghButton1) {
					// Our button has been pressed
					printf("Button clicked\r\n");
				}
				break;
 
			default:
				break;
		}
	}
 
	return 0;
}

There is no response to touching the button. What am I doing wrong? ginputCalibrateMouse() is executed, the driver ADS7843 works correctly...

 

Posted

Hi!

Have you tried just running the unmodified example found under /demos/modules/gwin/button ?

With regards to calibration: You would typically only ever do that once (or if you build a full application, have some "settings" menu where the user can re-launch the calibration sequence). Once calibration was performed, you'd typically store the calibration data and load it on power-on.
Have you had a look at the corresponding documentation? https://wiki.ugfx.io/index.php/Touchscreen_Calibration

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...