/* 
 * sensor number: 1
 * sensor name: +12V
 * brief: ltc4280
 */
int sensor_1_init(void)
{
	return 0;	
}

int sensor_1_write(void)
{
	return 0;
}

int sensor_1_read(uint8_t *reading)
{
	uint8_t buf = 5;
	int ret;
	int fd = open("/dev/i2c3", O_RDWR);
	ret = stm32_i2c_master_write(fd, 0xAA, &buf, 1);
	if(ret == 0)
	{
		ret = stm32_i2c_master_read(fd, 0xAA, &buf, 1);
		if(ret != 0)
		{
			printf("Sensor 1 read error!\n");
		}
	}
	else
	{
		printf("Sensor 1 write error!\n");
	}
	close(fd);
	//printf("read sensor 1: %#x!\n", buf);
	*reading = buf;
	return 0;
}

/* 
 * sensor number: 2
 * sensor name: +12V_Current
 * brief:  ltc4280
 */
int sensor_2_init(void)
{
//	log("init sensor 2!\r\n");
	return 0;	
}

int sensor_2_write(void)
{
//	log("write sensor 2!\r\n");
	return 0;
}

int sensor_2_read(uint8_t *reading)
{
	uint8_t buf = 4;
	int ret;
	int fd = open("/dev/i2c3", O_RDWR);
	ret = stm32_i2c_master_write(fd, 0xAA, &buf, 1);
	if(ret == 0)
	{
		ret = stm32_i2c_master_read(fd, 0xAA, &buf, 1);
		if(ret != 0)
			printf("Sensor 2 read error!\n");
	}
	else
		printf("Sensor 2 write error!\n");
	close(fd);
	*reading = buf;
	return 0;
}


/* 
 * sensor number: 3
 * sensor name: Temp_Board
 * brief: G780 local 
 */
int sensor_3_init(void)
{
//	log("init sensor 2!\r\n");
	return 0;	
}

int sensor_3_write(void)
{
//	log("write sensor 2!\r\n");
	return 0;
}

int sensor_3_read(uint8_t *reading)
{
	uint8_t buf = 0;
	int ret;
	int fd = open("/dev/i2c3", O_RDWR);
	ret = stm32_i2c_master_write(fd, 0x98, &buf, 1);
	if(ret == 0)
	{
		ret = stm32_i2c_master_read(fd, 0x98, &buf, 1);
		if(ret != 0)
			printf("Sensor 3 read error!\n");
	}
	else
		printf("Sensor 3 write error!\n");
	close(fd);
	*reading = buf;
	return 0;
}


/* 
 * sensor number: 4
 * sensor name: Temp_FPGA
 * brief: G780 remote 
 */
int sensor_4_init(void)
{
//	log("init sensor 2!\r\n");
	return 0;	
}

int sensor_4_write(void)
{
//	log("write sensor 2!\r\n");
	return 0;
}

int sensor_4_read(uint8_t *reading)
{
	uint8_t buf = 1;
	int ret;
	int fd = open("/dev/i2c3", O_RDWR);
	ret = stm32_i2c_master_write(fd, 0x98, &buf, 1);
	if(ret == 0)
	{
		ret = stm32_i2c_master_read(fd, 0x98, &buf, 1);
		if(ret != 0)
			printf("Sensor 4 read error!\n");
	}
	else
		printf("Sensor 4 write error\n");
	close(fd);
	*reading = buf;
	return 0;
}

/* 
 * sensor number: 5
 * sensor name: +1.5V
 * brief: adc_ch1
 */
int sensor_5_init(void)
{
	return 0;	
}

int sensor_5_write(void)
{
	return 0;
}

int sensor_5_read(uint8_t *reading)
{
	uint16_t buf;
	stm32_adc_get_value(1, &buf);
	*reading = buf>>4;
	return 0;
}

/* 
 * sensor number: 6
 * sensor name: +0.75V
 * brief: adc_ch2
 */
int sensor_6_init(void)
{
	return 0;	
}

int sensor_6_write(void)
{
	return 0;
}

int sensor_6_read(uint8_t *reading)
{
	uint16_t buf;
	stm32_adc_get_value(2, &buf);
	*reading = buf>>4;
	return 0;
}