diff --git a/src/MLX90640_API.cpp b/src/MLX90640_API.cpp index f4958e5..e23361e 100644 --- a/src/MLX90640_API.cpp +++ b/src/MLX90640_API.cpp @@ -20,8 +20,7 @@ int MLX90640::mlx90640_DumpEE(uint8_t slaveAddr, uint16_t *eeData) { - //return mlx90640_I2CRead(slaveAddr, mlx90640_EEPROM_START_ADDRESS, mlx90640_EEPROM_DUMP_NUM, eeData); - return mlx90640_I2CRead(slaveAddr, 0x00, 1300, eeData); + return mlx90640_I2CRead(slaveAddr, mlx90640_EEPROM_START_ADDRESS, mlx90640_EEPROM_DUMP_NUM, eeData); } int MLX90640::mlx90640_SynchFrame(uint8_t slaveAddr) diff --git a/src/MLX90640_API.h b/src/MLX90640_API.h index b44f787..3977114 100644 --- a/src/MLX90640_API.h +++ b/src/MLX90640_API.h @@ -149,12 +149,15 @@ public: int status; status = mlx90640_DumpEE (slaveAddress, eeMLX90640); - //status = mlx90640_ExtractParameters(eeMLX90640, &mlx90640); - //status = mlx90640_GetFrameData (0x33, mlx90640Frame); - //mlx90640_GetImage(mlx90640Frame, &mlx90640); + status = mlx90640_ExtractParameters(eeMLX90640, &mlx90640); + status = mlx90640_GetFrameData (0x33, mlx90640Frame); + mlx90640_GetImage(mlx90640Frame, &mlx90640); + for (int i = 0; i < 834; ++i) { + imageVect[i] = mlx90640Frame[i]; + } } - MLX90640() : imageVect(768){} + MLX90640() : imageVect(834){} QVector imageVect; protected: diff --git a/src/MLX90640_I2C_Driver.cpp b/src/MLX90640_I2C_Driver.cpp index 63d2965..24bd7c7 100644 --- a/src/MLX90640_I2C_Driver.cpp +++ b/src/MLX90640_I2C_Driver.cpp @@ -17,7 +17,7 @@ void mlx90640_I2CInit(void){ /// \return 0 if success /// int mlx90640_I2CGeneralReset(void){ - + return 0; } /// diff --git a/src/i2cif.cpp b/src/i2cif.cpp index 7bebeca..b383d6e 100644 --- a/src/i2cif.cpp +++ b/src/i2cif.cpp @@ -14,6 +14,11 @@ #include "conv.h" #include #include +#include +#include +#include +#include + #define DEFAULT_I2C_DEV QString("/dev/i2c-1/") I2cif::I2cif(QObject *parent) : @@ -149,19 +154,88 @@ Q_INVOKABLE void I2cif::i2cWrite(const uint8_t &slaveAddr, const uint16_t &write void I2cif::i2cRead(const uint8_t &slaveAddr, const uint16_t &startAddress, const uint16_t &nMemAddressRead, uint16_t *data) { int file; - char buf[2]; + Conv conv; + m_readResult = QString(); + const char* devNameChar = "/dev/i2c-1"; - fprintf(stderr, "reading from address %02x count %d\n", slaveAddr, nMemAddressRead); + if ((file = open (devNameChar, O_RDWR)) < 0) + { + fprintf(stderr,"open error\n"); + emit i2cError(); + return; + } + + struct i2c_rdwr_ioctl_data i2c_data; + struct i2c_msg msg[2]; + __u8 regAddrBytes[2] = {0,0}; + regAddrBytes[0] = (startAddress >> 8) & 0xFF; // High byte + regAddrBytes[1] = startAddress & 0xFF; // Low byte + i2c_data.msgs = msg; + i2c_data.nmsgs = 2; + + i2c_data.msgs[0].addr = slaveAddr; + i2c_data.msgs[0].flags = 0; + i2c_data.msgs[0].len = 2; + i2c_data.msgs[0].buf = regAddrBytes; + + i2c_data.msgs[1].addr = slaveAddr; + i2c_data.msgs[1].flags = I2C_M_RD; + i2c_data.msgs[1].len = nMemAddressRead; + i2c_data.msgs[1].buf = (__u8 *)data; + + int ret = ioctl(file, I2C_RDWR, &i2c_data); + + if (ret < 0) + { + fprintf(stderr, "read data fail %d\n", ret); + emit i2cError(); + return; + } + + close(file); + + fprintf(stderr, "read "); + for (int i=0; i> 8) & 0xFF; // startAddress high byte - buf[1] = (startAddress + i) & 0xFF; // startAddress low byte - if (write(file, buf, sizeof(buf)) != sizeof(buf)) - { - close(file); - fprintf(stderr,"write error\n"); - emit i2cError(); - return; - } - - if (read(file, buf, sizeof(buf)) != sizeof(buf)) - { - close(file); - fprintf(stderr,"read error\n"); - emit i2cError(); - return; - } - data[i] = ((uint16_t)buf[0] << 8) | buf[1]; // Combine high and low bytes into a 16-bit data + close(file); + fprintf(stderr,"read error\n"); + emit i2cError(); + return; } close(file); + /* copy buf to m_readResult */ + int i; + fprintf(stderr, "read "); - for (int i = 0; i < nMemAddressRead; i++) + for (i=0; i CHUNK_SIZE) - { - chunk = CHUNK_SIZE; - } - - /* Read data */ - if (read( file, buf, chunk ) != chunk) - { - close(file); - perror("read"); - emit i2cError(); - return; - } - - /* copy buf to m_readResult */ - fprintf(stderr, "read "); - for (int i=0; i