Пример #1
0
*  
****************************************************************************/
//int ReadIRSensors( int i2cDev, Get_IR_Value_t *adcVal ){
int ReadIRSensors( int i2cDev, uint8_t adcVal[4] ){
   
   if ( I2cReadBytes( i2cDev, GET_IR_VALUE, adcVal, 4 ) != 0 )
    {
        LogError( "I2C_IO_GetADC: I2cProcessBlock failed: %s (%d)\n", strerror( errno ), errno );
        return FALSE;
Пример #2
0
/**
  * @brief  This function read multiple bytes to I2C slave with address
  * @param  Buf: Buffer pointer to the data to be send
  * @param  Len: Data Length to be send in byte uint
  * @return
  *     @arg TRUE:  success
  *     @arg FALSE: fail
  */
bool I2cReadNByte(void* I2cMasterHandle, uint8_t SlaveAddr, uint8_t RegAddr, uint8_t* Buf, uint8_t Len)
{
	if(I2cSendAddr(I2cMasterHandle, SlaveAddr, RegAddr, IIC_READ))
	{
		I2cReadBytes(I2cMasterHandle, Buf, Len);
		I2cStop(I2cMasterHandle);
		return TRUE;
	}
	I2cStop(I2cMasterHandle);
	return FALSE;
}
Пример #3
0
void ProcessReadByteCommand( int i2cDev, uint8_t addr )
{
    uint8_t dataByte[ I2C_MAX_DATA_LEN ];
    int     rc;

    if (( rc = I2cReadBytes( i2cDev, addr, dataByte, gByteCount )) != 0 )
    {
        fprintf(stderr, "I2cReadByte failed: %d\n", rc );
        return;
    }

} // ProcessReadByteCommand
/** Performs the data transaction described in @a p_bus_request.
 */
void I2CBusRequestProcessorEndpoint::ExecuteBusRequest( BusRequest *p_bus_request )
{
  int request_type;
  uint8_t addr;
  uint8_t register_addr;

  if ( p_bus_request != NULL )
  {
    if ( p_bus_request->IsLockable() )
    {
      p_bus_request->Lock();
    }

    // Sanity check
    if ( 2 == p_bus_request->GetAddressBufferSize() ) 
    {
      request_type = p_bus_request->GetRequestType();
      addr = p_bus_request->GetAddressBuffer()[0];
      register_addr = p_bus_request->GetAddressBuffer()[1];

      if ( REQUEST_READ == request_type )
      {
        I2cSetSlaveAddress( _i2c_fd, addr, 0 );

        I2cReadBytes( _i2c_fd, register_addr,
                      p_bus_request->GetDataBuffer(),
                      p_bus_request->GetDataBufferSize() );
      }
      else if ( REQUEST_WRITE == request_type )
      {
        I2cSetSlaveAddress( _i2c_fd, addr, 0 );

        I2cWriteBytes(  _i2c_fd, register_addr,
                        p_bus_request->GetDataBuffer(),
                        p_bus_request->GetDataBufferSize() );
      }

      p_bus_request->SetRequestComplete( true );
    }
  
    // Done altering the request
    if ( p_bus_request->IsBlocked() )
    {
      p_bus_request->Unblock();
    }

    if ( p_bus_request->IsLocked() )
    {
      p_bus_request->Unlock();
    }
  }
}
Пример #5
0
void ReadTmp102_1()
{

  const char tdatafile[200]="/var/lib/i2chipd/tmp102_1_temperature";

  char message[200]="";

  int value;
  short temp;
  double temperature;

  const char query[ SQLITEQUERY_SIZE ] = "insert into tmp102 (name,temperature) values (?,?)";  
  const char mquery[ SQLITEQUERY_SIZE ] = "insert into tmp102 values(default,default,?,?)";
  float data[ SQLITE_FLOATS ];

  value = I2cReadBytes(TMP102_ADDRESS1, 2);
  if( value >= 0 )
  {
    temp = (short)(value);
    temp /= 16;
    temperature = (double)(temp*0.0625);

    sprintf(message, "TMP102_1 T=%+6.2f C", temperature);
    syslog(LOG_INFO|LOG_DAEMON, "%s", message);

    WriteFile( tdatafile, temp);

    data[0] = (float)temperature;
    if( dbsqlite == 1 ) InsertSQLite( dbfile, query, "T1", 1, data);
    if( dbmysql == 1 ) InsertMySQL(dbhost, dbuser, dbpswd, database, dbport, mquery, "T1", 1, data);
  }
  else
  {
    syslog(LOG_ERR|LOG_DAEMON, "TMP102_1 temperature reading failed");
  }
}