/****************************************************************************
 Title	:	TERMINAL FOR VISUALIZATION AND CONTROL CONDITIONS IN HOUSE
 Author	:	Patrik Szalay <xszala01@stud.feec.vutbr.cz>
 File	:	htu21d.h
 Software:	CodeWarrior Development Studio Version: 10.6 Build Id:140329
 Target	:	MC9S08LH64
*****************************************************************************/

#ifndef HTU21D_H_
#define HTU21D_H_
#include "iiclib.h"
#include <hidef.h>
#include "derivative.h"
#include "temp_meas.h"

/* HTU21D command definition */
#define HTU21D_TRIG_TEMP_MEAS_HOLD_MASTER 0xE3
#define HTU21D_TRIG_HUM_MEAS_HOLD_MASTER 0xE5
#define HTU21D_TRIG_TEMP_MEAS_NO_HOLD_MASTER 0xF3
#define HTU21D_TRIG_HUM_MEAS_NO_HOLD_MASTER 0xF5
#define HTU21D_WRITE_USER_REG 0xE6
#define HTU21D_READ_USER_REG 0xE7
#define HTU21D_SOFT_RESET 0xFE


/* HTU21D User register definition */

#define HTU21D_RES_MASK 0x81
#define HTU21D_END_OF_BAT_MASK 0x40
#define HTU21D_HEAT_MASK 0x04
#define HTU21D_OTP_RLD_MASK 0x02
#define HTU21D_MEAS_STAT_MASK 0x03


#define HTU21D_CRC_POLYNOMIAL 0x0131
#define HTU21D_SHIFTED_DIVISOR 0x988000 /* This is the 0x0131 polynomial shifted to farthest left of three bytes */

#ifdef __NO_FLOAT__
	#define HTU21D_RH_TEMP_COEFF_DECIMAL -10 /* HTU21D RH Temperature Coefficient (from 0°C to 80°C) */
#else
	#define HTU21D_RH_TEMP_COEFF_FLOAT -0.10
#endif
void htu21d_set_reg(ADDRESS addr, unsigned char ConfR, char* data);

unsigned char htu21d_get_reg(ADDRESS addr, char* data);

void htu21d_soft_reset(ADDRESS addr, char* data);

void htud21d_trigTempMeas(ADDRESS addr, char* data);

void htud21d_trigHumMeas(ADDRESS addr, char* data);

#ifdef __NO_FLOAT__
	decimal htu21d_readTemp_decimal(ADDRESS addr, char* data);
 	
 	decimal htu21d_readHum_decimal(ADDRESS addr, char* data);
#else
 	float htu21d_readTemp_float(ADDRESS addr, char* data);
 	 	 
 	float htu21d_readHum_float(ADDRESS addr, char* data);
#endif

char htu21d_readTemp_char(ADDRESS addr, char* data);

char htu21d_readHum_char(ADDRESS addr, char* data);

unsigned char htu21d_check_crc(unsigned int message_from_sensor, unsigned char check_value_from_sensor);


#endif /* HTU21D_H_ */
