<commit_before>#include "I2CBus.h"
#include <fcntl.h>
#include <linux/i2c-dev.h>
#include <stdio.h>
#include <cerrno>
#include <unistd.h>
//#include <system_error>

// TODO: throw some nicer type of exception that results in a nice error message

I2CBus::I2CBus(const char * devName) : currentAddress(-1), ownFd(true)
{
    // Open up the I2C bus device.
    fd = open(devName, O_RDWR);
    if (fd == -1)
    {
        perror(devName); // TODO: remove this if a nicer exeption is thrown below
        throw errno;
    }
}

I2CBus::I2CBus(int fd) : fd(fd), currentAddress(-1), ownFd(false)
{
    // nothing to do here
}

I2CBus::~I2CBus()
{
    if (ownFd)
    {
        close(fd);
    }
}

//void I2CBus::setAddress(uint8_t address)
//{
//    if (address == currentAddress){ return; }

//    int result = ioctl(fd, I2C_SLAVE, address);
//    if (result == -1)
//    {
//        throw errno;
//        //throw "Error setting slave address.";
//    }

//    currentAddress = address;
//}

void I2CBus::writeByte(int devFd, uint8_t command, uint8_t data)
{
    int result = i2c_smbus_write_byte_data(devFd, command, data);
    if (result == -1)
    {<commit_msg>comment out currentAddress<commit_after>#include "I2CBus.h"
#include <fcntl.h>
#include <linux/i2c-dev.h>
#include <stdio.h>
#include <cerrno>
#include <unistd.h>
//#include <system_error>

// TODO: throw some nicer type of exception that results in a nice error message

I2CBus::I2CBus(const char * devName) : ownFd(true), //currentAddress(-1)
{
    // Open up the I2C bus device.
    fd = open(devName, O_RDWR);
    if (fd == -1)
    {
        perror(devName); // TODO: remove this if a nicer exeption is thrown below
        throw errno;
    }
}

I2CBus::I2CBus(int fd) : fd(fd), ownFd(false) //currentAddress(-1)
{
    // nothing to do here
}

I2CBus::~I2CBus()
{
    if (ownFd)
    {
        close(fd);
    }
}

//void I2CBus::setAddress(uint8_t address)
//{
//    if (address == currentAddress){ return; }

//    int result = ioctl(fd, I2C_SLAVE, address);
//    if (result == -1)
//    {
//        throw errno;
//        //throw "Error setting slave address.";
//    }

//    currentAddress = address;
//}

void I2CBus::writeByte(int devFd, uint8_t command, uint8_t data)
{
    int result = i2c_smbus_write_byte_data(devFd, command, data);
    if (result == -1)
    {
{'fraction_non_alphanumeric': 0.15566037735849056, 'fraction_numerical': 0.018010291595197257, 'mean_word_length': 2.7328, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '6379062', 'n_tokens_mistral': 908, 'n_tokens_neox': 899, 'n_words': 222}