Esempio n. 1
0
// Read two bytes at an address as INT16
sint16 AT24C32Helper::ReadInt16(int addr)
{
	byte lowByte = i2c_eeprom_read_byte(deviceAddr, addr);
	byte highByte = i2c_eeprom_read_byte(deviceAddr, addr+1);

	return (sint16)(((lowByte << 0) & 0xFF) + ((highByte << 8) & 0xFF00));
}
Esempio n. 2
0
int getMenu(int id)
{
	int menu_start_addr=MENU_DATA_START_ADDR+(id*MENU_DATA_LENGTH);
	for(int i=0;i<MENU_DATA_LENGTH;i++)
	{
		Menu.data[i]=i2c_eeprom_read_byte(menu_start_addr+i);
		//delay(2);
	}
}
int eeprom_read(
	char *buffer, 
	unsigned char len, 
	unsigned short page, 
	unsigned char word)
{
	char i;
	for(i=0;i<len;i++){
		i2c_eeprom_read_byte(EEPROM_ADDRESS, page+word+i, (buffer+i));
	}
	return 1;
}
Esempio n. 4
0
// Read a string from an address until terminated (NUL)
String AT24C32Helper::ReadString(int addr)
{
	String str = "";
	for (int i = addr; i < EEPROM_LEN; i++)
	{
		byte val = i2c_eeprom_read_byte(deviceAddr, i);
		if (val == 0x00 || val == 0xFF)
			break;
		str += char(val);
	}
	return str;
}
Esempio n. 5
0
// Read a string from an address with an exact length
String AT24C32Helper::ReadStringExact(int addr, int len) {

	String str = "";

	for (int i = addr; i < addr + len; ++i)
	{
		byte val = i2c_eeprom_read_byte(deviceAddr, i);

		if ((0 < val) && (val < 255)) {
			str += char(val);
		}
	}
	return str;

}
Esempio n. 6
0
/*********************** PowerDownSensor start ***********************************/
void PowerDownSensor(void)
{
if(_led_status == _led_off)
{
uint8_t b0_0x32_off;
uint8_t b0_0x33_off;
uint8_t b0_0x35_off;
i2c_eeprom_write_byte(0x7F,0x00); //bank0
b0_0x32_off = i2c_eeprom_read_byte(0x32);
b0_0x33_off = i2c_eeprom_read_byte(0x33);
b0_0x35_off = i2c_eeprom_read_byte(0x35);
_b1_0x37_off = b0_0x32_off ;
_b1_0x36_off = 0x62 & (( b0_0x33_off & 0x3 ) << 5) ;
_b0_0x4d_off = 0x9A & (( b0_0x33_off & 0x4 ) << 5) ;
_b0_0x48_off = 0x0F & ( b0_0x35_off & 0xF ) ;
i2c_eeprom_write_byte(0x06,0x0A);
}
else
{
uint8_t b0_0x32_on;
uint8_t b0_0x33_on;
uint8_t b0_0x35_on;
i2c_eeprom_write_byte(0x7F,0x00); //bank0
b0_0x32_on = i2c_eeprom_read_byte(0x32);
b0_0x33_on = i2c_eeprom_read_byte(0x33);
b0_0x35_on = i2c_eeprom_read_byte(0x35);
_b1_0x37_on = b0_0x32_on ;
_b1_0x36_on = 0x62 & (( b0_0x33_on & 0x3 ) << 5) ;
_b0_0x4d_on = 0x9A & (( b0_0x33_on & 0x4 ) << 5) ;
_b0_0x48_on = 0x0F & ( b0_0x35_on & 0xF ) ;
if(_touch_flag == 0x80) //if no touch, do not go to power down.
i2c_eeprom_write_byte(0x06,0x0A);

else
{
i2c_eeprom_write_byte(0x7f,0x00); //for bank0
i2c_eeprom_write_byte(0x5, 0xB8);
i2c_eeprom_write_byte(0x7F, 0x01);
i2c_eeprom_write_byte(0x38, 0xFF);
}
}
}
Esempio n. 7
0
void led_ctrl(uint8_t touch)
{
if(touch == 0x80)
{
uint8_t data;
uint16_t Frame_Average, EP_L, EP_H, Exposure_Line;
i2c_eeprom_write_byte(0x7f,0x00);
i2c_eeprom_write_byte(0x05, 0x98);
data = i2c_eeprom_read_byte(0x33);
EP_H=data&0x03;
data = i2c_eeprom_read_byte(0x32);
EP_L=data;
Exposure_Line=(EP_H<<8)+EP_L;
i2c_eeprom_write_byte(0x7f,0x01);
if(_sleepflag==1)
{
i2c_eeprom_write_byte(0x38, (0xE0|DEFAULT_LED_STEP));
_sleepflag = 0 ;
}
if (_state_count <= STATE_COUNT_TH) {
_state_count++;
_led_current_change_flag = 0;
}
else {
_state_count = 0;
if(_state == 0)
{
if( (Exposure_Line>=LED_CTRL_EXPO_TIME_HI_BOUND) ||
(Exposure_Line<=LED_CTRL_EXPO_TIME_LOW_BOUND )
)
{
data = i2c_eeprom_read_byte(0x38);
_led_step=data&0x1f;
if( (Exposure_Line>=LED_CTRL_EXPO_TIME_HI_BOUND)
&& (_led_step < LED_CURRENT_HI))
{
_state = 1 ;
_led_step=_led_step+LED_INC_DEC_STEP;
if(_led_step>LED_CURRENT_HI)
_led_step=LED_CURRENT_HI;
i2c_eeprom_write_byte(0x38, (_led_step|0xE0));
_led_current_change_flag = 1;
}
else if((Exposure_Line<=LED_CTRL_EXPO_TIME_LOW_BOUND)
&& (_led_step > LED_CURRENT_LOW))
{
_state = 2 ;
if(_led_step<=(LED_CURRENT_LOW+LED_INC_DEC_STEP))
_led_step=LED_CURRENT_LOW;
else
_led_step=_led_step-LED_INC_DEC_STEP;
i2c_eeprom_write_byte(0x38, (_led_step|0xE0));

_led_current_change_flag = 1;
}else
{
_state = 0 ;
_led_current_change_flag = 0;
}
}
else {
_led_current_change_flag = 0;
}
}
else if(_state == 1)
{
if(Exposure_Line > LED_CTRL_EXPO_TIME_HI)
{
_state = 1 ;
_led_step=_led_step+LED_INC_DEC_STEP;
if(_led_step>=LED_CURRENT_HI)
{
_state = 0 ;
_led_step=LED_CURRENT_HI;
}
i2c_eeprom_write_byte(0x38, (_led_step|0xE0));
_led_current_change_flag = 1;
}
else
{
_state = 0 ;
_led_current_change_flag = 0;
}
}
else
{
if(Exposure_Line < LED_CTRL_EXPO_TIME_LOW)
{
_state = 2 ;
if(_led_step<=(LED_CURRENT_LOW+LED_INC_DEC_STEP))
{
_state = 0 ;
_led_step=LED_CURRENT_LOW;
}
else
_led_step=_led_step-LED_INC_DEC_STEP;
i2c_eeprom_write_byte(0x38, (_led_step|0xE0));
_led_current_change_flag = 1;
}
else
{
_state = 0;
_led_current_change_flag = 0;
}
}
}
}

else
{
i2c_eeprom_write_byte(0x7f,0x00);
i2c_eeprom_write_byte(0x05, 0xB8);
i2c_eeprom_write_byte(0x7F, 0x01); 
_led_step = DEFAULT_LED_STEP;
//i2c_eeprom_write_byte(0x38, (0xE0 | DEFAULT_LED_STEP)); //for Asian person only
i2c_eeprom_write_byte(0x38, 0xFF);
_sleepflag = 1;
_led_current_change_flag = 0;
}
}