/** * @copyright 2015 Indie Semiconductor. * * This file is proprietary to Indie Semiconductor. * All rights reserved. Reproduction or distribution, in whole * or in part, is forbidden except by express written permission * of Indie Semiconductor. * * @file applicationTask.c * @Author: Jack.Pan * @E-mail:jack.pan@indiemicro.com * @Date: 2020/09/10 */ #include #include #include #include #include "PINdef.h" #include "hwCtrl.h" #include "prjconfig.h" /*static uint8_t ledNum = LED0;*/ static TaskState_t applState = TASK_STATE_INIT; void ApplTimerExpired(SoftTimer_t *timer); void KeyScanTimerExpired(SoftTimer_t *timer); void TxMsgPro(void); static SoftTimer_t KeyScanTimer = { .mode = TIMER_PERIODIC_MODE, .interval = 5U, .handler = KeyScanTimerExpired }; static uint8_t LED_State = 0U; uint8_t APPL_GetLEDState(void) { return LED_State; } static SoftTimer_t ApplTimer = { .mode = TIMER_PERIODIC_MODE, .interval = 50U, .handler = ApplTimerExpired }; void LED_Ctrl(void); void ApplTimerExpired(SoftTimer_t *timer) { static uint8_t index = 0U; if (index == 0U){ index = 1U; }else{ index = 0; } LED_Ctrl(); } void APPL_TaskHandler(void) { switch(applState){ case TASK_STATE_INIT: SoftTimer_Start(&ApplTimer); SoftTimer_Start(&KeyScanTimer); ADC_Init(ADC_MEASURE_ITEM_VBAT_VTEMP, 0); ADC_Start(); applState = TASK_STATE_ACTIVE; break; case TASK_STATE_ACTIVE: break; default: break; } } void APPL_HandleControlCommands(LIN_Device_Frame_t const *frame) { } uint8_t APPL_PrepareLedParamRequest(uint8_t reqSid,uint8_t *const dataBuff, DiagPublishInfo_t *const diagRsp) { uint8_t response; CommLedParamInfo_t *const info = (CommLedParamInfo_t *)((void *)dataBuff); CommLedParamInfo_t *const infoRsp = (CommLedParamInfo_t *)((void *)diagRsp->payload); diagRsp->sid = reqSid; infoRsp->command = info->command; switch(info->command){ case APP_DIAG_GET_SDK_VERSION: infoRsp->Version.sdkApplication = SDK_APPL_VERSION; infoRsp->Version.linStack = ls_get_lin_version(); diagRsp->packLength = 2U + (uint16_t)sizeof(CommVersion_t); diagRsp->type = (diagRsp->packLength > SF_MAX_DATA_LENGTH)? PDU_TYPE_MULTI_PDU:PDU_TYPE_SINGLE_PDU; response = TRUE; break; default: response = FALSE; break; } return response; } /***************************************************************/ typedef struct { //BYTE 0 uint8_t HG:2;//滑轨 uint8_t AM:2;//按摩 uint8_t KB:2;//靠背 uint8_t REVERSE01:2; //BYTE 1 uint8_t TT:2; uint8_t REVERSE11:2; uint8_t ZY:2; uint8_t REVERSE12:2; //BYTE 2 uint8_t REVERSE21:4; uint8_t FW:1;//复位 uint8_t REVERSE22:3; //3-7 uint8_t REVERSE3; uint8_t REVERSE4; uint8_t REVERSE5; uint8_t REVERSE6; uint8_t REVERSE7; }LIN_MSG_TYPE; LIN_MSG_TYPE LIN_msg_buf; const uint8_t LIN_Init_data[] = {0x00,0x00,0x80,0xff,0xff,0xff,0xff,0x0f}; static uint16_t keydelay[KEY_NUM]={0}; static uint8_t keyflag[KEY_NUM]={0}; uint8_t fan_state,heat_state; #define KEY_DELAY_TIME 6 void KeyScanTimerExpired(SoftTimer_t *timer) { uint8_t keyval,i; for (i = 0; i < KEY_NUM; i++) { keyval = GetKeyState(i+1); if (keyval == 1 && keyflag[i] == 0) { keydelay[i]++; if (keydelay[i] > KEY_DELAY_TIME)//30ms { keyflag[i] = 1; keydelay[i] = KEY_DELAY_TIME; } } else if (keyval == 0) { keyflag[i] = 0; keydelay[i] = 0; } } TxMsgPro(); //ADC_Init(ADC_MEASURE_ITEM_VAMP, 0); ADC_Start(); } extern uint16_t g_AdVal[3]; uint8_t GetKeyFlag(uint8_t keyid) { if (keyid > 0 && keyid <= KEY_NUM) { return keyflag[keyid-1]?1:0; } else { return 0; } } uint8_t g_rxbuf[8],g_txbuf1[8],g_txbuf2[8]; void LED_Ctrl(void) { fan_state = (g_rxbuf[0]&0xc0)>>6; heat_state = (g_rxbuf[0]&0x30)>>4; FanLED_Ctrl(fan_state); HeatLED_Ctrl(heat_state); } void TxMsgPro(void) { uint8_t temp=0,i; temp = 0xf0; #if BOARDCFG == LEFT_BOARD LIN_msg_buf.FW = GetKeyFlag(SIGID_KEY13); LIN_msg_buf.TT = GetKeyFlag(SIGID_KEY6)<<1|GetKeyFlag(SIGID_KEY5); LIN_msg_buf.HG = GetKeyFlag(SIGID_KEY3)<<1|GetKeyFlag(SIGID_KEY4); LIN_msg_buf.AM = GetKeyFlag(SIGID_KEY8)<<1|GetKeyFlag(SIGID_KEY7); LIN_msg_buf.KB = GetKeyFlag(SIGID_KEY9)<<1|GetKeyFlag(SIGID_KEY11); LIN_msg_buf.ZY = GetKeyFlag(SIGID_KEY12)<<1|GetKeyFlag(SIGID_KEY10); temp |= GetKeyFlag(SIGID_KEY1)<<1; temp |= GetKeyFlag(SIGID_KEY2)<<0; #else LIN_msg_buf.FW = GetKeyFlag(SIGID_KEY13); LIN_msg_buf.HG = GetKeyFlag(SIGID_KEY5)<<1|GetKeyFlag(SIGID_KEY6); LIN_msg_buf.TT = GetKeyFlag(SIGID_KEY4)<<1|GetKeyFlag(SIGID_KEY3); LIN_msg_buf.AM = GetKeyFlag(SIGID_KEY7)<<1|GetKeyFlag(SIGID_KEY8); LIN_msg_buf.KB = GetKeyFlag(SIGID_KEY9)<<1|GetKeyFlag(SIGID_KEY11); LIN_msg_buf.ZY = GetKeyFlag(SIGID_KEY10)<<1|GetKeyFlag(SIGID_KEY12); temp |= GetKeyFlag(SIGID_KEY1)<<0; temp |= GetKeyFlag(SIGID_KEY2)<<1; #endif LIN_msg_buf.REVERSE01 = LIN_msg_buf.KB?1:0; /* LIN_msg_buf.REVERSE3 = (fan_state<<4) | (heat_state); LIN_msg_buf.REVERSE4 = g_AdVal[0]>>8; LIN_msg_buf.REVERSE5 = g_AdVal[0]&0xff; LIN_msg_buf.REVERSE6 = g_AdVal[1]>>8; LIN_msg_buf.REVERSE7 = g_AdVal[1]&0xff; */ for (i = 0; i < 8; i++) { g_txbuf1[i] = ((uint8_t *)(&LIN_msg_buf))[i]; } g_txbuf2[0] = temp; g_txbuf2[1] = 0x0b; }