#ifndef CUSTOM_VAR_H_
#define CUSTOM_VAR_H_

#include "main.h"
#include "custom_defines.h"

//#define buffer_size 512
//#define toMega(x) x/1000000
//#define toKilo(x) x/1000

//#define R1 2.671
//#define R2 345.1

struct var_values{
	double U1;
	double U1_OLD;

	uint16_t ADC1_Correct_values_counter;
	uint16_t ADC1_[buffer_size];	
	uint16_t ADC1_Buff[buffer_size];	
	uint16_t ADC1_BUFF_MID;
	uint16_t ADC1_BUFF_MID_OLD;	
	uint16_t ADC1_MID;
	uint16_t ADC1_MID_OLD;
	int ADC1_DELTA;
	int ADC1_DELTA_OLD;
	int ADC1_MID_DELTA;
	int ADC1_MID_DELTA_OLD;
	
	double U2;
	double U2_OLD;
	uint16_t ADC2_Correct_values_counter;
	uint16_t ADC2_[buffer_size];	
	uint16_t ADC2_Buff[buffer_size];	
	uint16_t ADC2_BUFF_MID;
	uint16_t ADC2_BUFF_MID_OLD;	
	uint16_t ADC2_MID;
	uint16_t ADC2_MID_OLD;
	int ADC2_DELTA;
	int ADC2_DELTA_OLD;
	int ADC2_MID_DELTA;
	int ADC2_MID_DELTA_OLD;
};

//struct flags{
//	unsigned Power_Turn_On : 1;
//};

struct adc{
	unsigned ADC_MAX;
	unsigned ADC_MIN;
	unsigned ADC_DELTA;
	double U_MAX;
	double U_MIN;
	double U_DELTA;
};
struct var_minmax{
	struct adc ADC1_;
	struct adc ADC2_;
};

struct var_result{
	double U_ALL;
	double U_ALL_ADC;
	float I;
	float R;
};

struct error_of_voltage_and_resistance_calculation{
	long long int Count_of_incorrect_ADC_JDR1_value;
	long long int Count_of_incorrect_ADC_JDR2_value;
	
};

void VAR_Power_Turn_OnOff(void);
void VAR_Average_Uint16(uint16_t *F, uint16_t *S);
void VAR_READ_ADC(void);
void VAR_Delta(struct var_values *VAR_VALUES);
uint16_t VAR_Average(uint16_t *Arry_of_ADC_Values, uint16_t lenght);
void VAR_Calculations(struct var_values *VAR_VALUES, struct var_result *VAR_RESULT);
void VAR_To_LCD(void);


#endif
