627 views
in Embedded Wizard Studio by

Hello team,

            How to update a variable right away?

            I have a Text,    

 

            and the code:

  	static int lastvalue=19;
        bool ret=false; 
        uint8_t SelectedChannelNum = g_DSPMaster.SelectedChannelNum;
                       
	if(lastvalue != SelectedChannelNum)
	{
        lastvalue = SelectedChannelNum;
        ApplicationDeviceClass__UpdateSelChannel(DeviceObject, (XInt32)lastvalue);
	ret = true; 
        }
 
	return ret;

question:   The lastvalue is the variable. and when the lastvalue change,the text is not change,

                 but if i change the another interface,Back to the interface ,the text will be change,why?

                  I want this text to change in real time.

                   when the (lastvalue == 5),the Text display (INPUT CHANNEL  5) in screen,when the (lastvalue == 6),the Text display (INPUT CHANNEL  6) in screen.

Best regards,

Tonny

                  

1 Answer

0 votes
by

Hi Tonny,

right now there is just one step missing. In your constellation each time when your device class method ‘ApplicationDeviceClass__UpdateSelChannel’ is called, it only calls the function ‘UpdateSelChannel’ without calling your application function ‘SelChannelSlot’. So, the slot function ‘SelChannelSlot’ is never triggered and your text won’t update too.

 

To connect your device class with any function within your application, it’s highly recommended to use an so called Property Observer. Therefore you should declare a variable ‘SelChannel’ in your device class which can be changed by the update method ‘UpdateSelChannel’. As you can see below, within the function ‘UpdateSelChannel’ the device class variable ‘SelChannel’ will be updated if it’s changes. Additionally with the command ‘notifyobservers ^SelChannel;’ your device class is able to inform property observer(s).

 

As next, you need to setup the already mentioned Property Observer. For this, please drag & drop the brick ‘Property Observer’ from ‘Templates->Device’ into your application class and set it up like in the picture below:

As you can see, the property observers ‘Outlet’ is connected to the device variable ‘SelChannel’ which is defined in the device class and the ‘OnEvent’ function is linked to your already defined slot method ‘SelChannelSlot’. Now, every time when you call the device class function ‘ApplicationDeviceClass__UpdateSelChannel’ within your C development project, it automatically updates the string element as well.

 

By the way, your slot function ‘SelChannelSlot’ is already configured correctly:

 

Hopefully this helps to modify your own project, otherwise you can download here the example project that I’ve used. With this project you can simulate with the keyboard key ‘A’ the behaviour when you use the Embedded Wizard Prototyper.

Best regards,

Tim

Ask Embedded Wizard - Archive

Welcome to the Ask Embedded Wizard archive. This community forum served us well for many years, but we've evolved our support approach!

Your resources:

The Embedded Wizard Online Documentation provides comprehensive documentation, tutorials, examples and ready-to-use software packages.

For dedicated assistance, explore our Embedded Wizard Product Support.

You can still browse the valuable discussions from our community history here.

Embedded Wizard Website | Privacy Policy | Imprint

...