Class for representing and controlling entire I2C transactions (the master side). This class allows one to separate in code the configuration of I2C transactions from their use. This property simplifies the process of executing transactions in, for example, the body of a real-time control loop.

I2CTransaction.h

Committer:
symbiotic
Date:
2014-05-22
Revision:
3:a9d61e73fe97
Parent:
1:5d9e9c0682f0
Child:
5:ad382f9f43ca

File content as of revision 3:a9d61e73fe97:

#ifndef I2CTRANSACTION_H
#define I2CTRANSACTION_H
#include "MODI2C.h"

class I2CTransaction
{
public:
    I2CTransaction(int address, char* writePacket, int writePacketLength, char* readPacket = NULL, int readPacketLength = 0);
    static void setFrequency(int frequency);
    bool completed();
    int getStatus(int i);
    bool initiateTransaction();
    bool waitForCompletion(int timeout = 1000);
    void displayStatus(Serial *pc, char * strg);
    bool success();
    bool transmissionError(); 

private:
    static MODI2C *i2c;

    int status[2];      // Status words for both the write and read halves of the transaction
    int address;
    char* writePacket;
    int writePacketLength;
    char* readPacket;
    int readPacketLength;
};


#endif