Commit 222a0f70 authored by 王佳伟's avatar 王佳伟

feat:新增日间夜间模式,日间以手机闪光灯亮度为基准,在夜间模式下,当手机闪光灯照射1.5秒后进入日间模式,关闭手机闪光灯1.5秒后进入夜间模式

parent 31721fa2
...@@ -20,7 +20,7 @@ User definitions ...@@ -20,7 +20,7 @@ User definitions
typedef unsigned short MD_STATUS; typedef unsigned short MD_STATUS;
#define HAS_BOOTLOADER (1u) // 仅仿真App时设置为0 #define HAS_BOOTLOADER (0u) // 仅仿真App时设置为0
#define APP_BASE (0x0000C400ul) #define APP_BASE (0x0000C400ul)
/* Status list definition */ /* Status list definition */
......
#include "Backlight.h" #include "Backlight.h"
#include "Components.h" #include "Components.h"
#define LIGHT_DATA_TIME 10u /*这里填写多长时间采集一个数据,单位ms*/
#define LIGHT_DATA_NUM 20u /*燃油电阻采集数据总数 最大255*/
#define LIGHT_CAL_START 5u /*数据排序后取中间部分计算平均:起始*/
#define LIGHT_CAL_END 15u /*数据排序后取中间部分计算平均:结束*/
Light_uint8_t LightADCompleteFlg = 0u;
Light_uint16_t LightR = 0u;
Light_uint16_t LightR_Status = 0;
Light_uint16_t LightR_Status_Count = 0u;
Light_uint16_t NtcDataCount;
Light_uint16_t NtcData[LIGHT_DATA_NUM];
typedef struct typedef struct
{ {
Light_uint16_t Temperature; /* 温度 */ Light_uint16_t Temperature; /* 温度 */
...@@ -41,6 +51,96 @@ _st_BacklightLevel BacklightLevelTable[BacklightLevel_Max] = ...@@ -41,6 +51,96 @@ _st_BacklightLevel BacklightLevelTable[BacklightLevel_Max] =
}; };
void Data_Light_Res_service(Light_uint8_t deltaTime)//获取光感阻值,并做平均
{
uint16_t LightRes = 0;
uint8_t i, j;
uint32_t temp32;
static uint16_t timeCount = 0;
if (timeCount >= LIGHT_DATA_TIME)
{
timeCount = 0;
if (NtcDataCount < LIGHT_DATA_NUM)
{
/*获取光敏电阻*/
LightRes = ADC_Read_Signal(ADC_CH_LIGHT_SENSITIVE); // ADC_Read_Signal(ADC_CH_FUEL1);
/*四舍五入*/
if (LightRes < 32000)
{
if (LightRes % 10 >= 5)
{
LightRes += 5;
}
}
else
{
LightRes = 32000;
}
/*由小到大插入数据*/
for (i = 0; i < NtcDataCount; i++)
{
if (LightRes < NtcData[i])
{
break;
}
}
for (j = NtcDataCount; j > i; j--)
{
NtcData[j] = NtcData[j - 1];
}
NtcData[i] = LightRes;
NtcDataCount++;
}
else
{
/*一组数据采集完毕,取中间部分计算平均值*/
temp32 = 0;
for (i = LIGHT_CAL_START; i < LIGHT_CAL_END; i++)
{
temp32 += NtcData[i];
}
LightR = (uint16_t) (temp32 / (LIGHT_CAL_END - LIGHT_CAL_START));
NtcDataCount = 0;
LightADCompleteFlg = 1;
}
}
timeCount += deltaTime;
if(LightADCompleteFlg)
{
if(LightR_Status == 0)
{
if(LightR >20)
{
LightR_Status_Count++;
}
else
{
LightR_Status_Count = 0 ;
}
}
else
{
if(LightR <20)
{
LightR_Status_Count++;
}
else
{
LightR_Status_Count = 0 ;
}
}
if(LightR_Status_Count>=150)
{
LightR_Status_Count = 0;
LightR_Status = !LightR_Status;
}
}
}
Light_uint16_t GetBacklightDutyByLevel(Light_uint16_t level) Light_uint16_t GetBacklightDutyByLevel(Light_uint16_t level)
......
...@@ -74,7 +74,7 @@ ADC_Data_st_t stADCData[ADC_SIGNAL_CH_NUMBER]; ...@@ -74,7 +74,7 @@ ADC_Data_st_t stADCData[ADC_SIGNAL_CH_NUMBER];
const uint8_t __attribute__((aligned(4))) u8ADCChList[ADC_CONV_CH_NUMBER] = const uint8_t __attribute__((aligned(4))) u8ADCChList[ADC_CONV_CH_NUMBER] =
{ {
2U, 3U, 7U, 5U, 6U, 2U, 3U, 7U, 5U, 6U, 4U, 12U,
}; };
const __attribute__((aligned(4))) ADC_Ch_Cfg_st_t stADCChCfg[ADC_SIGNAL_CH_NUMBER] = const __attribute__((aligned(4))) ADC_Ch_Cfg_st_t stADCChCfg[ADC_SIGNAL_CH_NUMBER] =
...@@ -84,6 +84,9 @@ const __attribute__((aligned(4))) ADC_Ch_Cfg_st_t stADCChCfg[ADC_SIGNAL_CH_NUMBE ...@@ -84,6 +84,9 @@ const __attribute__((aligned(4))) ADC_Ch_Cfg_st_t stADCChCfg[ADC_SIGNAL_CH_NUMBE
{ 2U, 0U, 0U, 0U, 0U, 1U, ADC_Voltage_Calc_Circuit101,}, { 2U, 0U, 0U, 0U, 0U, 1U, ADC_Voltage_Calc_Circuit101,},
{ 3U, 2U, 0U, 2U, 0U, 1U, ADC_Res_Calc_Circuit101,}, { 3U, 2U, 0U, 2U, 0U, 1U, ADC_Res_Calc_Circuit101,},
{ 4U, 2U, 0U, 2U, 0U, 1U, ADC_Res_Calc_Circuit101,}, { 4U, 2U, 0U, 2U, 0U, 1U, ADC_Res_Calc_Circuit101,},
{ 5U, 3U, 0U, 5000U, 0U, 10U, ADC_Res_Calc_Circuit201,},
{ 6U, 2U, 0U, 2U, 0U, 1U, ADC_Res_Calc_Circuit101,},
}; };
const __attribute__((aligned(4))) ADC_Res_List_st_t stADCResList[ADC_SIGNAL_CH_NUMBER] = const __attribute__((aligned(4))) ADC_Res_List_st_t stADCResList[ADC_SIGNAL_CH_NUMBER] =
...@@ -93,6 +96,8 @@ const __attribute__((aligned(4))) ADC_Res_List_st_t stADCResList[ADC_SIGNAL_CH_N ...@@ -93,6 +96,8 @@ const __attribute__((aligned(4))) ADC_Res_List_st_t stADCResList[ADC_SIGNAL_CH_N
{ 0U, 0U, 0U, 0U,}, { 0U, 0U, 0U, 0U,},
{ 0U, 0U, 500U, 300U,}, { 0U, 0U, 500U, 300U,},
{ 0U, 0U, 500U, 0U,}, { 0U, 0U, 500U, 0U,},
{ 47000U, 0U, 100000U, 0U,},
{ 0U, 0U, 500U, 0U,},
}; };
/* Private function prototypes ----------------------------------------------*/ /* Private function prototypes ----------------------------------------------*/
...@@ -170,7 +175,7 @@ void Analog_Signal_Conv_Service(void) ...@@ -170,7 +175,7 @@ void Analog_Signal_Conv_Service(void)
if (stADCCtrl.u8DebounceCnt == 0U) if (stADCCtrl.u8DebounceCnt == 0U)
{ {
stADCCtrl.enStatus = ADC_STAT_CONV; stADCCtrl.enStatus = ADC_STAT_CONV;
} }
else else
{ {
......
...@@ -33,11 +33,13 @@ enum ADCChName ...@@ -33,11 +33,13 @@ enum ADCChName
ADC_CH_FUEL_VREF, ADC_CH_FUEL_VREF,
ADC_CH_FUEL1, ADC_CH_FUEL1,
ADC_CH_COOLANT_TEMP1_R, ADC_CH_COOLANT_TEMP1_R,
ADC_CH_NTC_TEMP,
ADC_CH_LIGHT_SENSITIVE,
}; };
/* Exported macro ------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/
#define ADC_TOTAL_CH_NUMBER (5U) #define ADC_TOTAL_CH_NUMBER (7U)
#define ADC_SIGNAL_CH_NUMBER (5U) #define ADC_SIGNAL_CH_NUMBER (7U)
#define ADC_REF_VOLTAGE u16ADCRefVoltage #define ADC_REF_VOLTAGE u16ADCRefVoltage
/* Exported variables --------------------------------------------------------*/ /* Exported variables --------------------------------------------------------*/
......
...@@ -37,6 +37,7 @@ void Sys_10ms_Tasks(void) ...@@ -37,6 +37,7 @@ void Sys_10ms_Tasks(void)
Key_TimeOut_Service(); Key_TimeOut_Service();
Fuel_R_Cal(10u); Fuel_R_Cal(10u);
Coolant_R_Cal(10u); Coolant_R_Cal(10u);
Data_Light_Res_service(10);
} }
void Sys_20ms_Tasks(void) void Sys_20ms_Tasks(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment