diff --git a/src/gpio.h b/src/gpio.h index a152d67..dc12df8 100644 --- a/src/gpio.h +++ b/src/gpio.h @@ -6,18 +6,18 @@ using namespace std; enum GPIO_MAP_PIN { - GPIO2 = 2, GPIO14 = 14, - GPIO3 = 3, GPIO15 = 15, + GPIO2 = 2, GPIO14 = 14, + GPIO3 = 3, GPIO15 = 15, GPIO4 = 4, GPIO18 = 18, - GPIO17 = 17, GPIO23 = 23, - GPIO27 = 27, GPIO24 = 24, - GPIO22 = 22, GPIO25 = 25, - GPIO10 = 10, GPIO8 = 8, - GPIO9 = 9, GPIO7 = 7, - GPIO11 = 11, GPIO12 = 12, - GPIO5 = 5, GPIO16 = 16, - GPIO6 = 6, GPIO20 = 20, - GPIO13 = 13, GPIO21 = 21, + GPIO17 = 17, GPIO23 = 23, + GPIO27 = 27, GPIO24 = 24, + GPIO22 = 22, GPIO25 = 25, + GPIO10 = 10, GPIO8 = 8, + GPIO9 = 9, GPIO7 = 7, + GPIO11 = 11, GPIO12 = 12, + GPIO5 = 5, GPIO16 = 16, + GPIO6 = 6, GPIO20 = 20, + GPIO13 = 13, GPIO21 = 21, GPIO19 = 19, GPIO26 = 26, }; diff --git a/src/i2c.cpp b/src/i2c.cpp index 46fc240..5e2fff2 100644 --- a/src/i2c.cpp +++ b/src/i2c.cpp @@ -4,6 +4,8 @@ #include #include #include "i2c.h" +#include +#include I2c::I2c(const char * deviceName) { @@ -129,3 +131,27 @@ uint16_t I2c::readBlock(uint8_t command, uint8_t size, uint8_t * data) return result; } +std::vector> I2c::getDevices(uint8_t start /*=0*/, uint8_t end /*128*/) +{ + std::vector> i2cDevices; + std::regex i2cPattern("/dev/i2c-\\d+"); + for (const auto& entry : std::filesystem::directory_iterator("/dev")) { + std::string path = entry.path().string(); + if (std::regex_match(path, i2cPattern)) { + int f = open(path.c_str(), O_RDWR); + if(f == -1) continue; + for(uint8_t address = 0; address <= end; ++address) { + int result = ioctl(f, I2C_SLAVE, address); + if(result == 0) { + int res = i2c_smbus_read_byte(f); + if (res >0) + { + i2cDevices.push_back(std::make_pair(path, address)); + } + } + } + close(f); + } + } + return i2cDevices; +} diff --git a/src/i2c.h b/src/i2c.h index 02ff786..ba73842 100644 --- a/src/i2c.h +++ b/src/i2c.h @@ -48,6 +48,9 @@ class I2c { addressSet(address); return tryReadByte(command); } + + static std::vector> getDevices(uint8_t start = 0, u_int8_t end = 128); + private: int fd; }; diff --git a/src/led.h b/src/led.h index 572bada..6e77d74 100644 --- a/src/led.h +++ b/src/led.h @@ -53,7 +53,7 @@ class LED { 215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 }; } - void setWS2801(int numLed, vector colors, int BRIGHTNESS){ + void setWS2801(int numLed, vector& colors, int BRIGHTNESS){ int a; uint8_t buffer0[1], buffer1[4]; srand(time(NULL)); @@ -105,7 +105,7 @@ class LED { } } - void setAPA102(int numLed, vector colors, int BRIGHTNESS){ + void setAPA102(int numLed, vector& colors, int BRIGHTNESS){ int a; uint8_t buffer0[1], buffer1[4]; srand(time(NULL)); diff --git a/src/ofxGPIO.h b/src/ofxGPIO.h index 467dc03..3dcee60 100644 --- a/src/ofxGPIO.h +++ b/src/ofxGPIO.h @@ -47,12 +47,14 @@ using namespace LogHighLight; #include "mcp.h" #include "font.h" #include "readata.h" + /* only openframeworks */ #ifndef COMPILE_WITHOUT_OPENFRAMEWORKS #include "google_image.h" #include "gpio_state.h" #endif /* end OF */ + /* core high level */ #include "led.h" #include "oled.h"