Jump to content

TextEdit & GWIN Keyboard


tupak

Recommended Posts

Hi!

I have a GUI with a TextEdit and Virtual Keyboard, and I want, for example, change of screen when I press the "Intro" key. 

Something, like this:

 

  while (TRUE) {
     // Get an event
	pe = geventEventWait(&gl, TIME_INFINITE);
    switch(pe->type) {
		case GEVENT_GWIN_BUTTON:
			...
		break;
		case GEVENT_GWIN_KEYBOARD:
			if(key == ""KEY_INTRO") {
				guiShowPage(NEXT_PAGE);
			}
		break;
	}
}

How I can get and compare the key event?

Thanks!!

Link to comment
Share on other sites

You can get that information from the keyboard event structure. You are supposed to cast the generic GEvent struct to a GKeyboardObject to access the event arguments. You can find the struct definition at line 31 of the file /src/ginput/ginput_keyboard.h.

I'd recommend you to have a look at the demo /demos/modules/gwin/keyboard which shows how to do all that.

Please don't hesitate to ask if you have any further questions.

Link to comment
Share on other sites

  • 1 year later...

You never get back a string, you always just get a single character because each time a character is pressed on the keyboard an event gets generated. Therefore, just listen to the event as shown in the demos mentioned in my previous post and create an array from them yourself. It's really just a matter of having an array and a write pointer or an index variable.
If you need something more flexible than arrays you might want to consider using GQUEUES.

Link to comment
Share on other sites

@Joel Bodenmann

Does the code below made sense ? I cast the pe (which is geventWait return ) to a GEventKeyboard but seems I cannot access the byte.. Am I doing anything wrong ?

