cmcu为stm32h743IIt6
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

405 lines
19 KiB

/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2026-02-04 Administrator the first version
*/
#include <rtthread.h>
#include <string.h>
#include <applications/data/Variable.h>
#include <board.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <guider/custom/custom.h>
#include <guider/generated/events_init.h>
#include <guider/generated/gui_guider.h>
#include <guider/generated/widgets_init.h>
#include "lvgl.h"
#include <ui_data_labels.h>
#include "libcsv.h"
typedef struct {
char STEPNAME[16];
char STEPID[4];
} step_DATA_tab;
//
int STEP_SET_MODE=-1;//页面功能状态
char ProgramID[32];
char stepsql[512] = {0}; // 初始化为 0
step_DATA_tab STEP_NAME_S1;
step_DATA_tab STEP_NAME_S2;
step_DATA_tab STEP_NAME_S3;
static const int get_step_name(char * step_id)
{
int id_num = atoi(step_id);
switch(id_num) {
// --- 基础控制 ---
case 1: return 0;//"温度控制001"; // 001
case 7: return 1;//"水位进水007"; // 007 (AddWater + WaterLevel)
case 8: return 2;//"流量进水008"; // 008 (AddWater + Flowmeter)
case 13: return 3;//"水位水洗013"; // 013 (Washing + WaterLevel)
case 15: return 4;//"溢流水洗015"; // 015 (Washing + Overflow)
case 20: return 5;//"排水020"; // 020
case 22: return 6;//"主泵排水022"; // 022
case 31: return 7;//"运转031"; // 031
case 35: return 8;//"入布035"; // 035
case 36: return 9;//"出布036"; // 036
case 39: return 10;//"呼叫操作员039"; // 039
case 40: return 11;//"取样040"; // 040
case 41: return 12;//"程序结束041"; // 041
case 49: return 13;//"等待049"; // 049
case 50: return 14;//"加压050"; // 050
case 51: return 15;//"减压051"; // 051
case 54: return 16;//"泵风机速度054"; // 054 (Pump + Blower)
case 55: return 17;//"泵启动055"; // 055
case 56: return 18;//"泵停止056"; // 056
case 64: return 19;//"备药064"; // 064
case 65: return 20;//"加药065"; // 065
case 66: return 21;//"呼叫输送066"; // 066
case 67: return 22;//"呼叫准备067"; // 067
case 90: return 23;//"快速加酸090"; // 090
case 93: return 24;//"ph检测093"; // 093
case 94: return 25;//"ph控制094"; // 094
default: return 26;
}
}
static const int get_step_namer(char * step_id)
{
int id_num = atoi(step_id);
switch(id_num) {
// --- 基础控制 ---
case 1: return 0;//"降温水洗017"; // 001
case 50: return 1;//"加压050"; // 050
case 51: return 2;//"减压051"; // 051
case 64: return 3;//"备药064"; // 064
case 66: return 4;//"呼叫输送066"; // 066
case 90: return 5;//"快速加酸090"; // 090
case 91: return 6;//"温控加酸091"; // 090
case 93: return 7;//"ph检测093"; // 093
case 94: return 8;//"ph控制094"; // 094
default: return 9;
}
}
static void get_step_sql(int id_num)
{
switch(id_num) {
// --- 基础控制 ---
case 0:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"温度控制");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"001");
break;
case 1:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"水位进水");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"007");
break;
case 2:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"流量进水");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"008");
break;
case 3:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"水位水洗");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"013");
break;
case 4:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"溢流水洗");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"015");
break;
case 5:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"排水");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"020");
break;
case 6:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"主泵排水");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"022");
break;
case 7:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"运转");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"031");
break;
case 8:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"入布");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"035");
break;
case 9:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"出布");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"036");
break;
case 10:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"呼叫操作员");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"039");
break;
case 11:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"取样");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"040");
break;
case 12:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"程序结束");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"041");
break;
case 13:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"等待");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"049");
break;
case 14:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"加压");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"050");
break;
case 15:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"减压");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"051");
break;
case 16:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"泵风机速度");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"054");
break;
case 17:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"泵启动");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"055");
break;
case 18:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"泵停止");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"056");
break;
case 19:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"备药");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"064");
break;
case 20:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"加药");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"065");
break;
case 21:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"呼叫输送");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"066");
break;
case 22:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"呼叫准备");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"067");
break;
case 23:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"快速加酸");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"090");
break;
case 24:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"ph检测");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"093");
break;
case 25:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"ph控制");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"094");
break;
default:
rt_snprintf(STEP_NAME_S1.STEPNAME, sizeof(STEP_NAME_S1.STEPNAME),"");
rt_snprintf(STEP_NAME_S1.STEPID, sizeof(STEP_NAME_S1.STEPID),"000");
}
}
static void get_step_sqlr2(int id_num)
{
switch(id_num) {
// --- 基础控制 ---
case 0:
rt_snprintf(STEP_NAME_S2.STEPNAME, sizeof(STEP_NAME_S2.STEPNAME),"降温水洗");
rt_snprintf(STEP_NAME_S2.STEPID, sizeof(STEP_NAME_S2.STEPID),"017");
break;
case 1:
rt_snprintf(STEP_NAME_S2.STEPNAME, sizeof(STEP_NAME_S2.STEPNAME),"加压");
rt_snprintf(STEP_NAME_S2.STEPID, sizeof(STEP_NAME_S2.STEPID),"050");
break;
case 2:
rt_snprintf(STEP_NAME_S2.STEPNAME, sizeof(STEP_NAME_S2.STEPNAME),"减压");
rt_snprintf(STEP_NAME_S2.STEPID, sizeof(STEP_NAME_S2.STEPID),"051");
break;
case 3:
rt_snprintf(STEP_NAME_S2.STEPNAME, sizeof(STEP_NAME_S2.STEPNAME),"备药");
rt_snprintf(STEP_NAME_S2.STEPID, sizeof(STEP_NAME_S2.STEPID),"064");
break;
case 4:
rt_snprintf(STEP_NAME_S2.STEPNAME, sizeof(STEP_NAME_S2.STEPNAME),"呼叫输送");
rt_snprintf(STEP_NAME_S2.STEPID, sizeof(STEP_NAME_S2.STEPID),"066");
break;
case 5:
rt_snprintf(STEP_NAME_S2.STEPNAME, sizeof(STEP_NAME_S2.STEPNAME),"快速加酸");
rt_snprintf(STEP_NAME_S2.STEPID, sizeof(STEP_NAME_S2.STEPID),"090");
break;
case 6:
rt_snprintf(STEP_NAME_S2.STEPNAME, sizeof(STEP_NAME_S2.STEPNAME),"温控加酸");
rt_snprintf(STEP_NAME_S2.STEPID, sizeof(STEP_NAME_S2.STEPID),"091");
break;
case 7:
rt_snprintf(STEP_NAME_S2.STEPNAME, sizeof(STEP_NAME_S2.STEPNAME),"ph检测");
rt_snprintf(STEP_NAME_S2.STEPID, sizeof(STEP_NAME_S2.STEPID),"093");
break;
case 8:
rt_snprintf(STEP_NAME_S2.STEPNAME, sizeof(STEP_NAME_S2.STEPNAME),"ph控制");
rt_snprintf(STEP_NAME_S2.STEPID, sizeof(STEP_NAME_S2.STEPID),"094");
break;
default:
rt_snprintf(STEP_NAME_S2.STEPNAME, sizeof(STEP_NAME_S2.STEPNAME),"");
rt_snprintf(STEP_NAME_S2.STEPID, sizeof(STEP_NAME_S2.STEPID),"000");
}
}
static void get_step_sqlr3(int id_num)
{
switch(id_num) {
// --- 基础控制 ---
case 0:
rt_snprintf(STEP_NAME_S3.STEPNAME, sizeof(STEP_NAME_S3.STEPNAME),"降温水洗");
rt_snprintf(STEP_NAME_S3.STEPID, sizeof(STEP_NAME_S3.STEPID),"017");
break;
case 1:
rt_snprintf(STEP_NAME_S3.STEPNAME, sizeof(STEP_NAME_S3.STEPNAME),"加压");
rt_snprintf(STEP_NAME_S3.STEPID, sizeof(STEP_NAME_S3.STEPID),"050");
break;
case 2:
rt_snprintf(STEP_NAME_S3.STEPNAME, sizeof(STEP_NAME_S3.STEPNAME),"减压");
rt_snprintf(STEP_NAME_S3.STEPID, sizeof(STEP_NAME_S3.STEPID),"051");
break;
case 3:
rt_snprintf(STEP_NAME_S3.STEPNAME, sizeof(STEP_NAME_S3.STEPNAME),"备药");
rt_snprintf(STEP_NAME_S3.STEPID, sizeof(STEP_NAME_S3.STEPID),"064");
break;
case 4:
rt_snprintf(STEP_NAME_S3.STEPNAME, sizeof(STEP_NAME_S3.STEPNAME),"呼叫输送");
rt_snprintf(STEP_NAME_S3.STEPID, sizeof(STEP_NAME_S3.STEPID),"066");
break;
case 5:
rt_snprintf(STEP_NAME_S3.STEPNAME, sizeof(STEP_NAME_S3.STEPNAME),"快速加酸");
rt_snprintf(STEP_NAME_S3.STEPID, sizeof(STEP_NAME_S3.STEPID),"090");
break;
case 6:
rt_snprintf(STEP_NAME_S3.STEPNAME, sizeof(STEP_NAME_S3.STEPNAME),"温控加酸");
rt_snprintf(STEP_NAME_S3.STEPID, sizeof(STEP_NAME_S3.STEPID),"091");
break;
case 7:
rt_snprintf(STEP_NAME_S3.STEPNAME, sizeof(STEP_NAME_S3.STEPNAME),"ph检测");
rt_snprintf(STEP_NAME_S3.STEPID, sizeof(STEP_NAME_S3.STEPID),"093");
break;
case 8:
rt_snprintf(STEP_NAME_S3.STEPNAME, sizeof(STEP_NAME_S3.STEPNAME),"ph控制");
rt_snprintf(STEP_NAME_S3.STEPID, sizeof(STEP_NAME_S3.STEPID),"094");
break;
default:
rt_snprintf(STEP_NAME_S3.STEPNAME, sizeof(STEP_NAME_S3.STEPNAME),"");
rt_snprintf(STEP_NAME_S3.STEPID, sizeof(STEP_NAME_S3.STEPID),"000");
}
}
/**
* 数据信息显示
**/
#include "sql/DB_SQLite.h"
#include"ui_data_csv.h"
//数字格式化
void str_step_ui(char *buffer,double scaled_val)
{
int integer_part = (int) scaled_val;
int fractional_part = (int)((scaled_val * 10)-(integer_part*10));
if (fractional_part == 0) {
lv_snprintf(buffer, sizeof(buffer), "%d", integer_part);
} else {
lv_snprintf(buffer, sizeof(buffer), "%d.%d", integer_part, fractional_part);
}
}
void STEP_DATA_set_ui(IO_STEP_DATA* STEPDATA_inf)
{
//步骤信息页面填入
char str_str[4];
char str_step[5];
lv_snprintf(str_str, sizeof(str_str), "%03d", STEPDATA_inf->Step);
lv_label_set_text(guider_ui.screen_stepinf_step,(const char *)str_str);
lv_snprintf(ProgramID, sizeof(ProgramID), STEPDATA_inf->Dyelot);
lv_label_set_text(guider_ui.screen_stepinf_name,(const char *)STEPDATA_inf->Program);
lv_dropdown_set_selected(guider_ui.screen_stepinf_s1,get_step_name(STEPDATA_inf->StepID));
lv_dropdown_set_selected(guider_ui.screen_stepinf_s2,get_step_namer(STEPDATA_inf->StepID_S1));
lv_dropdown_set_selected(guider_ui.screen_stepinf_s3,get_step_namer(STEPDATA_inf->StepID_S2));
str_step_ui(str_step, STEPDATA_inf->Parameter1);
lv_textarea_set_text(guider_ui.screen_stepinf_p1,(const char *)str_step);
str_step_ui(str_step, STEPDATA_inf->Parameter2);
lv_textarea_set_text(guider_ui.screen_stepinf_p2,(const char *)str_step);
str_step_ui(str_step, STEPDATA_inf->Parameter3);
lv_textarea_set_text(guider_ui.screen_stepinf_p3,(const char *)str_step);
str_step_ui(str_step, STEPDATA_inf->Parameter4);
lv_textarea_set_text(guider_ui.screen_stepinf_p4,(const char *)str_step);
str_step_ui(str_step, STEPDATA_inf->Parameter5);
lv_textarea_set_text(guider_ui.screen_stepinf_p5,(const char *)str_step);
str_step_ui(str_step, STEPDATA_inf->Parameter1_S1);
lv_textarea_set_text(guider_ui.screen_stepinf_p1b1,(const char *)str_step);
str_step_ui(str_step, STEPDATA_inf->Parameter2_S1);
lv_textarea_set_text(guider_ui.screen_stepinf_p2b1,(const char *)str_step);
str_step_ui(str_step, STEPDATA_inf->Parameter3_S1);
lv_textarea_set_text(guider_ui.screen_stepinf_p3b1,(const char *)str_step);
str_step_ui(str_step, STEPDATA_inf->Parameter4_S1);
lv_textarea_set_text(guider_ui.screen_stepinf_p4b1,(const char *)str_step);
str_step_ui(str_step, STEPDATA_inf->Parameter5_S1);
lv_textarea_set_text(guider_ui.screen_stepinf_p5b1,(const char *)str_step);
str_step_ui(str_step, STEPDATA_inf->Parameter1_S2);
lv_textarea_set_text(guider_ui.screen_stepinf_p1b2,(const char *)str_step);
str_step_ui(str_step, STEPDATA_inf->Parameter2_S2);
lv_textarea_set_text(guider_ui.screen_stepinf_p2b2,(const char *)str_step);
str_step_ui(str_step, STEPDATA_inf->Parameter3_S2);
lv_textarea_set_text(guider_ui.screen_stepinf_p3b2,(const char *)str_step);
str_step_ui(str_step, STEPDATA_inf->Parameter4_S2);
lv_textarea_set_text(guider_ui.screen_stepinf_p4b2,(const char *)str_step);
str_step_ui(str_step, STEPDATA_inf->Parameter5_S2);
lv_textarea_set_text(guider_ui.screen_stepinf_p5b2,(const char *)str_step);
lv_obj_clear_flag(guider_ui.screen_stepinf_s1b, LV_OBJ_FLAG_HIDDEN);
STEP_SET_MODE=0;//程序页面步骤修改
}
void STEP_DATA_set_ui_w()
{
get_step_sql(lv_dropdown_get_selected (guider_ui.screen_stepinf_s1));
get_step_sqlr2(lv_dropdown_get_selected (guider_ui.screen_stepinf_s2));
get_step_sqlr3(lv_dropdown_get_selected (guider_ui.screen_stepinf_s3));
switch(STEP_SET_MODE){
case 0:
rt_snprintf(stepsql, sizeof(stepsql),"UPDATE ProgramSteps "
"SET StepID='%s',StepName='%s',StepID_S1='%s',StepID_S2='%s',"
"StepName_S1='%s',StepName_S1='%s',"
"P1=%s,P2=%s,P3=%s,P4=%s,P5=%s,"
"P1_S1=%s,P2_S1=%s,P3_S1=%s,P4_S1=%s,P5_S1=%s,"
"P1_S2=%s,P2_S2=%s,P3_S2=%s,P4_S2=%s,P5_S2=%s "
"WHERE Program='%s' and Step=%d;",
STEP_NAME_S1.STEPID,STEP_NAME_S1.STEPNAME,
STEP_NAME_S2.STEPID,STEP_NAME_S3.STEPID,
STEP_NAME_S2.STEPNAME,STEP_NAME_S3.STEPNAME,
lv_textarea_get_text(guider_ui.screen_stepinf_p1),
lv_textarea_get_text(guider_ui.screen_stepinf_p2),
lv_textarea_get_text(guider_ui.screen_stepinf_p3),
lv_textarea_get_text(guider_ui.screen_stepinf_p4),
lv_textarea_get_text(guider_ui.screen_stepinf_p5),
lv_textarea_get_text(guider_ui.screen_stepinf_p1b1),
lv_textarea_get_text(guider_ui.screen_stepinf_p2b1),
lv_textarea_get_text(guider_ui.screen_stepinf_p3b1),
lv_textarea_get_text(guider_ui.screen_stepinf_p4b1),
lv_textarea_get_text(guider_ui.screen_stepinf_p5b1),
lv_textarea_get_text(guider_ui.screen_stepinf_p1b2),
lv_textarea_get_text(guider_ui.screen_stepinf_p2b2),
lv_textarea_get_text(guider_ui.screen_stepinf_p3b2),
lv_textarea_get_text(guider_ui.screen_stepinf_p4b2),
lv_textarea_get_text(guider_ui.screen_stepinf_p5b2),
lv_label_get_text(guider_ui.screen_stepinf_name),
atoi(lv_label_get_text(guider_ui.screen_stepinf_step)));
if( db_send_command(DB_CMD_EXEC, stepsql, 500)==RT_EOK) //
{
}
break;
default: ;
}
STEP_SET_MODE=-1;
}