/*
*********************************************************************************************************
*
*	模块名称 : 光敏电阻检测车模块
*	文件名称 :
*	版    本 : V1.0
*	说    明 : 头文件
*
*	修改记录 :
*		版本号  日期       作者    说明
*		v1.0
*
*	Copyright (C)
*
*********************************************************************************************************
*/
#ifndef _BSP_PHOTORESISTOR_H
#define _BSP_PHOTORESISTOR_H
#include "user.h"
#define THR_PHO_RESISTOR_H thr_pho_resistor_h
#define THR_PHO_RESISTOR_L 100
#define PR_DEC_COUNT 4
#define DAY_OR_NIGHT day_or_night//0x765
#define DAY_OR_NIGHT2 day_or_night2//0x300
#define THR_night thr_night//0x300
#define THR_day thr_day//0x174
#define DiodeDrop (0.40/3.3*4096*10/308)
enum DeviceFault
{
	DeviceOk=0,
        BatLow=1,
	HumanDammage=2,
        MotorFault=4,
	QmcFault=8,
	PhoFault=16

};
enum STATUS{
        NO   = 0,
        YES  = 1,
};
#define T_3M 45//前三分钟不检测车离开
extern u8 time_T_60s;
extern int no_car_count;
enum //TIME_STATE//时刻表
{
    T_4s             = 1,
    T_10s            = 2,//10s
    T_20s         = 5,//20s
    T_30s         = 8,//30s
    T_40s          = 10,//40s
    T_60s            = 15,//1minute
    SELF_ADAPTION_TIMR    = 25,
    T_200s    = 51,//200s
    T_5m          = 75,//5mintutes
    NO_CAR                = 76//5mintutes+
};
extern int16_t day_or_night;//0x765
extern int16_t day_or_night2;//0x300
extern int16_t thr_night;//0x300
extern int16_t thr_day;//0x174

extern int16_t  thr_pho_resistor_h;
extern int16_t  ph_stable_value;
extern uint8_t dec_car_count;
extern int16_t ph_base;//光敏基准值
extern int16_t VAL_PHOTO;
extern int ph_wave_flag ;
extern int ph_wave_count;
extern uint8_t pho_fault_count;
extern int geo_wave_flag;
//extern enum SIGNAL_STATE photores_dete(void);
extern enum STATUS Ph_Dec_in_flag;//光敏检测到车标志
extern enum STATUS ph_state;//光敏是否正常标志
extern enum STATUS ge_state;
extern double BatVoltage[2];
extern uint32_t MotorRunCount;
extern uint8_t DelayTime4s;
extern u8 mag_time_count;
enum {
	first_dec = 1,
	next_dec
};

struct  BASE_DEC_FLAG
{
    bool QMC_BASE_FLAG;
    bool PHOTOR_BASE_FLAG;
};

void get_photoresistor_ad(void);

void BatVolDec(u8 state);


int ph_car_in(int flag);
int ph_car_out(void);
void judge_day_night(int flag);
void judge_ph_state(void);
void time_state(void);

#endif
/**************************************************************/