884 views
in Embedded Wizard Studio by
How to set current value for Gauge in Truestudio?

 

I build to embedded wizard project to truestudio project.

WidgetSetGauge_OnSetCurrentValue( WidgetSetGauge _this, XInt32 value );

This fuction is changing to gauge value.(real time)

 

But how to use this?

What input the WidgetSetGauge ?

2 Answers

0 votes
by

Hello,

your intention is to directly access and modify the state of the Gauge widget. To do this you would need to know the instance of the respective Gauge widget (the _this parameter in the function call). In fact your GUI application can consist of many different Gauges.

Thus the approach of accessing the widgets directly from the outside of the GUI application is not recommended. Instead you should implement in Embedded Wizard an interface to query the affected value. Your GUI component containing the Gauge widget can then access the interface and update the Gauge state. You can even implement the interface to notify the Gauge automatically as soon as the value has been changed.

Please see following documentation:

Device Class and Device Driver

Integrating with the device.

and

Connect the Gauge with a data provider

Hope it helps you further.

Best regards

Paul Banach

by
Thank you for your answer.

1. I should implement in Embedded Wizard an interface to query the affected value.

 ⓐ I created "Property int32"(ADCVALUE) in Embedded Wizard .

 ⓑ I changed to Outlet ->^ADCVALUE in property for Gauge.

 ⓒ ADCVALUE default value 50 -> start Prototyper -> The gauge was change.

 ⓓ After builded -> Make install -> Execute Truestudio (C)

 ⓔ Control(Project Unit) -> Control.c =>  

  WidgetSetGauge_OnSetCurrentValue( &_this->Gauge, 0 );
  _this->ADCVALUE = 50;

    WidgetSetGauge_OnSetOutlet( &_this->Gauge, EwNewRef( _this, ControlControl_OnGetADCVALUE, ControlControl_OnSetADCVALUE ));  

    in void ControlControl__Init( ControlControl _this, XObject aLink, XHandle aArg

/* 'C' function for method : 'Control::Control.OnSetADCVALUE()' */
void ControlControl_OnSetADCVALUE( ControlControl _this, XInt32 value )
{
  if ( _this->ADCVALUE == value )
    return;

  _this->ADCVALUE = value;
}

/* 'C' function for method : 'Control::Control.OnGetADCVALUE()' */
XInt32 ControlControl_OnGetADCVALUE( ControlControl _this )
{
  return _this->ADCVALUE;
}

 ⓕ I think if i change ADCVALUE , i have to control "void ControlControl_OnSetADCVALUE( ControlControl _this, XInt32 value )"

    Is it correct?

    If i control the fuction in main.c / How to compose to code?????
by

Hello,

your approach seems to point in the right direction. To avoid doubts let me recapitulate it:

Step 1: You add a new Control class.

This class should implement the interface between the GUI and the device. The simplest would be to use for this purpose the template Device Interface from the Gallery folder Device as demonstrated in the screenshot below. Just drag-and-drop it to one of your own project units:

Please note: with this template you get also an autoobject (a global instance of the interface class). This instance will be used wherever you want to access the interface.

Step 2: In your interface class implement a new property.

If you have created the interface class from the provided template (as explained in the step 1 above), the class contains already one property demonstrating this approach. The following is the screenshot of such class:

In this case you can use the already provided property. If desired you can rename it to e.g. ADCVALUE. As you see in the template the property is accompanied by it OnSet method and an additional UpdateProperty method. All other members within the class exist for demonstration purpose and is not relevant in your case. You can thus select and delete the members like TriggerEvent, SystemEvent, ...

If you want more properties in the interface, use the template Property from the Gallery folder Device as demonstrated in the screenshot below. This template is especially adapted to serve in interfaces:

Step 3: Connect the interface to e.g. Gauge:

Switch to your GUI component containing the Gauge, etc. widget you want to connect with the interface. Select the Gauge widget and in Inspector window look for its property Outlet. Activate the Assistant for this Outlet property and select the right interface property you want to connect the Gauge with. In this example, the property is named Property and it is a member of the global autoobject Application::Device.

Step 4: Generate code for your target device.

Step 5: Update the property value from your main application.

This is the point you have possibly doubts. How to feed the GUI application when the device receives new data?

Please recall the method UpdateProperty() mentioned in the step 2 above. Every time you call the method, the corresponding property is updated and a broadcast is sent to notify all the GUI components (e.g. the Gauge widget) about the value change. Thus all you have to do is to call the corresponding C function. The difficulty here: you have to call it in context of the same global autoobject you have connected the Gauge widget with (step 3 above).

The following is the necessary C code to perform the operation:

/* Obtain access to the global autoobject 'Application::Device' of the
   class 'Application::DeviceClass' */
ApplicationDeviceClass device = EwGetAutoObject( &ApplicationDevice, ApplicationDeviceClass );

/* In context of the object invoke the method 'UpdateProperty' */
ApplicationDeviceClass__UpdateProperty( device, 25 );

That is all. More details are found in the documentation:

Device Class and Device Driver

Integrating with the device.

and

Connect the Gauge with a data provider

Important: The GUI application is not thread safe. If you are running an operating system, you should call the UpdateProperty() always in context of the thread driving the GUI itself.

This here presented approach is optimized to react to random value changes in the device. The functiopn UpdateProperty() is called only when the corresponding value changes (like a push notification). If you have an application case with the value changing permanently, you don't need to be notified from the device about every change. Instead you will need to update the Gauge periodically. Do following:

Step 6: Ignore the above steps 3, 4 and 5.

Step 7: If not existing yet add a new OnGet method to your device class (where you implement the interface).

The method should be named corresponding to the name of the property e.g. OnGetADCVALUE. Following is the screenshot demonstrating this step:

Step 7: Edit the OnGet method

Implement the method to query the ADC vallue and return it. The target specific C code is enclosed insoide the native statement.  For example:

Step 8: Drive your GUI component to update the Gauge periodically.

Add a Timer object to the GUI component containing the Gauge widget. Configure the timer to e.g. expire every 100 ms. Add a slot method to your component and connect it to the OnTrigger property of the timer. In the slot method implement following code:

Don't forget to activate (enable) the timer.

Now with this approach, the Timer will cause the GUI component to query the latest ADC value 10 times per second and update the GUI component.

I hope it helps you further.

Best regards

Paul Banach

by
Thank you for answer.

I solved this probelm.
0 votes
by
Hello,

just an additional hint:

Within your Build Environment for an STM32 target you will find the example 'DeviceIntegration', which shows the interaction between GUI components and hardware components of the STM32 target: As soon as you press the hardware button on the Discovery board, a counter is increased. Each time the value of the counter has changed a progress bar is updated.

You can take this example and use the ADC value instead of the hardbutton / counter and use a gauge widget instead of a horizontal bar.

Maybe 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

...