#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/i2c.h>


// ---- Public Variables ----------------------------------------------------
// ---- Private Constants and Types -----------------------------------------

// ---- Private Variables ---------------------------------------------------

int gI2cAddr    = -1;

//#define TRUE    1
//#define FALSE   0

// ---- Private Function Prototypes -----------------------------------------

// ---- Functions -----------------------------------------------------------

//***************************************************************************
/**
*   Main entry point
*/

int main( int argc, char **argv )
{
    const char         *i2cDevName = "/dev/i2c-0";
    int                 i2cDev;
    char bufferRead[2];
    char bufferWrite = 2;
    char buff[2];
    float value;

    buff[0] = 0x12 + 0x20;
    buff[1] = 128;

    // Try to open the i2c device
    if (( i2cDev = open( i2cDevName, O_RDWR )) < 0 )
    {
        printf( "Error  opening '%s': %s\n", i2cDevName, strerror( errno ));
        exit( 1 );
    }

    // Indicate which slave we wish to speak to
//    ioctl(i2cDev, I2C_SLAVE, 0x71);
int j;
for(j = 0; j < 255; j+=10)
//while(1)
{
    ioctl(i2cDev, I2C_SLAVE, 0x0b);
buff[ 1 ] = j;
    write(i2cDev, buff, 2);

    usleep(65000);

//    write(i2cDev, &bufferWrite, 1);
//    read(i2cDev, bufferRead, 2);

//    printf("%d inches\n", bufferRead[0]*256 + bufferRead[1]);

/*    ioctl(i2cDev, I2C_SLAVE, 0x60);

    write(i2cDev, &bufferWrite, 1);
    read(i2cDev, bufferRead, 2);

    value = (bufferRead[0]*256 + bufferRead[1])/10;

    printf("%.1f deg\n", value);
*/
}
    close( i2cDev );

    return 0;

} // main
