Example/sample project

Description

This page provides a sample project and the teaching video. iCreator allows users to write code. Here is an example of a simple code.

Porject demo video

Example/timer

Description

Use timer widget, you need to write code. Below code is for demo, the demo is explan how to use timer widget to change layout when time out.

Code


// In layout1 create timer widget
static struct HMI_timer timer_1;

// In layout2 create timer widget
static struct HMI_timer timer_2;

void on_timer_1_time_out(void);
void on_timer_2_time_out(void);

void init_HMI_widget(void)
{
    layout[0].type = HMI_WIDGET_LAYOUT;
    layout[0].is_update = false;
    // change timer widget num to 1
    layout[0].timer_widget_num = 1;
    layout[0].widget_num = 0;
    layout[0].widget = pvPortMalloc(sizeof(uint8_t *) * layout[0].widget_num);
    strcpy((char *)layout[0].background_img_name, "Layout_0/bg.jpg");
    strcpy((char *)layout[0].screenshot_img_name, "Layout_0/sh.jpg");
    layout[0].index = 0;
    layout[0].left_layout_index = -1;
    layout[0].right_layout_index = -1;
    layout[0].up_layout_index = -1;
    layout[0].down_layout_index = -1;
    layout[0].group_num = 0;
    layout[0].group = (struct group_info*)pvPortMalloc(sizeof(struct group_info)*layout[0].group_num);
    // ==========timer_1 widget coding start========== 
    timer_1.type = HMI_WIDGET_TIMER;
    layout[0].timer_widget = pvPortMalloc(sizeof(uint8_t *) * layout[0].timer_widget_num);
    layout[0].timer_widget[0] = (uint8_t *)&timer_1;
    /* set time out ms time */
    timer_1.delay = 5000;
    /* trigger function when time out*/
    timer_1.time_out_callback = on_timer_1_time_out;
    // ==========timer_1 widget coding end========== 
    
    layout[1].type = HMI_WIDGET_LAYOUT;
    layout[1].is_update = false;
    // change timer widget num to 1
    layout[1].timer_widget_num = 1;
    layout[1].widget_num = 0;
    layout[1].widget = pvPortMalloc(sizeof(uint8_t *) * layout[1].widget_num);
    strcpy((char *)layout[1].background_img_name, "Layout_1/bg.jpg");
    strcpy((char *)layout[1].screenshot_img_name, "Layout_1/sh.jpg");
    layout[1].index = 1;
    layout[1].left_layout_index = -1;
    layout[1].right_layout_index = -1;
    layout[1].up_layout_index = -1;
    layout[1].down_layout_index = -1;
    layout[1].group_num = 0;
    layout[1].group = (struct group_info*)pvPortMalloc(sizeof(struct group_info)*layout[1].group_num);
    // ==========timer_2 widget coding start==========
    timer_2.type = HMI_WIDGET_TIMER;
    layout[1].timer_widget = pvPortMalloc(sizeof(uint8_t *) * layout[1].timer_widget_num);
    layout[1].timer_widget[0] = (uint8_t *)&timer_2;
    /* set time out ms time */
    timer_2.delay = 1000;
    /* trigger function when time out*/
    timer_2.time_out_callback = on_timer_2_time_out;
    // ==========timer_2 widget coding end==========
}

/* In layout 1 timer widget trigger timer event, change layout1 to layout2 when time out */
void on_timer_1_time_out(void)
{
    layout_change_to_layout(&layout[1]);
}

/* In layout 2 timer widget trigger timer event, change layout2 to layout1 when time out */
void on_timer_2_time_out(void)
{
    layout_change_to_layout(&layout[0]);
}
  	

Example/UART

Description

When iCreator App generate "HMI_widget.c", the "uart_cmd_parser" function will be generated. This function is used for handle device RX data, user can write code to handle it by yourself.
Below code is an example, the function will TX data when the buf parameter is "AT+FUN1", "AT+FUN2", "AT+FUN3".

Code


void uart_cmd_parser(uint8_t *buf)
{
    //example for uart cmd parser
    uint8_t tmp[20];
    if (strncmp((char *)buf, "AT+FUN1", 7) == 0) {
        uint8_t parameter1 = *(buf + 7);
        uint8_t parameter2 = *(buf + 8);
        sprintf(tmp, "FUN1 %d %d\n", parameter1, parameter2);
        UART_transfer_message(tmp, strlen(tmp));
    } else if (strncmp((char *)buf, "AT+FUN2", 7) == 0) {
        uint8_t parameter1 = *(buf + 7);
        uint8_t parameter2 = *(buf + 8);
        sprintf(tmp, "FUN2 %d %d\n", parameter1, parameter2);
        UART_transfer_message(tmp, strlen(tmp));
    } else if (strncmp((char*)buf, "AT+FUN3", 7) == 0) {
        uint8_t parameter1 = *(buf + 7);
        uint8_t parameter2 = *(buf + 8);
        sprintf(tmp, "FUN3 %d %d\n", parameter1, parameter2);
        UART_transfer_message(tmp, strlen(tmp));
    }
    return;         
}