modbus数据打包解包代码
This commit is contained in:
1 parent
135ce35517
commit
64ca79d1a3
15 files changed
+1220
-965
No files matched your search
@@ -546,9 +546,9 @@ CONFIG_PKG_CJSON_VER="v1.7.17"
|
|||||||
#
|
#
|
||||||
CONFIG_PKG_USING_LVGL=y
|
CONFIG_PKG_USING_LVGL=y
|
||||||
CONFIG_PKG_LVGL_PATH="/packages/multimedia/LVGL/LVGL"
|
CONFIG_PKG_LVGL_PATH="/packages/multimedia/LVGL/LVGL"
|
||||||
CONFIG_PKG_LVGL_THREAD_PRIO=15
|
CONFIG_PKG_LVGL_THREAD_PRIO=25
|
||||||
CONFIG_PKG_LVGL_THREAD_STACK_SIZE=4096
|
CONFIG_PKG_LVGL_THREAD_STACK_SIZE=4096
|
||||||
CONFIG_PKG_LVGL_DISP_REFR_PERIOD=20
|
CONFIG_PKG_LVGL_DISP_REFR_PERIOD=50
|
||||||
# CONFIG_PKG_USING_LVGL_SQUARELINE is not set
|
# CONFIG_PKG_USING_LVGL_SQUARELINE is not set
|
||||||
# CONFIG_PKG_LVGL_USING_EXAMPLES is not set
|
# CONFIG_PKG_LVGL_USING_EXAMPLES is not set
|
||||||
# CONFIG_PKG_LVGL_USING_DEMOS is not set
|
# CONFIG_PKG_LVGL_USING_DEMOS is not set
|
||||||
|
|||||||
+31
-2
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include "rtthread.h"
|
#include "rtthread.h"
|
||||||
#include "modbus.h"
|
#include "modbus.h"
|
||||||
|
#include "SC828_DATA_table.h"
|
||||||
|
|
||||||
#define DBG_TAG "plc.rtu"
|
#define DBG_TAG "plc.rtu"
|
||||||
#define DBG_LVL DBG_LOG
|
#define DBG_LVL DBG_LOG
|
||||||
@@ -37,7 +38,35 @@ static void mb_plc_read_regs(mb_inst_t *hinst)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
u16 regs[64];
|
//输入m0000->rtu2000
|
||||||
|
uint8_t r_buffer[(DI_TABLE_SIZE + 7) / 8];
|
||||||
|
//读取 Modbus bits
|
||||||
|
int mrx = mb_read_bits(hinst, 2000, DI_TABLE_SIZE, r_buffer);
|
||||||
|
if (mrx > 0)
|
||||||
|
{ //解包到数据表
|
||||||
|
for (int i = 0; i < DI_TABLE_SIZE; i++) {
|
||||||
|
di_table[i].current_state = (r_buffer[i / 8] >> (i % 8)) & 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 输出 m0256 -> RTU 2256
|
||||||
|
uint8_t w_buffer[(DO_TABLE_SIZE + 7) / 8]; // 关键:初始化为0
|
||||||
|
// 打包 do_table 到 bit_buffer
|
||||||
|
for (int i = 0; i < DO_TABLE_SIZE; i++) {
|
||||||
|
const int byte_idx = i / 8;
|
||||||
|
const int bit_idx = i % 8;
|
||||||
|
const uint8_t bit_mask = (1U << bit_idx);
|
||||||
|
if (do_table[i].current_state) {
|
||||||
|
w_buffer[byte_idx] |= bit_mask;
|
||||||
|
} else {
|
||||||
|
w_buffer[byte_idx] &= ~bit_mask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 写入 Modbus
|
||||||
|
mb_write_bits(hinst, 2256, DO_TABLE_SIZE, w_buffer);
|
||||||
|
|
||||||
|
|
||||||
|
/* u16 regs[64];
|
||||||
int addr = 7000;
|
int addr = 7000;
|
||||||
int nb = 10;
|
int nb = 10;
|
||||||
int total = mb_write_regs(hinst, addr, nb, regs);
|
int total = mb_write_regs(hinst, addr, nb, regs);
|
||||||
@@ -52,7 +81,7 @@ static void mb_plc_read_regs(mb_inst_t *hinst)
|
|||||||
if (totalM <= 0)
|
if (totalM <= 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mb_plc_thread(void *args)//线程服务函数
|
static void mb_plc_thread(void *args)//线程服务函数
|
||||||
|
|||||||
@@ -457,7 +457,7 @@ void pasre_DAT(const char *api, const char *json_str)
|
|||||||
}
|
}
|
||||||
else if (strcmp(api, "SC851") == 0)
|
else if (strcmp(api, "SC851") == 0)
|
||||||
{//创建数组
|
{//创建数组
|
||||||
cJSON *Dev = cJSON_CreateArray();
|
/* cJSON *Dev = cJSON_CreateArray();
|
||||||
for (int i = 0; i < DIO_TABLE_SIZE; i++) {
|
for (int i = 0; i < DIO_TABLE_SIZE; i++) {
|
||||||
cJSON* item = cJSON_CreateObject();
|
cJSON* item = cJSON_CreateObject();
|
||||||
// 添加 IO 编号
|
// 添加 IO 编号
|
||||||
@@ -469,11 +469,11 @@ void pasre_DAT(const char *api, const char *json_str)
|
|||||||
// 将当前项添加到数组中
|
// 将当前项添加到数组中
|
||||||
cJSON_AddItemToArray(Dev, item);
|
cJSON_AddItemToArray(Dev, item);
|
||||||
}
|
}
|
||||||
cJSON_AddItemToObject(dat,"DIO",Dev);
|
cJSON_AddItemToObject(dat,"DIO",Dev);*/
|
||||||
}
|
}
|
||||||
else if (strcmp(api, "SC852") == 0)
|
else if (strcmp(api, "SC852") == 0)
|
||||||
{//创建数组
|
{//创建数组
|
||||||
cJSON *Dev = cJSON_CreateArray();
|
/* cJSON *Dev = cJSON_CreateArray();
|
||||||
for (int i = 0; i < AIO_TABLE_SIZE; i++) {
|
for (int i = 0; i < AIO_TABLE_SIZE; i++) {
|
||||||
cJSON* item = cJSON_CreateObject();
|
cJSON* item = cJSON_CreateObject();
|
||||||
// 添加 IO 编号
|
// 添加 IO 编号
|
||||||
@@ -483,11 +483,11 @@ void pasre_DAT(const char *api, const char *json_str)
|
|||||||
// 将当前项添加到数组中
|
// 将当前项添加到数组中
|
||||||
cJSON_AddItemToArray(Dev, item);
|
cJSON_AddItemToArray(Dev, item);
|
||||||
}
|
}
|
||||||
cJSON_AddItemToObject(dat,"A",Dev);
|
cJSON_AddItemToObject(dat,"A",Dev);*/
|
||||||
}
|
}
|
||||||
else if (strcmp(api, "SC853") == 0)
|
else if (strcmp(api, "SC853") == 0)
|
||||||
{//创建数组
|
{//创建数组
|
||||||
cJSON *Dev = cJSON_CreateArray();
|
/* cJSON *Dev = cJSON_CreateArray();
|
||||||
for (int i = 0; i < DATA_TABLE_SIZE; i++) {
|
for (int i = 0; i < DATA_TABLE_SIZE; i++) {
|
||||||
cJSON* item = cJSON_CreateObject();
|
cJSON* item = cJSON_CreateObject();
|
||||||
// 添加 IO 编号
|
// 添加 IO 编号
|
||||||
@@ -497,7 +497,7 @@ void pasre_DAT(const char *api, const char *json_str)
|
|||||||
// 将当前项添加到数组中
|
// 将当前项添加到数组中
|
||||||
cJSON_AddItemToArray(Dev, item);
|
cJSON_AddItemToArray(Dev, item);
|
||||||
}
|
}
|
||||||
cJSON_AddItemToObject(dat,"M",Dev);
|
cJSON_AddItemToObject(dat,"M",Dev);*/
|
||||||
}
|
}
|
||||||
else if (strcmp(api, "SC854") == 0) {
|
else if (strcmp(api, "SC854") == 0) {
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include "SC828_DATA_table.h"
|
#include "SC828_DATA_table.h"
|
||||||
#include <rtthread.h>
|
|
||||||
#include "Variable.h"
|
#include "Variable.h"
|
||||||
|
|
||||||
// 系统数据状态表(表格)
|
// 系统数据状态表(表格)
|
||||||
@@ -19,7 +18,7 @@ IO_State_DATA data_table[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// DIO状态表(表格)
|
// DIO状态表(表格)
|
||||||
IO_State_DIO dio_table[] = {
|
IO_State_DIO di_table[] = {
|
||||||
{2001, 0, STR_EMERGENCY_STOP},
|
{2001, 0, STR_EMERGENCY_STOP},
|
||||||
{2002, 0, STR_TEMP_LOCK},
|
{2002, 0, STR_TEMP_LOCK},
|
||||||
{2003, 0, STR_PRESSURE_LOCK},
|
{2003, 0, STR_PRESSURE_LOCK},
|
||||||
@@ -102,8 +101,10 @@ IO_State_DIO dio_table[] = {
|
|||||||
{2080, 0, STR_MATERIAL3_FILL},
|
{2080, 0, STR_MATERIAL3_FILL},
|
||||||
{2081, 0, STR_MATERIAL3_HEAT},
|
{2081, 0, STR_MATERIAL3_HEAT},
|
||||||
{2082, 0, STR_MATERIAL3_STIR},
|
{2082, 0, STR_MATERIAL3_STIR},
|
||||||
|
};
|
||||||
// --- DIO 输出(3001~3066)---
|
// --- DIO 输出(3001~3066)---
|
||||||
{3001, 0, STR_RED}, // 红
|
IO_State_DIO do_table[] = {
|
||||||
|
{3001, 1, STR_RED}, // 红
|
||||||
{3002, 0, STR_GREEN}, // 绿
|
{3002, 0, STR_GREEN}, // 绿
|
||||||
{3003, 0, STR_YELLOW}, // 黄
|
{3003, 0, STR_YELLOW}, // 黄
|
||||||
{3004, 0, STR_ALARM}, // 警报
|
{3004, 0, STR_ALARM}, // 警报
|
||||||
@@ -215,15 +216,21 @@ IO_State_AIO aio_table[] = {
|
|||||||
//步骤数据表最大99
|
//步骤数据表最大99
|
||||||
IO_STEP_DATA step_table[99];
|
IO_STEP_DATA step_table[99];
|
||||||
|
|
||||||
const unsigned char DIO_TABLE_SIZE = sizeof(dio_table) / sizeof(dio_table[0]);
|
const unsigned char DI_TABLE_SIZE = sizeof(di_table) / sizeof(di_table[0]);
|
||||||
|
const unsigned char DO_TABLE_SIZE = sizeof(do_table) / sizeof(do_table[0]);
|
||||||
const unsigned char AIO_TABLE_SIZE = sizeof(aio_table) / sizeof(aio_table[0]);
|
const unsigned char AIO_TABLE_SIZE = sizeof(aio_table) / sizeof(aio_table[0]);
|
||||||
const unsigned char DATA_TABLE_SIZE = sizeof(data_table) / sizeof(data_table[0]);
|
const unsigned char DATA_TABLE_SIZE = sizeof(data_table) / sizeof(data_table[0]);
|
||||||
|
|
||||||
void DATA_Table_Init(){
|
void DATA_Table_Init(){
|
||||||
for(int i=0;i<DIO_TABLE_SIZE;i++)
|
for(int i=0;i<DI_TABLE_SIZE;i++)
|
||||||
{
|
{
|
||||||
dio_table[i].current_state = 0;
|
di_table[i].current_state = 0;
|
||||||
}
|
}
|
||||||
|
for(int i=0;i<DO_TABLE_SIZE;i++)
|
||||||
|
{
|
||||||
|
do_table[i].current_state = 0;
|
||||||
|
}
|
||||||
|
|
||||||
for(int i=0;i<AIO_TABLE_SIZE;i++)
|
for(int i=0;i<AIO_TABLE_SIZE;i++)
|
||||||
{
|
{
|
||||||
aio_table[i].current_Value = 0;
|
aio_table[i].current_Value = 0;
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
#ifndef APPLICATIONS_SC828_DATA_Table_H
|
#ifndef APPLICATIONS_SC828_DATA_Table_H
|
||||||
#define APPLICATIONS_SC828_DATA_Table_H
|
#define APPLICATIONS_SC828_DATA_Table_H
|
||||||
|
|
||||||
|
#include <rtthread.h>
|
||||||
#include "stdbool.h"
|
#include "stdbool.h"
|
||||||
#include "language.h"
|
#include "language.h"
|
||||||
|
|
||||||
// IO状态结构体(可扩展)
|
// IO状态结构体(可扩展)
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int pin; // PLCID
|
int pin; // PLCID
|
||||||
unsigned char current_state; // 当前电平:0=低,1=高
|
rt_bool_t current_state; // 当前电平:0=低,1=高
|
||||||
str_id_t name; // 名称(可选,用于调试)
|
str_id_t name; // 名称(可选,用于调试)
|
||||||
} IO_State_DIO;
|
} IO_State_DIO;
|
||||||
|
|
||||||
@@ -51,12 +52,14 @@ typedef struct {
|
|||||||
double Parameter5_S3;
|
double Parameter5_S3;
|
||||||
} IO_STEP_DATA;
|
} IO_STEP_DATA;
|
||||||
|
|
||||||
extern IO_State_DIO dio_table[];
|
extern IO_State_DIO di_table[];
|
||||||
|
extern IO_State_DIO do_table[];
|
||||||
extern IO_State_AIO aio_table[];
|
extern IO_State_AIO aio_table[];
|
||||||
extern IO_State_DATA data_table[];
|
extern IO_State_DATA data_table[];
|
||||||
extern IO_STEP_DATA step_table[99];
|
extern IO_STEP_DATA step_table[99];
|
||||||
|
|
||||||
extern const unsigned char DIO_TABLE_SIZE;
|
extern const unsigned char DI_TABLE_SIZE;
|
||||||
|
extern const unsigned char DO_TABLE_SIZE;
|
||||||
extern const unsigned char AIO_TABLE_SIZE;
|
extern const unsigned char AIO_TABLE_SIZE;
|
||||||
extern const unsigned char DATA_TABLE_SIZE;
|
extern const unsigned char DATA_TABLE_SIZE;
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
rt_int32_t sys_temperature;//主机环境温度
|
rt_int32_t sys_temperature;//主机环境温度
|
||||||
rt_int32_t sys_humidity;//主机环境湿度
|
rt_int32_t sys_humidity;//主机环境湿度
|
||||||
char sys_var[8];//主机版本0.0.00A
|
char sys_var[8];//主机版本0.0.00A
|
||||||
unsigned char sys_time[6];//系统时间
|
char sys_time[9]="00:00:00";//系统时间
|
||||||
unsigned int sys_run_time;//运行时间
|
unsigned int sys_run_time=0;//运行时间
|
||||||
int pow_bat;//电池电压
|
int pow_bat;//电池电压
|
||||||
int pow_code;//主电压
|
int pow_code;//主电压
|
||||||
int pow_dev1;//设备电压.通讯
|
int pow_dev1;//设备电压.通讯
|
||||||
@@ -28,7 +28,7 @@ char MACHINE_CALL = 0;
|
|||||||
char MACHINE_USER = 0;
|
char MACHINE_USER = 0;
|
||||||
|
|
||||||
// 字符串变量(RAM 中可修改)
|
// 字符串变量(RAM 中可修改)
|
||||||
char Work[25];
|
char Work[25]="SC----------";
|
||||||
char Dye[25];
|
char Dye[25];
|
||||||
char Process[50];
|
char Process[50];
|
||||||
char Message[40];
|
char Message[40];
|
||||||
@@ -42,25 +42,25 @@ unsigned int RUN = 0;
|
|||||||
unsigned int STEPID = 0;
|
unsigned int STEPID = 0;
|
||||||
|
|
||||||
// 浮点变量
|
// 浮点变量
|
||||||
float MTT = 0.0f;
|
float MTT = 0.0f;//主缸温度
|
||||||
float MTL = 0.0f;
|
float MTL = 0.0f;//主缸水位
|
||||||
float MTH = 6.0f; // 默认目标温度
|
float MTH = 6.0f;//主缸ph
|
||||||
float MST = 0.0f;
|
float MST = 0.0f;//目标温度
|
||||||
float MUT = 0.0f;
|
float MUT = 0.0f;//主缸温度2
|
||||||
float STTA = 0.0f;
|
float STTA = 0.0f;//料a温度
|
||||||
float STLA = 0.0f;
|
float STLA = 0.0f;//料a水位
|
||||||
float STTB = 0.0f;
|
float STTB = 0.0f;//料b温度
|
||||||
float STLB = 0.0f;
|
float STLB = 0.0f;//料b水位
|
||||||
float STTC = 0.0f;
|
float STTC = 0.0f;//料c温度
|
||||||
float STLC = 0.0f;
|
float STLC = 0.0f;//料c水位
|
||||||
|
|
||||||
// 控制输出
|
// 控制输出
|
||||||
unsigned int Pump = 0;
|
unsigned int Pump = 0;//主泵
|
||||||
unsigned int TC = 0;
|
unsigned int TC = 0;//温度比例
|
||||||
unsigned int Fan = 0;
|
unsigned int Fan = 0;//风机
|
||||||
unsigned int Pull = 0;
|
unsigned int Pull = 0;//提布
|
||||||
unsigned int Swing = 0;
|
unsigned int Swing = 0;//摆布
|
||||||
unsigned int STA = 0;
|
unsigned int STA = 0;//料a比例
|
||||||
unsigned int STB = 0;
|
unsigned int STB = 0;
|
||||||
unsigned int STC = 0;
|
unsigned int STC = 0;
|
||||||
unsigned int Time = 0;
|
unsigned int Time = 0;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
extern rt_int32_t sys_temperature;//主机环境温度
|
extern rt_int32_t sys_temperature;//主机环境温度
|
||||||
extern rt_int32_t sys_humidity;//主机环境湿度
|
extern rt_int32_t sys_humidity;//主机环境湿度
|
||||||
extern char sys_var[8];//主机版本0.0.00A
|
extern char sys_var[8];//主机版本0.0.00A
|
||||||
extern unsigned char sys_time[6];//系统时间
|
extern char sys_time[9];//系统时间
|
||||||
extern unsigned int sys_run_time;//运行时间
|
extern unsigned int sys_run_time;//运行时间
|
||||||
extern int pow_bat;//电池电压
|
extern int pow_bat;//电池电压
|
||||||
extern int pow_code;//主电压
|
extern int pow_code;//主电压
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
*********************/
|
*********************/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "lvgl.h"
|
#include "lvgl.h"
|
||||||
|
#include "custom.h"
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "lvgl.h"
|
#include "lvgl.h"
|
||||||
|
#include "gui_guider.h"
|
||||||
|
|
||||||
#if LV_USE_GUIDER_SIMULATOR && LV_USE_FREEMASTER
|
#if LV_USE_GUIDER_SIMULATOR && LV_USE_FREEMASTER
|
||||||
#include "freemaster_client.h"
|
#include "freemaster_client.h"
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
#include "lvgl.h"
|
#include "lvgl.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "gui_guider.h"
|
||||||
|
#include "widgets_init.h"
|
||||||
|
|
||||||
#if LV_USE_GUIDER_SIMULATOR && LV_USE_FREEMASTER
|
#if LV_USE_GUIDER_SIMULATOR && LV_USE_FREEMASTER
|
||||||
#include "gg_external_data.h"
|
#include "gg_external_data.h"
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
#include "lvgl.h"
|
#include "lvgl.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "widgets_init.h"
|
||||||
|
#include "gui_guider.h"
|
||||||
|
|
||||||
void setup_scr_screen(lv_ui *ui)
|
void setup_scr_screen(lv_ui *ui)
|
||||||
{
|
{
|
||||||
@@ -138,7 +140,7 @@ void setup_scr_screen(lv_ui *ui)
|
|||||||
lv_label_set_text(ui->screen_temp, "120.5");
|
lv_label_set_text(ui->screen_temp, "120.5");
|
||||||
lv_label_set_long_mode(ui->screen_temp, LV_LABEL_LONG_CLIP);
|
lv_label_set_long_mode(ui->screen_temp, LV_LABEL_LONG_CLIP);
|
||||||
lv_obj_set_pos(ui->screen_temp, 50, 10);
|
lv_obj_set_pos(ui->screen_temp, 50, 10);
|
||||||
lv_obj_set_size(ui->screen_temp, 70, 25);
|
lv_obj_set_size(ui->screen_temp, 75, 25);
|
||||||
|
|
||||||
//Write style for screen_temp, Part: LV_PART_MAIN, State: LV_STATE_DEFAULT.
|
//Write style for screen_temp, Part: LV_PART_MAIN, State: LV_STATE_DEFAULT.
|
||||||
lv_obj_set_style_border_width(ui->screen_temp, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
|
lv_obj_set_style_border_width(ui->screen_temp, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
|
||||||
@@ -190,7 +192,7 @@ void setup_scr_screen(lv_ui *ui)
|
|||||||
lv_obj_set_style_border_width(ui->screen_order, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
|
lv_obj_set_style_border_width(ui->screen_order, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
|
||||||
lv_obj_set_style_radius(ui->screen_order, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
|
lv_obj_set_style_radius(ui->screen_order, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
|
||||||
lv_obj_set_style_text_color(ui->screen_order, lv_color_hex(0x000000), LV_PART_MAIN|LV_STATE_DEFAULT);
|
lv_obj_set_style_text_color(ui->screen_order, lv_color_hex(0x000000), LV_PART_MAIN|LV_STATE_DEFAULT);
|
||||||
lv_obj_set_style_text_font(ui->screen_order, &lv_font_simsun_32, LV_PART_MAIN|LV_STATE_DEFAULT);
|
lv_obj_set_style_text_font(ui->screen_order, &lv_font_simsun_30, LV_PART_MAIN|LV_STATE_DEFAULT);
|
||||||
lv_obj_set_style_text_opa(ui->screen_order, 255, LV_PART_MAIN|LV_STATE_DEFAULT);
|
lv_obj_set_style_text_opa(ui->screen_order, 255, LV_PART_MAIN|LV_STATE_DEFAULT);
|
||||||
lv_obj_set_style_text_letter_space(ui->screen_order, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
|
lv_obj_set_style_text_letter_space(ui->screen_order, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
|
||||||
lv_obj_set_style_text_line_space(ui->screen_order, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
|
lv_obj_set_style_text_line_space(ui->screen_order, 0, LV_PART_MAIN|LV_STATE_DEFAULT);
|
||||||
@@ -5805,7 +5807,7 @@ void setup_scr_screen(lv_ui *ui)
|
|||||||
lv_textarea_set_accepted_chars(ui->screen_pname_set, "");
|
lv_textarea_set_accepted_chars(ui->screen_pname_set, "");
|
||||||
lv_textarea_set_max_length(ui->screen_pname_set, 32);
|
lv_textarea_set_max_length(ui->screen_pname_set, 32);
|
||||||
#if LV_USE_KEYBOARD != 0 || LV_USE_ZH_KEYBOARD != 0
|
#if LV_USE_KEYBOARD != 0 || LV_USE_ZH_KEYBOARD != 0
|
||||||
// lv_obj_add_event_cb(ui->screen_pname_set, ta_event_cb, LV_EVENT_ALL, ui->g_kb_top_layer);
|
lv_obj_add_event_cb(ui->screen_pname_set, ta_event_cb, LV_EVENT_ALL, ui->g_kb_top_layer);
|
||||||
#endif
|
#endif
|
||||||
lv_obj_set_pos(ui->screen_pname_set, 305, -1);
|
lv_obj_set_pos(ui->screen_pname_set, 305, -1);
|
||||||
lv_obj_set_size(ui->screen_pname_set, 679, 50);
|
lv_obj_set_size(ui->screen_pname_set, 679, 50);
|
||||||
@@ -5965,7 +5967,7 @@ void setup_scr_screen(lv_ui *ui)
|
|||||||
lv_textarea_set_accepted_chars(ui->screen_machine_name, "");
|
lv_textarea_set_accepted_chars(ui->screen_machine_name, "");
|
||||||
lv_textarea_set_max_length(ui->screen_machine_name, 32);
|
lv_textarea_set_max_length(ui->screen_machine_name, 32);
|
||||||
#if LV_USE_KEYBOARD != 0 || LV_USE_ZH_KEYBOARD != 0
|
#if LV_USE_KEYBOARD != 0 || LV_USE_ZH_KEYBOARD != 0
|
||||||
//lv_obj_add_event_cb(ui->screen_machine_name, ta_event_cb, LV_EVENT_ALL, ui->g_kb_top_layer);
|
lv_obj_add_event_cb(ui->screen_machine_name, ta_event_cb, LV_EVENT_ALL, ui->g_kb_top_layer);
|
||||||
#endif
|
#endif
|
||||||
lv_obj_set_pos(ui->screen_machine_name, 150, 70);
|
lv_obj_set_pos(ui->screen_machine_name, 150, 70);
|
||||||
lv_obj_set_size(ui->screen_machine_name, 200, 50);
|
lv_obj_set_size(ui->screen_machine_name, 200, 50);
|
||||||
@@ -6051,7 +6053,7 @@ void setup_scr_screen(lv_ui *ui)
|
|||||||
lv_textarea_set_accepted_chars(ui->screen_machine_id, "");
|
lv_textarea_set_accepted_chars(ui->screen_machine_id, "");
|
||||||
lv_textarea_set_max_length(ui->screen_machine_id, 32);
|
lv_textarea_set_max_length(ui->screen_machine_id, 32);
|
||||||
#if LV_USE_KEYBOARD != 0 || LV_USE_ZH_KEYBOARD != 0
|
#if LV_USE_KEYBOARD != 0 || LV_USE_ZH_KEYBOARD != 0
|
||||||
//lv_obj_add_event_cb(ui->screen_machine_id, ta_event_cb, LV_EVENT_ALL, ui->g_kb_top_layer);
|
lv_obj_add_event_cb(ui->screen_machine_id, ta_event_cb, LV_EVENT_ALL, ui->g_kb_top_layer);
|
||||||
#endif
|
#endif
|
||||||
lv_obj_set_pos(ui->screen_machine_id, 150, 10);
|
lv_obj_set_pos(ui->screen_machine_id, 150, 10);
|
||||||
lv_obj_set_size(ui->screen_machine_id, 200, 50);
|
lv_obj_set_size(ui->screen_machine_id, 200, 50);
|
||||||
|
|||||||
@@ -9,12 +9,16 @@
|
|||||||
*/
|
*/
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
#include <rtdevice.h>
|
#include <rtdevice.h>
|
||||||
|
#include <applications/data/Variable.h>
|
||||||
#include <board.h>
|
#include <board.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <string.h>
|
||||||
#include <guider/custom/custom.h>
|
#include <guider/custom/custom.h>
|
||||||
#include <guider/generated/events_init.h>
|
#include <guider/generated/events_init.h>
|
||||||
#include <guider/generated/gui_guider.h>
|
#include <guider/generated/gui_guider.h>
|
||||||
|
#include <guider/generated/widgets_init.h>
|
||||||
#include "lvgl.h"
|
#include "lvgl.h"
|
||||||
//#include "lv_demo_widgets.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define DBG_TAG "gui"
|
#define DBG_TAG "gui"
|
||||||
@@ -24,11 +28,54 @@
|
|||||||
#define LCD_BL_PIN GET_PIN(D,12)
|
#define LCD_BL_PIN GET_PIN(D,12)
|
||||||
#define LCD_RST_PIN GET_PIN(D,11)
|
#define LCD_RST_PIN GET_PIN(D,11)
|
||||||
|
|
||||||
|
|
||||||
|
void setup_user_screen(lv_ui *ui)
|
||||||
|
{
|
||||||
|
lv_obj_clear_flag(lv_tabview_get_content(ui->screen_tabview), LV_OBJ_FLAG_SCROLLABLE);//禁止左右滑动
|
||||||
|
lv_textarea_set_text(ui->screen_machine_id, machine_ID);//设备id
|
||||||
|
lv_textarea_set_text(ui->screen_machine_name, machine_name);//设备名
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t nows;
|
||||||
|
char time_str[9]; //"0000:00\0"
|
||||||
|
char temp_str[6]; //"120.5"
|
||||||
|
char wter_str[6]; //"120.5"
|
||||||
|
void setup_s_screen(lv_ui *ui)
|
||||||
|
{
|
||||||
|
//系统时间
|
||||||
|
time(&nows);
|
||||||
|
struct tm *t = localtime(&nows);
|
||||||
|
snprintf(sys_time, sizeof(sys_time), "%02d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec);
|
||||||
|
lv_label_set_text(ui->screen_SYS_TIME, (const char *)sys_time);//系统时间
|
||||||
|
//运行时间
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wformat-truncation"
|
||||||
|
snprintf(time_str, sizeof(time_str), "%04d:%02d", sys_run_time / 60, sys_run_time % 60);
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
lv_label_set_text(ui->screen_RUN_TIME, (const char *)time_str);//显示运行时间
|
||||||
|
//工单
|
||||||
|
lv_label_set_text(ui->screen_order, (const char *)Work);
|
||||||
|
//水位
|
||||||
|
snprintf(wter_str, sizeof(wter_str), "%04.0f", MTL);
|
||||||
|
lv_label_set_text(ui->screen_water, (const char *)wter_str);
|
||||||
|
//温度
|
||||||
|
snprintf(temp_str, sizeof(temp_str), "%05.1f", MTT);
|
||||||
|
lv_label_set_text(ui->screen_temp, (const char *)temp_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void time_update_timer_cb(lv_timer_t * timer)
|
||||||
|
{
|
||||||
|
setup_s_screen(&guider_ui);
|
||||||
|
}
|
||||||
|
|
||||||
void lv_user_gui_init(void)
|
void lv_user_gui_init(void)
|
||||||
{
|
{
|
||||||
//gui_guider_setup();
|
|
||||||
//lv_demo_widgets();
|
|
||||||
setup_ui(&guider_ui);
|
setup_ui(&guider_ui);
|
||||||
events_init(&guider_ui);
|
events_init(&guider_ui);
|
||||||
custom_init(&guider_ui);
|
custom_init(&guider_ui);
|
||||||
|
setup_user_screen(&guider_ui);
|
||||||
|
|
||||||
|
// 创建一个每 500ms 触发一次的定时器
|
||||||
|
lv_timer_create(time_update_timer_cb, 500, NULL);
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ static int lvgl_thread_init(void)
|
|||||||
rt_err_t err;
|
rt_err_t err;
|
||||||
|
|
||||||
err = rt_thread_init(&lvgl_thread, "LVGL", lvgl_thread_entry, RT_NULL,
|
err = rt_thread_init(&lvgl_thread, "LVGL", lvgl_thread_entry, RT_NULL,
|
||||||
&lvgl_thread_stack[0], sizeof(lvgl_thread_stack), PKG_LVGL_THREAD_PRIO, 10);
|
&lvgl_thread_stack[0], sizeof(lvgl_thread_stack), PKG_LVGL_THREAD_PRIO, 20);
|
||||||
if(err != RT_EOK)
|
if(err != RT_EOK)
|
||||||
{
|
{
|
||||||
LOG_E("Failed to create LVGL thread");
|
LOG_E("Failed to create LVGL thread");
|
||||||
|
|||||||
+2
-2
@@ -263,9 +263,9 @@
|
|||||||
/* LVGL: powerful and easy-to-use embedded GUI library */
|
/* LVGL: powerful and easy-to-use embedded GUI library */
|
||||||
|
|
||||||
#define PKG_USING_LVGL
|
#define PKG_USING_LVGL
|
||||||
#define PKG_LVGL_THREAD_PRIO 15
|
#define PKG_LVGL_THREAD_PRIO 25
|
||||||
#define PKG_LVGL_THREAD_STACK_SIZE 4096
|
#define PKG_LVGL_THREAD_STACK_SIZE 4096
|
||||||
#define PKG_LVGL_DISP_REFR_PERIOD 20
|
#define PKG_LVGL_DISP_REFR_PERIOD 50
|
||||||
#define PKG_LVGL_USING_V080310
|
#define PKG_LVGL_USING_V080310
|
||||||
#define PKG_LVGL_VER_NUM 0x080310
|
#define PKG_LVGL_VER_NUM 0x080310
|
||||||
/* end of LVGL: powerful and easy-to-use embedded GUI library */
|
/* end of LVGL: powerful and easy-to-use embedded GUI library */
|
||||||
|
|||||||
Reference in new issue
Block a user