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.

Committer:
symbiotic
Date:
Thu May 22 20:13:48 2014 +0000
Revision:
2:19e7e472a51f
Parent:
0:96a7926b9d64
changed error() to transmissionError() (don't know why it won't compile in other project)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
symbiotic 0:96a7926b9d64 1 #ifndef I2CTRANSACTION_H
symbiotic 0:96a7926b9d64 2 #define I2CTRANSACTION_H
symbiotic 0:96a7926b9d64 3 #include "MODI2C.h"
symbiotic 0:96a7926b9d64 4
symbiotic 0:96a7926b9d64 5 class I2CTransaction
symbiotic 0:96a7926b9d64 6 {
symbiotic 0:96a7926b9d64 7 public:
symbiotic 0:96a7926b9d64 8 I2CTransaction(int address, char* writePacket, int writePacketLength, char* readPacket = NULL, int readPacketLength = 0);
symbiotic 0:96a7926b9d64 9 static void setFrequency(int frequency);
symbiotic 0:96a7926b9d64 10 bool completed();
symbiotic 0:96a7926b9d64 11 int getStatus(int i);
symbiotic 0:96a7926b9d64 12 bool initiateTransaction();
symbiotic 0:96a7926b9d64 13 bool waitForCompletion(int timeout = 1000);
symbiotic 0:96a7926b9d64 14 void displayStatus(Serial *pc, char * strg);
symbiotic 0:96a7926b9d64 15 bool success();
symbiotic 2:19e7e472a51f 16 bool transmissionError();
symbiotic 0:96a7926b9d64 17
symbiotic 0:96a7926b9d64 18 private:
symbiotic 0:96a7926b9d64 19 static MODI2C *i2c;
symbiotic 0:96a7926b9d64 20
symbiotic 0:96a7926b9d64 21 int status[2]; // Status words for both the write and read halves of the transaction
symbiotic 0:96a7926b9d64 22 int address;
symbiotic 0:96a7926b9d64 23 char* writePacket;
symbiotic 0:96a7926b9d64 24 int writePacketLength;
symbiotic 0:96a7926b9d64 25 char* readPacket;
symbiotic 0:96a7926b9d64 26 int readPacketLength;
symbiotic 0:96a7926b9d64 27 };
symbiotic 0:96a7926b9d64 28
symbiotic 0:96a7926b9d64 29
symbiotic 0:96a7926b9d64 30 #endif
symbiotic 0:96a7926b9d64 31