Is there a better way of clearing lv_table_add_cell_ctrl?

Description

I currently colour a table column based on a temp, red, blue and green.

What MCU/Processor/Board and compiler are you using?

Simulator but Raspberry Pi eventually

What LVGL version are you using?

What do you want to achieve?

I’d like to clear an control without having to check each one first

What have you tried so far?

		bool chk = lv_table_has_cell_ctrl(sensorTable, arraypos, 1, LV_TABLE_CELL_CTRL_CUSTOM_1);
		if(chk) lv_table_clear_cell_ctrl(sensorTable, arraypos, 1, LV_TABLE_CELL_CTRL_CUSTOM_1);
		
		chk = lv_table_has_cell_ctrl(sensorTable, arraypos, 1, LV_TABLE_CELL_CTRL_CUSTOM_2);
		if(chk) lv_table_clear_cell_ctrl(sensorTable, arraypos, 1, LV_TABLE_CELL_CTRL_CUSTOM_2);
		
		chk = lv_table_has_cell_ctrl(sensorTable, arraypos, 1, LV_TABLE_CELL_CTRL_CUSTOM_3);
		if(chk) lv_table_clear_cell_ctrl(sensorTable, arraypos, 1, LV_TABLE_CELL_CTRL_CUSTOM_3);

		lv_table_add_cell_ctrl(sensorTable, arraypos, 1, outCol);

Code to reproduce

Same as above

Screenshot and/or video

image

Thanks!!

First you need clear the field of cell only if sensor change data considerably compared to an old stored value (i dont see the complete code here)
Second not need clear cell but just use a formatted output that cover all field (i think 8 chars is enough, depend how many decimal you want use)
with: voidlv_table_set_cell_value (lv_obj_ttable , uint16_trow , uint16_tcol , const char*txt* )

here is the full code:

	bool colourUpdateRequired = true;

    //sensor = sensor.substring(0,11);
    int arraypos = ((curserpos)/10);

    if(arraypos<0)
    {
      arraypos = 0;
    }

    if(strcmp("green", json_object_get_string(colour_struct)) == 0)
    {
		printDateTime();
		printf("Colour::::: %s\n", "Green");

		if(lv_table_has_cell_ctrl(sensorTable, arraypos, 1, LV_TABLE_CELL_CTRL_CUSTOM_1))
		{
			colourUpdateRequired = false;
		}

    	outCol = LV_TABLE_CELL_CTRL_CUSTOM_1;
    }
    if(strcmp("red", json_object_get_string(colour_struct)) == 0)
    {
		printDateTime();
		printf("Colour::::: %s\n", "Red");

		if(lv_table_has_cell_ctrl(sensorTable, arraypos, 1, LV_TABLE_CELL_CTRL_CUSTOM_2))
		{
			colourUpdateRequired = false;
		}

    	outCol = LV_TABLE_CELL_CTRL_CUSTOM_2;
    }
    if(strcmp("blue", json_object_get_string(colour_struct)) == 0)
    {
		printDateTime();
		printf("Colour::::: %s\n", "Blue");

		if(lv_table_has_cell_ctrl(sensorTable, arraypos, 1, LV_TABLE_CELL_CTRL_CUSTOM_3))
		{
			colourUpdateRequired = false;
		}

    	outCol = LV_TABLE_CELL_CTRL_CUSTOM_3;
    }

    lv_table_set_cell_value(sensorTable, arraypos, 0, json_object_get_string(sensor_struct));


	if(colourUpdateRequired)
	{
		bool chk = lv_table_has_cell_ctrl(sensorTable, arraypos, 1, LV_TABLE_CELL_CTRL_CUSTOM_1);
		if(chk) lv_table_clear_cell_ctrl(sensorTable, arraypos, 1, LV_TABLE_CELL_CTRL_CUSTOM_1);
		
		chk = lv_table_has_cell_ctrl(sensorTable, arraypos, 1, LV_TABLE_CELL_CTRL_CUSTOM_2);
		if(chk) lv_table_clear_cell_ctrl(sensorTable, arraypos, 1, LV_TABLE_CELL_CTRL_CUSTOM_2);
		
		chk = lv_table_has_cell_ctrl(sensorTable, arraypos, 1, LV_TABLE_CELL_CTRL_CUSTOM_3);
		if(chk) lv_table_clear_cell_ctrl(sensorTable, arraypos, 1, LV_TABLE_CELL_CTRL_CUSTOM_3);

		lv_table_add_cell_ctrl(sensorTable, arraypos, 1, outCol);
	}

I still think that there could (should) be a better way. iE are there any flags? Clear it…

Thanks
Alex

And this is in main loop?..or is called by a timer?..and i dont know how is set LV_TABLE_CELL_CTRL_CUSTOM_x
better way for overwrite a cell is made a string that cover all cell (is enough 8 chars) and covert em in char array and overwrite old chars.
And you need consider use of a variable that read old cell value, and if variation is more that decimals, call a redraw cell routine, or is a continue screen update (also if use Json) due by variations of sensors.