cancel
Showing results for 
Search instead for 
Did you mean: 

Proper way to synchronize with toggle button

Jtron.11
Senior

Hi all,

I am looking for an advice to how-to sync the back-end signal and the toggle button.

For example toggle button by default is OFF, Signal output Low.

Clicked button, the button state = ON, Signal output High.

View still display the button is ON.

Due to some error condition, the signal output is turned off to Low.  The View still show button is ON.  How can I turn the toggle button to OFF in View in this case?

Thank you 

1 ACCEPTED SOLUTION

Accepted Solutions
JohanAstrup
ST Employee

Are you using the TBS available in TouchGFX Designer? If so, connect a logic analyzer and measure the VSYNC frequency. This should be approximately 16.67 ms, as shown in the measurement below.

JohanAstrup_0-1757338884949.png

You can find the signals on the spare GPIO connector (CN1) located on the left side of the DK board. The mapping is also mentioned in the readme file of the TBS. VSYNC_FREQ is mapped to PC0 (CN1 pin 14).

Best regards,
Johan

View solution in original post

3 REPLIES 3
JohanAstrup
ST Employee

Hello @Jtron.11.

I have attached a small example that updates the state of the toggle button from the model every second.

The ToggleButton widget has a function called forceState() that updates the state of the button. Assuming you are using the model as the interface to the backend, use the model listener to call a function in your view class whenever the backend needs to update the state of the toggle button. I recommend looking at this thread for a detailed explanation of how to use the model listener to call a function in the view from the model.

Best regards,
Johan

Thank you Johan for the information.  I have implemented exactly the same, but I was not sure it is the right way or most simplest and correct way.  Everything has to go thru MPV model.

One thing I found I lost is you are using %60 for the 1 second but my tick somehow way faster.  Is it my STM32U5G9-DK2 has different clock setup so the Model::tick() will be call in 60?

 

void Model::tick()
{
    tickCount++;

    // Update button state every second
    if (!(tickCount % 60))
    {
        currentState = !currentState;
        modelListener->newExternalEvent(currentState);
    }
}

Edited by ST moderator to be inline with the community rules especially with the code sharing. In next time please use </> button to paste your code. Please read this post: How to insert source code

JohanAstrup
ST Employee

Are you using the TBS available in TouchGFX Designer? If so, connect a logic analyzer and measure the VSYNC frequency. This should be approximately 16.67 ms, as shown in the measurement below.

JohanAstrup_0-1757338884949.png

You can find the signals on the spare GPIO connector (CN1) located on the left side of the DK board. The mapping is also mentioned in the readme file of the TBS. VSYNC_FREQ is mapped to PC0 (CN1 pin 14).

Best regards,
Johan