Program Listing for File mcp230xx.cpp

Return to documentation for file (src/mcp230xx.cpp)

#include "mcp230xx/mcp230xx.hh"

using iplo::MCP230XX;

bool MCP230XX::writeRegister(std::uint8_t reg, std::uint8_t value) {
    const auto res = _bus.writeByteData(reg, value);
    if (res < 0) {
        _error = I2C_ERROR;
        return false;
    }

    _error = OK;
    return true;
}

std::uint8_t MCP230XX::readRegister(std::uint8_t reg) {
    const auto res = _bus.readByteData(reg);
    if (res < 0) {
        _error = I2C_ERROR;
        return 0;
    }

    _error = OK;
    return res;
}

int MCP230XX::lastError() {
    int e = _error;
    _error = OK;
    return e;
}