diff --git a/I2CMasterUtils.cpp b/I2CMasterUtils.cpp deleted file mode 100644 index 9bc0488..0000000 --- a/I2CMasterUtils.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "I2CMasterUtils.h" -#include "I2CCommands.h" - -void I2CMasterUtils::scanI2C(Stream &output) { - output.println("Scanning for I2C devices..."); - for (uint8_t addr = 1; addr < 127; addr++) { - Wire.beginTransmission(addr); - if (Wire.endTransmission() == 0) { - output.print("Found device at 0x"); - output.println(addr, HEX); - } - } -} - -void I2CMasterUtils::changeSlaveAddress(uint8_t oldAddr, uint8_t newAddr, Stream &output) { - Wire.beginTransmission(oldAddr); - Wire.write(0xAA); // Command code for address change - Wire.write(newAddr); - Wire.endTransmission(); - output.print("Sent address change command to 0x"); - output.print(oldAddr, HEX); - output.print(" -> 0x"); - output.println(newAddr, HEX); -} - -bool I2CMasterUtils::parseChangeAddressCommand(const String &input, uint8_t &oldAddr, uint8_t &newAddr) { - if (!input.startsWith("ch")) return false; - int o, n; - int matched = sscanf(input.c_str(), "ch %x %x", &o, &n); - if (matched == 2) { - oldAddr = (uint8_t)o; - newAddr = (uint8_t)n; - return true; - } - return false; -} diff --git a/I2CMasterUtils.h b/I2CMasterUtils.h deleted file mode 100644 index 5be05b9..0000000 --- a/I2CMasterUtils.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef I2CMASTERUTILS_H -#define I2CMASTERUTILS_H - -#include -#include - -class I2CMasterUtils { -public: - static void scanI2C(Stream &output = Serial); - static void changeSlaveAddress(uint8_t oldAddr, uint8_t newAddr, Stream &output = Serial); - static bool parseChangeAddressCommand(const String &input, uint8_t &oldAddr, uint8_t &newAddr); -}; - -#endif diff --git a/examples/Master/Master.ino b/examples/Master/Master.ino index bf35a73..a83b5de 100644 --- a/examples/Master/Master.ino +++ b/examples/Master/Master.ino @@ -2,7 +2,7 @@ #include #include -RelayI2CMaster relayMaster(0x08); // Default address, can be changed via setAddress() +I2CRelay relayMaster(0x08); // Default address, can be changed via setAddress() void setup() { Serial.begin(115200); diff --git a/library.properties b/library.properties index ffa5015..9ceeffd 100644 --- a/library.properties +++ b/library.properties @@ -1,4 +1,4 @@ -name=I2CMasterUtils +name=I2C Relay version=1.0.0 author=Fatima Idrees maintainer=Fatima Idrees diff --git a/src/I2CRelay.cpp b/src/I2CRelay.cpp index 9b62e0d..770b3c9 100644 --- a/src/I2CRelay.cpp +++ b/src/I2CRelay.cpp @@ -4,24 +4,24 @@ #include "I2CMasterUtils.h" #include "I2CCommands.h" -RelayI2CMaster::RelayI2CMaster(uint8_t slaveAddress) : _slaveAddress(slaveAddress) {} +I2CRelay::I2CRelay(uint8_t slaveAddress) : _slaveAddress(slaveAddress) {} -void RelayI2CMaster::setAddress(uint8_t newAddress) { +void I2CRelay::setAddress(uint8_t newAddress) { _slaveAddress = newAddress; } -void RelayI2CMaster::begin() { +void I2CRelay::begin() { Wire.begin(); } -void RelayI2CMaster::setRelay(uint8_t relayIndex, bool state) { +void I2CRelay::setRelay(uint8_t relayIndex, bool state) { Wire.beginTransmission(_slaveAddress); Wire.write(relayIndex); Wire.write(state ? 1 : 0); Wire.endTransmission(); } -uint8_t RelayI2CMaster::scanDevices(uint8_t* foundAddresses, uint8_t maxDevices) { +uint8_t I2CRelay::scanDevices(uint8_t* foundAddresses, uint8_t maxDevices) { uint8_t count = 0; for(uint8_t addr = 1; addr < 127; addr++) { Wire.beginTransmission(addr); diff --git a/src/I2CRelay.h b/src/I2CRelay.h index f3190d0..026d97e 100644 --- a/src/I2CRelay.h +++ b/src/I2CRelay.h @@ -1,12 +1,12 @@ -#ifndef RELAY_I2C_MASTER_H -#define RELAY_I2C_MASTER_H +#ifndef I2CRelay_H +#define I2CRelay_H #include #include -class RelayI2CMaster { +class I2CRelay { public: - RelayI2CMaster(uint8_t slaveAddress); + I2CRelay(uint8_t slaveAddress); void begin(); void setRelay(uint8_t relayIndex, bool state); uint8_t scanDevices(uint8_t* foundAddresses, uint8_t maxDevices);