#ifndef _DOG_SENSOR_H_
#define _DOG_SENSOR_H_

#include "zf_common_headfile.h"
#include "zf_common_debug.h"

#include "DOG_data.h"

struct DOG_ENCODER;
struct DOG_IMU;
struct DOG_CURRENT;
struct DOG_VOLTAGE;

/****************************************************************************************************************************/
/*  */
typedef struct DOG_ENCODER{
	/*  */
	encoder_index_enum encoder_idx;
	encoder_channel1_enum ch1_pin;	// ͨ1
	encoder_channel2_enum ch2_pin;	// ͨ2
	_bool_ rotate_reverse_flag;	// תο־λ
	uint16 encoder_line_num;	// 
	float encoder_IT_time;		// жʱms
	float gear_ratio;			// ݱȣת/ת٣
	float wheel_circumference;	// ܳcm
	/* ȡֵ */
	int16 encoder_raw;	// ԭʼֵߣ
	float encoder_rpm;	// ת٣ת/s
	float motor_rpm;	// ת٣ת/s
	float wheel_speed;	// ٣cm/s
	
	/* Ա */
	void (*encoder_get)(struct DOG_ENCODER* this);	// ֵȡ
}DOG_ENCODER;

// ֵȡ
void encoder_get(struct DOG_ENCODER* this);

// 캯
void encoder(struct DOG_ENCODER* this, encoder_index_enum encoder_idx, encoder_channel1_enum ch1_pin, encoder_channel2_enum ch2_pin, _bool_ rotate_reverse_flag, uint16 encoder_line_num, uint16 encoder_IT_time, float gear_ratio, float wheel_circumference);
// 
void _encoder(struct DOG_ENCODER* this);
/****************************************************************************************************************************/
/* Դ */
typedef struct DOG_IMU{
	/* ǲ */	
	_bool_ X_reverse_flag;			// X תο־λ
	_bool_ Y_reverse_flag;			// Y תο־λ
	_bool_ Z_reverse_flag;			// Z תο־λҪ֤󸺣
	/* ȥƮ */
	_bool_ gyro_calibration_flag;	// ȥƮ־λ
	_bool_ acc_calibration_flag;	// ٶȼȥƮ־λ
	uint32 calibration_epoch;		// ȥƮִ
	uint32 epoch;					// ִ
	float gyro_x_calibration;		
	float gyro_y_calibration;
	float gyro_z_calibration;
	float gyro_x_max;
	float gyro_x_min;
	float gyro_y_max;
	float gyro_y_min;
	float gyro_z_max;
	float gyro_z_min;
	float acc_x_calibration;
	float acc_y_calibration;
	float acc_z_calibration;
	float acc_x_max;
	float acc_x_min;
	float acc_y_max;
	float acc_y_min;
	float acc_z_max;
	float acc_z_min;
	
	/* ȡֵ */
	float gyro_x;
	float gyro_y;
	float gyro_z;
	float acc_x;
	float acc_y;
	float acc_z;

	/* Ա */
	void (*gyro_get)(struct DOG_IMU* this);	// ֵȡ
	void (*acc_get)(struct DOG_IMU* this);	// ٶȼֵȡ
}DOG_IMU;

// ֵȡ
void gyro_get(struct DOG_IMU* this);
// ٶȼֵȡ
void acc_get(struct DOG_IMU* this);	

// 캯
void imu(struct DOG_IMU* this, _bool_ X_reverse_flag, _bool_ Y_reverse_flag, _bool_ Z_reverse_flag, uint32 calibration_epoch);
// 
void _imu(struct DOG_IMU* this);
/****************************************************************************************************************************/
/*  */
typedef struct DOG_CURRENT{
	/* ADC */
	adc_channel_enum adc_ch;			// ADC
	adc_resolution_enum resolution;		// ADCֱ
	float current_ratio;				// ѹ-ϵѹ/
	_bool_ current_reverse_flag;	    // ת־λ
	/* ȥƮ */
	_bool_ current_calibration_flag;	// ȥƮ־λ

	uint32 calibration_epoch;			// ȥƮִ
	uint32 epoch;						// ִ
	float current_calibration;		// ȥƮֵ
	/* ȡֵ */
	float current;						// 

	float (*current_get)(struct DOG_CURRENT* this);	// ȡ
}DOG_CURRENT;

// ȡ
float current_get(struct DOG_CURRENT* this);

// 캯
void current(struct DOG_CURRENT* this, adc_channel_enum adc_ch, adc_resolution_enum resolution, float current_ratio, uint32 calibration_epoch,_bool_ current_reverse_flag);
// 
void _current(struct DOG_CURRENT* this);
/****************************************************************************************************************************/
/* ѹ */
typedef struct DOG_VOLTAGE{
	/* ADC */
	adc_channel_enum adc_ch;			// ADC
	adc_resolution_enum resolution;		// ADCֱ
	/* ȡֵ */
	float voltage;
	
	float (*voltage_get)(struct DOG_VOLTAGE* this);	// ȡ
}DOG_VOLTAGE;

// ѹȡ
float voltage_get(struct DOG_VOLTAGE* this);

// 캯
void voltage(struct DOG_VOLTAGE* this, adc_channel_enum adc_ch, adc_resolution_enum resolution);
// 
void _voltage(struct DOG_VOLTAGE* this);
/****************************************************************************************************************************/

#endif