How to modify a text view string from device driver

199 views
asked Nov 19, 2019 in GUI Development by ezed413
I am using the ESP32 Wrover board. I have two GPIO buttons set as inputs for push button switches. I have written the device driver and set up my pin inputs. I simply want to change the text to the button that is pressed. I see how I can call an Onset method for a string property, but I don't know how to relay that string to the text view. Very confusing.

2 Answers

0 votes
answered Nov 20, 2019 by Paul Banach

Hello,

if you are using the Push Button widget, you change the text of the button (the label) by modifying its property Label. For example, if you want the text tio toggle each time the user activates the button, implement following code in the slot method connected the Push Button's OnActivate property:

if ( PushButton.Label == "ON" )
  PushButton.Label = "OFF";
else
  PushButton.Label = "ON";

If you have created youz own Push Button (e.g. based on the provided templates), you have surely added a Text View to the push button to display the label. You should also add a property (named e.g. Label or Caption) to the Push Button and in the OnSet method of the property implement code to relay the text:

// The value doesn't change - nothing to do.
if ( pure Label == value )
  return;

// Remember the property's new value.
pure Label = value;

// Now you can store the text in the text view
Text.String = value;

If both aspects above do not address your application case, please explain it more in detail.

Best regards

Paul Banach

commented Nov 20, 2019 by ezed413
Paul,

I think I was not clear. I am using physical push button swithes connected to GPIO pins of the ESP32-Wrover-kit board. I think I might have figured out how to do it. But now I am trying to get the arduino-esp32 module working with the ESP-IDF. I am including the arduino.h file in the device driver file.

 

On another note, I am using the free version of EW. I notice that I can not use any of the component templates. I am guessing it's because of it being the free version. We want to evaluate the product before buying it. I know that my CTO likes the product.
commented Nov 21, 2019 by Paul Banach

Hello,

Ok, it is more clear now. You want the GUI to react to an event generated by GPIO. For this purpose let me refer to the articles Integrating with the device and Device Class and Device Driver, both are part of our online documentation. They explain all basics about natvie code and the integration of external software APIs or hardware drivers.

In case of hardware buttons, however, I would follow another approach. Embedded Wizard implements an infrastructure and interfaces to allow the GUI application to be controlled by keyboard or event hardware buttons. From the GUI point of view you handle such events by the so-called Key Press Handler. From the integration point of view, you can feed the keyboard (or hardware button) events to the GUI application as explained in the chapter Main-Loop. Please note there the usage of the function CoreRoot__DriveKeyboardHitting().

Regarding the component templates, there is no limitation for the Free edition. The unique limitation of Free affects the max. size of the project.

Does it help you further?

Best regards

Paul Banach

commented Nov 21, 2019 by ezed413
Thanks Paul! I'll have a look.
0 votes
answered Nov 21, 2019 by Manfred Schweyer

Hello,

within many Build Environments (e.g. STM32 or NXP LPC / iMXRT) there is an example "DeviceIntegration" which demonstrates how to change the GUI content when a hardware button (via GPIOs) is pressed. The example is located within the folder /Examples/DeviceIntegration. Unfortunately, this example is not provided for the ESP-WROVER-KIT. 

Maybe you have the chance to see how it works on one of the STM or NXP boards.

Anyhow, as already mentioned, please have a look to the articles Integrating with the device and Device Class and Device Driver, both are part of our online documentation.

Best regards,

Manfred.

commented Nov 21, 2019 by ezed413
Thanks Manfred, I'll take a look at it. I think I might have figured it out. I have a property in the device class that I can update from the device driver. I then have a property observer in application class that has a connection to the property in the device class that will trigger the onEvent slot method when the property update is executed. Only problem I am having now is the esp-idf gpio_get_level and gpio_set_level functions don't seem to be working. Everything compiles fine but I can not read a pin level nor set a pin output. I have the pin setup and initialization in the devicedriver initialization function. I then have the reading of the pins in the devicedriver processdata function. Is this correct? It might be that I have to run the esp-idf code in the appmain function which in the main.c file. But then why would I need the devicedriver.c file? I will look at the deviceintegration example.
commented Nov 22, 2019 by Manfred Schweyer
Hi,

yes, your description seems to be correct.

So far I did not test any GPIOs on ESP32 - so I cannot give you helpful advices. The DeviceIntegration example for ESP32 is still on the 'ToDo' list...

You can try to toggle a GPIO directly in the mainloop in ewmain.c. If this works, then it will be also possible within your device driver. Otherwise, maybe some ESP32 forums can help concerning the GPIOs...

Best regards,

Manfred
commented Nov 22, 2019 by ezed413
Update, I have the GUI reacting to one of the push button switches. But there is an odd thing happening. The display is off until I press the button. It then comes on as long as the button is pushed, and the text view changes to "Button 2 pressed". I am do this by reading the switch input level and then updating a property in the device class. I'm going to try different pins for inputs and see what happens. Maybe I will try the keyboard handler approach if this method doesn't work. Or maybe I will use an interrupt. Do you think I shouldn't use the RTOS.

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...