1 #ifndef LIBPROPELLER_EEPROM_H_ 
    2 #define LIBPROPELLER_EEPROM_H_ 
   27     void Init(
const int scl = 28, 
const int sda = 29) {
 
   37     bool Put(
const unsigned short address, 
const char byte) {
 
   38         char bytes[] = {byte};
 
   39         return Put(address, bytes, 1);
 
   51     bool Put(
unsigned short address, 
char bytes [], 
int size) {
 
   56         while (bytesWritten < size) {
 
   57             if (PollForAcknowledge() == 
false) {
 
   60             base_.
SendByte((address >> 8) & 0xFF); 
 
   66             } 
while ((address & 0b1111111) != 0 && bytesWritten < size); 
 
   83     bool PutNumber(
const unsigned short address, 
const int bytes, 
const int length) {
 
   87         temp[3] = (((unsigned) bytes) & 0xFF000000) >> 24;
 
   88         temp[2] = (((unsigned) bytes) & 0xFF0000) >> 16;
 
   89         temp[1] = (((unsigned) bytes) & 0xFF00) >> 8;
 
   90         temp[0] = (((unsigned) bytes) & 0xFF) >> 0;
 
   91         return Put(address, temp, length);
 
   99     int Get(
unsigned short address) {
 
  101         int result = 
Get(address, byte, 1);
 
  118     int Get(
unsigned short address, 
char bytes [], 
const int length) {
 
  120         while (bytesRead < length) {
 
  121             if (PollForAcknowledge() == 
false) {
 
  124             base_.
SendByte((address >> 8) & 0xFF); 
 
  130             while (((address + 1) & 0b1111111) != 0
 
  131                     && bytesRead + 1 < length) {
 
  132                 bytes[bytesRead] = base_.
ReadByte(
true);
 
  137             bytes[bytesRead] = base_.
ReadByte(
false);
 
  158         Get(address, temp, length);
 
  169             result = (result << 8) | temp[3];
 
  172             result = (result << 8) | temp[2];
 
  175             result = (result << 8) | temp[1];
 
  178             result = (result << 8) | temp[0];
 
  186     bool PollForAcknowledge() {
 
  189         while (base_.
SendByte(kI2CAddress) == 
false) { 
 
  190             if (++counter == 100) { 
 
  200     static const unsigned char kI2CAddress = 0b10100000;
 
  204 #endif // LIBPROPELLER_EEPROM_H_