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.
Diff: I2CTransaction.h
- Revision:
- 0:96a7926b9d64
- Child:
- 1:5d9e9c0682f0
- Child:
- 2:19e7e472a51f
diff -r 000000000000 -r 96a7926b9d64 I2CTransaction.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/I2CTransaction.h Wed May 21 21:12:32 2014 +0000 @@ -0,0 +1,31 @@ +#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 error(); + +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 +