TestI2c.cpp



/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 2 -*- */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <linux/i2c-dev.h>

#include <i2c.hpp>

int main(int argc, char *argv[])
{

  if(argc<2)
  {
    puts("\nUSE:\nTestI2C <type>\n");
    puts("types:");
    puts("\tsend <address> <data_to_send>");
    puts("\trecv <address> <command>");
    puts("\t  e.g.");
    puts("\t    TestI2C send 13 01 => Sends '48' and '49' to 0x13 I2C address.");
    puts("\t    TestI2C recv 13 1 => Sends the '49' to 0x13 I2C address and receive the response.\n");
    
    exit(EXIT_SUCCESS);
  }
  
  if (strcmp(argv[1],"recv") == 0)
  {
    CMI2c dispositivo("/dev/i2c-0",atoi(argv[2]));
    char *word=(char*)malloc(6 * sizeof(char));
    
    if (dispositivo.recvWord(word,atoi(argv[3])) == 0)
      printf("\nLo recibido es:\t%d\n",atoi(word));

    free(word);
  }
  
  else if (strcmp(argv[1],"send") == 0)
  {
    CMI2c dispositivo("/dev/i2c-0",atoi(argv[2]));
    if (dispositivo.sendBlock(reinterpret_cast<unsigned char*>(argv[3])) == 0)
      printf("\nSended!\n");
  }

}
 All Data Structures Functions Variables
Generated on Mon Sep 12 07:59:09 2011 for API MokArdu by  doxygen 1.6.3