Esempio n. 1
0
/**
 * Create a led objects
 * @param par pointer to an object, it will be the parent of the new led
 * @param copy pointer to a led object, if not NULL then the new object will be copied from it
 * @return pointer to the created led
 */
lv_obj_t * lv_led_create(lv_obj_t * par, lv_obj_t * copy)
{
    /*Create the ancestor basic object*/
	lv_obj_t * new_led = lv_obj_create(par, copy);
    dm_assert(new_led);
    
    /*Allocate the object type specific extended data*/
    lv_led_ext_t * ext = lv_obj_alloc_ext(new_led, sizeof(lv_led_ext_t));
    dm_assert(ext);
    ext->bright = LV_LED_BRIGHT_ON;

    if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_f(new_led);

    lv_obj_set_signal_f(new_led, lv_led_signal);
    lv_obj_set_design_f(new_led, lv_led_design);

    /*Init the new led object*/
    if(copy == NULL) {
    	lv_obj_set_style(new_led, lv_style_get(LV_STYLE_PRETTY_COLOR, NULL));
    	lv_obj_set_size(new_led, LV_LED_WIDTH_DEF, LV_LED_HEIGHT_DEF);
    }
    /*Copy an existing object*/
    else {
    	lv_led_ext_t * copy_ext = lv_obj_get_ext(copy);
    	ext->bright = copy_ext->bright;

        /*Refresh the style with new signal function*/
        lv_obj_refr_style(new_led);
    }
    
    return new_led;
}
Esempio n. 2
0
/**
 * Create a label objects
 * @param par pointer to an object, it will be the parent of the new label
 * @param copy pointer to a button object, if not NULL then the new object will be copied from it
 * @return pointer to the created button
 */
lv_obj_t * lv_label_create(lv_obj_t * par, lv_obj_t * copy)
{
    /*Create a basic object*/
    lv_obj_t * new_label = lv_obj_create(par, copy);
    lv_mem_assert(new_label);
    if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_label);
    
    /*Extend the basic object to a label object*/
    lv_obj_allocate_ext_attr(new_label, sizeof(lv_label_ext_t));
    
    lv_label_ext_t * ext = lv_obj_get_ext_attr(new_label);
    lv_mem_assert(ext);
    ext->text = NULL;
    ext->static_txt = 0;
    ext->recolor = 0;
    ext->no_break = 0;
    ext->body_draw = 0;
    ext->align = LV_LABEL_ALIGN_LEFT;
    ext->dot_end = LV_LABEL_DOT_END_INV;
    ext->long_mode = LV_LABEL_LONG_EXPAND;
    ext->anim_speed = LV_LABEL_SCROLL_SPEED;
    ext->offset.x = 0;
    ext->offset.y = 0;
	lv_obj_set_design_func(new_label, lv_label_design);
	lv_obj_set_signal_func(new_label, lv_label_signal);

    /*Init the new label*/
    if(copy == NULL) {
		lv_obj_set_click(new_label, false);
		lv_label_set_long_mode(new_label, LV_LABEL_LONG_EXPAND);
		lv_label_set_text(new_label, "Text");
        lv_label_set_style(new_label, NULL);        /*Inherit parent's style*/
    }
    /*Copy 'copy' if not NULL*/
    else {
        lv_label_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
        lv_label_set_long_mode(new_label, lv_label_get_long_mode(copy));
        lv_label_set_recolor(new_label, lv_label_get_recolor(copy));
        lv_label_set_body_draw(new_label, lv_label_get_body_draw(copy));
        lv_label_set_align(new_label, lv_label_get_align(copy));
        if(copy_ext->static_txt == 0) lv_label_set_text(new_label, lv_label_get_text(copy));
        else lv_label_set_static_text(new_label, lv_label_get_text(copy));

        /*In DOT mode save the text byte-to-byte because a '\0' can be in the middle*/
        if(copy_ext->long_mode == LV_LABEL_LONG_DOT) {
            ext->text = lv_mem_realloc(ext->text, lv_mem_get_size(copy_ext->text));
            memcpy(ext->text, copy_ext->text, lv_mem_get_size(copy_ext->text));
        }

        memcpy(ext->dot_tmp, copy_ext->dot_tmp, sizeof(ext->dot_tmp));
        ext->dot_end = copy_ext->dot_end;

        /*Refresh the style with new signal function*/
        lv_obj_refresh_style(new_label);
    }
    return new_label;
}
Esempio n. 3
0
/**
 * Create a led objects
 * @param par pointer to an object, it will be the parent of the new led
 * @param copy pointer to a led object, if not NULL then the new object will be copied from it
 * @return pointer to the created led
 */
lv_obj_t * lv_led_create(lv_obj_t * par, const lv_obj_t * copy)
{
    LV_LOG_TRACE("led create started");

    /*Create the ancestor basic object*/
    lv_obj_t * new_led = lv_obj_create(par, copy);
    lv_mem_assert(new_led);
    if(new_led == NULL) return NULL;

    if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_led);
    if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_func(new_led);

    /*Allocate the object type specific extended data*/
    lv_led_ext_t * ext = lv_obj_allocate_ext_attr(new_led, sizeof(lv_led_ext_t));
    lv_mem_assert(ext);
    if(ext == NULL) return NULL;

    ext->bright = LV_LED_BRIGHT_ON;

    lv_obj_set_signal_func(new_led, lv_led_signal);
    lv_obj_set_design_func(new_led, lv_led_design);

    /*Init the new led object*/
    if(copy == NULL) {
        lv_obj_set_size(new_led, LV_LED_WIDTH_DEF, LV_LED_HEIGHT_DEF);

        /*Set the default styles*/
        lv_theme_t * th = lv_theme_get_current();
        if(th) {
            lv_led_set_style(new_led, th->led);
        } else {
            lv_led_set_style(new_led, &lv_style_pretty_color);
        }
    }
    /*Copy an existing object*/
    else {
        lv_led_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
        ext->bright = copy_ext->bright;

        /*Refresh the style with new signal function*/
        lv_obj_refresh_style(new_led);
    }


    LV_LOG_INFO("led created");

    return new_led;
}
Esempio n. 4
0
static void ssd1306_task(void *pvParameters)
{
    printf("%s: Started user interface task\n", __FUNCTION__);
    vTaskDelay(SECOND);
    ssd1306_set_whole_display_lighting(&dev, false);

    //Set a style for the obj
    lv_style_copy(&style, &lv_style_transp);
    style.text.font = &lv_font_dejavu_10;   /*Unicode and symbol fonts already assigned by the library*/
    style.text.color.full = 1;
    style.text.opa = 255;

    style.body.main_color.full = 0;
    style.body.grad_color.full = 0;
    style.body.shadow.color.full = 0;
    style.body.border.color.full = 0;
    style.body.empty = 1;

    style.image.color.full = 1;
    style.image.intense = 255;
    style.image.opa = 255;

    style.line.color.full = 1;
    style.line.opa = 255;
    style.line.width = 1;
    style.line.rounded = false;

    //Create main screen obj
    lv_obj_t * scr = lv_obj_create(NULL, NULL);
    lv_scr_load(scr);
    lv_obj_set_style(scr, &style);

    //Create a simple label
    label = lv_label_create(lv_scr_act(), NULL);
    lv_obj_set_style(label, &style);

    lv_obj_align(label, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 0, 0);
    lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK);
    lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
    lv_label_set_text(label, "lvgl work with esp-open-rtos");
    lv_obj_set_width(label, LV_HOR_RES);

    while (1) {
        /*draw system call */
        lv_task_handler();
        vTaskDelay(1);
    }
}