// This file was generated by SquareLine Studio
// SquareLine Studio version: SquareLine Studio 1.5.4
// LVGL version: 9.1.0
// Project name: SquareLine_Project

#include "ui.h"
#include <stdint.h>

#include "app_ui_helper.h"

void volume_change_callback(lv_event_t *e)
{
    // Your code here
    uint8_t value = lv_slider_get_value(lv_event_get_target_obj(e));
    LV_LOG_USER("volume_change_callback, value: %d", value);
    app_ui_set_volume_value(value);
}

void reset_button_callback(lv_event_t *e)
{
    // Your code here
    lv_event_code_t event_code    = lv_event_get_code(e);
    static uint32_t pressed_start = 0;

    if (LV_EVENT_PRESSED == event_code) {
        pressed_start = lv_tick_get();
        LV_LOG_USER("reset_button_pressed, start: %d", pressed_start);
    } else if (LV_EVENT_PRESSING == event_code) {
        uint32_t elapsed = lv_tick_elaps(pressed_start);
        if (elapsed > 3000) {
            LV_LOG_USER("reset_button_pressing, elapsed: %d", elapsed);
            app_ui_reset_device();
        }
    }
}
void home_screen_loaded(lv_event_t *e)
{
    // Your code here
    ui_home_screen_gif_enable(1);
}

void home_screen_unloaded(lv_event_t *e)
{
    // Your code here
    ui_home_screen_gif_enable(0);
}

void setting_screen_loaded(lv_event_t *e)
{
    // Your code here
    // get volume
    uint8_t volume = app_ui_get_volume_value();
    ui_setting_volume_slider_update(volume);
    // get date
    uint32_t year = 0, month = 0, day = 0;
    app_ui_get_date(&year, &month, &day);
    ui_setting_date_update(year, month, day);
    // get time
    uint32_t hour = 0, minute = 0;
    app_ui_get_time(&hour, &minute);
    ui_setting_time_update(hour, minute);
    // get wifi status
    uint8_t wifi_status = 0;
    app_ui_get_wifi_status(&wifi_status);
    ui_setting_wifi_update(wifi_status);
    // get battery status

    // start time/date update timer
    app_ui_get_date_time_loop_start();
    // subscribe network status change event
    app_ui_network_status_change_subscribe();
}

void setting_screen_unloaded(lv_event_t *e)
{
    // Your code here
    // stop time/date update timer
    app_ui_get_date_time_loop_stop();
    // unsubscribe network status change event
    app_ui_network_status_change_unsubscribe();
}
