263 lines
7.4 KiB
C
263 lines
7.4 KiB
C
// This file was generated by SquareLine Studio
|
|
// SquareLine Studio version: SquareLine Studio 1.5.1
|
|
// LVGL version: 8.3.6
|
|
// Project name: ESP32S3_UI
|
|
|
|
#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"
|
|
|
|
#define LOWERST_LIGHT_LEVEL (7222)
|
|
|
|
#define RESULT_RIGHT lv_obj_set_style_bg_color(ui_pageHome_panelTestResult,lv_color_hex(0x00FF00),LV_PART_MAIN);\
|
|
lv_label_set_text(ui_pageHome_labelTestResult,"V");
|
|
|
|
#define RESULT_FAULT lv_obj_set_style_bg_color(ui_pageHome_panelTestResult,lv_color_hex(0xFF0000),LV_PART_MAIN);\
|
|
lv_label_set_text(ui_pageHome_labelTestResult,"X");
|
|
|
|
/*更新当前测试标准*/
|
|
static void standardVolumeRefresh(void);
|
|
|
|
void on_sliderLight_valueChanged(lv_event_t * e)
|
|
{
|
|
// Your code here
|
|
// Your code here
|
|
uint32_t value = 8192-lv_slider_get_value(e->target);
|
|
//ESP_LOGI("lightSliderCallback", "value = %u", value);
|
|
if (value>LOWERST_LIGHT_LEVEL)
|
|
{
|
|
value = LOWERST_LIGHT_LEVEL;
|
|
}
|
|
|
|
ESP_ERROR_CHECK(ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, value));
|
|
// Update duty to apply the new value
|
|
ESP_ERROR_CHECK(ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0));
|
|
}
|
|
|
|
|
|
void on_dropdownDeviceType_valueChanged(lv_event_t * e)
|
|
{
|
|
char buf[32]={};
|
|
uint16_t index = lv_dropdown_get_selected(e->target);
|
|
|
|
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);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
void on_buttonSearchWifi_clicked(lv_event_t * e)
|
|
{
|
|
wifi_scan();
|
|
}
|
|
|
|
void on_panelReadSDCard_clicked(lv_event_t * e)
|
|
{
|
|
// Your code here
|
|
|
|
}
|
|
|
|
void on_dropDownWifiName_valueChanged(lv_event_t * e)
|
|
{
|
|
// Your code here
|
|
int currentIndex=0;
|
|
|
|
currentIndex = lv_dropdown_get_selected(e->target);
|
|
|
|
lv_label_set_text_fmt(ui_pageWifiConnect_labelRssi, "RSSI:%d dBm ", ap_info[currentIndex].rssi);
|
|
lv_label_set_text_fmt(ui_pageWifiConnect_labelConnectWifi,"connect to %s",ap_info[currentIndex].ssid);
|
|
|
|
if (strcmp((char*)ap_info[currentIndex].ssid,"yuwell")==0)
|
|
{
|
|
lv_textarea_set_text(ui_pageWifiConnect_textAreaWifiPassword, "yuwell123456");
|
|
}
|
|
|
|
}
|
|
|
|
void on_buttonConnectWifi_clicked(lv_event_t * e)
|
|
{
|
|
if(strcmp(lv_label_get_text(ui_pageWifiConnect_labelConnectWifi),"disconnect") == 0 )
|
|
{
|
|
esp_wifi_disconnect();
|
|
ESP_ERROR_CHECK(esp_wifi_stop());
|
|
return;
|
|
}
|
|
|
|
int currentIndex=0;
|
|
ESP_ERROR_CHECK(esp_wifi_stop());
|
|
currentIndex = lv_dropdown_get_selected(ui_pageWifiConnect_dropdownWifiName);
|
|
|
|
|
|
// Your code here
|
|
wifi_config_t wifi_config = {
|
|
.sta = {
|
|
.ssid = "yuwell",
|
|
.password = "yuwell123456",
|
|
/* Authmode threshold resets to WPA2 as default if password matches WPA2 standards (password len => 8).
|
|
* If you want to connect the device to deprecated WEP/WPA networks, Please set the threshold value
|
|
* to WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK and set the password with length and format matching to
|
|
* WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK standards.
|
|
*/
|
|
.threshold = {
|
|
.authmode = ap_info[currentIndex].authmode,
|
|
},
|
|
.sae_pwe_h2e = WPA3_SAE_PWE_BOTH,
|
|
.sae_h2e_identifier = "",
|
|
},
|
|
};
|
|
|
|
lv_dropdown_get_selected_str(ui_pageWifiConnect_dropdownWifiName,(char*)wifi_config.sta.ssid,32);
|
|
|
|
strncpy((char*)wifi_config.sta.password,lv_textarea_get_text(ui_pageWifiConnect_textAreaWifiPassword),64);
|
|
|
|
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
|
|
|
|
ESP_ERROR_CHECK(esp_wifi_start() );
|
|
ESP_LOGI("TAG", "wifi_init_sta finished.");
|
|
|
|
esp_wifi_connect();
|
|
|
|
}
|
|
|
|
void on_buttonClearPassword_clicked(lv_event_t * e)
|
|
{
|
|
// Your code here
|
|
lv_textarea_set_text(ui_pageWifiConnect_textAreaWifiPassword, "");
|
|
}
|
|
|
|
void on_buttonStartTest_clicked(lv_event_t * e)
|
|
{
|
|
// Your code here
|
|
/* start to test */
|
|
lv_label_set_text(ui_pageHome_labelStartTest,"Testing...");
|
|
vTaskDelay(2000/portTICK_PERIOD_MS);
|
|
lv_label_set_text(ui_pageHome_labelStartTest,"Test Complete!");
|
|
}
|
|
|
|
|
|
void on_buttonFluxRead_clicked(lv_event_t * e)
|
|
{
|
|
flux_frame.DATA[1] = (unsigned char)lv_spinbox_get_value(ui_pageDebug_spinboxAddr);
|
|
flux_frame.DATA[3] = (unsigned char)lv_spinbox_get_value(ui_pageDebug_spinboxNum);
|
|
|
|
ESP_ERROR_CHECK(ModbusRTU_Send(ECHO_UART_PORT_NUM1,&flux_frame));
|
|
}
|
|
|
|
|
|
void on_buttonClearTextarea_clicked(lv_event_t * e)
|
|
{
|
|
lv_textarea_set_text(ui_pageDebug_textAreaContent, "");
|
|
}
|
|
|
|
void on_buttonReadSDCard_clicked(lv_event_t * e)
|
|
{
|
|
/*首先清空显示页面*/
|
|
lv_textarea_set_text(ui_pageSDCard_textAreaSDCard,"");
|
|
esp_vfs_fat_info(MOUNT_POINT,&total_bytes,&free_bytes);
|
|
free_percent = (float)free_bytes / (float)total_bytes * 100;
|
|
|
|
printf("total:%llu free:%llu\n",total_bytes,free_bytes);
|
|
|
|
lv_label_set_text_fmt(ui_pageSDCard_labelSDCardFree,"%.2f free",free_percent);
|
|
lv_label_set_text_fmt(ui_pageSDCard_labelSDCardUsed,"used: %.2f GB",(double)(total_bytes-free_bytes)/(1024*1024*1024.0));
|
|
lv_label_set_text_fmt(ui_pageSDCard_labelSDCardSize,"size: %.2f GB",(double)total_bytes/(1024*1024*1024.0));
|
|
|
|
lv_arc_set_value(ui_pageSDCard_arcSDCardFree,free_percent);
|
|
|
|
}
|
|
|
|
|
|
void on_buttonRateMinus_clicked(lv_event_t * e)
|
|
{
|
|
uint16_t value = lv_spinbox_get_value(ui_pageHome_spinboxRate);
|
|
|
|
lv_spinbox_set_value(ui_pageHome_spinboxRate,value-5);
|
|
}
|
|
|
|
void on_buttonRatePlus_clicked(lv_event_t * e)
|
|
{
|
|
uint16_t value = lv_spinbox_get_value(ui_pageHome_spinboxRate);
|
|
|
|
lv_spinbox_set_value(ui_pageHome_spinboxRate,value+5);
|
|
}
|
|
|
|
|
|
/*切换挡位之后*/
|
|
void on_spinboxStage_valueChanged(lv_event_t * e)
|
|
{
|
|
int32_t value = lv_spinbox_get_value(e->target);
|
|
lv_label_set_text_fmt(ui_pageHome_labelResultStage,"%ld",value);
|
|
|
|
standardVolumeRefresh();
|
|
}
|
|
|
|
|
|
void on_spinboxRate_valueChanged(lv_event_t * e)
|
|
{
|
|
int32_t value = lv_spinbox_get_value(e->target);
|
|
lv_label_set_text_fmt(ui_pageHome_labelResultRate,"%ld",value);
|
|
|
|
standardVolumeRefresh();
|
|
}
|
|
|
|
|
|
static void standardVolumeRefresh(void)
|
|
{
|
|
/*获取当前的呼吸频率及挡位*/
|
|
fluxProtocol.currentBPM = lv_spinbox_get_value(ui_pageHome_spinboxRate);
|
|
fluxProtocol.currentStage = lv_spinbox_get_value(ui_pageHome_spinboxStage);
|
|
|
|
/*获取当前测试设备类型*/
|
|
fluxProtocol.currentDevice = lv_dropdown_get_selected(ui_pageSetting_dropdownDeviceType);
|
|
|
|
if (fluxProtocol.currentDevice == Spirit3)
|
|
{
|
|
/*判定当前测试设备为Spirit-3*/
|
|
/*获取标准体积数据*/
|
|
fluxProtocol.nominalVolumeStage = Spirit3_Volume[fluxProtocol.currentStage-1];
|
|
}else if (fluxProtocol.currentDevice == Spirit6)
|
|
{
|
|
/*判定当前测试设备为Spirit-6*/
|
|
fluxProtocol.nominalVolumeStage = Spirit6_Volume[fluxProtocol.currentStage-1];
|
|
}else if(fluxProtocol.currentDevice == YU_Lite8)
|
|
{
|
|
/*判定当前测试设备为YU-Lite-8*/
|
|
fluxProtocol.nominalVolumeStage = YULite8_Volume[fluxProtocol.currentStage-1];
|
|
}
|
|
|
|
float Volume_nominal = fluxProtocol.nominalVolumeStage /fluxProtocol.currentBPM*1.0;
|
|
float VolumeMax = Volume_nominal*1.15;
|
|
float VolumeMin = Volume_nominal*0.85;
|
|
|
|
lv_label_set_text_fmt(ui_pageHome_labelNominalVolume,"%.2f",Volume_nominal);
|
|
lv_label_set_text_fmt(ui_pageHome_labelNominalVolumeMax,"%.2f",VolumeMax);
|
|
lv_label_set_text_fmt(ui_pageHome_labelNominalVolumeMin,"%.2f",VolumeMin);
|
|
}
|
|
|
|
/*获取当前流量数据*/
|
|
void on_buttonReadFlux_clicked(lv_event_t * e)
|
|
{
|
|
flux_frame.DATA[1] = 0;
|
|
flux_frame.DATA[3] = 120;
|
|
|
|
ESP_ERROR_CHECK(ModbusRTU_Send(ECHO_UART_PORT_NUM1,&flux_frame));
|
|
|
|
} |