#include "APPDEF.H"
#include "stdio.h"
#include "string.h"
#include "math.h"
uint8_t pageNum = 13;
extern void DataPrint(uint8_t *buf, uint8_t len);
extern uint8_t DataInbuf[60u];
extern osSemaphoreId semDataBack;
extern float Temperature;
//

struct Pset Set;
uint8_t DataLogValue[100]; // 当前数据记录
//
uint8_t MaxWeight;
uint8_t MaxTemp;
float Resolution;
float ResolutionWater;
float SHIZHONG;
float HUICHAO;
float StartWeight      = 0;
float StopWeight       = 0;
float PercentData     = 0.0f;
float WaterPercentData     = 0.0f;
float WeightOld        = 0.0f;
uint16_t CountNochange = 0;
uint16_t CountDelay    = 0;
uint8_t SCount         = 0;
uint16_t SRange        = 100;
float DisData          = 0;
float FinishDisData;
uint8_t NameBuf[40];
uint8_t startTime[20];
bool Finisflag = false;
//

void FM24DataCRC()
{
    FM24_Read(RW_Set, (uint8_t *)&Set, sizeof(Set));
    FM24_Read(RW_Set, (uint8_t *)&Set, sizeof(Set));
    if ((CRCHead != Set.CRC_Head) || (CRCEnd != Set.CRC_Tail)) { // 如果EEPROM中的数据未初始化或异常，则重新写入默认值
        Set.CRC_Head         = CRCHead;
        Set.AutoTimeStop     = 60;                                 // 60秒
        Set.AutoWeightChange = 5;                                  // 5mg
        Set.TempSet          = 105;                                // 105℃
        Set.TimeStop         = 5;                                  // 5分钟
        Set.AutoStyle        = 0;                                  // 停机方式 自动停机
        Set.FastStyle        = 0;                                  // 干燥模式 快速
        Set.FilterQ          = 5;                                  // 滤波器信任度
        Set.SensorQ          = 2;                                  // 传感器信任度
        Set.HoldTime         = 5;                                  // 稳定时间 5秒
        Set.RuBianLiang      = 5;                                  // 蠕变量
        Set.RuBianTime       = 0;                                  // 蠕变时间
        Set.ZeroTrack        = 1;                                  // 零点跟踪
        Set.TempDelta        = 0;                                  // 校准温度差
        Set.WeightSet        = 0;                                  // 校准重量
        Set.BaudRate         = 9600;                               // 波特率
        Set.SW0              = false;                              // 自定义开关1
        Set.SW1              = false;                              // 自定义开关2
        Set.SW2              = false;                              // 自定义开关3
        Set.PercentType    = 0;                              			 // 默认显示含水量
        sprintf((char *)Set.Title, "测试结果");                    // 标题
        sprintf((char *)Set.TitleOne, "山东云唐智能科技有限公司"); // 标题1
        sprintf((char *)Set.TitleTwo, "");                         // 标题2
        sprintf((char *)Set.TitleThree, "");                       // 标题3
        sprintf((char *)Set.UserName, "实验室");                   // 用户名
        sprintf((char *)Set.UserPwd, "123456");                    // 密码
        Set.CRC_Tail = CRCEnd;
        FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
        FM24_Write(CalibrateWeight2Set, (uint8_t *)&CalibrateWeight2, sizeof(CalibrateWeight2));
    }
    FM24_Read(CalibrateWeight2Set, (uint8_t *)&CalibrateWeight2, sizeof(CalibrateWeight2));
    if (CalibrateWeight2.WeightSlope < 0.0000001) 
		{
			  CalibrateWeight2.WeightSlope = 0.0000818f;
        CalibrateWeight2.WeightZero  = 745430;
    }

}
//bool t17Dis = false;
//uint16_t t17DisCount =0;
bool t18Dis = false;
uint16_t t18DisCount =0;
osSemaphoreId semDataChange;
void DataUnpack(const void *p_arg)
{
    static uint8_t buf[150]__attribute__((at(0x20000000 + 0x1000)));
    osSemaphoreDef(semDataChange);
    semDataChange = osSemaphoreCreate(osSemaphore(semDataChange), 0);
    uint8_t i, j;
    for (;;) //
    {
        osSemaphoreWait(semDataBack, osWaitForever);
        switch ((DataInbuf[1] << 8) | (DataInbuf[2])) // 页面控件ID
        {
        case 0x0002: // 开始按钮
            if (weightChanging) {
                sprintf((char *)buf, "play 1,3,0\xFF\xFF\xFF\0");
                DataPrint(buf, strlen((const char *)buf));
//                    sprintf((char *)buf, "t17.txt=\"传感器不稳定\"\xFF\xFF\xFF\0");
//                    DataPrint(buf, strlen((const char *)buf));
//										t17Dis = true;
//										t17DisCount =0;
                break;
            }
            if (WeightData2 < 1) {
                sprintf((char *)buf, "play 1,6,0\xFF\xFF\xFF\0");
                DataPrint(buf, strlen((const char *)buf));
//                    sprintf((char *)buf, "t17.txt=\"样品重量过轻\"\xFF\xFF\xFF\0");
//                    DataPrint(buf, strlen((const char *)buf));
//										t17Dis = true;
//										t17DisCount =0;
                break;
            }
            if (WeightData2 > MaxWeight) {
                sprintf((char *)buf, "play 1,7,0\xFF\xFF\xFF\0");
                DataPrint(buf, strlen((const char *)buf));
//                    sprintf((char *)buf, "t17.txt=\"样品重量过重\"\xFF\xFF\xFF\0");
//                    DataPrint(buf, strlen((const char *)buf));
//										t17Dis = true;
//										t17DisCount =0;
                break;
            }
            if (SafeCheck())
            {   // 请关闭加热仓
                sprintf((char *)buf, "play 1,8,0\xFF\xFF\xFF\0");
                DataPrint(buf, strlen((const char *)buf));
//                    sprintf((char *)buf, "t17.txt=\"请关闭加热仓\"\xFF\xFF\xFF\0");
//                    DataPrint(buf, strlen((const char *)buf));
//										t17Dis = true;
//										t17DisCount =0;
                break;
            }

            sprintf((char *)buf, "play 1,5,0\xFF\xFF\xFF\0");
            DataPrint(buf, strlen((const char *)buf));
            osDelay(100);
            pageNum = 1;
            sprintf((char *)startTime, "%04d-%02d-%02d %02d:%02d", (DataInbuf[4] << 8 | DataInbuf[3]), DataInbuf[5], DataInbuf[6], DataInbuf[7], DataInbuf[8]);
            for (i = 0; i < strlen((const char *)(&DataInbuf[9])) - 1; i++) {
                NameBuf[i] = DataInbuf[i + 9];
            }
            break;
        case 0x0013: // 定时停机时间
        {
            uint16_t TimeSt = DataInbuf[3] + (DataInbuf[4] << 8);
            if (TimeSt == 0) {
                Set.TimeStop = 1;
            } else if (TimeSt > 99) {
                Set.TimeStop = 99;
            } else {
                Set.TimeStop = TimeSt;
            }
            sprintf((char *)buf, "main.n0.val=%d\xFF\xFF\xFF\0", Set.TimeStop);
            DataPrint(buf, strlen((const char *)buf));
        }
        FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
        break;
        case 0x0014: // 干燥温度
        {
            uint16_t TempSe = DataInbuf[3] + (DataInbuf[4] << 8);
            if (TempSe < 40) {
                Set.TempSet = 40;
            } else if (TempSe > MaxTemp) {
                Set.TempSet = MaxTemp;
            } else {
                Set.TempSet = TempSe;
            }
            sprintf((char *)buf, "main.n1.val=%d\xFF\xFF\xFF\0", Set.TempSet);
            DataPrint(buf, strlen((const char *)buf));
        }
        FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
        break;
        case 0x0015: // 称重调零
            if( fabs(WeightData2) <= MaxWeight * 0.04 )	//	型评  置零装置的效果不得大于总秤量的4%
            {
                i = 0;
                osDelay(100);
                sprintf((char *)buf, "tsw b1,0\xFF\xFF\xFF\0");
                DataPrint(buf, strlen((const char *)buf));
                do {
                    i++;
                    if (fabs(CalibrateWeight2.WeightZero - ADvalue2filter) > 5) 
										{
                        WeightZeroOld = CalibrateWeight2.WeightZero = ADvalue2filter;
                        osDelay(600);
                    } 
										else
										{
											  WeightZeroOld = CalibrateWeight2.WeightZero = ADvalue2filter;
                        sprintf((char *)buf, "t18.txt=\"调零成功\"\xFF\xFF\xFF\0");
                        DataPrint(buf, strlen((const char *)buf));
                        t18Dis = true;
                        t18DisCount =0;
                        break;
                    }
                } while (i < 12);
            }
            else
            {
                i = 12;
            }
            if( i >= 12 )
            {
                sprintf((char *)buf, "t18.txt=\"调零失败\"\xFF\xFF\xFF\0");
                DataPrint(buf, strlen((const char *)buf));
                t18Dis = true;
                t18DisCount =0;
            }
            sprintf((char *)buf, "tsw b1,1\xFF\xFF\xFF\0");
            DataPrint(buf, strlen((const char *)buf));
            FM24_Write(CalibrateWeight2Set, (uint8_t *)&CalibrateWeight2, sizeof(CalibrateWeight2));
            break;
        case 0x0022: // 停机方式
            Set.AutoStyle = DataInbuf[3];
            FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
            break;
        case 0x0023: //  干燥模式
            Set.FastStyle = DataInbuf[3];
            FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
            break;
        case 0x0101: // 停止/返回按钮
            if ((Set.AutoStyle == 1) && (!Finisflag)) {
                Finisflag = true;
            } else {
                Finisflag = false;
                pageNum   = 0;
            }
            break;
        case 0x0129: // 保存
						if( (SHIZHONG == 999) && (HUICHAO == 999))
						{
							sprintf((char *)buf, "DataDeal.DataLog.insert(\"%s^%s^%.3fg^%.3fg^%.2f%%^%.2f%%^-----%%^-----%%\")\xFF\xFF\xFF\0", NameBuf, startTime, StartWeight, StopWeight, WaterPercentData, 100.0f - WaterPercentData);
						}
						if( (SHIZHONG == 999) && (HUICHAO != 999))
						{						
							sprintf((char *)buf, "DataDeal.DataLog.insert(\"%s^%s^%.3fg^%.3fg^%.2f%%^%.2f%%^-----%%^%.2f%%\")\xFF\xFF\xFF\0", NameBuf, startTime, StartWeight, StopWeight, WaterPercentData, 100.0f - WaterPercentData, HUICHAO);
						}
						if( (SHIZHONG != 999) && (HUICHAO == 999))
						{
							sprintf((char *)buf, "DataDeal.DataLog.insert(\"%s^%s^%.3fg^%.3fg^%.2f%%^%.2f%%^%.2f%%^-----%%\")\xFF\xFF\xFF\0", NameBuf, startTime, StartWeight, StopWeight, WaterPercentData, 100.0f - WaterPercentData, SHIZHONG);
						}
						if( (SHIZHONG != 999) && (HUICHAO != 999))
						{
							sprintf((char *)buf, "DataDeal.DataLog.insert(\"%s^%s^%.3fg^%.3fg^%.2f%%^%.2f%%^%.2f%%^%.2f%%\")\xFF\xFF\xFF\0", NameBuf, startTime, StartWeight, StopWeight, WaterPercentData, 100.0f - WaterPercentData, SHIZHONG, HUICHAO);
						}
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "RunPage.t8.txt=\"保存成功!\"\xFF\xFF\xFF\0");
            DataPrint(buf, strlen((const char *)buf));
            break;
        case 0x012A: // 打印
            sprintf((char *)buf, "/****************************/\r\n  %s\r\n\0", Set.Title);
            USART2Print(buf, strlen((const char *)buf));
            if (Set.SW0) {
                sprintf((char *)buf, "  %s\r\n\0", Set.TitleOne);
                USART2Print(buf, strlen((const char *)buf));
            }
            if (Set.SW1) {
                sprintf((char *)buf, "  %s\r\n\0", Set.TitleTwo);
                USART2Print(buf, strlen((const char *)buf));
            }
            if (Set.SW2) {
                sprintf((char *)buf, "  %s\r\n\0", Set.TitleThree);
                USART2Print(buf, strlen((const char *)buf));
            }
						
						if( (SHIZHONG == 999) && (HUICHAO == 999))
						{
							sprintf((char *)buf, "  样品名：%s\r\n  测试时间：%s\r\n  起始重量：%.3fg\r\n  结束重量: %.3fg\r\n  含水量: %.2f%% \r\n  含固量: %.2f%%\r\n  湿重率: -----%%\r\n  回潮率: -----%%\r\n\0", NameBuf, startTime, StartWeight, StopWeight, WaterPercentData, 100.0f - WaterPercentData);
						}
						if( (SHIZHONG == 999) && (HUICHAO != 999))
						{						
							sprintf((char *)buf, "  样品名：%s\r\n  测试时间：%s\r\n  起始重量：%.3fg\r\n  结束重量: %.3fg\r\n  含水量: %.2f%% \r\n  含固量: %.2f%%\r\n  湿重率: -----%%\r\n  回潮率: %.2f%%\r\n\0", NameBuf, startTime, StartWeight, StopWeight, WaterPercentData, 100.0f - WaterPercentData, HUICHAO);
						}
						if( (SHIZHONG != 999) && (HUICHAO == 999))
						{
							sprintf((char *)buf, "  样品名：%s\r\n  测试时间：%s\r\n  起始重量：%.3fg\r\n  结束重量: %.3fg\r\n  含水量: %.2f%% \r\n  含固量: %.2f%%\r\n  湿重率: %.2f%%\r\n  回潮率:-----%%\r\n\0", NameBuf, startTime, StartWeight, StopWeight, WaterPercentData, 100.0f - WaterPercentData, SHIZHONG);
						}
						if( (SHIZHONG != 999) && (HUICHAO != 999))
						{
							sprintf((char *)buf, "  样品名：%s\r\n  测试时间：%s\r\n  起始重量：%.3fg\r\n  结束重量: %.3fg\r\n  含水量: %.2f%% \r\n  含固量: %.2f%%\r\n  湿重率: %.2f%%\r\n  回潮率: %.2f%%\r\n\0", NameBuf, startTime, StartWeight, StopWeight, WaterPercentData, 100.0f - WaterPercentData, SHIZHONG, HUICHAO);
						}

						
            USART2Print(buf, strlen((const char *)buf));
            sprintf((char *)buf, "/****************************/\r\n\r\n\r\n\r\n \0");
            USART2Print(buf, strlen((const char *)buf));
            break;
        case 0x012B: // 查询
            break;
        case 0x012C://含固量含水量
            Set.PercentType = Set.PercentType + 1;
            if(Set.PercentType >= 4 )
                Set.PercentType = 0;
            FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
            break;
        case 0x0201: // 称重设置
            sprintf((char *)buf, "page WeightSet\xFF\xFF\xFF\0");
            DataPrint(buf, strlen((const char *)buf));
            pageNum = 3;
            sprintf((char *)buf, "WeightSet.cb5.val=%d\xFF\xFF\xFF\0", Set.FilterQ);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "WeightSet.cb4.val=%d\xFF\xFF\xFF\0", Set.RuBianLiang);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "WeightSet.cb3.val=%d\xFF\xFF\xFF\0", Set.SensorQ);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "WeightSet.cb2.val=%d\xFF\xFF\xFF\0", Set.RuBianTime);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "WeightSet.cb1.val=%d\xFF\xFF\xFF\0", Set.HoldTime);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "WeightSet.cb0.val=%d\xFF\xFF\xFF\0", Set.ZeroTrack);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "WeightSet.n0.val=%d\xFF\xFF\xFF\0", Set.AutoTimeStop);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "WeightSet.n1.val=%d\xFF\xFF\xFF\0", Set.AutoWeightChange);
            DataPrint(buf, strlen((const char *)buf));
            break;
        case 0x0202: // 标定设置
            pageNum = 4;
            break;
        case 0x0203: // 打印设置
            pageNum = 5;
            break;
        case 0x0206: // 系统设置
            pageNum = 8;
            sprintf((char *)buf, "SysSet.t14.txt=\"%s\"\xFF\xFF\xFF\0", Set.UserName);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "SysSet.t0.txt=\"\"\xFF\xFF\xFF\0");
            DataPrint(buf, strlen((const char *)buf));
            break;
        case 0x0207: // 返回
            pageNum = 0;
            break;
        case 0x030C: // 滤波器信任度
            Set.FilterQ = DataInbuf[3];
            FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
            break;
        case 0x030A: // 传感器信任度
            Set.SensorQ = DataInbuf[3];
            FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
            break;
        case 0x0308: // 稳定时间
            Set.HoldTime = DataInbuf[3];
            FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
            break;
        case 0x030B: // 蠕变量
            Set.RuBianLiang = DataInbuf[3];
            FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
            break;
        case 0x0309: // 蠕变时间
            Set.RuBianTime = DataInbuf[3];
            FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
            break;
        case 0x0307: // 零点跟踪
            Set.ZeroTrack = DataInbuf[3];
            FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
            break;
        case 0x0301: // 自动停机时间
            if(DataInbuf[3] <= 5)
            {
                Set.AutoTimeStop = 5;
            }
            else if(DataInbuf[3] > 120)
            {
                Set.AutoTimeStop = 120;
            }
            else
            {
                Set.AutoTimeStop =  DataInbuf[3];
            }
            FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
            break;
        case 0x0302: // 自动停机重量
            if(DataInbuf[3] <= 5)
            {
                Set.AutoWeightChange = 5;
            }
            else if(DataInbuf[3] > 200)
            {
                Set.AutoWeightChange = 200;
            }
            else
            {
                Set.AutoWeightChange =  DataInbuf[3];
            }
            FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
            break;
        case 0x0310: // 返回
            pageNum = 2;
            break;
        case 0x0401:
            Set.TempDelta = (DataInbuf[3] + (DataInbuf[4] << 8)) / 10.0f - (Temperature - Set.TempDelta);
            FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
            break;
        case 0x0403:
            CalibrateWeight2.WeightSlope = ((DataInbuf[3] + (DataInbuf[4] << 8) + (DataInbuf[5] << 16) + (DataInbuf[6] << 24)) / 10000.0f) / ((int32_t)ADvalue2filter - (int32_t)CalibrateWeight2.WeightZero);
            FM24_Write(CalibrateWeight2Set, (uint8_t *)&CalibrateWeight2, sizeof(CalibrateWeight2));
            break;
        case 0x0406:
            WeightZeroOld = CalibrateWeight2.WeightZero = ADvalue2filter;
            break;
        case 0x040A: // 返回
            pageNum = 2;
            break;
        case 0x0501:
            for (i = 0; i < strlen((const char *)(&DataInbuf[3])) - 1; i++) {
                Set.Title[i] = DataInbuf[i + 3];
            }
            Set.Title[i] = '\0';
            FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
            break;
        case 0x0502:
            for (i = 0; i < strlen((const char *)(&DataInbuf[3])) - 1; i++) {
                Set.TitleOne[i] = DataInbuf[i + 3];
            }
            Set.TitleOne[i] = '\0';
            FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
            break;
        case 0x0503:
            for (i = 0; i < strlen((const char *)(&DataInbuf[3])) - 1; i++) {
                Set.TitleTwo[i] = DataInbuf[i + 3];
            }
            Set.TitleTwo[i] = '\0';
            FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
            break;
        case 0x0504:
            for (i = 0; i < strlen((const char *)(&DataInbuf[3])) - 1; i++) {
                Set.TitleThree[i] = DataInbuf[i + 3];
            }
            Set.TitleThree[i] = '\0';
            FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
            break;
        case 0x0506:
            Set.SW0 = DataInbuf[3];
            FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
            break;
        case 0x0507:

            switch(DataInbuf[3] + (DataInbuf[4] << 8) + (DataInbuf[5] << 16) + (DataInbuf[6] << 24) )
            {
            case 0:
                Set.BaudRate = 1200;
                break;
            case 1:
                Set.BaudRate = 2400;
                break;
            case 2:
                Set.BaudRate = 4800;
                break;
            case 3:
                Set.BaudRate = 9600;
                break;
            case 4:
                Set.BaudRate = 19200;
                break;
            case 5:
                Set.BaudRate = 38400;
                break;
            case 6:
                Set.BaudRate = 57600;
                break;
            case 7:
            default:
                Set.BaudRate = 115200;
                break;

            }
            FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
            BIOS_USART2_Init(Set.BaudRate);
            break;
        case 0x0512:
            Set.SW1 = DataInbuf[3];
            FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
            break;
        case 0x0513:
            Set.SW2 = DataInbuf[3];
            FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
            break;
        case 0x050E: // 返回
            pageNum = 2;
            break;
        case 0x0704:
            // 打印
            for (i = 0; i < strlen((const char *)(&DataInbuf[3])) - 1; i++) {
                DataLogValue[i] = DataInbuf[i + 3];
            }
            uint8_t NameBufSelect[30];
            uint8_t startTimeSelect[30];
            uint8_t StartWeightSelect[20];
            uint8_t StopWeightSelect[20];
            uint8_t WaterPercentSelect[20];
            uint8_t WaterPercentSelect_1[20];
            uint8_t SHIZHONGSelect[20];
            uint8_t HUICHAOSelect[20];
            i = 0;
            j = 0;
            do {
                NameBufSelect[j++] = DataLogValue[i++];
            } while (DataLogValue[i] != '^');
            i++;
            j = 0;
            do {
                startTimeSelect[j++] = DataLogValue[i++];
            } while (DataLogValue[i] != '^');
            i++;
            j = 0;
            do {
                StartWeightSelect[j++] = DataLogValue[i++];
            } while (DataLogValue[i] != '^');
            i++;
            j = 0;
            do {
                StopWeightSelect[j++] = DataLogValue[i++];
            } while (DataLogValue[i] != '^');
            i++;
            j = 0;
            do {
                WaterPercentSelect[j++] = DataLogValue[i++];
            } while (DataLogValue[i] != '^');
            i++;
            j = 0;
            do {
                WaterPercentSelect_1[j++] = DataLogValue[i++];
            } while (DataLogValue[i] != '^');
            i++;
            j = 0;
            do {
                SHIZHONGSelect[j++] = DataLogValue[i++];
            } while (DataLogValue[i] != '^');
            i++;
            j = 0;
            do {
                HUICHAOSelect[j++] = DataLogValue[i++];
            } while (i < strlen((const char *)DataLogValue));
            sprintf((char *)buf, "/****************************/\r\n  %s\r\n\0", Set.Title);
            USART2Print(buf, strlen((const char *)buf));
            osDelay(200);
            if (Set.SW0) {
                sprintf((char *)buf, "  %s\r\n\0", Set.TitleOne);
                USART2Print(buf, strlen((const char *)buf));
                osDelay(200);
            }
            if (Set.SW1) {
                sprintf((char *)buf, "  %s\r\n\0", Set.TitleTwo);
                USART2Print(buf, strlen((const char *)buf));
                osDelay(200);
            }
            if (Set.SW2) {
                sprintf((char *)buf, "  %s\r\n\0", Set.TitleThree);
                USART2Print(buf, strlen((const char *)buf));
                osDelay(200);
            }
            sprintf((char *)buf, "  样品名：%s\r\n  测试时间：%s\r\n  起始重量：%s\r\n  结束重量: %s\r\n  含水量: %s\r\n  含固量: %s\r\n  湿重率: %s\r\n  回潮率: %s\r\n \0", NameBufSelect, startTimeSelect, StartWeightSelect, StopWeightSelect, WaterPercentSelect, WaterPercentSelect_1, SHIZHONGSelect, HUICHAOSelect );
            USART2Print(buf, strlen((const char *)buf));
            osDelay(200);
            sprintf((char *)buf, "/****************************/\r\n\r\n\r\n\r\n \0");
            USART2Print(buf, strlen((const char *)buf));
            break;
        case 0x0801:
            sprintf((char *)buf, "page SysSet\xFF\xFF\xFF\0");
            DataPrint(buf, strlen((const char *)buf));
            break;
        case 0x0802:
            sprintf((char *)buf, "page VL\xFF\xFF\xFF\0");
            DataPrint(buf, strlen((const char *)buf));
            break;
        case 0x0803:
            sprintf((char *)buf, "page About\xFF\xFF\xFF\0");
            DataPrint(buf, strlen((const char *)buf));
            break;
        case 0x0809:
            j = 0;
            uint8_t NameBuf[16];
            uint8_t PwdBuf[16];
            i = 3;
            do {
                NameBuf[j++] = DataInbuf[i++];
            } while (DataInbuf[i] != '^');
            j = 0;
            i++;
            do {
                PwdBuf[j++] = DataInbuf[i++];
            } while (i < strlen((const char *)DataInbuf) - 1);
            if ((strcmp((const char *)NameBuf, (const char *)Set.UserName) == 0) && (strcmp((const char *)PwdBuf, (const char *)Set.UserPwd) == 0)) {
                sprintf((char *)buf, "UserLogIn.t14.txt=%s\xFF\xFF\xFF\0", NameBuf);
                DataPrint(buf, strlen((const char *)buf));
                sprintf((char *)buf, "UserLogIn.t0.txt=\"\"\xFF\xFF\xFF\0");
                DataPrint(buf, strlen((const char *)buf));
                sprintf((char *)buf, "UserLogIn.t3.txt=\"\"\xFF\xFF\xFF\0");
                DataPrint(buf, strlen((const char *)buf));
                sprintf((char *)buf, "page UserLogIn\xFF\xFF\xFF\0");
                DataPrint(buf, strlen((const char *)buf));
                pageNum = 9;
            } else {
                sprintf((char *)buf, "play 1,1,0\xFF\xFF\xFF\0");
                DataPrint(buf, strlen((const char *)buf));
            }
            break;
        case 0x0909:
            j = 0;
            i = 3;
            do {
                NameBuf[j++] = DataInbuf[i++];
            } while (DataInbuf[i] != '^');
            j = 0;
            i++;
            do {
                PwdBuf[j++] = DataInbuf[i++];
            } while (i < strlen((const char *)DataInbuf) - 1);
            strcpy((char *)Set.UserName, (const char *)NameBuf);
            strcpy((char *)Set.UserPwd, (const char *)PwdBuf);
            FM24_Write(RW_Set, (uint8_t *)&Set, sizeof(Set));
        case 0x0C00:
            pageNum = 0;
            break;
        case 0x0C01:
            sprintf((char *)buf, "LogIn.t14.txt=\"%s\"\xFF\xFF\xFF\0", Set.UserName);
            DataPrint(buf, strlen((const char *)buf));
            break;
        case 0x0D05:
            j = 0;
            i = 3;
            do {
                NameBuf[j++] = DataInbuf[i++];
            } while (DataInbuf[i] != '^');
            j = 0;
            i++;
            do {
                PwdBuf[j++] = DataInbuf[i++];
            } while (i < strlen((const char *)DataInbuf) - 1);
            if ((strcmp((const char *)NameBuf, (const char *)Set.UserName) == 0) && (strcmp((const char *)PwdBuf, (const char *)Set.UserPwd) == 0)) {
                sprintf((char *)buf, "page main\xFF\xFF\xFF\0");
                DataPrint(buf, strlen((const char *)buf));
                pageNum = 0;
            } else {
                sprintf((char *)buf, "play 1,1,0\xFF\xFF\xFF\0");
                DataPrint(buf, strlen((const char *)buf));
            }
        default:
            break;
        }
        osSemaphoreRelease(semDataChange);
    }
}