pe = geventEventWait(&glistener,TIME_INFINITE );
        switch (pe->type) {
            {
            case GEVENT_GWIN_BUTTON:
                if (((GEventGWinButton*)pe)->gwin == touch_button_df_pg) {

                        gwinDestroy(ghContainerPage0);
                        guiCreate();
                    //gwinPrintf(ghTextedit1, "fgdfg");
//                    createPagePage1();
//                    guiShowPage(1);
                
                    //(((GEventGWinButton*)pe)->gwin == ghButton1)    
                            
                    break;
                }
                
                else if (((GEventGWinButton*)pe)->gwin == ghButton1)  // main page
                    
                {
                        gwinHide(ghContainerPage1);
                        gwinDestroy(ghContainerPage1);
                        
                    createPagePage0();
                    guiShowPage(0);
                    break;
                }
                
            }
            break;
            case GEVENT_GWIN_KEYBOARD || GEVENT_KEYBOARD:
            {        
            if (((GEventKeyboard*)pe)->bytecount >0)
                    {
                        pk = (GEventKeyboard *)pe;
                        for (int x =0; x < 4; x++)
                            {
                                dynamic_array[x] = (uint8_t)pk->c[x];
                                dynamic_array[1]++;
                                //gwinPrintf(ghTextedit1, "ERROR");
                            }

Link to comment
Share on other sites

The documentations is quite poor, but I know you are very busy with uGFX dev.. which most likely need to dig down the code to understand what's happening. I am very confused between gwin_keyboard and keyboard.. How do we read a char from gwin_keyboard ? I am only receiving the trigger for GEVENT_GWIN_KEYBOARD in switch statement only when I press return button no reaction when I press characters like a b c d and so on. What I have tried to change the parameter of  source attachers   geventAttachSource(&glistener, gwinKeyboardGetEventSource(ghKeyboard1),GLISTEN_KEYTRANSITIONS|GLISTEN_KEYUP);  GKEYBOARD_ALL_INSTANCES) none of this seems to help me.. I really hope there is a documentations says how to attach the source from gwin_keyboard(virtual) to listener and how to retrieve each character from the virtual keyboard. Can you help me clear this doubt out. I promise I will write a brief explanation a-z for new uGFX comers to use the library with ease.

 

@Joel Bodenmann @inmarket

Edited by manoj
Link to comment
Share on other sites

Thank you for your feedback regarding the documentation. But did you have a look at the /modules/gwin/keyboard? It shows clearly how to  use the virtual keyboard. It doesn't get much more detailed than that. It even shows how to grab virtual keyboard visibility changes.

Please stop highlighting me or inmarket in your posts just in hopes that we reply sooner. We reply when we have time for it.

Link to comment
Share on other sites

Sorry, I hope someone will help. 

I do look at demo/modules/gwin/keyboard.

Below is my code I tried but no luck, moreover I try setting breakpoint at few lines related to keyboard it's did not stop anywhere. Which means my key presses are not listened at all. How do I go about is it uGFX config or bugs or etc. Anyone who have done reading char from keyboard event mind to help ? and is my english bad that most of you guys don't understand what I am talking about ?

 

Cheers !

 

if (((GEventKeyboard*)pe)->bytecount >0)
                    {
                        pk = (GEventKeyboard *)pe;
                        for (int x =0; x < 4; x++)
                            {
                                dynamic_array[x] = (uint8_t)pk->c[x];
                                dynamic_array[1]++;
                                //gwinPrintf(ghTextedit1, "ERROR");
                            }

Edited by manoj
Link to comment
Share on other sites

Hi, got it working using the demo file but I noticed the keyboard is only displayed on screen if I define below statement, heap size

#define GFX_OS_HEAP_SIZE                         2000

, mind to tell why ?. BTW how to estimate hw much stack and heap size is required for my uGFX GUI implementation ?

.  

Link to comment
Share on other sites

uGFX uses a 3 step strategy to implement the heap (gfxAlloc and gfxFree)...

1. If the operating system provides heap functions then those used to manage the heap in whatever way the operating system normally does. If the operating system has no heap functions eg RAW32 then step 2 or 3 is implemented by uGFX.

2. If GFX_OS_HEAP_SIZE is not set or if it is 0 then uGFX uses your c library malloc() and free().

3. If GFX_OS_HEAP_SIZE is non-zero then uGFX provides it own heap implementation using GFX_OS_HEAP_SIZE bytes of RAM.

Based on your symptoms it looks like on your platform that option 1 is not possible (you never told us what platform you were using in the posts above). It also looks like your compiler c library malloc/free routines are buggy and hence option 2 did not work. That is why when you specified GFX_OS_HEAP_SIZE (option 3) it suddenly started working.

Now that you have a working keyboard demo you should be able to use that as a starting point for your own program. Change a little bit at a time and test after each change until you have it doing what you want.

How much heap, stack, rom or ram you need is very dependant on the program you write. There is no fixed size that is going to work in all situations. Generally start as large as you can on your platform for heap and stack and reduce them as you need to to make space for other things.

It is usually a very good idea to build it first to run on windows/linux/osx. A well written uGFX program will be completley portable to your embedded platform with minimal or no code changes. This enables you to test that you have written your code properly without any memory/stack issues and gives you the full suite of desktop debugging tools making it much easier to find bugs in your code.

Link to comment
Share on other sites

As @inmarket mentioned the implementations of things like malloc()setjmp() and so on are often buggy on standard libraries provided with the toolchains for embedded targets. That's why we provide our own generic implementations that work anywhere. The configuration allows to choose any of the options which means that the user of the µGFX library can always pick what's best for his case.

Link to comment
Share on other sites

hi also found out why my own implementation of keyboard don't work but gwin example worked as mentioned last time is because few defination in  ugfx config


//#define GEVENT_ASSERT_NO_RESOURCE                    FALSE
//#define GEVENT_MAXIMUM_SIZE                          32 //dEFAULT VALUE: 32
//#define GEVENT_MAX_SOURCE_LISTENERS                  3 //dEFAULT VALUE: 32

commenting out the three stuff got my gevent listening to my keyboard, do you mind to tell why it happens

Link to comment
Share on other sites

I see, thanks to pointing it out. Is there anyway to monitor my stack and heap real time ?..... I am using the stm32f7 dis board package, so the uGFX only uses the internal ram during code execution and the external ram only for frame buffer ? am I right ?

Link to comment
Share on other sites

Often the underlying system (that provides the memory management) provides utilities required to track heap usage. However, there's no real magic to that. For embedded systems it's usually just a matter of filling the entire heap area with a known pattern (eg. 0x55555555) at initialization and then using the debugger to dump the memory area to examine how much was left unused. The Raw32 heap manager doesn't offer this. It's also not that critical because RAM usage of µGFX is deterministic once you know what you're doing / what your requirements are. Towards the rest of your application that's completely uncritical as well because µGFX reserves a block of memory the size of GFX_OS_HEAP_SIZE which is known prior to compilation.

It's correct that the "default behavior" of µGFX with the STM32F746G-Discovery board files only uses the external SDRAM for the framebuffer(s).

Link to comment
Share on other sites

Hi, thanks for your reply. I will try to fill the heap with known patter and see. and when I set the gfx_os_heap_size does it mean it's dynamically allocated only for ugfx usage and could not conflict with other code section that uses malloc ?. 

Link to comment
Share on other sites

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...