280 lines
12 KiB
C
280 lines
12 KiB
C
#include "service_lucky_clover.h"
|
|
#include "TjdUiMsgCenter.h"
|
|
#include "cmsis_os2.h"
|
|
#include "common_def.h"
|
|
#include "rtc_api.h"
|
|
#include "securec.h"
|
|
#include "service_gsensor.h"
|
|
#include "service_hrsensor.h"
|
|
#include "soc_osal.h"
|
|
#include "sql_fit.h"
|
|
#include "sys_config.h"
|
|
#include "sys_typedef.h"
|
|
#include "task_service_timer.h"
|
|
|
|
#define ENABLE_PRINT_INFO 1
|
|
#if ENABLE_PRINT_INFO
|
|
#define static_print_info(...) sys_ui_log_i(__VA_ARGS__) // 一般信息打印宏控制
|
|
#define static_print_warn(...) sys_ui_log_w(__VA_ARGS__) // 警告信息打印一般常开
|
|
#define static_print_error(...) sys_ui_log_e(__VA_ARGS__) // 错误信息打印一般常开
|
|
#else
|
|
#define static_print_info(...)
|
|
#define static_print_warn(...)
|
|
#define static_print_error(...)
|
|
#endif
|
|
|
|
typedef struct
|
|
{
|
|
uint8_t hour;
|
|
uint8_t minute;
|
|
uint8_t second;
|
|
} TimePoint;
|
|
|
|
static popup_lucky_clover_t lastData;
|
|
static popup_lucky_clover_t curData;
|
|
static uint16_t last_step = 0;
|
|
static uint16_t last_calories = 0;
|
|
static uint16_t cur_step = 0;
|
|
static uint16_t cur_calories = 0;
|
|
// static uint16_t calories_goal = 0;
|
|
static uint16_t step_goal = 0;
|
|
static uint8_t gsensor_remove_count = 0;
|
|
static gsensor_xyz_info temp_data;
|
|
static float data,last_data;
|
|
static struct rtc_time localTime;
|
|
|
|
static uint32_t time_difference_in_minutes(TimePoint t1, TimePoint t2)
|
|
{
|
|
int diff_hours = t2.hour - t1.hour;
|
|
int diff_minutes = t2.minute - t1.minute;
|
|
int diff_seconds = t2.second - t1.second;
|
|
int total_diff_seconds = diff_hours * 3600 + diff_minutes * 60 + diff_seconds;
|
|
|
|
// 考虑跨越午夜的情况
|
|
if (total_diff_seconds < 0) {
|
|
total_diff_seconds += 24 * 3600;
|
|
} else if (total_diff_seconds > 24 * 3600) {
|
|
total_diff_seconds -= 24 * 3600;
|
|
}
|
|
|
|
return total_diff_seconds;
|
|
}
|
|
|
|
static signed int tjd_service_lucky_clover_handle(void *param)
|
|
{
|
|
// static_print_info("lucky clover service start");
|
|
|
|
cur_step = sql_fit_get_day_step(localTime.tm_wday) - last_step;
|
|
cur_calories = sql_fit_get_day_calorie(localTime.tm_wday) - last_calories;
|
|
// calories_goal = sql_fit_get_goalCalorieNum_data();
|
|
// step_goal = sql_fit_get_goalStepNum_data();
|
|
tjd_service_get_lucky_clover_data(&curData);
|
|
CompareLuckyCloverData(&lastData, &curData);
|
|
tjd_service_gs_get_xyz_fifo(GSEN_SERVICE_LUCKY_CLOVER, &temp_data, 1);
|
|
data = lis2doc_from_fs8_lp1_to_mg(temp_data.gsensor_z.raw_data);
|
|
// printf("lucky clover service data.gsensor_z.real_data = %f,last_data.gsensor_z.real_data = %f\n",
|
|
// data.gsensor_z.real_data, last_data.gsensor_z.real_data);
|
|
if ((data - last_data < 2) ||(data - last_data < -1)) {
|
|
last_data = data;
|
|
gsensor_remove_count++;
|
|
// printf("lucky clover gsensor_remove_count = %d\n", gsensor_remove_count);
|
|
if (gsensor_remove_count == 3600 && sql_fit_get_hand_up_flag() /* 后续需要增加抬手判断 */) {
|
|
lucky_clover_msg_t msg_data;
|
|
msg_data.msg_type = 11;
|
|
if (!popTaskWindowMsg[11].if_triggered) {
|
|
gsensor_remove_count = 0;
|
|
popTaskWindowMsg[11].if_triggered = true;
|
|
TjdUiMsgEventPublish(TJDUI_TOPIC_EVENT_LUCKY_CLOVER, &msg_data, sizeof(msg_data));
|
|
}
|
|
}
|
|
} else
|
|
gsensor_remove_count = 0;
|
|
|
|
lucky_clover_msg_t msg_data;
|
|
if (curData.currentTaskNum >= curData.goalTaskNum && curData.goalTaskNum != 0) {
|
|
msg_data.msg_type = 10;
|
|
lastData = curData;
|
|
if (!popTaskWindowMsg[10].if_triggered) {
|
|
popTaskWindowMsg[10].if_triggered = true;
|
|
TjdUiMsgEventPublish(TJDUI_TOPIC_EVENT_LUCKY_CLOVER, &msg_data, sizeof(msg_data));
|
|
}
|
|
} else if (curData.currentStandNum >= curData.goalStandNum && curData.currentCalorieNum >= curData.goalCalorieNum &&
|
|
curData.currentStepNum >= curData.goalStepNum &&
|
|
curData.currentStrengthTime >= curData.goalStrengthTime) {
|
|
msg_data.msg_type = 9;
|
|
lastData = curData;
|
|
if (!popTaskWindowMsg[9].if_triggered) {
|
|
popTaskWindowMsg[9].if_triggered = true;
|
|
TjdUiMsgEventPublish(TJDUI_TOPIC_EVENT_LUCKY_CLOVER, &msg_data, sizeof(msg_data));
|
|
}
|
|
|
|
} else {
|
|
for (int i = 0; i < 9; i++) {
|
|
// printf("i = %d, popTaskWindow[%d] = %d\n", i, i, popTaskWindowMsg[i].if_need_popup);
|
|
if (popTaskWindowMsg[i].if_need_popup) {
|
|
msg_data.msg_type = i;
|
|
// printf("lucky clover msg_data.msg_type = %d\n", msg_data.msg_type);
|
|
if (msg_data.msg_type <= POPWINDOW_TYPE && !popTaskWindowMsg[i].if_triggered) {
|
|
lastData = curData;
|
|
msg_data.lucky_clover_data = curData;
|
|
popTaskWindowMsg[i].if_triggered = true;
|
|
TjdUiMsgEventPublish(TJDUI_TOPIC_EVENT_LUCKY_CLOVER, &msg_data, sizeof(msg_data));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
tjd_driver_rtc_get_ops()->get_rtc_time(&localTime);
|
|
TimePoint current_time = {.hour = localTime.tm_hour, .minute = localTime.tm_min, .second = localTime.tm_sec};
|
|
TimePoint trigger_time = {.hour = 22, .minute = 0, .second = 0};
|
|
return time_difference_in_minutes(current_time, trigger_time) * 1000;
|
|
}
|
|
|
|
static void tjd_service_lucky_clover_start_send(void)
|
|
{
|
|
tjd_driver_rtc_get_ops()->get_rtc_time(&localTime);
|
|
last_step = sql_fit_get_day_step(localTime.tm_wday);
|
|
last_calories = sql_fit_get_day_calorie(localTime.tm_wday);
|
|
// printf("cxin line = %d, last_step = %d, last_calories = %d\n",__LINE__, last_step, last_calories);
|
|
tjd_service_get_lucky_clover_data(&lastData);
|
|
|
|
TimePoint current_time = {.hour = localTime.tm_hour, .minute = localTime.tm_min, .second = localTime.tm_sec};
|
|
TimePoint trigger_time = {.hour = 22, .minute = 0, .second = 0};
|
|
queue_default_info_t msg_data = {tjd_service_lucky_clover_handle, NULL,
|
|
time_difference_in_minutes(current_time, trigger_time) * 1000, NULL};
|
|
osal_msg_queue_write_copy(tjd_task_service_timer_get_queue_id(), (void *)&msg_data, sizeof(queue_default_info_t),
|
|
0);
|
|
}
|
|
|
|
static void tjd_service_lucky_clover_end_send(void)
|
|
{
|
|
queue_default_info_t msg_data = {tjd_service_lucky_clover_handle, NULL, 0, NULL};
|
|
osal_msg_queue_write_copy(tjd_task_service_timer_get_queue_id(), (void *)&msg_data, sizeof(queue_default_info_t),
|
|
0);
|
|
}
|
|
|
|
void tjd_service_lucky_clover_open(void) { tjd_service_lucky_clover_start_send(); }
|
|
|
|
void tjd_service_lucky_clover_close(void) { tjd_service_lucky_clover_end_send(); }
|
|
|
|
void tjd_service_get_lucky_clover_data(popup_lucky_clover_t *popup_data)
|
|
{
|
|
// static_print_info("lucky clover get data");
|
|
popup_data->goalTaskNum = sql_fit_get_goalTaskNum_data();
|
|
popup_data->currentTaskNum = sql_fit_get_currentTaskNum_data();
|
|
popup_data->goalStandNum = sql_fit_get_goalStandNum_data();
|
|
popup_data->currentStandNum = sql_fit_get_currentStandNum_data();
|
|
popup_data->goalCalorieNum = sql_fit_get_goalCalorieNum_data();
|
|
// popup_data->currentCalorieNum =
|
|
// cur_calories > sql_fit_get_currentCalorieNum_data() ? cur_calories : sql_fit_get_currentCalorieNum_data();
|
|
popup_data->goalStrengthTime = sql_fit_get_goalStrengthTime_data();
|
|
popup_data->currentStrengthTime = sql_fit_get_currentStrengthTime_data();
|
|
popup_data->goalStepNum = sql_fit_get_goalStepNum_data();
|
|
// popup_data->currentStepNum =
|
|
// cur_step > sql_fit_get_currentStepNum_data() ? cur_step : sql_fit_get_currentStepNum_data();
|
|
popup_data->goalDrinkNum = sql_fit_get_goalDrinkNum_data();
|
|
popup_data->currentDrinkNum = sql_fit_get_currentDrinkNum_data();
|
|
popup_data->goalMedicineNum = sql_fit_get_goalMedicineNum_data();
|
|
popup_data->currentMedicineNum = sql_fit_get_currentMedicineNum_data();
|
|
popup_data->goalBloodPressureMeasurTime = sql_fit_get_goalBloodPressureMeasurTime_data();
|
|
popup_data->curBloodPressureMeasurTime = sql_fit_get_curBloodPressureMeasurTime_data();
|
|
popup_data->goalSleepTime = sql_fit_get_goalSleepTime_data();
|
|
popup_data->currentSleepTime = sql_fit_get_currentSleepTime_data();
|
|
popup_data->sleepEarly = sql_fit_get_sleepEarly_data();
|
|
popup_data->custom123 = sql_fit_get_custom123_data();
|
|
}
|
|
|
|
bool *CompareLuckyCloverData(const popup_lucky_clover_t *lastData, const popup_lucky_clover_t *curData)
|
|
{
|
|
// printf("%d====%d\n", lastData->currentStandNum, curData->currentStandNum);
|
|
if (lastData->currentStandNum != curData->currentStandNum) {
|
|
popTaskWindowMsg[0].if_need_popup = true;
|
|
} else {
|
|
popTaskWindowMsg[0].if_need_popup = false;
|
|
if (lastData->currentStandNum < curData->currentStandNum)
|
|
popTaskWindowMsg[0].if_triggered = false;
|
|
}
|
|
// printf("%d====%d\n", cur_calories, calories_goal);
|
|
// if (((cur_calories > curData->currentCalorieNum) ? cur_calories : curData->currentCalorieNum) >=
|
|
// curData->goalCalorieNum)
|
|
if (cur_calories >= curData->goalCalorieNum) {
|
|
popTaskWindowMsg[1].if_need_popup = true;
|
|
} else {
|
|
popTaskWindowMsg[1].if_need_popup = false;
|
|
if (((cur_calories > curData->currentCalorieNum) ? cur_calories : curData->currentCalorieNum) <
|
|
curData->goalCalorieNum)
|
|
popTaskWindowMsg[1].if_triggered = false;
|
|
}
|
|
// printf("%d====%d\n", lastData->currentStrengthTime, curData->currentStrengthTime);
|
|
if (lastData->currentStrengthTime != curData->currentStrengthTime) {
|
|
popTaskWindowMsg[2].if_need_popup = true;
|
|
} else {
|
|
popTaskWindowMsg[2].if_need_popup = false;
|
|
if (lastData->currentStrengthTime < curData->currentStrengthTime)
|
|
popTaskWindowMsg[2].if_triggered = false;
|
|
}
|
|
#if 1
|
|
// printf("line = %d,cur_step = %d==step==%d\n", __LINE__,
|
|
// ((cur_step > curData->currentStepNum) ? cur_step : curData->currentStepNum), curData->goalStepNum);
|
|
// if (((cur_step > curData->currentStepNum) ? cur_step : curData->currentStepNum) >= curData->goalStepNum)
|
|
printf("line = %d,cur_step = %d==step==%d\n", __LINE__, cur_step, curData->goalStepNum);
|
|
if (cur_step >= curData->goalStepNum) {
|
|
popTaskWindowMsg[3].if_need_popup = true;
|
|
} else {
|
|
popTaskWindowMsg[3].if_need_popup = false;
|
|
if (((cur_step > curData->currentStepNum) ? cur_step : curData->currentStepNum) < curData->goalStepNum)
|
|
popTaskWindowMsg[3].if_triggered = false;
|
|
}
|
|
#else // 调试使用
|
|
printf("line = %d, cur_step = %d==step==%d\n", __LINE__, cur_step, curData->goalStepNum);
|
|
if (cur_step >= 2) {
|
|
popTaskWindowMsg[3].if_need_popup = true;
|
|
} else {
|
|
popTaskWindowMsg[3].if_need_popup = false;
|
|
if (cur_step < curData->goalStepNum)
|
|
popTaskWindowMsg[3].if_triggered = false;
|
|
}
|
|
#endif
|
|
// printf("%d====%d\n", lastData->currentDrinkNum, curData->currentDrinkNum);
|
|
if (lastData->currentDrinkNum != curData->currentDrinkNum) {
|
|
popTaskWindowMsg[4].if_need_popup = true;
|
|
} else {
|
|
popTaskWindowMsg[4].if_need_popup = false;
|
|
if (lastData->currentDrinkNum < curData->currentDrinkNum)
|
|
popTaskWindowMsg[4].if_triggered = false;
|
|
}
|
|
|
|
if (lastData->sleepEarly != curData->sleepEarly) {
|
|
popTaskWindowMsg[5].if_need_popup = true;
|
|
} else {
|
|
popTaskWindowMsg[5].if_need_popup = false;
|
|
// popTaskWindowMsg[5].if_triggered = false;
|
|
}
|
|
|
|
if (lastData->currentSleepTime != curData->currentSleepTime) {
|
|
popTaskWindowMsg[6].if_need_popup = true;
|
|
} else {
|
|
popTaskWindowMsg[6].if_need_popup = false;
|
|
// popTaskWindowMsg[6].if_triggered = false;
|
|
}
|
|
|
|
if (lastData->curBloodPressureMeasurTime != curData->curBloodPressureMeasurTime) {
|
|
popTaskWindowMsg[7].if_need_popup = true;
|
|
} else {
|
|
popTaskWindowMsg[7].if_need_popup = false;
|
|
// popTaskWindowMsg[8].if_triggered = false;
|
|
}
|
|
|
|
if (lastData->custom123 != curData->custom123) {
|
|
popTaskWindowMsg[8].if_need_popup = true;
|
|
} else {
|
|
popTaskWindowMsg[8].if_need_popup = false;
|
|
// popTaskWindowMsg[8].if_triggered = false;
|
|
}
|
|
|
|
return popTaskWindowMsg;
|
|
}
|
|
|
|
bool get_lucky_clover_popup_flag(void) { return lucky_clover_popup_flag; }
|
|
|
|
void set_lucky_clover_popup_flag(bool flag) { lucky_clover_popup_flag = flag; } |