Sure, here's your revised and translated question in English:
In my Embedded Wizard project, I have an object called Type
, and I want it to change colors depending on the seasons. In tmScreenMain::HomePage
, I have a slot where I implemented the logic necessary for my hardware to understand the seasons:
plaintext
Copia codice
$if $prototyper trace ("UpdateSpecialLed"); $endif var int32 noOfItems = Outline.CountViews(); var tmScreenMain::BtnText item; var int32 i; $if $prototyper // Iterate all items in the LedStatusSim array. Simulate the LED state change. // If an LED is off (0), it is turned on (1), and if it is on, it is turned off. for ( i = 0; i < LedStatusSim.size; i = i + 1 ) { if (LedStatusSim[i] == 0) LedStatusSim[i] = 1; else LedStatusSim[i] = 0; } $endif // lcounter keeps track of the number of LEDs handled, ignoring vertical lines. var int32 lcounter = 0; for ( i = 0; i < noOfItems; i = i + 1 ) { // Get the current item item = (tmScreenMain::BtnText) Outline.GetViewAtIndex( i ); if ( item != null ) { item.Bounds.h = Outline.Bounds.h; item.Visible = GetLedStatus( /*i - 1*/ lcounter ) && ( item.FrameNumber != 0 ); // Added the final part to hide the special LED if FrameNumber = 0 item.Enabled = GetLedStatus( /*i - 1*/ lcounter ) && ( item.FrameNumber != 0 ); // Handling vertical lines var Views::Line ln = (Views::Line) Outline.GetViewAtIndex( i + 1 ); if ( ln != null ) { ln.Visible = item.Visible; } lcounter = lcounter + 1; } } if (GetLedStatus(0) && !GetLedStatus(1) && !GetLedStatus(2)) { tmScreenMain::GlobalVariable.Season = 0; // summer } else if (!GetLedStatus(0) && GetLedStatus(1) && !GetLedStatus(2)) { tmScreenMain::GlobalVariable.Season= 1; // winter } else if (!GetLedStatus(0) && !GetLedStatus(1) && GetLedStatus(2)) { tmScreenMain::GlobalVariable.Season = 2; // holiday }
Then in Synoptic::Zone
, I have a property ^int16 ContactZone
.
plaintext
Copia codice
OnSetContactZone: // Check if the new Temperature differs from the currently used Temperature if ( pure ContactZone == value ) return; // Detach from the previous Temperature if ( pure ContactZone != null ) detachobserver OnContactZone, pure ContactZone; // Store the new Temperature ... pure ContactZone = value; // ... and attach to the new one if ( value != null ) attachobserver OnContactZone, value; // Finally, retrieve the current state of the property associated via 'Temperature'. //if ( value != null ) postsignal OnContactZone;
After that, I implemented a slot to manage the color of the Type
object based on the season:
plaintext
Copia codice
if (ContactZone == null){ return; } if (ContactZone^ == 0 ) Type.Color = Res::color10; else{ if (tmScreenMain::GlobalVariable.Season == 0 ) Type.Color = Res::color09; // summer else if (tmScreenMain::GlobalVariable.Season == 1 ) Type.Color = Res::color02; // winter else if (tmScreenMain::GlobalVariable.Season == 2) Type.Color = Res::color10; // holiday }
Initially, this approach works, but if I try to change the season without first turning the potentiometer off and on, the color of Type
does not change, and I have to power cycle the potentiometer.
I was thinking of using a property observer or creating an event, but I don't know how to proceed.