From 2f48115ba43a92967af12862f4777f86b6194c50 Mon Sep 17 00:00:00 2001
From: Zhangwen <13970730+mkc46119@user.noreply.gitee.com>
Date: Sun, 29 Sep 2024 16:19:28 +0800
Subject: [PATCH] =?UTF-8?q?feature=EF=BC=9A=E5=AF=B9=E7=A6=BB=E5=BA=8A?=
 =?UTF-8?q?=E6=8A=A5=E8=AD=A6=E5=8A=9F=E8=83=BD=E6=B7=BB=E5=8A=A01.5s?=
 =?UTF-8?q?=E7=9A=84=E5=88=A4=E6=96=AD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 source/app/app_weight.c       |  2 +-
 source/app/task_bedalarm.c    | 27 ++++++++++++++----
 source/app/task_bedalarm.h    |  1 +
 source/app/task_screen.c      | 53 ++++++++---------------------------
 source/app/task_weight_keep.c | 32 ++++++++++-----------
 5 files changed, 52 insertions(+), 63 deletions(-)

diff --git a/source/app/app_weight.c b/source/app/app_weight.c
index bc392ec..074cf77 100644
--- a/source/app/app_weight.c
+++ b/source/app/app_weight.c
@@ -199,7 +199,7 @@ void L3_task_weight_handler(TS_TASK_weight_ *s)
 		{
 			s->kgx10_out = 0 ;
 		}
-		R.weight.kgx10_out = s->kgx10_out;
+		R.weight.kgx10_out = s->kgx10_out; //屏幕显示的为串口对外输出的重量数值,受kgx10_zero影响:s->kgx10_out = s->kgx10 - s->kgx10_zero;
 		// L0_uart1_str("s->kgx10_out ");
 		// L0_uart1_ushex(s->kgx10_out);
 		// L0_uart1_0d0a(); 
diff --git a/source/app/task_bedalarm.c b/source/app/task_bedalarm.c
index 6affaaa..6c86479 100644
--- a/source/app/task_bedalarm.c
+++ b/source/app/task_bedalarm.c
@@ -23,6 +23,7 @@ void L3_task_bed_alarm_init(void)
 {
 	L1_task_init(&_s_task_bed_alarm.task);
 	_s_task_bed_alarm.mode_flag = R.LeaveForbid_flag;
+	_s_task_bed_alarm.times = 6;	//经过测试_s_task_bed_alarm.times = 10时,判断时长为2.5s;_s_task_bed_alarm.times = 6时,判断时长为1.5s
 	L3_task_s_go(_s_task_bed_alarm,D_task_init);
 }
 
@@ -40,14 +41,28 @@ void L3_task_bed_alarm_handler(S_TASK_Bed_ALARM *s)
 		if(R.LeaveForbid_flag == LeaveForbid_OPEN && R.beep == beep_off)
 		{
 			// R.weight.differ = R.Weight_Ref - D_get_weight();
-			R.weight.differ = R.Weight_Ref - R.weight.kgx10_out; //只用输出值来判断
+			R.weight.differ = R.Weight_Ref - R.weight.kgx10_out; //串口对外输出的重量值的前后差值来判断
 			// 检测到体重变化超10kg
-			if( R.weight.differ > 50) // 50 5kg   100  10kg
+			if(R.weight.differ > 50) // 50 5kg   100  10kg
 			{
-				R.beep = beep_on;
-				L0_uart1_str("Enter Alarm->");	
+				L0_uart1_str(" After Compare 50, s->times  = ");	
+				L0_uart1_uchex(s->times);
 				L0_uart1_0d0a();
-				R.beep_startime = D_sys_now;
+				if(--s->times == 0)
+				{
+					R.beep = beep_on;
+					L0_uart1_str("Enter Alarm->");	
+					L0_uart1_0d0a();
+					R.beep_startime = D_sys_now;
+					s->times = 6;
+				}
+				L0_uart1_str("After Count 10, s->times  = ");	
+				L0_uart1_uchex(s->times);
+				L0_uart1_0d0a();
+			}
+			else
+			{
+				s->times = 6;
 			}
 		}
 		//模式开启情况下,蜂鸣器响的时候 
