#include "bh1750.h"



Bh1750::Bh1750(I2C *i2c)
{
	i2c_bh1750 = i2c;
	currentMode = 0; // no mode selected
}

uint8_t Bh1750::sleep()
{
	i2c_bh1750->writeByte(BH1750_ADDR,BH1750_POWER_DOWN);
	return 0; 
}

uint8_t Bh1750::wake()
{	
	i2c_bh1750->writeByte(BH1750_ADDR,BH1750_POWER_ON);
	return 0; 
} 

uint8_t Bh1750::reset()
{
	i2c_bh1750->writeByte(BH1750_ADDR,BH1750_RESET);
	return 0; 
} 


float Bh1750::oneShot(uint8_t mode)
{
	if(mode > 0)
	{
		if(	mode == BH1750_ONE_TIME_HIGH_RES_MODE_1 ||
			mode == BH1750_ONE_TIME_HIGH_RES_MODE_2 ||
			mode == BH1750_ONE_TIME_LOW_RES_MODE)
		{
			return i2c_bh1750->readWord(BH1750_ADDR,mode) / 1.2 ;

		}
	}
	std::cout<< "please seelct a one shot mode "<< std::endl;
	exit(1); 
	return 0; 
}

float Bh1750::continious(uint8_t mode, uint8_t delayMs)
{
	if(mode > 0)
	{
		if(	mode == BH1750_CONTINUOUS_HIGH_RES_MODE_1 ||
			mode == BH1750_CONTINUOUS_HIGH_RES_MODE_2 ||
			mode == BH1750_CONTINUOUS_LOW_RES_MODE)
		{
			return i2c_bh1750->readWord(BH1750_ADDR,mode) / 1.2;
		}
	}
	std::cout<< "please seelct a continious mode "<< std::endl;
	exit(1); 
	return 0; 
}