#include "math.h"
extern float OutputMax;
uint32_t LastTick, lostTick;
uint8_t Err = 0;
float WeightDataBuf[410];
float  DiffWeight= 0;
uint16_t DataBufIndex = 0;
uint16_t DataOld;
uint16_t LCount = 200;
_Bool	StartFirst = true;
void Moisturing(const void *p_arg)
{
    static uint8_t buf[150]__attribute__((at(0x20000000 + 0x1200)));
    uint8_t TempRefresh = 0;
    uint16_t SRangeTemp = 100;
    FM24DataCRC();
		Set.PercentType = 0;
    osDelay(1000);
		if(fabs(ADvalue2filter -  CalibrateWeight2.WeightZero) * CalibrateWeight2.WeightSlope < MaxWeight *0.2f )
		{
			CalibrateWeight2.WeightZero = ADvalue2filter;			
		}
		BIOS_USART2_Init(Set.BaudRate);
    float WeightDataS = 0;
    sprintf((char *)buf, "main.t6.txt=\"Max=%dg D=%1.3fg\"\xFF\xFF\xFF\0", MaxWeight, Resolution);
    DataPrint(buf, strlen((const char *)buf));
    osDelay(300);
    sprintf((char *)buf, "RunPage.t6.txt=\"Max=%dg D=%1.3fg\"\xFF\xFF\xFF\0", MaxWeight, Resolution);
    DataPrint(buf, strlen((const char *)buf));
    for (;;) {
        if (pageNum == 0) // 主界面
        {
            sprintf((char *)buf, "main.cb1.val=%d\xFF\xFF\xFF\0", Set.FastStyle);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "main.n1.val=%d\xFF\xFF\xFF\0", Set.TempSet);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "main.cb0.val=%d\xFF\xFF\xFF\0", Set.AutoStyle);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "main.n0.val=%d\xFF\xFF\xFF\0", Set.TimeStop);
            DataPrint(buf, strlen((const char *)buf));
            WeightDataS = (float)(((int32_t)((WeightData2+Resolution / 2) / Resolution)) * Resolution);
            if (WeightDataS <= MaxWeight) {
                sprintf((char *)buf, "main.t0.txt=\"%3.3f\"\xFF\xFF\xFF\0", WeightDataS);
            } else {
                sprintf((char *)buf, "main.t0.txt=\"---.---\"\xFF\xFF\xFF\0");
            }
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "main.t5.txt=\"%s\"\xFF\xFF\xFF\0", Set.UserName);
            DataPrint(buf, strlen((const char *)buf));

            sprintf((char *)buf, "main.t12.txt=\"%3.0f\"\xFF\xFF\xFF\0", Temperature);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "page main\xFF\xFF\xFF\0");
            DataPrint(buf, strlen((const char *)buf));
            while (pageNum == 0) {
//								if(t17Dis == true)
//								{
//									if(t17DisCount ++ > 5)
//									{
//										t17Dis = false;
//										t17DisCount = 0;
//										sprintf((char *)buf, "t17.txt=\" \"\xFF\xFF\xFF\0");
//										DataPrint(buf, strlen((const char *)buf));
//										osDelay(100);
//									}
//								}
//								else
//								{
//									t17DisCount = 0;
//								}
                if(t18Dis == true)
                {
                    if(t18DisCount ++ > 5)
                    {
                        t18Dis = false;
                        t18DisCount = 0;
                        sprintf((char *)buf, "t18.txt=\" \"\xFF\xFF\xFF\0");
                        DataPrint(buf, strlen((const char *)buf));
                        osDelay(100);
                    }
                }
                else
                {
                    t18DisCount = 0;
                }

                WeightDataS = (float)(((int32_t)((WeightData2+Resolution / 2) / Resolution)) * Resolution);
                if (WeightDataS <= MaxWeight+Resolution*9) {
                    sprintf((char *)buf, "main.t0.txt=\"%3.3f\"\xFF\xFF\xFF\0", WeightDataS);
                } else {
                    sprintf((char *)buf, "main.t0.txt=\"---.---\"\xFF\xFF\xFF\0");
                }
                DataPrint(buf, strlen((const char *)buf));
                if (TempRefresh++ > 3) {
                    TempRefresh = 0;
                    sprintf((char *)buf, "main.t12.txt=\"%3.0f\"\xFF\xFF\xFF\0", Temperature);
                    DataPrint(buf, strlen((const char *)buf));
                }
                osSemaphoreWait(semDataChange, 300);
            }
        }
        if (pageNum == 1) // 运行界面
        {

            LCount = Set.AutoTimeStop * 1000.0f / 300.0f - 1;
            StartFirst = true;
            CountDelay    = 0;
            CountNochange = 0;
            DataBufIndex = 0;
            memset(WeightDataBuf,0,410);
            WeightDataS   = (float)(((int32_t)((WeightData2+Resolution / 2) / Resolution)) * Resolution);
            StartWeight   = WeightDataS;
            switch (Set.FastStyle) {
            case 0:
                OutputMax = 1;
                break;
            case 1:
                OutputMax = 0.75;
                break;
            case 2:
                OutputMax = 0.5;
                break;
            default:
                break;
            }

            switch( Set.PercentType )
            {
            default:
            case 0:
                sprintf((char *)buf, "RunPage.b1.txt=\"含水量\"\xFF\xFF\xFF\0");
                break;
            case 1:
                sprintf((char *)buf, "RunPage.b1.txt=\"含固量\"\xFF\xFF\xFF\0");
                break;
            case 2:
                sprintf((char *)buf, "RunPage.b1.txt=\"回潮率\"\xFF\xFF\xFF\0");
                break;
            case 3:
                sprintf((char *)buf, "RunPage.b1.txt=\"湿重率\"\xFF\xFF\xFF\0");
                break;
            }
            DataPrint(buf, strlen((const char *)buf));

            sprintf((char *)buf, "RunPage.t5.txt=\"%s\"\xFF\xFF\xFF\0", Set.UserName);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "RunPage.t14.txt=\"%s\"\xFF\xFF\xFF\0", NameBuf);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "RunPage.cb0.val=%d\xFF\xFF\xFF\0", Set.FastStyle);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "RunPage.n2.val=%d\xFF\xFF\xFF\0", Set.TempSet);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "RunPage.cb1.val=%d\xFF\xFF\xFF\0", Set.AutoStyle);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "RunPage.n3.val=%d\xFF\xFF\xFF\0", Set.TimeStop);
            DataPrint(buf, strlen((const char *)buf));
            if (SafeCheck())
            {   // 请关闭加热仓
                sprintf((char *)buf, "play 1,8,0\xFF\xFF\xFF\0");
                DataPrint(buf, strlen((const char *)buf));
                do {
                    osDelay(300);
                } while ((SafeCheck()) && (pageNum == 1));
            }
            Pump_OutCmd(true);
            osSemaphoreWait(semDataChange, 800);
            sprintf((char *)buf, "cle s0.id,0\xFF\xFF\xFF\0");
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "page RunPage\xFF\xFF\xFF\0");
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "cle s0.id,0\xFF\xFF\xFF\0");
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "va0.val=0\xFF\xFF\xFF\0");
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "tm0.en=1\xFF\xFF\xFF\0");
            DataPrint(buf, strlen((const char *)buf));
						sprintf((char *)buf, "tsw b0,0\xFF\xFF\xFF\0");
						DataPrint(buf, strlen((const char *)buf));
						sprintf((char *)buf, "tsw b3,0\xFF\xFF\xFF\0");
						DataPrint(buf, strlen((const char *)buf));
						sprintf((char *)buf, "tsw cb0,0\xFF\xFF\xFF\0");
						DataPrint(buf, strlen((const char *)buf));
						sprintf((char *)buf, "tsw cb1,0\xFF\xFF\xFF\0");
						DataPrint(buf, strlen((const char *)buf));

            DisData = WeightOld = WeightDataS;
            //	定间隔延时
            const uint32_t oneTick = osKernelSysTickMicroSec(1000u); // 微秒计时 oneTick 1ms
            LastTick = osKernelSysTick();
            do {
                if (SafeCheck())
                {   // 请关闭加热仓
                    sprintf((char *)buf, "play 1,8,0\xFF\xFF\xFF\0");
                    DataPrint(buf, strlen((const char *)buf));
                    Pump_OutCmd(false);
                    do {
                        osDelay(300);
                    } while ((SafeCheck()) && (pageNum == 1));
                    Pump_OutCmd(true);
                }
                //	计算已经逝去的tick计时单位
                lostTick = (uint32_t)(osKernelSysTick() + oneTick / 2 - LastTick) / oneTick;
                //	计算余下需要的延时周期(设定间隔时间：300ms)
                if (lostTick < 300u)
                {
                    osDelay(300u - lostTick);
                    LastTick = osKernelSysTick();
                } else { //	已经逝去的时间超过设定的间隔，重新计算时间起点后少量延时。
                    osDelay(30);
                    LastTick = osKernelSysTick();
                }

                StopWeight = DisData;
                switch (Set.AutoStyle)
                {
                case 0:                                                    // 自动模式
                    if(CountNochange > 3 * 20 ) // 停止加热
                    {
                        Finisflag = true;
                    }
                    break;
                case 1: // 手动模式
                    break;
                case 2:                                                  // 定时模式
                    if (CountDelay++ > Set.TimeStop * 60 *  1000.0f / 300.0f) // 当计数器大于设定时间时，停止加热)
                    {
                        Finisflag = true;
                    }
                    break;
                default:
                    break;
                }
                if (Finisflag)
                {
										FinishDisData = DisData;
                    sprintf((char *)buf, "RunPage.tm0.en=0\xFF\xFF\xFF\0");
                    DataPrint(buf, strlen((const char *)buf));
                    Pump_OutCmd(false);
                    sprintf((char *)buf, "RunPage.t8.txt=\"测试已完成!\"\xFF\xFF\xFF\0");
                    DataPrint(buf, strlen((const char *)buf));
                    sprintf((char *)buf, "play 1,4,0\xFF\xFF\xFF\0");
                    DataPrint(buf, strlen((const char *)buf));
                    sprintf((char *)buf, "tsw b0,1\xFF\xFF\xFF\0");
                    DataPrint(buf, strlen((const char *)buf));
                    sprintf((char *)buf, "tsw b3,1\xFF\xFF\xFF\0");
                    DataPrint(buf, strlen((const char *)buf));
//                    sprintf((char *)buf, "tsw b1,1\xFF\xFF\xFF\0");
//                    DataPrint(buf, strlen((const char *)buf));
                    HUICHAO = (float)(((uint32_t)(((StartWeight - DisData) / DisData * 100.0f) / ResolutionWater)) * ResolutionWater);
                    if(HUICHAO > 999)
                    {
                        HUICHAO = 999;
                    }
                    SHIZHONG = (float)(((uint32_t)((StartWeight  / DisData * 100.0f) / ResolutionWater)) * ResolutionWater);
                    if(SHIZHONG > 999)
                    {
                        SHIZHONG = 999;
                    }

										
                    do {
												switch( Set.PercentType )
												{
												default:
												case 0:
														sprintf((char *)buf, "RunPage.b1.txt=\"含水量\"\xFF\xFF\xFF\0");
														PercentData = WaterPercentData;
														break;
												case 1:
														sprintf((char *)buf, "RunPage.b1.txt=\"含固量\"\xFF\xFF\xFF\0");
														PercentData = 100 - WaterPercentData;
														break;
												case 2:
														sprintf((char *)buf, "RunPage.b1.txt=\"回潮率\"\xFF\xFF\xFF\0");
														PercentData = HUICHAO;
														break;
												case 3:
														sprintf((char *)buf, "RunPage.b1.txt=\"湿重率\"\xFF\xFF\xFF\0");
														PercentData = SHIZHONG;
														break;
												}
												DataPrint(buf, strlen((const char *)buf));
												if(PercentData  >= 999)
												{
													sprintf((char *)buf, "RunPage.t3.txt=\"-----%\"\xFF\xFF\xFF\0");
												}
												else
												{
													sprintf((char *)buf, "RunPage.t3.txt=\"%.2f%%\"\xFF\xFF\xFF\0", PercentData);
												}
												DataPrint(buf, strlen((const char *)buf));
												osSemaphoreWait(semDataChange, osWaitForever);
                    } while (pageNum == 1);
										sprintf((char *)buf, "tsw cb0,0\xFF\xFF\xFF\0");
										DataPrint(buf, strlen((const char *)buf));
										sprintf((char *)buf, "tsw cb1,0\xFF\xFF\xFF\0");
										DataPrint(buf, strlen((const char *)buf));

                }
                WeightDataS = (float)(((int32_t)((WeightData2 + Resolution / 2) / Resolution)) * Resolution);
                if( WeightData2 >= 0)
                {
                    if (WeightOld - WeightDataS > Resolution) // 当重量变化大于0.001g时,更新数据 （只能减不能加）
                    {
                        DisData = WeightOld = WeightDataS;
                    }
                    /* */
                    WeightDataBuf[DataBufIndex++] = WeightData2;
                    if(DataBufIndex >= 405)
                        DataBufIndex = 0;
                    if(!StartFirst)
                    {
                        DataOld = DataBufIndex - LCount;
                        if(DataBufIndex < LCount )
                        {
                            DataOld = DataBufIndex + 405 - LCount;
                        }
                        DiffWeight =  WeightDataBuf[DataOld] - WeightData2;
                        if( DiffWeight > Set.AutoWeightChange / 1000.0f )
                        {
                            CountNochange = 0;
//                            DisData = WeightOld = WeightDataS;
                        }
                        else
                        {
                            CountNochange ++;
                        }
                    }
                    else
                    {
                        if(DataBufIndex > LCount)
                            StartFirst = false;
                    }
                    /* */



                    if ((StartWeight != 0) && (DisData != 0))
                    {
                        switch( Set.PercentType )
                        {
                        default:
                        case 0://含水量
                            PercentData = (float)(((uint32_t)(((StartWeight - DisData) / StartWeight * 100.0f) / ResolutionWater)) * ResolutionWater);
                            break;
                        case 1://含固量
                            PercentData = (float)(((uint32_t)(( DisData / StartWeight * 100.0f) / ResolutionWater)) * ResolutionWater);
                            break;
                        case 2://回潮率
                            PercentData = (float)(((uint32_t)(((StartWeight - DisData) / DisData * 100.0f) / ResolutionWater)) * ResolutionWater);
                            if(PercentData > 999)
                            {
                                PercentData = 999;
                            }
                            break;
                        case 3://湿重率
                            PercentData = (float)(((uint32_t)((StartWeight  / DisData * 100.0f) / ResolutionWater)) * ResolutionWater);
                            if(PercentData > 999)
                            {
                                PercentData = 999;
                            }
                            break;
                        }
										}
                    WaterPercentData =(float)(((uint32_t)(((StartWeight - DisData) / StartWeight * 100.0f) / ResolutionWater)) * ResolutionWater);
                }
                sprintf((char *)buf, "RunPage.t0.txt=\"%3.3f\"\xFF\xFF\xFF\0", DisData);
                DataPrint(buf, strlen((const char *)buf));
                sprintf((char *)buf, "RunPage.t12.txt=\"%3.0f\"\xFF\xFF\xFF\0", Temperature);
                DataPrint(buf, strlen((const char *)buf));

                switch( Set.PercentType )
                {
                default:
                case 0:
                    sprintf((char *)buf, "RunPage.b1.txt=\"含水量\"\xFF\xFF\xFF\0");
                    break;
                case 1:
                    sprintf((char *)buf, "RunPage.b1.txt=\"含固量\"\xFF\xFF\xFF\0");
                    break;
                case 2:
                    sprintf((char *)buf, "RunPage.b1.txt=\"回潮率\"\xFF\xFF\xFF\0");
                    break;
                case 3:
                    sprintf((char *)buf, "RunPage.b1.txt=\"湿重率\"\xFF\xFF\xFF\0");
                    break;
                }
                DataPrint(buf, strlen((const char *)buf));
								if(PercentData  >= 999)
								{
									sprintf((char *)buf, "RunPage.t3.txt=\"-----%\"\xFF\xFF\xFF\0");
								}
								else
								{
									sprintf((char *)buf, "RunPage.t3.txt=\"%.2f%%\"\xFF\xFF\xFF\0", PercentData);
								}
                DataPrint(buf, strlen((const char *)buf));

                sprintf((char *)buf, "RunPage.t17.txt=\"%2.2f%%\"\xFF\xFF\xFF\0", WaterPercentData);
                DataPrint(buf, strlen((const char *)buf));
                sprintf((char *)buf, "RunPage.j0.val=%d\xFF\xFF\xFF\0", (uint8_t)WaterPercentData);
                DataPrint(buf, strlen((const char *)buf));


                if (SCount++ >= 3)
                {
                    SCount = 0;


                    if (WaterPercentData <= 38.0f) {
                        SRangeTemp = 200;
                    }
                    if (WaterPercentData > 38.0f && WaterPercentData <= 76.0f) {
                        SRangeTemp = 100;
                    }
                    if (WaterPercentData > 76.0f && WaterPercentData <= 100.0f) {
                        SRangeTemp = 70;
                    }
                    if( WaterPercentData > 100.0f) {
                        SRangeTemp = 50;
                    }
                    if (SRangeTemp != SRange) {
                        SRange = SRangeTemp;
                        sprintf((char *)buf, "s0.dis=%d\xFF\xFF\xFF\0", SRange);
                        DataPrint(buf, strlen((const char *)buf));
                    }
                    sprintf((char *)buf, "add s0.id,0,%d\xFF\xFF\xFF\0", (uint8_t)(( WaterPercentData > 100.0f? 100.0f:WaterPercentData ) / 100.0f * 255));
                    DataPrint(buf, strlen((const char *)buf));
                }
            } while (pageNum == 1);
            sprintf((char *)buf, "tm0.en=0\xFF\xFF\xFF\0");
            DataPrint(buf, strlen((const char *)buf));
            Pump_OutCmd(false);
        }
        if (pageNum == 3) // 称重设置
        {
            if(osSemaphoreWait(semDataChange, 300) > 0)
            {
                osDelay(50);
                sprintf((char *)buf, "WeightSet.cb5.val=%d\xFF\xFF\xFF\0", Set.FilterQ);
                DataPrint(buf, strlen((const char *)buf));
                sprintf((char *)buf, "WeightSet.cb4.val=%d\xFF\xFF\xFF\0", Set.RuBianLiang);
                DataPrint(buf, strlen((const char *)buf));
                sprintf((char *)buf, "WeightSet.cb3.val=%d\xFF\xFF\xFF\0", Set.SensorQ);
                DataPrint(buf, strlen((const char *)buf));
                sprintf((char *)buf, "WeightSet.cb2.val=%d\xFF\xFF\xFF\0", Set.RuBianTime);
                DataPrint(buf, strlen((const char *)buf));
                sprintf((char *)buf, "WeightSet.cb1.val=%d\xFF\xFF\xFF\0", Set.HoldTime);
                DataPrint(buf, strlen((const char *)buf));
                sprintf((char *)buf, "WeightSet.cb0.val=%d\xFF\xFF\xFF\0", Set.ZeroTrack);
                DataPrint(buf, strlen((const char *)buf));
                sprintf((char *)buf, "WeightSet.n0.val=%d\xFF\xFF\xFF\0", Set.AutoTimeStop);
                DataPrint(buf, strlen((const char *)buf));
                sprintf((char *)buf, "WeightSet.n1.val=%d\xFF\xFF\xFF\0", Set.AutoWeightChange);
                DataPrint(buf, strlen((const char *)buf));
            }
        }
        if (pageNum == 4) // 校准设置
        {
            sprintf((char *)buf, "Calibration.t8.txt=\"%3.4f\"\xFF\xFF\xFF\0", WeightData2Finally);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "Calibration.t6.txt=\"%3.0f\"\xFF\xFF\xFF\0", Temperature);
            DataPrint(buf, strlen((const char *)buf));
            osSemaphoreWait(semDataChange, 300);
        }
        if (pageNum == 5) // 打印设置
        {
            sprintf((char *)buf, "Print.cb0.txt=\"%d\"\xFF\xFF\xFF\0", Set.BaudRate);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "Print.bt0.val=%d\xFF\xFF\xFF\0", Set.SW0 ? 1 : 0);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "Print.bt1.val=%d\xFF\xFF\xFF\0", Set.SW1 ? 1 : 0);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "Print.bt2.val=%d\xFF\xFF\xFF\0", Set.SW2 ? 1 : 0);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "Print.t5.txt=\"%s\"\xFF\xFF\xFF\0", Set.Title);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "Print.t6.txt=\"%s\"\xFF\xFF\xFF\0", Set.TitleOne);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "Print.t7.txt=\"%s\"\xFF\xFF\xFF\0", Set.TitleTwo);
            DataPrint(buf, strlen((const char *)buf));
            sprintf((char *)buf, "Print.t8.txt=\"%s\"\xFF\xFF\xFF\0", Set.TitleThree);
            DataPrint(buf, strlen((const char *)buf));
            osSemaphoreWait(semDataChange, 300);
        }
        if (pageNum == 6) // 数据记录
        {
            osSemaphoreWait(semDataChange, 300);
        }
    }
}
osThreadDef(Moisturing, osPriorityNormal, 1, 0);
void MoisturingRun()
{
    osThreadCreate(osThread(Moisturing), NULL);
}

osThreadDef(DataUnpack, osPriorityNormal, 1, 0);
void HMICMDInit()
{
    osThreadCreate(osThread(DataUnpack), NULL);
    MoisturingRun();
}
