
#include "LtDet_ORAP_29044.h"
#include "LtDet_Simulated_IIC_Master.h"

#define  ORAP_29044_DEVICE_ADDR 0x88u


void LtDet_i2c_write_one_byte(uint8_t DEVICE_ADDR,uint8_t REG_ADDR,uint8_t data)
{
    LtDet_IIC_Delay(); 
    LtDet_IIC_Start();
    LtDet_IIC_Transmit_Data(DEVICE_ADDR);

    LtDet_IIC_Transmit_Data(REG_ADDR);

    LtDet_IIC_Transmit_Data(data);

    LtDet_IIC_Stop();  
}

uint8_t LtDet_i2c_read_one_byte(uint8_t DEVICE_ADDR,uint8_t REG_ADDR)
{
    uint8_t data = 0u; 
    LtDet_IIC_Delay(); 
    LtDet_IIC_Start();
    LtDet_IIC_Transmit_Data(DEVICE_ADDR);

    LtDet_IIC_Transmit_Data(REG_ADDR);

    LtDet_IIC_Start();
    LtDet_IIC_Transmit_Data(DEVICE_ADDR +1);

    data = LtDet_IIC_Receive_Data();
    LtDet_IIC_Transmit_ACK(IIC_ACK);
    LtDet_IIC_Stop();  
	  return data;
}
void ORAP_29044_Init(void)
{
    LtDet_IIC_Init();
//    LtDet_i2c_write_one_byte(ORAP_29044_DEVICE_ADDR,0x01,0x00);
//    LtDet_i2c_write_one_byte(ORAP_29044_DEVICE_ADDR,0x0F,0x29);
//    LtDet_i2c_write_one_byte(ORAP_29044_DEVICE_ADDR,0x0E,0x00);
//    LtDet_i2c_write_one_byte(ORAP_29044_DEVICE_ADDR,0x0F,0x00);
    LtDet_i2c_write_one_byte(ORAP_29044_DEVICE_ADDR,0x01,0x06);
//    LtDet_i2c_write_one_byte(ORAP_29044_DEVICE_ADDR,0x01,0x06);
//    LtDet_i2c_write_one_byte(ORAP_29044_DEVICE_ADDR,0x01,0x06);
//    LtDet_i2c_write_one_byte(ORAP_29044_DEVICE_ADDR,0x01,0x06);
}

uint16_t Read_Light_value(void)
{
    uint16_t temp16;
//    LtDet_i2c_write_one_byte(ORAP_29044_DEVICE_ADDR,0x01,0x06);
//    LtDet_i2c_write_one_byte(ORAP_29044_DEVICE_ADDR,0x01,0x06);
//    LtDet_i2c_write_one_byte(ORAP_29044_DEVICE_ADDR,0x01,0x06);
    temp16 = LtDet_i2c_read_one_byte(ORAP_29044_DEVICE_ADDR,0x0A);
    LtDet_i2c_write_one_byte(ORAP_29044_DEVICE_ADDR,0x01,0x06);
    temp16 <<= 8;
    temp16 |= LtDet_i2c_read_one_byte(ORAP_29044_DEVICE_ADDR,0x09);
    
    return temp16;

}
