#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

#include "./SYSTEM/sys/sys.h"
#include "./BSP/RTC/rtc.h"

#include "./hmi/hmi_cmd.h"
#include "./hmi/hmi_rx_parse.h"
#include "./hmi/hmi_hex_parse.h"

#include "./hmi_select_text_example.h"

void hmi_select_text_example_hex_cmd(struct hex_cmd_fmt *fram)
{
    uint8_t wid_id = fram->func;
    int year, month, day, hour, min, sec = 0;
    cmd_res_t *back = hmi_cmd_back_res();

    if (wid_id == 0) // 日期按钮
    {
        API_GET(sys.year);
        back = hmi_cmd_back_res();
        year = back->val.value;

        API_GET(sys.month);
        back = hmi_cmd_back_res();
        month = back->val.value;

        API_GET(sys.day);
        back = hmi_cmd_back_res();
        day = back->val.value;

        rtc_set_time(year, month, day, calendar.hour, calendar.min, calendar.sec);
    }
    if (wid_id == 1) // 时间按钮
    {
        API_GET(sys.hour);
        back = hmi_cmd_back_res();
        hour = back->val.value;

        API_GET(sys.min);
        back = hmi_cmd_back_res();
        min = back->val.value;

        API_GET(sys.sec);
        back = hmi_cmd_back_res();
        sec = back->val.value;
        rtc_set_time(calendar.year, calendar.month, calendar.date, hour, min, sec);
    }
    if (wid_id == 2) // 获取时间按钮
    {
        API_RTCS(calendar.year, calendar.month, calendar.date, calendar.hour, calendar.min, calendar.sec);
    }
}

void hmi_select_text_example_timer_update_50ms(uint16_t page_id)
{
    if (page_id != 3)
        return;
}
