661 views
in System Integration by
I added an Indicator, Button, and ButtonAction (Slot method) to my Application Gui. The slot method called toggleIndicator() toggles the Indicator state when the button is pressed. How can i call this Application.toggleIndicator() from within my Device/DeviceClass? The end goal is to be able to control the Indicator state from device custom code.

What i tried is this:
From my devices (Raspberry Pi) custom code i call ApplicationDeviceClass__ToggleIndicator( DeviceObject);

DeviceClass.toggleIndicator()  gets executed and should call Application.toggleIndicator(). I tried just the line Application.ButtonAction in the Device.toggleIndicator() slot method, but the error i get is "Unknown identifier 'Application' found". Also Application::Application.toggleIndicator() does not work.

What is the right way to do it? Is it impossible to call Application.xxx functions from Device.xxx ? Is the right way to setup properties and observers?

Thanks...

1 Answer

+1 vote
by

Hi,

the problem is, there is no direct way to access the Application object from the Device object. They don't know each other. What you can do:

Approach 1: Use the System Event object to broadcast the state alternation:

Step1: In your Device class add a new System Event object.

Step2. In your GUI (or application) component add a new System Event Handler.

Step3. Connect the System Event object to the property Event of the System Event Handler.

Step4. With the System Event Handler you got a slot method onEvent. Open the method and implement there the code to toggle the desired state.

With the System Event object (added to the Device class in Step1) comes per default the method TriggerEvent(). When you call the method (e.g. from your Rasberry Pi) code, the corresponding system event is broadcasted and all associated System Event Handler are notified. Accordingly, the code of the method onEvent is executed. To call the method from the 'C' code use following code:

ApplicationDeviceClass__TriggerEvent( DeviceObject );

Approach 2: Use Properties in the Device Object and Property Observer:

With this approach you enhance your Device class by a kind of variable, where the current (toggle) state is stored.

Step1: In your Device class add a new Property. Since you want the property to store the value true/false only, configure its data type to be bool.

Step2. The property comes per default accompanied by the method UpdateProperty(). Open the method and change the data type of its argument aNewValue to be also bool. See also: Implementing an UpdateProperty method.

Step3. In your GUI (or application) component add a new Property Observer.

Step4. Connect the Property (from Step1) to the property Outlet of the Property Observer.

Step5. With the Property Observer you got a slot method onEvent. Open the method and implement there the code to update your component according to the actual state of the property in the Device object.

With the Property (added to the Device class in Step1) comes per default the method UpdateProperty(). When you call the method (e.g. from your Rasberry Pi) code, the corresponding property is updated and all associated Property observer are notified. Accordingly, the code of the method onEvent is executed. To call the method from the 'C' code use following code:

ApplicationDeviceClass__Updateproperty( DeviceObject, 1 ); // Set the property TRUE

ApplicationDeviceClass__Updateproperty( DeviceObject, 0 ); // Set the property FALSE

Approach 3: Use Properties in the Device Object and the 'Outlet' concept:

Similarly to Approach 2 you enhance your Device class by a kind of variable, where the current (toggle) state is stored. Then you connect your widget (e.g. the indicator) directly with the property. When the property changes, the widget updates itself automatically.

Step1: In your Device class add a new Property. Since you want the property to store the value true/false only, configure its data type to be bool.

Step2. The property comes per default accompanied by the method UpdateProperty(). Open the method and change the data type of its argument aNewValue to be also bool. See also: Implementing an UpdateProperty method.

Step3. In your GUI component select the Indicator widget and connect the property (from Step1) to the property Outlet of this widget.

With the Property (added to the Device class in Step1) comes per default the method UpdateProperty(). When you call the method (e.g. from your Rasberry Pi) code, the corresponding property is updated and all connected Widgets (e.g. the indicator) are notified. To call the method from the 'C' code use following code:

ApplicationDeviceClass__Updateproperty( DeviceObject, 1 ); // Set the property TRUE

ApplicationDeviceClass__Updateproperty( DeviceObject, 0 ); // Set the property FALSE

Hope it helps you further

Best regards

Paul Banach

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

...