#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(); }