<commit_before>#include "ModI2CGuest.h"

CModI2CGuest::CModI2CGuest(void)
{
  // nothing
}

void CModI2CGuest::Begin(void)
{
  CModTemplate::Begin();
  ModGUID = 9; // GUID of this specific mod

  if (!Global.HasUSB) // if no usb
  {
    Wire.begin(8);
    Wire.onRequest(RequestEvent);
    Wire.onReceive(ReceiveEvent);
  }
}

void CModI2CGuest::OnRequest()
{
  Wire.write(SlaveArray, SlaveIndex);
  SlaveIndex = 0;
}

void CModI2CGuest::OnReceive(int numBytes)
{

  byte type = Wire.read();
  if (type == 1) // received templay
  {
    byte input = Wire.read();
    Global.TempLayer = input;
  }
  else if (type == 2) // setEEPROM
  {
    byte packetSize = Wire.read();
    while (Wire.available())
    {
      EEPROM.update(EEPROMPointerIndex, (byte)Wire.read());
      EEPROMPointerIndex++;
    }
    if (packetSize != 30) // packet is at EOL
    {
      EEPROMPointerIndex = 0;
    }
  }
  else if (type == 3) // set board setting (eeprom start addr at 900)
  {
    byte packetSize = Wire.read();
    if (EEPROMPointerIndex < 900)
    {<commit_msg>bugfix: i2c guest hangs master without any signals<commit_after>#include "ModI2CGuest.h"

CModI2CGuest::CModI2CGuest(void)
{
  // nothing
}

void CModI2CGuest::Begin(void)
{
  CModTemplate::Begin();
  ModGUID = 9; // GUID of this specific mod

  if (!Global.HasUSB) // if no usb
  {
    Wire.begin(8);
    Wire.onRequest(RequestEvent);
    Wire.onReceive(ReceiveEvent);
  }
}

void CModI2CGuest::OnRequest()
{
  if (SlaveIndex == 0) // if slave array is empty, add single byte
  {
    Wire.write(0);
  }
  Wire.write(SlaveArray, SlaveIndex);
  SlaveIndex = 0;
}

void CModI2CGuest::OnReceive(int numBytes)
{

  byte type = Wire.read();
  if (type == 1) // received templay
  {
    byte input = Wire.read();
    Global.TempLayer = input;
  }
  else if (type == 2) // setEEPROM
  {
    byte packetSize = Wire.read();
    while (Wire.available())
    {
      EEPROM.update(EEPROMPointerIndex, (byte)Wire.read());
      EEPROMPointerIndex++;
    }
    if (packetSize != 30) // packet is at EOL
    {
      EEPROMPointerIndex = 0;
    }
  }
  else if (type == 3) // set board setting (eeprom start addr at 900)
  {
    byte packetSize = Wire.read();
    if (EEPROMPointerIndex < 900)
    {
{'fraction_non_alphanumeric': 0.14036656236030398, 'fraction_numerical': 0.02011622708985248, 'mean_word_length': 2.905759162303665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '959831', 'n_tokens_mistral': 894, 'n_tokens_neox': 813, 'n_words': 187}