Browse Source

feature:新增重量保持功能,测试通过

weight-flt
Zhangwen 9 months ago
parent
commit
be1bf6cf9b
  1. 4
      .vscode/settings.json
  2. 120
      keilp/stcTTSS2_W5.uvguix.Administrator
  3. 5
      source/app/app_config.c
  4. 4
      source/app/app_config.h
  5. 3
      source/app/app_weight.c
  6. 2
      source/app/app_weight.h
  7. 5
      source/app/main.c
  8. 1
      source/app/main.h
  9. 7
      source/app/task_bedalarm.c
  10. 24
      source/app/task_screen.c
  11. 133
      source/app/task_weight_keep.c
  12. 57
      source/app/task_weight_keep.h

4
.vscode/settings.json

@ -18,6 +18,8 @@
"msp_eeprom.h": "c",
"app_weight.h": "c",
"bsp_msa300.h": "c",
"c_lib.h": "c"
"c_lib.h": "c",
"task_weight_keep.h": "c",
"c_type51.h": "c"
}
}

120
keilp/stcTTSS2_W5.uvguix.Administrator

File diff suppressed because one or more lines are too long

5
source/app/app_config.c

@ -56,6 +56,11 @@ void L3_reg_reset(void)
//校准体重
R.calib_kg_x100 = 0;
//称重保持
//上电为保持状态
R.weight_keep_flag = 1;
R.weight_keep_kgx10 = 0;
}

4
source/app/app_config.h

@ -247,6 +247,10 @@ typedef struct global_register
// 校准重量
U16 calib_kg_x100;
//称重保持
U8 weight_keep_flag;
U16 weight_keep_kgx10;
} GlobalRegister;
extern GlobalRegister R;

3
source/app/app_weight.c

@ -200,6 +200,9 @@ void L3_task_weight_handler(TS_TASK_weight_ *s)
s->kgx10_out = 0 ;
}
R.weight.kgx10_out = s->kgx10_out;
// L0_uart1_str("s->kgx10_out ");
// L0_uart1_ushex(s->kgx10_out);
// L0_uart1_0d0a();
//// D_LED1_REV(); L4_weight_out(); D_LED1_REV();

2
source/app/app_weight.h

@ -231,7 +231,7 @@ extern void L4_weight_out(void);
extern void L4_WPoint_out(void);
extern void L4_kgx10zero_out(void);
#define D_get_weight() tst_weight.kgx10
#define D_get_weight() tst_weight.kgx10 //计算出的重量值

5
source/app/main.c

@ -96,7 +96,7 @@ void L0_main_init(void)
printf1("\r\nD_sys_MainFre %ld",D_sys_MainFre);
//上电时控制蜂鸣器响一声
L1_uart1_Array((U8 *)&scrBeepPowOnPkg, sizeof(scrBeepPowOnPkg));
// L1_uart1_Array((U8 *)&scrBeepPowOnPkg, sizeof(scrBeepPowOnPkg));
r = L3_S_init();
printf1("\r\nL3_S_init %d",r);
@ -116,6 +116,7 @@ void main(void)
L3_task_weight_init();
L3_task_screen_init();
L3_task_bed_alarm_init();
L3_task_weight_keep_init();
TTSS_run_every_init(s_nos_tick.stamp,10);
@ -148,6 +149,8 @@ void main(void)
L3_task_bed_alarm_handler(&_s_task_bed_alarm);
L3_task_weight_keep_handler(&_s_task_weight_keep);
}
}

1
source/app/main.h

@ -94,6 +94,7 @@
#include "task_screen.h"
#include "app_screen_save.h"
#include "task_bedalarm.h"
#include "task_weight_keep.h"
#include "app_config.h"

7
source/app/task_bedalarm.c

