Where & How to Initiate a Timer for an Arc

Hi @Damien_Norris ,

I am not familiar with Squareline Studio to be honest but hopefully you should be able to work with this…

Here is a function that should work for you:

void start_timer_with_count( uint32_t count) {

	timer_value = count;
    lv_arc_set_range(arc_1, 0, count);
	lv_arc_set_value(arc_1, count);
	lv_timer_reset(arc_timer);
	update_knob_label( klabel );
}

So when you want to set the timer going for say 60 seconds just call this function as follows:

start_timer_with_count( 60 ) ;

I think this is what you are trying to achieve, if I have mis-understood, my apologies…

Here is the original example complete, but reworked with this method:

static lv_obj_t		*arc_1;
static lv_obj_t		*klabel;
static uint32_t		timer_value = 0;
static lv_timer_t 	*arc_timer;

static void update_knob_label( lv_obj_t *label ) {

	/*Rotate the label to the current position of the arc*/
	lv_label_set_text_fmt(label, "%d", timer_value );
	lv_arc_rotate_obj_to_angle(arc_1, label, 35);
}

static void update_arc_cb( lv_timer_t *timer ) {

	if( timer_value ) lv_arc_set_value( arc_1, --timer_value );
	printf( "tick:%d\r\n", lv_tick_get());
	fflush(stdout);
	update_knob_label( klabel );
}

void start_timer_with_count( uint32_t count) {

	timer_value = count;
    lv_arc_set_range(arc_1, 0, count);
	lv_arc_set_value(arc_1, count);
	lv_timer_reset(arc_timer);
	update_knob_label( klabel );
}

static void btn_cb( lv_event_t *e ) {

	start_timer_with_count( 60 );  // Start the timer with 60 seconds when button is pressed.
}

void test( lv_obj_t *parent ) {

	klabel = lv_label_create( parent );
	lv_obj_set_style_text_color( klabel, lv_palette_main(LV_PALETTE_BLUE), LV_PART_MAIN);
	arc_1 = lv_arc_create(parent);

	lv_arc_set_mode(arc_1, LV_ARC_MODE_NORMAL);
	lv_arc_set_angles(arc_1, 45, 315);
	lv_obj_set_style_arc_rounded(arc_1, 0, LV_PART_INDICATOR|LV_STATE_DEFAULT);
	lv_obj_set_style_arc_rounded(arc_1, 0, LV_STATE_DEFAULT);
	lv_obj_set_pos(arc_1,  120, 120);
	lv_obj_set_size(arc_1, 100, 100);
	update_knob_label( klabel );

	lv_obj_t *btn = lv_btn_create( parent );
	lv_obj_t *txt = lv_label_create( btn );
	lv_obj_set_pos( btn, 20, 20);
	lv_label_set_text( txt, "60 Secs" );
	lv_obj_add_event_cb(btn, btn_cb, LV_EVENT_CLICKED, NULL);

	arc_timer = lv_timer_create(update_arc_cb, 1000, arc_1);

	start_timer_with_count( 10 );  // Make the timer start with 10 seconds at startup
}

I hope that makes sense…

If you have trouble integrating it post back with some code and I will take a look at it again a make some suggestions if necessary.

Kind Regards,

Pete

1 Like