// // Created by YY on 2020/12/16. // #include "prepare.h" #include "../native-lib.h" #include "../driver_test.h" #include "../test_common/car_sensor.h" #include "../common/apptimer.h" #include "../jni_log.h" #define DEBUG(fmt, args...) LOGD(" <%s>: " fmt, __func__, ##args) static int touch[4]; static int hint_cnt; static bool exec = false; static void TtsBack(int seq); static void PrepareTimeout(apptimer_var_t val); static void PrepareTimeout2(apptimer_var_t val); void StartPrepare(void) { exec = true; hint_cnt = 0; memset(touch, 0, sizeof(touch)); PlayTTS(examParam.prepare_tts, TtsBack); DEBUG("开始上车准备"); } void TerminatePrepare(void) { exec = false; AppTimer_delete(PrepareTimeout); AppTimer_delete(PrepareTimeout2); } void handlePrepare(uint16_t sensor_id, int value) { if (!exec) return; if (sensor_id == SEATBELT) { if (value == INSERT_SEATBELT) { AppTimer_delete(PrepareTimeout); // 检查绕车传感器情况 if (touch[0] + touch[1] + touch[2] + touch[3] != 4) { exec = false; PrepareOver(-1); } else { exec = false; PrepareOver(0); } } else { // 安全带解开 AppTimer_delete(PrepareTimeout2); } } if (sensor_id == SURROUND_CAR_1 && value == SURROUND_CAR_ACTIVE && touch[0] != 1) { touch[0] = 1; PlayTTS(examParam.touch_leftfront_tts, NULL); DEBUG("触摸传感器1"); } if (sensor_id == SURROUND_CAR_2 && value == SURROUND_CAR_ACTIVE && touch[1] != 1) { touch[1] = 1; PlayTTS(examParam.touch_leftrear_tts, NULL); DEBUG("触摸传感器2"); } if (sensor_id == SURROUND_CAR_3 && value == SURROUND_CAR_ACTIVE && touch[2] != 1) { touch[2] = 1; PlayTTS(examParam.touch_rightrear_tts, NULL); DEBUG("触摸传感器3"); } if (sensor_id == SURROUND_CAR_4 && value == SURROUND_CAR_ACTIVE && touch[3] != 1) { touch[3] = 1; PlayTTS(examParam.touch_rightfront_tts, NULL); DEBUG("触摸传感器4"); } } static void TtsBack(int seq) { if (hint_cnt == 0) { if (ReadCarStatus(SEATBELT) == INSERT_SEATBELT) { // 再次提示 AppTimer_add(PrepareTimeout2, D_SEC(10)); DEBUG("设置再次提醒"); } AppTimer_add(PrepareTimeout, D_MIN(2)); DEBUG("设置2分钟超时"); } hint_cnt++; } static void PrepareTimeout(apptimer_var_t val) { DEBUG("上车准备超时"); exec = false; PrepareOver(-2); } static void PrepareTimeout2(apptimer_var_t val) { PlayTTS(examParam.prepare_tts, TtsBack); }