FluxDC/components/FluxUI/ui_events.c

200 lines
5.3 KiB
C
Raw Normal View History

// 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"
2025-03-07 16:26:42 +08:00
#include "driver/ledc.h"
#include "esp_err.h"
#include "esp_log.h"
#include "FluxWifi.h"
2025-03-13 10:26:19 +08:00
#include "FluxUart.h"
#include "FluxSD.h"
#include "esp_vfs_fat.h"
#include "sdmmc_cmd.h"
#include "driver/sdmmc_host.h"
2025-03-08 10:23:13 +08:00
2025-03-07 17:42:37 +08:00
#define LOWERST_LIGHT_LEVEL (7222)
2025-03-17 09:50:22 +08:00
#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");
void on_sliderLight_valueChanged(lv_event_t * e)
{
// Your code here
2025-03-07 17:42:37 +08:00
// Your code here
uint32_t value = 8192-lv_slider_get_value(e->target);
2025-03-07 16:26:42 +08:00
//ESP_LOGI("lightSliderCallback", "value = %u", value);
2025-03-07 17:42:37 +08:00
if (value>LOWERST_LIGHT_LEVEL)
{
value = LOWERST_LIGHT_LEVEL;
}
2025-03-07 16:26:42 +08:00
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));
}
2025-03-08 14:45:49 +08:00
void on_dropdownDeviceType_valueChanged(lv_event_t * e)
2025-03-08 14:45:49 +08:00
{
char buf[32]={};
2025-03-17 09:50:22 +08:00
uint16_t index = lv_dropdown_get_selected(e->target);
2025-03-08 14:45:49 +08:00
lv_dropdown_get_selected_str(e->target,buf,32);
lv_label_set_text(ui_pageHome_labelTitle, buf);
2025-03-08 14:45:49 +08:00
2025-03-17 09:50:22 +08:00
if (index == 0)
{
lv_spinbox_set_range(ui_pageHome_spinboxStage,1,4);
}else{
lv_spinbox_set_range(ui_pageHome_spinboxStage,1,6);
}
2025-03-11 18:55:34 +08:00
}
void on_buttonSearchWifi_clicked(lv_event_t * e)
2025-03-11 18:55:34 +08:00
{
wifi_scan();
2025-03-11 18:55:34 +08:00
}
void on_panelReadSDCard_clicked(lv_event_t * e)
2025-03-11 18:55:34 +08:00
{
// Your code here
2025-03-11 18:55:34 +08:00
}
void on_dropDownWifiName_valueChanged(lv_event_t * e)
2025-03-11 18:55:34 +08:00
{
// 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");
}
2025-03-11 18:55:34 +08:00
}
void on_buttonConnectWifi_clicked(lv_event_t * e)
{
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)
2025-03-11 18:55:34 +08:00
{
// 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_obj_clear_flag(ui_pageHome_spinnerStateBusy, LV_OBJ_FLAG_HIDDEN);
2025-03-13 15:13:27 +08:00
}
2025-03-13 10:26:19 +08:00
void on_buttonFluxRead_clicked(lv_event_t * e)
{
ESP_ERROR_CHECK(ModbusRTU_Send(ECHO_UART_PORT_NUM1,&flux_frame));
2025-03-13 10:26:19 +08:00
}
void on_buttonClearTextarea_clicked(lv_event_t * e)
{
lv_textarea_set_text(ui_pageDebug_textAreaContent, "");
}
void on_buttonReadSDCard_clicked(lv_event_t * e)
{
2025-03-17 09:50:22 +08:00
/*首先清空显示页面*/
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);
}
2025-03-15 15:51:44 +08:00
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);
}
2025-03-17 09:50:22 +08:00
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);
}
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);
}