/*
  Michael Simmons
  Master Project: gRAPI: an indoor four-wheeled robot API for a gumstix connex
  
  Last Modified: 17 Feb 2009
  
  Header file for the Srf10 class
*/

#ifndef SRF10_H
#define SRF10_H

#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/i2c.h>
//#include <stdio.h>
//#include <stdlib.h>
#include <unistd.h>

class Srf10
{
  private:
    int i2cHandle;  // file handle from open of I2C
    int i2cAddr;  // address on I2C bus
    char pingBuf[2];  // result specifier
    char readBuf[2];  // result value
    char gainBuf[2];  // set gain
    char rangeBuf[2];  // set range
    char readReg;  // value of 2 is register to read from
    int i2cBusWait;

  public:
    Srf10(int handle, int addr, char rt = 'c' );
    void ping();  // fire sensor
    int readS();  // read stored register value
    void setGain(int); // set sensitivity to signal, 8 = gain 140, or 2 meters
    void setRange(int); // set range (Reg * 43 mm + 43 mm),
                        // 24 = 1 meter, 47 = 2 meters, 70 = 3 meters, 93 = 4 meters
    void setResultType(char); // i = inches, c = centimeters, s = micro-seconds

/*
  ** NOTE **: only one sensor can be on the i2c line when changing an
              address

  There are 16 addresses available to the srf10 range sensor (0-15).  The
  changeAddress method will take a number from 0 - 15 and perform the 
  necessary commands to change the address of that sensor.

  ** REMEMBER **: only one sensor can be on the i2c line when changing an
                  address
*/
    void changeAddress(int newAddress); // To change the srf10 i2c device address
}; // Srf10

#endif