@ -24,7 +24,6 @@ void L3_task_bed_alarm_init(void)
L1_task_init(&_s_task_bed_alarm.task);
_s_task_bed_alarm.mode_flag = R.LeaveForbid_flag;
L3_task_s_go(_s_task_bed_alarm,D_task_init);
R.weight.differ = R.Weight_Ref - R.weight.kgx10_out;
}
#define D_task_JUDGE 0x50
@ -37,10 +36,11 @@ void L3_task_bed_alarm_handler(S_TASK_Bed_ALARM *s)
L2_task_go(D_task_JUDGE);
//判定是否触发报警
TTSS_Task_step(D_task_JUDGE):
R.weight.differ = R.Weight_Ref - R.weight.kgx10_out;
//模式开启情况下,蜂鸣器不响的时候
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; //只用输出值来判断
// 检测到体重变化超10kg
if( R.weight.differ > 50) // 50 5kg 100 10kg
{
@ -91,7 +91,8 @@ void L3_task_bed_alarm_handler(S_TASK_Bed_ALARM *s)
// 而上一刻的是关闭,说明是手动打开了模式
if (_s_task_bed_alarm.mode_flag == LeaveForbid_OFF)
{
R.Weight_Ref = tst_weight.kgx10;//记录下参考重量
// R.Weight_Ref = D_get_weight();//记录下参考重量(计算出的实际重量值)
R.Weight_Ref = R.weight.kgx10_out;//记录下参考重量(计算出的实际重量值)
L0_uart1_str("LeaveForbid_OPEN!!!");
L0_uart1_0d0a();
}

24
source/app/task_screen.c

@ -222,18 +222,26 @@ void L3_task_screen_handler(S_TASK_SCREEN *s)
void constructor_scr_pkg()
{
U16 CRC = 0;
// L0_uart1_str("R.weight.kgx10_out: ");
// L0_uart1_us(R.weight.kgx10_out);
// L0_uart1_0d0a();
U16 weight_kgx100 = 0;
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);
if(R.danwei == KG)
{
scrSetValPkg.weight_kgx100[0] = (R.weight.kgx10_out * 10) >> 8 & 0xFF;
scrSetValPkg.weight_kgx100[1] = (R.weight.kgx10_out * 10) >> 0 & 0xFF;
// scrSetValPkg.weight_kgx100[0] = (R.weight.kgx10_out * 10) >> 8 & 0xFF;
// scrSetValPkg.weight_kgx100[1] = (R.weight.kgx10_out * 10) >> 0 & 0xFF;
scrSetValPkg.weight_kgx100[0] = weight_kgx100 >> 8 & 0xFF;
scrSetValPkg.weight_kgx100[1] = weight_kgx100 >> 0 & 0xFF;
}
else if(R.danwei == lb) //1kg = 2.20462262磅
{
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] = (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;
}
CRC = CRC_16(((U8 *)&scrSetValPkg) + 3, 5);
@ -438,7 +446,7 @@ U16 CRC_16(U8 *pMsg, U16 Len)
void ScreenPingOff_judge()
{
U32 Nowtime = D_sys_now;
if( Nowtime - R.ScrTouch_time > D_COUNT_JIFFIES(60000)) //180000 180秒 30000 30秒 60000 60秒
if( Nowtime - R.ScrTouch_time > D_COUNT_JIFFIES(180000)) //180000 180秒 30000 30秒 60000 60秒
{
R.ScrTouch_flag = 0;
R.power_mode = POWER_LOW;

133
source/app/task_weight_keep.c

@ -0,0 +1,133 @@
#include "task_weight_keep.h"
#include "app_config.h"
#include "../bsp/TTSSbsp/bsp_config.h"
#include "../msp/uart/msp_uart1.h"
#include "../clib/c_type51.h"
S_TASK_WEIGHT_KEEP _s_task_weight_keep;
//=============================================
void L3_task_weight_keep_init(void)
{
L1_task_init(&_s_task_weight_keep.task);
L3_task_s_go(_s_task_weight_keep,D_task_init);
}
#define D_task_WEIGHT_KEEP_1 0x50
#define D_task_WEIGHT_KEEP_LEAVE_JUDGE 0x51
#define D_task_WEIGHT_KEEP_ENTER_JUDGE 0x52
#define D_task_WEIGHT_KEEP_4 0x53
void L3_task_weight_keep_handler(S_TASK_WEIGHT_KEEP *s)
{
U16 weight_keep_kgx10 = 0;
U16 weight_real_kgx10 = 0;
TTSS_Task_init():
L2_task_go(D_task_WEIGHT_KEEP_1);
TTSS_Task_step(D_task_WEIGHT_KEEP_1):
if(R.weight_keep_flag == 1)
{
// LED0 = LED0_OFF;
L0_uart1_str("keep status ");
L0_uart1_0d0a();
//当前处于保持状态
//判定是否打破
//连续1s,100ms检测一次,判断实际重量相比保持重量,超过3kg,取消保持
s->levelJudgeTimes = 10;
//3kg
s->levelWeightThresholdKgx10 = 30;
// s->levelTimesThreshold = 10;
s->levelTimes = 8;
s->levelTimes = 0;
L2_task_go_Tdelay(D_task_WEIGHT_KEEP_LEAVE_JUDGE, 0);
}
else
{
// LED0 = LED0_ON;
L0_uart1_str("not keep status ");
L0_uart1_0d0a();
//当前处于非保持状态
//判定是否进入保持状态
//保持判定:连续2s,100ms检测一次,检测实际称重变化小于0.5kg,则设定保持标志为1,weight_keep_kgx10取3s均值
s->enterJudgeTimes = 20;
s->enterTimes = s->enterJudgeTimes;
//0.5kg
s->enterWeightThresholdKgx10 = 5; //10 1kg 5 0.5kg
s->enterMaxWeight = 0;
s->enterMinWeight = R.weight.kgx10_out;
s->enterSumWeight = 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)
{
s->levelTimes++;
// L0_uart1_str("i get here here!! s->levelJudgeTimes = ");
// L0_uart1_uchex(s->levelJudgeTimes);
// L0_uart1_0d0a();
// L0_uart1_str("s->levelTimes = ");
// L0_uart1_uchex(s->levelTimes);
// L0_uart1_0d0a();
}
if(--s->levelJudgeTimes > 0)
{
L2_task_go_Tdelay(D_task_WEIGHT_KEEP_LEAVE_JUDGE, D_Tdelay_100ms);
}
else
{
if(s->levelTimes >= s->levelTimesThreshold)
{
R.weight_keep_flag = 0;
L0_uart1_str("s->levelTimesThreshold = ");
L0_uart1_uchex(s->levelTimesThreshold);
L0_uart1_0d0a();
}
L2_task_go_Tdelay(D_task_WEIGHT_KEEP_1, 0);
}
TTSS_Task_step(D_task_WEIGHT_KEEP_ENTER_JUDGE):
weight_real_kgx10 = R.weight.kgx10_out;
s->enterSumWeight += weight_real_kgx10;
if(weight_real_kgx10 < s->enterMinWeight)
{
s->enterMinWeight = weight_real_kgx10;
}
if(weight_real_kgx10 > s->enterMaxWeight)
{
s->enterMaxWeight = weight_real_kgx10;
}
if(-- s->enterTimes > 0)
{
L0_uart1_str("s->enterTimes = ");
L0_uart1_uchex(s->enterTimes);
L0_uart1_0d0a();
L2_task_go_Tdelay(D_task_WEIGHT_KEEP_ENTER_JUDGE, D_Tdelay_100ms);
}
else
{
if(Lc_abs(s->enterMaxWeight, s->enterMinWeight) < s->enterWeightThresholdKgx10)
{
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);
}
L2_task_go_Tdelay(D_task_WEIGHT_KEEP_1, 0);
}
TTSS_Task_end();
}

57
source/app/task_weight_keep.h

@ -0,0 +1,57 @@
////////////////////////////////////////////////////////////////////////////
///@copyright Copyright (c) 2018, 传控科技 All rights reserved.
///-------------------------------------------------------------------------
/// @file bsp_drv.h
/// @brief bsp @ driver config
///-------------------------------------------------------------------------
/// @version 1.0
/// @author CC
/// @date 20180331
/// @note cc_AS_stc02
//////////////////////////////////////////////////////////////////////////////
#ifndef _APP_TASK_WEIGHT_KEEP_H
#define _APP_TASK_WEIGHT_KEEP_H
#include "../ctask/TTSS_task.h"
#include "../clib/c_lib.h"
#include "../clib/c_type51.h"
typedef struct _s_task_weight_keep
{
TS_task task;
//100ms一次,离开保持状态判定的次数
U8 levelJudgeTimes;
//离开保持重量阈值
U16 levelWeightThresholdKgx10;
//阈值
U8 levelTimesThreshold;
//单位时间呢,超过阈值的次数
U8 levelTimes;
//100ms一次,进入保持状态判定的次数
U8 enterJudgeTimes;
//单位时间,超过阈值的次数
U8 enterTimes;
//进入保持重量阈值
U16 enterWeightThresholdKgx10;
//最大值
U16 enterMaxWeight;
//最小值
U16 enterMinWeight;
//求和
U32 enterSumWeight;
}S_TASK_WEIGHT_KEEP;
extern S_TASK_WEIGHT_KEEP _s_task_weight_keep;
extern void L3_task_weight_keep_init(void);
extern void L3_task_weight_keep_handler(S_TASK_WEIGHT_KEEP *s);
#endif // #ifndef _APP_TASK_WEIGHT_KEEP_H
Loading…
Cancel
Save