#include "comms.h"
#include "board.h"
#include "Wire.h"



uint8_t getAddress(void)
{
  uint8_t address = 0;

  address += (digitalRead(ADDR0)) ? 1 : 0;
  address += (digitalRead(ADDR1)) ? 2 : 0;
  address += (digitalRead(ADDR2)) ? 4 : 0;
  address += (digitalRead(ADDR3)) ? 8 : 0;

  return address;
}

void receiveI2CEvent(int bytes) {
  Wire.read();    // read one character from the I2C
}

void requestI2CEvent() {
  Wire.read();    // read one character from the I2C
}


uint8_t address;

void initI2C( void)
{
  pinMode(ADDR0, INPUT_PULLUP);
  pinMode(ADDR1, INPUT_PULLUP);
  pinMode(ADDR2, INPUT_PULLUP);
  pinMode(ADDR3, INPUT_PULLUP);

  address = getAddress();

  // Start the I2C Bus as Slave on address 9
  Wire.begin(address); 
  // Attach a function to trigger when something is received.
  Wire.onReceive(receiveI2CEvent);
  Wire.onRequest(requestI2CEvent);
}

void handleI2C ( void )
{

}



