FluxDC/components/FluxUI/ui_events.c
2025-04-22 13:51:54 +08:00

198 lines
4.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @file ui_event.c
* @brief 此文件中专门实现事件的处理
*
* @author wang xiang en
* @date 2025-04-19
* @version 版本号
* @copyright 版权声明((C)2025, YUWELL MEDTECH Co.ltd
*/
#include "ui.h"
#include "driver/ledc.h"
#include "esp_err.h"
#include "esp_log.h"
#include "FluxWifi.h"
#include "FluxUart.h"
#include "FluxSD.h"
#include "esp_vfs_fat.h"
#include "sdmmc_cmd.h"
#include "driver/sdmmc_host.h"
#include "FluxProtocol.h"
#if CONFIG_WIFI_SCAN_ENABLE
/*包含SNTP的头文件*/
#include "lwip/apps/sntp.h"
#endif
/**
* @brief 更改测试的设备类型
*
* 设备类型选择回调函数
*
* @param[in] e 设置页的设备下拉菜单
*/
void on_dropdownDeviceType_valueChanged(lv_event_t * e)
{
char buf[32]={};
uint16_t index = lv_dropdown_get_selected(e->target);
/* 更新SD卡中的数据存储 */
sdData.flux_test_result.current_device_type = index;
lv_dropdown_get_selected_str(e->target,buf,32);
lv_label_set_text(ui_pageHome_labelTitle, buf);
if (index == Spirit3)
{
lv_spinbox_set_range(ui_pageHome_spinboxStage,1,4);
}else{
lv_spinbox_set_range(ui_pageHome_spinboxStage,1,6);
}
#if LOG_RECORD_ENABLE
example_write_log("on_dropdownDeviceType_valueChanged 设备类型修改成功");
#endif
}
/**
* @brief 读取当前SD卡剩余空间信息并更新页面
*
* SD卡读取回调函数
*
* @param[in] e not used
*/
void on_buttonReadSDCard_clicked(lv_event_t * e)
{
/*首先清空显示页面*/
lv_textarea_set_text(ui_pageSDCard_textAreaSDCard,"");
esp_vfs_fat_info(MOUNT_POINT,&sdData.total_bytes,&sdData.free_bytes);
sdData.free_percent = (float)sdData.free_bytes / (float)sdData.total_bytes * 100;
printf("total:%llu free:%llu\n",sdData.total_bytes,sdData.free_bytes);
lv_label_set_text_fmt(ui_pageSDCard_labelSDCardFree,"%.2f free",sdData.free_percent);
lv_label_set_text_fmt(ui_pageSDCard_labelSDCardUsed,"used: %.2f GB",(double)(sdData.total_bytes-sdData.free_bytes)/(1024*1024*1024.0));
lv_label_set_text_fmt(ui_pageSDCard_labelSDCardSize,"size: %.2f GB",(double)sdData.total_bytes/(1024*1024*1024.0));
lv_arc_set_value(ui_pageSDCard_arcSDCardFree,sdData.free_percent);
}
/**
* @brief pageFluxRead 向流量计索要120个参数
*
* 获取当前流量数据
*
* @param[in] e not used
*/
void on_buttonReadFlux_clicked(lv_event_t * e)
{
/*下发数据获取指令*/
/* 起始地址为 0x00 */
flux_frame.DATA[0] = 0;
flux_frame.DATA[1] = 0;
/* 数据长度为 120 */
flux_frame.DATA[2] = 0;
flux_frame.DATA[3] = 120;
flux_frame.FUNC = FLUX_FUNC_READ;
/*下发问询120个参数*/
ESP_ERROR_CHECK(ModbusRTU_Send_0306(ECHO_UART_PORT_NUM1,&flux_frame));
}
/*更新测试结果 —— 功能已屏蔽*/
void on_labelTestVolume_valueChanged(lv_event_t * e)
{
#if 0
/* 测试结果刷新放到label更新函数中 */
RefreshResult();
#endif
}
/*更新工作模式 —— 功能已屏蔽*/
void on_dropDownWorkmode_valueChanged(lv_event_t * e)
{
#if 0
FluxMachineData.workMode = (enum FluxMachineWorkMode)lv_dropdown_get_selected(e->target);
#endif
}
/*向流量计下发计时时间*/
void on_spinboxTime_valueChanged(lv_event_t * e)
{
#if 0
/* 0x10 设置多个参数报文格式 */
/* 地址 功能码 起始地址 寄存器数量 字节计数(写入寄存器数量*2 数据1 数据2 。。。 CRC */
/* 0x01 0x10 0x00 02 0x00 02 0x04 0x0078 0x0077 CRC*/
/*下发配置参数(其实只是配置时间)*/
flux_frame2Reg.ADDR = FLUX_ADDR;
flux_frame2Reg.FUNC = FLUX_FUNC_SET;
/*时间寄存器起始地址*/
flux_frame2Reg.regAddr = 0x0002;
flux_frame2Reg.regNum = 0x0002;
flux_frame2Reg.ByteNum = 0x04;
/*将时间的浮点数转为字节数组*/
uint8_t bytes[4];
float time = (float)lv_spinbox_get_value(e->target);
memcpy(bytes, &time, 4);
ESP_LOGI("FluxProtocol", "time:%f", time);
ESP_LOGI("FluxProtocol", "time:0-%02x 1-%02x 2-%02x 3-%02x", bytes[0],bytes[1],bytes[2],bytes[3]);
flux_frame2Reg.DATA[0] = bytes[3];
flux_frame2Reg.DATA[1] = bytes[2];
flux_frame2Reg.DATA[2] = bytes[1];
flux_frame2Reg.DATA[3] = bytes[0];
ESP_ERROR_CHECK(ModbusRTU_Send_0x10(ECHO_UART_PORT_NUM1,&flux_frame2Reg));
#elif 0
/*使用0306报文格式*/
uint8_t bytes[4];
float time = (float)lv_spinbox_get_value(ui_pageFluxRead_spinboxTime);
memcpy(bytes, &time, 4);
/*下发命令*/
flux_frame.ADDR = FLUX_ADDR;
flux_frame.FUNC = FLUX_FUNC_SET_SINGLE;
flux_frame.DATA[0] = 0x00;
flux_frame.DATA[1] = 0x02;
flux_frame.DATA[2] = bytes[3];
flux_frame.DATA[3] = bytes[2];
ESP_ERROR_CHECK(ModbusRTU_Send_0306(ECHO_UART_PORT_NUM1,&flux_frame));
#endif
}
/**
* @brief pageFlux页面中 启动按键Not Used
*
* 启动流量计 开始测试
*
* @param[in] e not used
*/
void on_buttonFluxStart_clicked(lv_event_t * e)
{
FLUX_TEST_START;
}
/*不执行任何操作*/
void on_buttonTimeUpdate_clicked(lv_event_t * e)
{
/*不实现任何功能*/
}