803 views
in GUI Development by

Hi,

My application implements, among many other GUI components, a global data storage class with numerous properties. I intend to access this class by means of an 'autoobject' from numerous other GUI components.
Reading and writing from/to the data objects works fine. In addition, I need to react to changes of the properties, and this is what I haven't found a solution for so far.

My idea was to attach an observer to the property, but this does not work out.
The code in init() is as follows:

attachobserver SlotMethod, ^UI::Data.Property;

In the OnSet method of the property, the observer is notified as follows:

if ( pure Property == value )
  return;
pure Property = value;                                     
notifyobservers ^Property;

In the prototyper, this gives unstable results (sometimes working, sometimes not), and on the target (STM32F769-Discovery board) it does not work at all.

I have read the following article and downloaded the example:
https://doc.embedded-wizard.de/implementing-component-interface?v=8.30#5

The downloaded example obviously works, but I am not sure how to apply the concept given to notify a GUI component upon change of a property?

1 Answer

0 votes
by

Hi,

as you mentioned, your data storage class is accessed as an autoobject.

Please consider the livetime of autoobjects. Everytime, the autoobject is no more in use, the instance will be deleted by the Garbage Collector. Within the Prototyper on PC, the Garabage Collector is running after a couple of seconds - this explains, why you get sometimes the expected behavior and sometimes the notification does not work. 

In order to prevent the Garbage Collector from freeing an autoobject, please add a variable to the root class, set the type to your class UI::Data and the value to the instance (autoobject) of the class. 

I hope this helps....

Best regards,

Manfred.

by
Thanks Manfred,

This actually solved the issue.
by

This does not work for me.

I have a lot of property data in my DeviceClassLT, also some Core::Time objects. When the properties are set from my device, the values of the properties are ok in all update functions.

When I access the same data in an observer or I want to use the data in an UpdateViews method, the data is different and data modifications by the update functions are not visisble.

Creating an instance of the object in the init function of the application object to prevent the garbage collector from deleting it did not solve the problem:

DevClassLT = new Supervisor::DeviceClassLT;

However, it seems that data of simple data types do work (e.g. int), whereas data of type Core::Time does not work.

by

Maybe you are accessing two different instances of your device class.

Just create one autoobject of the device class and put a variable into your application class that refers to this autoobject. 

Within your device driver (C-Code) you can get access to the autoobject in order to call the update methods, for example:

DeviceObject = EwGetAutoObject( &ApplicationDevice, ApplicationDeviceClass );

If you create an additional instance of the device class within Init(), you will not see the same data within your GUI application as you set from the device driver.

I hope this helps.

Best regards,

Manfred

 

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

...