How to get the state of a switch or checkbox in Squareline generated codes

Hi,

I am not able to find any predefined getter functions for widgets like buttons, switches, or checkbox. Am I missing something?
Some widgets like slider or dropdown menu have predefined getter functions and report the state or the value. I was wondering that we probably should have for simpler widgets like a button. that if its pressed we can get the value 1 from a function in the generated code.

Thanks

I explain the project is to run a frequency generator :
It include 3 checkbox for meg, kilo an hertz and one button to sweep from F1 to F2.
When i press 1 checkbox it must clear the two others. Look The ui_events.c

void megchk(lv_event_t * e)  // Megahertz 
{

    lv_obj_t * obj = lv_event_get_target(e);
	const bool state = lv_obj_get_state(obj) & LV_STATE_CHECKED ? true : false;
	if(state)
		{
			lv_textarea_set_text(ui_TextMega, "");
			lv_textarea_set_text(ui_Textenter,"");
		        lv_obj_clear_state(ui_Checkhz, LV_STATE_CHECKED); // Kilohertz
			lv_obj_clear_state(ui_Checkkhz, LV_STATE_CHECKED); // Unit Hz
			EnterStat = 0;
			lv_keyboard_set_textarea(ui_Keyboard2, ui_TextMega);
		}
		else
		{
			lv_textarea_set_text(ui_TextMega, "XX");
		}

}

Now for the button :

void ValFreq(lv_event_t * e)
{
FreqF1F2 = lv_obj_get_state(ui_Swfreq ) & LV_STATE_CHECKED ? true : false;
FreqReady = true;
}

Now let see the main :
( French comments :slightly_smiling_face: )

// declare extern types before includes
extern bool FreqReady ; // set in ui_event.c when a button is pressed
extern bool FreqF1F2 ; // set in ui_event.c false = F1, true = F2  ( switch 2 positions)

// main loop 

void loop()
{
    lv_timer_handler(); /* let the GUI do its work */
    delay(5);

    if(sweepFreq == true) {Wobule();}
    
    if(FreqReady == true)
    {
    // test
    lv_textarea_set_text(ui_Textenter,lv_textarea_get_text(ui_TextMega));
    lv_textarea_add_text(ui_Textenter,lv_textarea_get_text(ui_TextKilo));
    lv_textarea_add_text(ui_Textenter,lv_textarea_get_text(ui_TextUnit));

    freqstring = lv_textarea_get_text(ui_Textenter);

    strcpy(buffer, freqstring);
    if (testFrequence(buffer))
        {
        
          rx = atof(buffer);
          if (rx <= 30000000)
          {
            if(FreqF1F2 == true) // switch wobule
              {
              lv_textarea_set_text(ui_Textenter,"freq 2 ok" );
              rx2 = rx;
              sweepFreq = true;
              }
            else 
              {
              lv_textarea_set_text(ui_Textenter,"freq 1 ok" );
              sweepFreq = false;
              rx1 = rx;
              tx =  rx;
              sendFrequency(tx); // ça Marche !!!
              }
          }
          else
          {
            lv_textarea_set_text(ui_Textenter,"freq > 30 Mhz" );
          }

        }

    else {lv_textarea_set_text(ui_Textenter,"invalide" );}// error}  

        FreqReady = false;   // do not forget to reset this lvglevent
    }     
}

Thanks for the response, But I’m really not following whats happening. its hard without knowing the visual interface of the graphics.
So are you confirming that LVGL does not provide a direct getter function for widgets like “button” or “checkbox”?

From v 8

To check if an object is in a given state use lv_obj_has_state(obj, LV_STATE_...) . It will return true if the object is currently in that state.

An other way shorter than mine ok for use it in the main loop…