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