Changeset 15 in flair-src for trunk/lib/FlairCore/src/Unix_I2cPort.cpp


Ignore:
Timestamp:
04/08/16 15:40:57 (6 years ago)
Author:
Bayard Gildas
Message:

sources reformatted with flair-format-dir script

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairCore/src/Unix_I2cPort.cpp

    r2 r15  
    1818#include "Unix_I2cPort.h"
    1919#include <errno.h>
    20 #include <fcntl.h>   /* File control definitions */
     20#include <fcntl.h> /* File control definitions */
    2121#include <unistd.h>
    2222#include <sys/ioctl.h>
    2323#include <linux/i2c-dev.h>
    2424
    25 
    2625using std::string;
    2726
    28 namespace flair
    29 {
    30 namespace core
    31 {
     27namespace flair {
     28namespace core {
    3229
    33 Unix_I2cPort::Unix_I2cPort(const Object* parent,string name,string device) : I2cPort(parent,name)
    34 {
    35     //open port
    36     fd = open( device.c_str(), O_RDWR );
    37         if (fd == -1)
    38         {
    39                 Err("open_port: Unable to open %s\n",device.c_str());
    40         }
     30Unix_I2cPort::Unix_I2cPort(const Object *parent, string name, string device)
     31    : I2cPort(parent, name) {
     32  // open port
     33  fd = open(device.c_str(), O_RDWR);
     34  if (fd == -1) {
     35    Err("open_port: Unable to open %s\n", device.c_str());
     36  }
    4137}
    4238
    43 Unix_I2cPort::~Unix_I2cPort()
    44 {
    45     close(fd);
     39Unix_I2cPort::~Unix_I2cPort() { close(fd); }
     40
     41void Unix_I2cPort::SetRxTimeout(core::Time timeout_ns) {
     42  Warn("not implemented\n");
    4643}
    4744
    48 void Unix_I2cPort::SetRxTimeout(core::Time timeout_ns)
    49 {
    50     Warn("not implemented\n");
     45void Unix_I2cPort::SetTxTimeout(core::Time timeout_ns) {
     46  Warn("not implemented\n");
    5147}
    5248
    53 void Unix_I2cPort::SetTxTimeout(core::Time timeout_ns)
    54 {
    55     Warn("not implemented\n");
     49int Unix_I2cPort::SetSlave(uint16_t address) {
     50  int err = ioctl(fd, I2C_SLAVE_FORCE, address);
     51  if (err < 0) {
     52    Err("Failed to set slave address\n");
     53  }
     54
     55  return err;
    5656}
    5757
    58 int Unix_I2cPort::SetSlave(uint16_t address)
    59 {
    60     int err=ioctl( fd, I2C_SLAVE_FORCE, address);
    61         if( err < 0 )
    62     {
    63         Err("Failed to set slave address\n");
    64     }
    65 
    66         return err;
     58ssize_t Unix_I2cPort::Write(const void *buf, size_t nbyte) {
     59  return write(fd, buf, nbyte);
    6760}
    6861
    69 ssize_t Unix_I2cPort::Write(const void *buf,size_t nbyte)
    70 {
    71     return write(fd,buf, nbyte);
    72 }
    73 
    74 ssize_t Unix_I2cPort::Read(void *buf,size_t nbyte)
    75 {
    76     return read(fd,buf, nbyte);
     62ssize_t Unix_I2cPort::Read(void *buf, size_t nbyte) {
     63  return read(fd, buf, nbyte);
    7764}
    7865
    7966} // end namespace core
    8067} // end namespace flair
    81 
Note: See TracChangeset for help on using the changeset viewer.