@@ -99,6 +114,8 @@ void L3_task_bed_alarm_handler(S_TASK_Bed_ALARM *s)
 		}
 
 		_s_task_bed_alarm.mode_flag = R.LeaveForbid_flag;
+
+		L2_task_go_Tdelay(D_task_JUDGE, D_Tdelay_200ms);
 			
 		TTSS_Task_end();
 }
diff --git a/source/app/task_bedalarm.h b/source/app/task_bedalarm.h
index 173a0b0..c75d9d1 100644
--- a/source/app/task_bedalarm.h
+++ b/source/app/task_bedalarm.h
@@ -34,6 +34,7 @@ typedef struct _s_task_low_power
 {
 	TS_task task;
 	U8 mode_flag;
+	U8 times;
 }S_TASK_Bed_ALARM;
 
 extern S_TASK_Bed_ALARM _s_task_bed_alarm;
diff --git a/source/app/task_screen.c b/source/app/task_screen.c
index fe0842c..1677931 100644
--- a/source/app/task_screen.c
+++ b/source/app/task_screen.c
@@ -123,17 +123,6 @@ SCReturnPkg scrPkgIconYClearPkg = {
 	0xFC,0xA5,   // CRC
 };
 
-// //	A5 5A 08 82 06 D3 01 00 00 FF 7D 清除报警图标
-// SCReturnPkg scrPkgAlarmClearPkg = {
-// 	0xA5, 0x5A,
-// 	0x08,		 //指令字节长度(不含帧头)
-// 	0x82,		 //指令
-// 	0x06, 0xD3,  //变量存储地址
-// 	0x01, 		 //数据字长度
-// 	0x00,0x00,   // 数据内容
-// 	0xFF,0x7D,   // CRC
-// };
-
 // A5 5A 08 82 06 D7 01 00 00 FE 4D  切换单位
 SCReturnPkg scrPkgUnitSwitchPkg = {
 	0xA5, 0x5A,
@@ -203,7 +192,7 @@ void L3_task_screen_handler(S_TASK_SCREEN *s)
 		L2_task_go_Tdelay(D_task_RS485_SEND, D_Tdelay_400ms);		
 	//发送
 	TTSS_Task_step(D_task_RS485_SEND):
-		if(R.power_mode == POWER_NORMAL)
+		if(R.power_mode == POWER_NORMAL)		//熄屏情况下不发送重量信息
 		{
 			//构造pkg
 			constructor_scr_pkg();
@@ -222,12 +211,11 @@ void L3_task_screen_handler(S_TASK_SCREEN *s)
 void constructor_scr_pkg()
 {
 	U16 CRC = 0;
-	U16 weight_kgx100 = 0;
-	L0_uart1_str("R.weight.kgx10_out: ");
-	L0_uart1_ushex(R.weight.kgx10_out);
-	L0_uart1_0d0a(); 
+	// L0_uart1_str("R.weight.kgx10_out: ");
+	// L0_uart1_ushex(R.weight.kgx10_out);
+	// L0_uart1_0d0a(); 
 
-	weight_kgx100 = R.weight_keep_flag == 0? (R.weight.kgx10_out * 10)  : (R.weight_keep_kgx10 * 10);
+	U16 weight_kgx100 = R.weight_keep_flag == 0? (R.weight.kgx10_out * 10)  : (R.weight_keep_kgx10 * 10);
 	
 	if(R.danwei == KG)
 	{
@@ -240,8 +228,8 @@ void constructor_scr_pkg()
 	{
 		// scrSetValPkg.weight_kgx100[0] = (R.weight.kgx10_out * 22) >> 8 & 0xFF;
 		// scrSetValPkg.weight_kgx100[1] = (R.weight.kgx10_out * 22) >> 0 & 0xFF;	
-		scrSetValPkg.weight_kgx100[0] = weight_kgx100 >> 8 & 0xFF;
-		scrSetValPkg.weight_kgx100[1] = weight_kgx100 >> 0 & 0xFF;
+		scrSetValPkg.weight_kgx100[0] = (U16)(weight_kgx100 * 2.2) >> 8 & 0xFF;
+		scrSetValPkg.weight_kgx100[1] = (U16)(weight_kgx100 * 2.2) >> 0 & 0xFF;
 	}
 
 	CRC = CRC_16(((U8 *)&scrSetValPkg) + 3, 5);
@@ -271,15 +259,9 @@ void constructor_weightsave_pkg()
 void parse_screen_pkg()
 {
 	SCReturnPkg *p = (SCReturnPkg *) ts_Urec[D_UART1].sp;
-	// p->ocr =  p->buf[p->num[0] << 8 | p->num[1]];
-	L0_uart1_str("ts_Urec[D_UART1].sp = ");
-	L1_uart1_Array(p, sizeof(*p));	
-	L0_uart1_0d0a();
-	// L0_uart1_str("sizeof(*p) = ");
-	// L0_uart1_ushex(sizeof(*p));
+	// L0_uart1_str("ts_Urec[D_UART1].sp = ");
+	// L1_uart1_Array(p, sizeof(*p));	
 	// L0_uart1_0d0a();
-	// L0_uart1_str("sizeof(&p) = ");
-	// L0_uart1_ushex(sizeof(&p));
 	
 	if(p->head[0] == 0xA5 && p->head[1] == 0x5A/*count_ocr()*/)
 	{
@@ -309,28 +291,17 @@ void parse_screen_pkg()
 						if(p->Data[1] == 1)
 						{
 							tst_weight.kgx10_zero = tst_weight.kgx10;
+							R.weight_keep_kgx10 = 0 ;
 						}					
 						break;
 					case 0xD3://离床报警	
-						R.LeaveForbid_flag ^= 1;// R.LeaveForbid_flag = R.LeaveForbid_flag ^ 1;							
-						// if(R.LeaveForbid_flag != LeaveForbid_OPEN)
-						// {
-						// 	R.LeaveForbid_flag = LeaveForbid_OPEN;  
-						// 	L0_uart1_str("LeaveForbid_OPEN!!!");	 
-						// 	L0_uart1_0d0a();	
-						// }
-						// else if(R.LeaveForbid_flag == LeaveForbid_OPEN)
-						// {
-						// 	R.LeaveForbid_flag = LeaveForbid_OFF;
-						// 	L0_uart1_str("LeaveForbid_OFF!!!");	
-						// 	L0_uart1_0d0a(); 
-						// }			
+						R.LeaveForbid_flag ^= 1;// R.LeaveForbid_flag = R.LeaveForbid_flag ^ 1;									
 						break;
 					case 0xD4://保存
 						if(p->Data[1] == 1)
 						{
 							// screen_save_push(tst_weight.kgx10);			
-							screen_save_push(tst_weight.kgx10_out);	
+							screen_save_push(R.weight_keep_kgx10);	//总是保存 保持的重量(看到的是多少,保存的就是多少)
 						}		
 							break;
 					case 0xD5://校准菜单按钮
diff --git a/source/app/task_weight_keep.c b/source/app/task_weight_keep.c
index 83cd746..105eb85 100644
--- a/source/app/task_weight_keep.c
+++ b/source/app/task_weight_keep.c
@@ -31,15 +31,15 @@ void L3_task_weight_keep_handler(S_TASK_WEIGHT_KEEP *s)
 		if(R.weight_keep_flag == 1)
 		{
 //			LED0 = LED0_OFF;
-			L0_uart1_str("keep status ");
-			L0_uart1_0d0a(); 
+			// L0_uart1_str("keep status ");
+			// L0_uart1_0d0a(); 
 			//当前处于保持状态
 			//判定是否打破
 			//连续1s,100ms检测一次,判断实际重量相比保持重量,超过3kg,取消保持
 			s->levelJudgeTimes = 10;
 			//3kg
 			s->levelWeightThresholdKgx10 = 30;
-			// s->levelTimesThreshold = 10;
+			s->levelTimesThreshold = 10;
 			s->levelTimes  = 8;
 			s->levelTimes = 0;
 			L2_task_go_Tdelay(D_task_WEIGHT_KEEP_LEAVE_JUDGE, 0);
@@ -59,18 +59,18 @@ void L3_task_weight_keep_handler(S_TASK_WEIGHT_KEEP *s)
 			s->enterMaxWeight = 0;
 			s->enterMinWeight = R.weight.kgx10_out;
 			s->enterSumWeight = 0;
-			L2_task_go_Tdelay(D_task_WEIGHT_KEEP_ENTER_JUDGE, 0);
+			L2_task_go_Tdelay(D_task_WEIGHT_KEEP_ENTER_JUDGE, 0);  
 		}
 
 	TTSS_Task_step(D_task_WEIGHT_KEEP_LEAVE_JUDGE):
 		weight_keep_kgx10 = R.weight_keep_kgx10;
 		weight_real_kgx10 = R.weight.kgx10_out;
 		if(Lc_abs(weight_keep_kgx10, weight_real_kgx10) > s->levelWeightThresholdKgx10)
-		{
+		{   //每次触发进入该if的执行语句时,第一次输出的s->levelJudgeTimes是个随机数,且它要先减为0,再从10减为0
 			s->levelTimes++;
-			// L0_uart1_str("i get here here!! s->levelJudgeTimes =  ");
-			// L0_uart1_uchex(s->levelJudgeTimes);
-			// L0_uart1_0d0a(); 
+			L0_uart1_str("KEEP_LEAVE_JUDGE CountDown :");    
+			L0_uart1_uchex(s->levelJudgeTimes);
+			L0_uart1_0d0a(); 
 			// L0_uart1_str("s->levelTimes =  ");
 			// L0_uart1_uchex(s->levelTimes);
 			// L0_uart1_0d0a(); 
@@ -81,14 +81,14 @@ void L3_task_weight_keep_handler(S_TASK_WEIGHT_KEEP *s)
 		}
 		else
 		{
-			if(s->levelTimes >= s->levelTimesThreshold)
+			if(s->levelTimes >= s->levelTimesThreshold)	//这里的s->levelTimesThreshold 在哪里赋的值???
 			{
 
 				R.weight_keep_flag = 0;
 
-				L0_uart1_str("s->levelTimesThreshold =  ");
-				L0_uart1_uchex(s->levelTimesThreshold);
-				L0_uart1_0d0a(); 
+				// L0_uart1_str("s->levelTimesThreshold =  ");  
+				// L0_uart1_uchex(s->levelTimesThreshold);
+				// L0_uart1_0d0a(); 
 			}
 			L2_task_go_Tdelay(D_task_WEIGHT_KEEP_1, 0);
 		}
@@ -106,7 +106,7 @@ void L3_task_weight_keep_handler(S_TASK_WEIGHT_KEEP *s)
 		}
 		if(-- s->enterTimes > 0)
 		{
-			L0_uart1_str("s->enterTimes =  ");
+			L0_uart1_str("KEEP_ENTER_JUDGE CountDown :  ");
 			L0_uart1_uchex(s->enterTimes);
 			L0_uart1_0d0a(); 
 			L2_task_go_Tdelay(D_task_WEIGHT_KEEP_ENTER_JUDGE, D_Tdelay_100ms);
@@ -118,9 +118,9 @@ void L3_task_weight_keep_handler(S_TASK_WEIGHT_KEEP *s)
 				R.weight_keep_flag = 1;
 				R.weight_keep_kgx10 = (U16)(s->enterSumWeight / s->enterJudgeTimes);
 				
-			// L0_uart1_str("i get final !!!!!!!!!!! ");
-			// L0_uart1_str("R.weight_keep_kgx10: ");
-			// L0_uart1_ushex(R.weight_keep_kgx10);
+			L0_uart1_str("I KEEP THIS WEIGHT : ");
+			L0_uart1_ushex(R.weight_keep_kgx10);
+			L0_uart1_0d0a();
 			}
 			L2_task_go_Tdelay(D_task_WEIGHT_KEEP_1, 0);
 		}