diff --git a/qml/pages/FirstPage.qml b/qml/pages/FirstPage.qml index 9a00fc3..dc2fc79 100644 --- a/qml/pages/FirstPage.qml +++ b/qml/pages/FirstPage.qml @@ -1,43 +1,61 @@ import QtQuick 2.0 import Sailfish.Silica 1.0 +import harbour.i2ctool.I2cif 1.0 +import melexis.driver 1.0 Page { - id: page + id: probePage + property string deviceName: "/dev/i2c-1" - // The effective value will be restricted by ApplicationWindow.allowedOrientations allowedOrientations: Orientation.All + SilicaFlickable + { + Grid + { + Button + { + id: probeBTN + text: "check camera present" + onClicked: {probeBTN.text="probing..."; i2cif.tohVddSet("on"); i2cif.i2cProbe(deviceName)} + } + Label + { - // To enable PullDownMenu, place our content in a SilicaFlickable - SilicaFlickable { - anchors.fill: parent + id: resultLabel + text: "0" + } - // PullDownMenu and PushUpMenu must be declared in SilicaFlickable, SilicaListView or SilicaGridView - PullDownMenu { - MenuItem { - text: qsTr("Show Page 2") - onClicked: pageStack.animatorPush(Qt.resolvedUrl("SecondPage.qml")) + } + } + + I2cif + { + id: i2cif + + onI2cProbingChanged: + { + var results = i2cif.i2cProbingStatus; + for (var i=0 ; i -int MLX90640::MLX90640_DumpEE(uint8_t slaveAddr, uint16_t *eeData) +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, mlx90640_EEPROM_START_ADDRESS, mlx90640_EEPROM_DUMP_NUM, eeData); + return mlx90640_I2CRead(slaveAddr, 0x00, 1300, eeData); } -int MLX90640::MLX90640_SynchFrame(uint8_t slaveAddr) +int MLX90640::mlx90640_SynchFrame(uint8_t slaveAddr) { uint16_t dataReady = 0; uint16_t statusRegister; int error = 1; - error = MLX90640_I2CWrite(slaveAddr, MLX90640_STATUS_REG, MLX90640_INIT_STATUS_VALUE); - if(error == -MLX90640_I2C_NACK_ERROR) + error = mlx90640_I2CWrite(slaveAddr, mlx90640_STATUS_REG, mlx90640_INIT_STATUS_VALUE); + if(error == -mlx90640_I2C_NACK_ERROR) { return error; } while(dataReady == 0) { - error = MLX90640_I2CRead(slaveAddr, MLX90640_STATUS_REG, 1, &statusRegister); - if(error != MLX90640_NO_ERROR) + error = mlx90640_I2CRead(slaveAddr, mlx90640_STATUS_REG, 1, &statusRegister); + if(error != mlx90640_NO_ERROR) { return error; } //dataReady = statusRegister & 0x0008; - dataReady = MLX90640_GET_DATA_READY(statusRegister); + dataReady = mlx90640_GET_DATA_READY(statusRegister); } - return MLX90640_NO_ERROR; + return mlx90640_NO_ERROR; } -int MLX90640::MLX90640_TriggerMeasurement(uint8_t slaveAddr) +int MLX90640::mlx90640_TriggerMeasurement(uint8_t slaveAddr) { int error = 1; uint16_t ctrlReg; - error = MLX90640_I2CRead(slaveAddr, MLX90640_CTRL_REG, 1, &ctrlReg); + error = mlx90640_I2CRead(slaveAddr, mlx90640_CTRL_REG, 1, &ctrlReg); - if ( error != MLX90640_NO_ERROR) + if ( error != mlx90640_NO_ERROR) { return error; } - ctrlReg |= MLX90640_CTRL_TRIG_READY_MASK; - error = MLX90640_I2CWrite(slaveAddr, MLX90640_CTRL_REG, ctrlReg); + ctrlReg |= mlx90640_CTRL_TRIG_READY_MASK; + error = mlx90640_I2CWrite(slaveAddr, mlx90640_CTRL_REG, ctrlReg); - if ( error != MLX90640_NO_ERROR) + if ( error != mlx90640_NO_ERROR) { return error; } - error = MLX90640_I2CGeneralReset(); + error = mlx90640_I2CGeneralReset(); - if ( error != MLX90640_NO_ERROR) + if ( error != mlx90640_NO_ERROR) { return error; } - error = MLX90640_I2CRead(slaveAddr, MLX90640_CTRL_REG, 1, &ctrlReg); + error = mlx90640_I2CRead(slaveAddr, mlx90640_CTRL_REG, 1, &ctrlReg); - if ( error != MLX90640_NO_ERROR) + if ( error != mlx90640_NO_ERROR) { return error; } - if ((ctrlReg & MLX90640_CTRL_TRIG_READY_MASK) != 0) + if ((ctrlReg & mlx90640_CTRL_TRIG_READY_MASK) != 0) { - return -MLX90640_MEAS_TRIGGER_ERROR; + return -mlx90640_MEAS_TRIGGER_ERROR; } - return MLX90640_NO_ERROR; + return mlx90640_NO_ERROR; } -int MLX90640::MLX90640_GetFrameData(uint8_t slaveAddr, uint16_t *frameData) +int MLX90640::mlx90640_GetFrameData(uint8_t slaveAddr, uint16_t *frameData) { uint16_t dataReady = 0; uint16_t controlRegister1; @@ -102,54 +103,54 @@ int MLX90640::MLX90640_GetFrameData(uint8_t slaveAddr, uint16_t *frameData) while(dataReady == 0) { - error = MLX90640_I2CRead(slaveAddr, MLX90640_STATUS_REG, 1, &statusRegister); - if(error != MLX90640_NO_ERROR) + error = mlx90640_I2CRead(slaveAddr, mlx90640_STATUS_REG, 1, &statusRegister); + if(error != mlx90640_NO_ERROR) { return error; } //dataReady = statusRegister & 0x0008; - dataReady = MLX90640_GET_DATA_READY(statusRegister); + dataReady = mlx90640_GET_DATA_READY(statusRegister); } - error = MLX90640_I2CWrite(slaveAddr, MLX90640_STATUS_REG, MLX90640_INIT_STATUS_VALUE); - if(error == -MLX90640_I2C_NACK_ERROR) + error = mlx90640_I2CWrite(slaveAddr, mlx90640_STATUS_REG, mlx90640_INIT_STATUS_VALUE); + if(error == -mlx90640_I2C_NACK_ERROR) { return error; } - error = MLX90640_I2CRead(slaveAddr, MLX90640_PIXEL_DATA_START_ADDRESS, MLX90640_PIXEL_NUM, frameData); - if(error != MLX90640_NO_ERROR) + error = mlx90640_I2CRead(slaveAddr, mlx90640_PIXEL_DATA_START_ADDRESS, mlx90640_PIXEL_NUM, frameData); + if(error != mlx90640_NO_ERROR) { return error; } - error = MLX90640_I2CRead(slaveAddr, MLX90640_AUX_DATA_START_ADDRESS, MLX90640_AUX_NUM, data); - if(error != MLX90640_NO_ERROR) + error = mlx90640_I2CRead(slaveAddr, mlx90640_AUX_DATA_START_ADDRESS, mlx90640_AUX_NUM, data); + if(error != mlx90640_NO_ERROR) { return error; } - error = MLX90640_I2CRead(slaveAddr, MLX90640_CTRL_REG, 1, &controlRegister1); + error = mlx90640_I2CRead(slaveAddr, mlx90640_CTRL_REG, 1, &controlRegister1); frameData[832] = controlRegister1; //frameData[833] = statusRegister & 0x0001; - frameData[833] = MLX90640_GET_FRAME(statusRegister); + frameData[833] = mlx90640_GET_FRAME(statusRegister); - if(error != MLX90640_NO_ERROR) + if(error != mlx90640_NO_ERROR) { return error; } error = ValidateAuxData(data); - if(error == MLX90640_NO_ERROR) + if(error == mlx90640_NO_ERROR) { - for(cnt=0; cnt> MLX90640_CTRL_RESOLUTION_SHIFT; + resolutionRAM = (controlRegister1 & ~mlx90640_CTRL_RESOLUTION_MASK) >> mlx90640_CTRL_RESOLUTION_SHIFT; return resolutionRAM; } //------------------------------------------------------------------------------ -int MLX90640::MLX90640_SetRefreshRate(uint8_t slaveAddr, uint8_t refreshRate) +int MLX90640::mlx90640_SetRefreshRate(uint8_t slaveAddr, uint8_t refreshRate) { uint16_t controlRegister1; uint16_t value; int error; //value = (refreshRate & 0x07)<<7; - value = ((uint16_t)refreshRate << MLX90640_CTRL_REFRESH_SHIFT); - value &= ~MLX90640_CTRL_REFRESH_MASK; + value = ((uint16_t)refreshRate << mlx90640_CTRL_REFRESH_SHIFT); + value &= ~mlx90640_CTRL_REFRESH_MASK; - error = MLX90640_I2CRead(slaveAddr, MLX90640_CTRL_REG, 1, &controlRegister1); - if(error == MLX90640_NO_ERROR) + error = mlx90640_I2CRead(slaveAddr, mlx90640_CTRL_REG, 1, &controlRegister1); + if(error == mlx90640_NO_ERROR) { - value = (controlRegister1 & MLX90640_CTRL_REFRESH_MASK) | value; - error = MLX90640_I2CWrite(slaveAddr, MLX90640_CTRL_REG, value); + value = (controlRegister1 & mlx90640_CTRL_REFRESH_MASK) | value; + error = mlx90640_I2CWrite(slaveAddr, mlx90640_CTRL_REG, value); } return error; @@ -297,36 +298,36 @@ int MLX90640::MLX90640_SetRefreshRate(uint8_t slaveAddr, uint8_t refreshRate) //------------------------------------------------------------------------------ -int MLX90640::MLX90640_GetRefreshRate(uint8_t slaveAddr) +int MLX90640::mlx90640_GetRefreshRate(uint8_t slaveAddr) { uint16_t controlRegister1; int refreshRate; int error; - error = MLX90640_I2CRead(slaveAddr, MLX90640_CTRL_REG, 1, &controlRegister1); - if(error != MLX90640_NO_ERROR) + error = mlx90640_I2CRead(slaveAddr, mlx90640_CTRL_REG, 1, &controlRegister1); + if(error != mlx90640_NO_ERROR) { return error; } - refreshRate = (controlRegister1 & ~MLX90640_CTRL_REFRESH_MASK) >> MLX90640_CTRL_REFRESH_SHIFT; + refreshRate = (controlRegister1 & ~mlx90640_CTRL_REFRESH_MASK) >> mlx90640_CTRL_REFRESH_SHIFT; return refreshRate; } //------------------------------------------------------------------------------ -int MLX90640::MLX90640_SetInterleavedMode(uint8_t slaveAddr) +int MLX90640::mlx90640_SetInterleavedMode(uint8_t slaveAddr) { uint16_t controlRegister1; uint16_t value; int error; - error = MLX90640_I2CRead(slaveAddr, MLX90640_CTRL_REG, 1, &controlRegister1); + error = mlx90640_I2CRead(slaveAddr, mlx90640_CTRL_REG, 1, &controlRegister1); if(error == 0) { - value = (controlRegister1 & ~MLX90640_CTRL_MEAS_MODE_MASK); - error = MLX90640_I2CWrite(slaveAddr, MLX90640_CTRL_REG, value); + value = (controlRegister1 & ~mlx90640_CTRL_MEAS_MODE_MASK); + error = mlx90640_I2CWrite(slaveAddr, mlx90640_CTRL_REG, value); } return error; @@ -334,18 +335,18 @@ int MLX90640::MLX90640_SetInterleavedMode(uint8_t slaveAddr) //------------------------------------------------------------------------------ -int MLX90640::MLX90640_SetChessMode(uint8_t slaveAddr) +int MLX90640::mlx90640_SetChessMode(uint8_t slaveAddr) { uint16_t controlRegister1; uint16_t value; int error; - error = MLX90640_I2CRead(slaveAddr, MLX90640_CTRL_REG, 1, &controlRegister1); + error = mlx90640_I2CRead(slaveAddr, mlx90640_CTRL_REG, 1, &controlRegister1); if(error == 0) { - value = (controlRegister1 | MLX90640_CTRL_MEAS_MODE_MASK); - error = MLX90640_I2CWrite(slaveAddr, MLX90640_CTRL_REG, value); + value = (controlRegister1 | mlx90640_CTRL_MEAS_MODE_MASK); + error = mlx90640_I2CWrite(slaveAddr, mlx90640_CTRL_REG, value); } return error; @@ -353,25 +354,25 @@ int MLX90640::MLX90640_SetChessMode(uint8_t slaveAddr) //------------------------------------------------------------------------------ -int MLX90640::MLX90640_GetCurMode(uint8_t slaveAddr) +int MLX90640::mlx90640_GetCurMode(uint8_t slaveAddr) { uint16_t controlRegister1; int modeRAM; int error; - error = MLX90640_I2CRead(slaveAddr, MLX90640_CTRL_REG, 1, &controlRegister1); + error = mlx90640_I2CRead(slaveAddr, mlx90640_CTRL_REG, 1, &controlRegister1); if(error != 0) { return error; } - modeRAM = (controlRegister1 & MLX90640_CTRL_MEAS_MODE_MASK) >> MLX90640_CTRL_MEAS_MODE_SHIFT; + modeRAM = (controlRegister1 & mlx90640_CTRL_MEAS_MODE_MASK) >> mlx90640_CTRL_MEAS_MODE_SHIFT; return modeRAM; } //------------------------------------------------------------------------------ -void MLX90640::MLX90640_CalculateTo(uint16_t *frameData, const paramsMLX90640 *params, float emissivity, float tr, float *result) +void MLX90640::mlx90640_CalculateTo(uint16_t *frameData, const paramsMLX90640 *params, float emissivity, float tr, float *result) { float vdd; float ta; @@ -399,8 +400,8 @@ void MLX90640::MLX90640_CalculateTo(uint16_t *frameData, const paramsMLX90640 *p float kv; subPage = frameData[833]; - vdd = MLX90640_GetVdd(frameData, params); - ta = MLX90640_GetTa(frameData, params); + vdd = mlx90640_GetVdd(frameData, params); + ta = mlx90640_GetTa(frameData, params); ta4 = (ta + 273.15); ta4 = ta4 * ta4; @@ -424,7 +425,7 @@ void MLX90640::MLX90640_CalculateTo(uint16_t *frameData, const paramsMLX90640 *p gain = (float)params->gainEE / (int16_t)frameData[778]; //------------------------- To calculation ------------------------------------- - mode = (frameData[832] & MLX90640_CTRL_MEAS_MODE_MASK) >> 5; + mode = (frameData[832] & mlx90640_CTRL_MEAS_MODE_MASK) >> 5; irDataCP[0] = (int16_t)frameData[776] * gain; irDataCP[1] = (int16_t)frameData[808] * gain; @@ -504,7 +505,7 @@ void MLX90640::MLX90640_CalculateTo(uint16_t *frameData, const paramsMLX90640 *p //------------------------------------------------------------------------------ -void MLX90640::MLX90640_GetImage(uint16_t *frameData, const paramsMLX90640 *params, float *result) +void MLX90640::mlx90640_GetImage(uint16_t *frameData, const paramsMLX90640 *params) { float vdd; float ta; @@ -525,8 +526,8 @@ void MLX90640::MLX90640_GetImage(uint16_t *frameData, const paramsMLX90640 *para float kv; subPage = frameData[833]; - vdd = MLX90640_GetVdd(frameData, params); - ta = MLX90640_GetTa(frameData, params); + vdd = mlx90640_GetVdd(frameData, params); + ta = mlx90640_GetTa(frameData, params); ktaScale = POW2(params->ktaScale); kvScale = POW2(params->kvScale); @@ -537,7 +538,7 @@ void MLX90640::MLX90640_GetImage(uint16_t *frameData, const paramsMLX90640 *para //------------------------- Image calculation ------------------------------------- - mode = (frameData[832] & MLX90640_CTRL_MEAS_MODE_MASK) >> 5; + mode = (frameData[832] & mlx90640_CTRL_MEAS_MODE_MASK) >> 5; irDataCP[0] = (int16_t)frameData[776] * gain; irDataCP[1] = (int16_t)frameData[808] * gain; @@ -586,21 +587,22 @@ void MLX90640::MLX90640_GetImage(uint16_t *frameData, const paramsMLX90640 *para image = irData*alphaCompensated; - result[pixelNumber] = image; + imageVect[pixelNumber] = image; } } + emit dataReady(); } //------------------------------------------------------------------------------ -float MLX90640::MLX90640_GetVdd(uint16_t *frameData, const paramsMLX90640 *params) +float MLX90640::mlx90640_GetVdd(uint16_t *frameData, const paramsMLX90640 *params) { float vdd; float resolutionCorrection; uint16_t resolutionRAM; - resolutionRAM = (frameData[832] & ~MLX90640_CTRL_RESOLUTION_MASK) >> MLX90640_CTRL_RESOLUTION_SHIFT; + resolutionRAM = (frameData[832] & ~mlx90640_CTRL_RESOLUTION_MASK) >> mlx90640_CTRL_RESOLUTION_SHIFT; resolutionCorrection = POW2(params->resolutionEE) / POW2(resolutionRAM); vdd = (resolutionCorrection * (int16_t)frameData[810] - params->vdd25) / params->kVdd + 3.3; @@ -609,14 +611,14 @@ float MLX90640::MLX90640_GetVdd(uint16_t *frameData, const paramsMLX90640 *param //------------------------------------------------------------------------------ -float MLX90640::MLX90640_GetTa(uint16_t *frameData, const paramsMLX90640 *params) +float MLX90640::mlx90640_GetTa(uint16_t *frameData, const paramsMLX90640 *params) { int16_t ptat; float ptatArt; float vdd; float ta; - vdd = MLX90640_GetVdd(frameData, params); + vdd = mlx90640_GetVdd(frameData, params); ptat = (int16_t)frameData[800]; @@ -630,14 +632,14 @@ float MLX90640::MLX90640_GetTa(uint16_t *frameData, const paramsMLX90640 *params //------------------------------------------------------------------------------ -int MLX90640::MLX90640_GetSubPageNumber(uint16_t *frameData) +int MLX90640::mlx90640_GetSubPageNumber(uint16_t *frameData) { return frameData[833]; } //------------------------------------------------------------------------------ -void MLX90640::MLX90640_BadPixelsCorrection(uint16_t *pixels, float *to, int mode, paramsMLX90640 *params) +void MLX90640::mlx90640_BadPixelsCorrection(uint16_t *pixels, float *to, int mode, paramsMLX90640 *params) { float ap[4]; uint8_t pix; @@ -740,37 +742,37 @@ void MLX90640::MLX90640_BadPixelsCorrection(uint16_t *pixels, float *to, int mod //------------------------------------------------------------------------------ -void MLX90640::ExtractVDDParameters(uint16_t *eeData, paramsMLX90640 *mlx90640) +void MLX90640::ExtractVDDParameters(uint16_t *eeData, paramsMLX90640 *MLX90640) { int8_t kVdd; int16_t vdd25; - kVdd = MLX90640_MS_BYTE(eeData[51]); + kVdd = mlx90640_MS_BYTE(eeData[51]); - vdd25 = MLX90640_LS_BYTE(eeData[51]); + vdd25 = mlx90640_LS_BYTE(eeData[51]); vdd25 = ((vdd25 - 256) << 5) - 8192; - mlx90640->kVdd = 32 * kVdd; - mlx90640->vdd25 = vdd25; + MLX90640->kVdd = 32 * kVdd; + MLX90640->vdd25 = vdd25; } //------------------------------------------------------------------------------ -void MLX90640::ExtractPTATParameters(uint16_t *eeData, paramsMLX90640 *mlx90640) +void MLX90640::ExtractPTATParameters(uint16_t *eeData, paramsMLX90640 *MLX90640) { float KvPTAT; float KtPTAT; int16_t vPTAT25; float alphaPTAT; - KvPTAT = (eeData[50] & MLX90640_MSBITS_6_MASK) >> 10; + KvPTAT = (eeData[50] & mlx90640_MSBITS_6_MASK) >> 10; if(KvPTAT > 31) { KvPTAT = KvPTAT - 64; } KvPTAT = KvPTAT/4096; - KtPTAT = eeData[50] & MLX90640_LSBITS_10_MASK; + KtPTAT = eeData[50] & mlx90640_LSBITS_10_MASK; if(KtPTAT > 511) { KtPTAT = KtPTAT - 1024; @@ -779,76 +781,76 @@ void MLX90640::ExtractPTATParameters(uint16_t *eeData, paramsMLX90640 *mlx90640) vPTAT25 = eeData[49]; - alphaPTAT = (eeData[16] & MLX90640_NIBBLE4_MASK) / POW2(14) + 8.0f; + alphaPTAT = (eeData[16] & mlx90640_NIBBLE4_MASK) / POW2(14) + 8.0f; - mlx90640->KvPTAT = KvPTAT; - mlx90640->KtPTAT = KtPTAT; - mlx90640->vPTAT25 = vPTAT25; - mlx90640->alphaPTAT = alphaPTAT; + MLX90640->KvPTAT = KvPTAT; + MLX90640->KtPTAT = KtPTAT; + MLX90640->vPTAT25 = vPTAT25; + MLX90640->alphaPTAT = alphaPTAT; } //------------------------------------------------------------------------------ -void MLX90640::ExtractGainParameters(uint16_t *eeData, paramsMLX90640 *mlx90640) +void MLX90640::ExtractGainParameters(uint16_t *eeData, paramsMLX90640 *MLX90640) { - mlx90640->gainEE = (int16_t)eeData[48];; + MLX90640->gainEE = (int16_t)eeData[48];; } //------------------------------------------------------------------------------ -void MLX90640::ExtractTgcParameters(uint16_t *eeData, paramsMLX90640 *mlx90640) +void MLX90640::ExtractTgcParameters(uint16_t *eeData, paramsMLX90640 *MLX90640) { - mlx90640->tgc = (int8_t)MLX90640_LS_BYTE(eeData[60]) / 32.0f; + MLX90640->tgc = (int8_t)mlx90640_LS_BYTE(eeData[60]) / 32.0f; } //------------------------------------------------------------------------------ -void MLX90640::ExtractResolutionParameters(uint16_t *eeData, paramsMLX90640 *mlx90640) +void MLX90640::ExtractResolutionParameters(uint16_t *eeData, paramsMLX90640 *MLX90640) { uint8_t resolutionEE; resolutionEE = (eeData[56] & 0x3000) >> 12; - mlx90640->resolutionEE = resolutionEE; + MLX90640->resolutionEE = resolutionEE; } //------------------------------------------------------------------------------ -void MLX90640::ExtractKsTaParameters(uint16_t *eeData, paramsMLX90640 *mlx90640) +void MLX90640::ExtractKsTaParameters(uint16_t *eeData, paramsMLX90640 *MLX90640) { - mlx90640->KsTa = (int8_t)MLX90640_MS_BYTE(eeData[60]) / 8192.0f; + MLX90640->KsTa = (int8_t)mlx90640_MS_BYTE(eeData[60]) / 8192.0f; } //------------------------------------------------------------------------------ -void MLX90640::ExtractKsToParameters(uint16_t *eeData, paramsMLX90640 *mlx90640) +void MLX90640::ExtractKsToParameters(uint16_t *eeData, paramsMLX90640 *MLX90640) { int32_t KsToScale; int8_t step; step = ((eeData[63] & 0x3000) >> 12) * 10; - mlx90640->ct[0] = -40; - mlx90640->ct[1] = 0; - mlx90640->ct[2] = MLX90640_NIBBLE2(eeData[63]); - mlx90640->ct[3] = MLX90640_NIBBLE3(eeData[63]); + MLX90640->ct[0] = -40; + MLX90640->ct[1] = 0; + MLX90640->ct[2] = mlx90640_NIBBLE2(eeData[63]); + MLX90640->ct[3] = mlx90640_NIBBLE3(eeData[63]); - mlx90640->ct[2] = mlx90640->ct[2]*step; - mlx90640->ct[3] = mlx90640->ct[2] + mlx90640->ct[3]*step; - mlx90640->ct[4] = 400; + MLX90640->ct[2] = MLX90640->ct[2]*step; + MLX90640->ct[3] = MLX90640->ct[2] + MLX90640->ct[3]*step; + MLX90640->ct[4] = 400; - KsToScale = MLX90640_NIBBLE1(eeData[63]) + 8; + KsToScale = mlx90640_NIBBLE1(eeData[63]) + 8; KsToScale = 1UL << KsToScale; - mlx90640->ksTo[0] = (int8_t)MLX90640_LS_BYTE(eeData[61]) / (float)KsToScale; - mlx90640->ksTo[1] = (int8_t)MLX90640_MS_BYTE(eeData[61]) / (float)KsToScale; - mlx90640->ksTo[2] = (int8_t)MLX90640_LS_BYTE(eeData[62]) / (float)KsToScale; - mlx90640->ksTo[3] = (int8_t)MLX90640_MS_BYTE(eeData[62]) / (float)KsToScale; - mlx90640->ksTo[4] = -0.0002; + MLX90640->ksTo[0] = (int8_t)mlx90640_LS_BYTE(eeData[61]) / (float)KsToScale; + MLX90640->ksTo[1] = (int8_t)mlx90640_MS_BYTE(eeData[61]) / (float)KsToScale; + MLX90640->ksTo[2] = (int8_t)mlx90640_LS_BYTE(eeData[62]) / (float)KsToScale; + MLX90640->ksTo[3] = (int8_t)mlx90640_MS_BYTE(eeData[62]) / (float)KsToScale; + MLX90640->ksTo[4] = -0.0002; } //------------------------------------------------------------------------------ -void MLX90640::ExtractAlphaParameters(uint16_t *eeData, paramsMLX90640 *mlx90640) +void MLX90640::ExtractAlphaParameters(uint16_t *eeData, paramsMLX90640 *MLX90640) { int accRow[24]; int accColumn[32]; @@ -862,22 +864,22 @@ void MLX90640::ExtractAlphaParameters(uint16_t *eeData, paramsMLX90640 *mlx90640 float temp; - accRemScale = MLX90640_NIBBLE1(eeData[32]); - accColumnScale = MLX90640_NIBBLE2(eeData[32]); - accRowScale = MLX90640_NIBBLE3(eeData[32]); - alphaScale = MLX90640_NIBBLE4(eeData[32]) + 30; + accRemScale = mlx90640_NIBBLE1(eeData[32]); + accColumnScale = mlx90640_NIBBLE2(eeData[32]); + accRowScale = mlx90640_NIBBLE3(eeData[32]); + alphaScale = mlx90640_NIBBLE4(eeData[32]) + 30; alphaRef = eeData[33]; for(int i = 0; i < 6; i++) { p = i * 4; - accRow[p + 0] = MLX90640_NIBBLE1(eeData[34 + i]); - accRow[p + 1] = MLX90640_NIBBLE2(eeData[34 + i]); - accRow[p + 2] = MLX90640_NIBBLE3(eeData[34 + i]); - accRow[p + 3] = MLX90640_NIBBLE4(eeData[34 + i]); + accRow[p + 0] = mlx90640_NIBBLE1(eeData[34 + i]); + accRow[p + 1] = mlx90640_NIBBLE2(eeData[34 + i]); + accRow[p + 2] = mlx90640_NIBBLE3(eeData[34 + i]); + accRow[p + 3] = mlx90640_NIBBLE4(eeData[34 + i]); } - for(int i = 0; i < MLX90640_LINE_NUM; i++) + for(int i = 0; i < mlx90640_LINE_NUM; i++) { if (accRow[i] > 7) { @@ -888,13 +890,13 @@ void MLX90640::ExtractAlphaParameters(uint16_t *eeData, paramsMLX90640 *mlx90640 for(int i = 0; i < 8; i++) { p = i * 4; - accColumn[p + 0] = MLX90640_NIBBLE1(eeData[40 + i]); - accColumn[p + 1] = MLX90640_NIBBLE2(eeData[40 + i]); - accColumn[p + 2] = MLX90640_NIBBLE3(eeData[40 + i]); - accColumn[p + 3] = MLX90640_NIBBLE4(eeData[40 + i]); + accColumn[p + 0] = mlx90640_NIBBLE1(eeData[40 + i]); + accColumn[p + 1] = mlx90640_NIBBLE2(eeData[40 + i]); + accColumn[p + 2] = mlx90640_NIBBLE3(eeData[40 + i]); + accColumn[p + 3] = mlx90640_NIBBLE4(eeData[40 + i]); } - for(int i = 0; i < MLX90640_COLUMN_NUM; i++) + for(int i = 0; i < mlx90640_COLUMN_NUM; i++) { if (accColumn[i] > 7) { @@ -902,9 +904,9 @@ void MLX90640::ExtractAlphaParameters(uint16_t *eeData, paramsMLX90640 *mlx90640 } } - for(int i = 0; i < MLX90640_LINE_NUM; i++) + for(int i = 0; i < mlx90640_LINE_NUM; i++) { - for(int j = 0; j < MLX90640_COLUMN_NUM; j ++) + for(int j = 0; j < mlx90640_COLUMN_NUM; j ++) { p = 32 * i +j; alphaTemp[p] = (eeData[64 + p] & 0x03F0) >> 4; @@ -915,13 +917,13 @@ void MLX90640::ExtractAlphaParameters(uint16_t *eeData, paramsMLX90640 *mlx90640 alphaTemp[p] = alphaTemp[p]*(1 << accRemScale); alphaTemp[p] = (alphaRef + (accRow[i] << accRowScale) + (accColumn[j] << accColumnScale) + alphaTemp[p]); alphaTemp[p] = alphaTemp[p] / POW2(alphaScale); - alphaTemp[p] = alphaTemp[p] - mlx90640->tgc * (mlx90640->cpAlpha[0] + mlx90640->cpAlpha[1])/2; + alphaTemp[p] = alphaTemp[p] - MLX90640->tgc * (MLX90640->cpAlpha[0] + MLX90640->cpAlpha[1])/2; alphaTemp[p] = SCALEALPHA/alphaTemp[p]; } } temp = alphaTemp[0]; - for(int i = 1; i < MLX90640_PIXEL_NUM; i++) + for(int i = 1; i < mlx90640_PIXEL_NUM; i++) { if (alphaTemp[i] > temp) { @@ -936,20 +938,20 @@ void MLX90640::ExtractAlphaParameters(uint16_t *eeData, paramsMLX90640 *mlx90640 alphaScale = alphaScale + 1; } - for(int i = 0; i < MLX90640_PIXEL_NUM; i++) + for(int i = 0; i < mlx90640_PIXEL_NUM; i++) { temp = alphaTemp[i] * POW2(alphaScale); - mlx90640->alpha[i] = (temp + 0.5); + MLX90640->alpha[i] = (temp + 0.5); } - mlx90640->alphaScale = alphaScale; + MLX90640->alphaScale = alphaScale; } //------------------------------------------------------------------------------ -void MLX90640::ExtractOffsetParameters(uint16_t *eeData, paramsMLX90640 *mlx90640) +void MLX90640::ExtractOffsetParameters(uint16_t *eeData, paramsMLX90640 *MLX90640) { int occRow[24]; int occColumn[32]; @@ -960,21 +962,21 @@ void MLX90640::ExtractOffsetParameters(uint16_t *eeData, paramsMLX90640 *mlx9064 uint8_t occRemScale; - occRemScale = MLX90640_NIBBLE1(eeData[16]); - occColumnScale = MLX90640_NIBBLE2(eeData[16]); - occRowScale = MLX90640_NIBBLE3(eeData[16]); + occRemScale = mlx90640_NIBBLE1(eeData[16]); + occColumnScale = mlx90640_NIBBLE2(eeData[16]); + occRowScale = mlx90640_NIBBLE3(eeData[16]); offsetRef = (int16_t)eeData[17]; for(int i = 0; i < 6; i++) { p = i * 4; - occRow[p + 0] = MLX90640_NIBBLE1(eeData[18 + i]); - occRow[p + 1] = MLX90640_NIBBLE2(eeData[18 + i]); - occRow[p + 2] = MLX90640_NIBBLE3(eeData[18 + i]); - occRow[p + 3] = MLX90640_NIBBLE4(eeData[18 + i]); + occRow[p + 0] = mlx90640_NIBBLE1(eeData[18 + i]); + occRow[p + 1] = mlx90640_NIBBLE2(eeData[18 + i]); + occRow[p + 2] = mlx90640_NIBBLE3(eeData[18 + i]); + occRow[p + 3] = mlx90640_NIBBLE4(eeData[18 + i]); } - for(int i = 0; i < MLX90640_LINE_NUM; i++) + for(int i = 0; i < mlx90640_LINE_NUM; i++) { if (occRow[i] > 7) { @@ -985,13 +987,13 @@ void MLX90640::ExtractOffsetParameters(uint16_t *eeData, paramsMLX90640 *mlx9064 for(int i = 0; i < 8; i++) { p = i * 4; - occColumn[p + 0] = MLX90640_NIBBLE1(eeData[24 + i]); - occColumn[p + 1] = MLX90640_NIBBLE2(eeData[24 + i]); - occColumn[p + 2] = MLX90640_NIBBLE3(eeData[24 + i]); - occColumn[p + 3] = MLX90640_NIBBLE4(eeData[24 + i]); + occColumn[p + 0] = mlx90640_NIBBLE1(eeData[24 + i]); + occColumn[p + 1] = mlx90640_NIBBLE2(eeData[24 + i]); + occColumn[p + 2] = mlx90640_NIBBLE3(eeData[24 + i]); + occColumn[p + 3] = mlx90640_NIBBLE4(eeData[24 + i]); } - for(int i = 0; i < MLX90640_COLUMN_NUM; i ++) + for(int i = 0; i < mlx90640_COLUMN_NUM; i ++) { if (occColumn[i] > 7) { @@ -999,25 +1001,25 @@ void MLX90640::ExtractOffsetParameters(uint16_t *eeData, paramsMLX90640 *mlx9064 } } - for(int i = 0; i < MLX90640_LINE_NUM; i++) + for(int i = 0; i < mlx90640_LINE_NUM; i++) { - for(int j = 0; j < MLX90640_COLUMN_NUM; j ++) + for(int j = 0; j < mlx90640_COLUMN_NUM; j ++) { p = 32 * i +j; - mlx90640->offset[p] = (eeData[64 + p] & MLX90640_MSBITS_6_MASK) >> 10; - if (mlx90640->offset[p] > 31) + MLX90640->offset[p] = (eeData[64 + p] & mlx90640_MSBITS_6_MASK) >> 10; + if (MLX90640->offset[p] > 31) { - mlx90640->offset[p] = mlx90640->offset[p] - 64; + MLX90640->offset[p] = MLX90640->offset[p] - 64; } - mlx90640->offset[p] = mlx90640->offset[p]*(1 << occRemScale); - mlx90640->offset[p] = (offsetRef + (occRow[i] << occRowScale) + (occColumn[j] << occColumnScale) + mlx90640->offset[p]); + MLX90640->offset[p] = MLX90640->offset[p]*(1 << occRemScale); + MLX90640->offset[p] = (offsetRef + (occRow[i] << occRowScale) + (occColumn[j] << occColumnScale) + MLX90640->offset[p]); } } } //------------------------------------------------------------------------------ -void MLX90640::ExtractKtaPixelParameters(uint16_t *eeData, paramsMLX90640 *mlx90640) +void MLX90640::ExtractKtaPixelParameters(uint16_t *eeData, paramsMLX90640 *MLX90640) { int p = 0; int8_t KtaRC[4]; @@ -1027,17 +1029,17 @@ void MLX90640::ExtractKtaPixelParameters(uint16_t *eeData, paramsMLX90640 *mlx90 float ktaTemp[768]; float temp; - KtaRC[0] = (int8_t)MLX90640_MS_BYTE(eeData[54]);; - KtaRC[2] = (int8_t)MLX90640_LS_BYTE(eeData[54]);; - KtaRC[1] = (int8_t)MLX90640_MS_BYTE(eeData[55]);; - KtaRC[3] = (int8_t)MLX90640_LS_BYTE(eeData[55]);; + KtaRC[0] = (int8_t)mlx90640_MS_BYTE(eeData[54]);; + KtaRC[2] = (int8_t)mlx90640_LS_BYTE(eeData[54]);; + KtaRC[1] = (int8_t)mlx90640_MS_BYTE(eeData[55]);; + KtaRC[3] = (int8_t)mlx90640_LS_BYTE(eeData[55]);; - ktaScale1 = MLX90640_NIBBLE2(eeData[56]) + 8; - ktaScale2 = MLX90640_NIBBLE1(eeData[56]); + ktaScale1 = mlx90640_NIBBLE2(eeData[56]) + 8; + ktaScale2 = mlx90640_NIBBLE1(eeData[56]); - for(int i = 0; i < MLX90640_LINE_NUM; i++) + for(int i = 0; i < mlx90640_LINE_NUM; i++) { - for(int j = 0; j < MLX90640_COLUMN_NUM; j ++) + for(int j = 0; j < mlx90640_COLUMN_NUM; j ++) { p = 32 * i +j; split = 2*(p/32 - (p/64)*2) + p%2; @@ -1054,7 +1056,7 @@ void MLX90640::ExtractKtaPixelParameters(uint16_t *eeData, paramsMLX90640 *mlx90 } temp = fabs(ktaTemp[0]); - for(int i = 1; i < MLX90640_PIXEL_NUM; i++) + for(int i = 1; i < mlx90640_PIXEL_NUM; i++) { if (fabs(ktaTemp[i]) > temp) { @@ -1069,27 +1071,27 @@ void MLX90640::ExtractKtaPixelParameters(uint16_t *eeData, paramsMLX90640 *mlx90 ktaScale1 = ktaScale1 + 1; } - for(int i = 0; i < MLX90640_PIXEL_NUM; i++) + for(int i = 0; i < mlx90640_PIXEL_NUM; i++) { temp = ktaTemp[i] * POW2(ktaScale1); if (temp < 0) { - mlx90640->kta[i] = (temp - 0.5); + MLX90640->kta[i] = (temp - 0.5); } else { - mlx90640->kta[i] = (temp + 0.5); + MLX90640->kta[i] = (temp + 0.5); } } - mlx90640->ktaScale = ktaScale1; + MLX90640->ktaScale = ktaScale1; } //------------------------------------------------------------------------------ -void MLX90640::ExtractKvPixelParameters(uint16_t *eeData, paramsMLX90640 *mlx90640) +void MLX90640::ExtractKvPixelParameters(uint16_t *eeData, paramsMLX90640 *MLX90640) { int p = 0; int8_t KvT[4]; @@ -1102,40 +1104,40 @@ void MLX90640::ExtractKvPixelParameters(uint16_t *eeData, paramsMLX90640 *mlx906 float kvTemp[768]; float temp; - KvRoCo = MLX90640_NIBBLE4(eeData[52]); + KvRoCo = mlx90640_NIBBLE4(eeData[52]); if (KvRoCo > 7) { KvRoCo = KvRoCo - 16; } KvT[0] = KvRoCo; - KvReCo = MLX90640_NIBBLE3(eeData[52]); + KvReCo = mlx90640_NIBBLE3(eeData[52]); if (KvReCo > 7) { KvReCo = KvReCo - 16; } KvT[2] = KvReCo; - KvRoCe = MLX90640_NIBBLE2(eeData[52]); + KvRoCe = mlx90640_NIBBLE2(eeData[52]); if (KvRoCe > 7) { KvRoCe = KvRoCe - 16; } KvT[1] = KvRoCe; - KvReCe = MLX90640_NIBBLE1(eeData[52]); + KvReCe = mlx90640_NIBBLE1(eeData[52]); if (KvReCe > 7) { KvReCe = KvReCe - 16; } KvT[3] = KvReCe; - kvScale = MLX90640_NIBBLE3(eeData[56]); + kvScale = mlx90640_NIBBLE3(eeData[56]); - for(int i = 0; i < MLX90640_LINE_NUM; i++) + for(int i = 0; i < mlx90640_LINE_NUM; i++) { - for(int j = 0; j < MLX90640_COLUMN_NUM; j ++) + for(int j = 0; j < mlx90640_COLUMN_NUM; j ++) { p = 32 * i +j; split = 2*(p/32 - (p/64)*2) + p%2; @@ -1145,7 +1147,7 @@ void MLX90640::ExtractKvPixelParameters(uint16_t *eeData, paramsMLX90640 *mlx906 } temp = fabs(kvTemp[0]); - for(int i = 1; i < MLX90640_PIXEL_NUM; i++) + for(int i = 1; i < mlx90640_PIXEL_NUM; i++) { if (fabs(kvTemp[i]) > temp) { @@ -1160,26 +1162,26 @@ void MLX90640::ExtractKvPixelParameters(uint16_t *eeData, paramsMLX90640 *mlx906 kvScale = kvScale + 1; } - for(int i = 0; i < MLX90640_PIXEL_NUM; i++) + for(int i = 0; i < mlx90640_PIXEL_NUM; i++) { temp = kvTemp[i] * POW2(kvScale); if (temp < 0) { - mlx90640->kv[i] = (temp - 0.5); + MLX90640->kv[i] = (temp - 0.5); } else { - mlx90640->kv[i] = (temp + 0.5); + MLX90640->kv[i] = (temp + 0.5); } } - mlx90640->kvScale = kvScale; + MLX90640->kvScale = kvScale; } //------------------------------------------------------------------------------ -void MLX90640::ExtractCPParameters(uint16_t *eeData, paramsMLX90640 *mlx90640) +void MLX90640::ExtractCPParameters(uint16_t *eeData, paramsMLX90640 *MLX90640) { float alphaSP[2]; int16_t offsetSP[2]; @@ -1189,54 +1191,54 @@ void MLX90640::ExtractCPParameters(uint16_t *eeData, paramsMLX90640 *mlx90640) uint8_t ktaScale1; uint8_t kvScale; - alphaScale = MLX90640_NIBBLE4(eeData[32]) + 27; + alphaScale = mlx90640_NIBBLE4(eeData[32]) + 27; - offsetSP[0] = (eeData[58] & MLX90640_LSBITS_10_MASK); + offsetSP[0] = (eeData[58] & mlx90640_LSBITS_10_MASK); if (offsetSP[0] > 511) { offsetSP[0] = offsetSP[0] - 1024; } - offsetSP[1] = (eeData[58] & MLX90640_MSBITS_6_MASK) >> 10; + offsetSP[1] = (eeData[58] & mlx90640_MSBITS_6_MASK) >> 10; if (offsetSP[1] > 31) { offsetSP[1] = offsetSP[1] - 64; } offsetSP[1] = offsetSP[1] + offsetSP[0]; - alphaSP[0] = (eeData[57] & MLX90640_LSBITS_10_MASK); + alphaSP[0] = (eeData[57] & mlx90640_LSBITS_10_MASK); if (alphaSP[0] > 511) { alphaSP[0] = alphaSP[0] - 1024; } alphaSP[0] = alphaSP[0] / POW2(alphaScale); - alphaSP[1] = (eeData[57] & MLX90640_MSBITS_6_MASK) >> 10; + alphaSP[1] = (eeData[57] & mlx90640_MSBITS_6_MASK) >> 10; if (alphaSP[1] > 31) { alphaSP[1] = alphaSP[1] - 64; } alphaSP[1] = (1 + alphaSP[1]/128) * alphaSP[0]; - cpKta = (int8_t)MLX90640_LS_BYTE(eeData[59]); + cpKta = (int8_t)mlx90640_LS_BYTE(eeData[59]); - ktaScale1 = MLX90640_NIBBLE2(eeData[56]) + 8; - mlx90640->cpKta = cpKta / POW2(ktaScale1); + ktaScale1 = mlx90640_NIBBLE2(eeData[56]) + 8; + MLX90640->cpKta = cpKta / POW2(ktaScale1); - cpKv = (int8_t)MLX90640_MS_BYTE(eeData[59]); + cpKv = (int8_t)mlx90640_MS_BYTE(eeData[59]); - kvScale = MLX90640_NIBBLE3(eeData[56]); - mlx90640->cpKv = cpKv / POW2(kvScale); + kvScale = mlx90640_NIBBLE3(eeData[56]); + MLX90640->cpKv = cpKv / POW2(kvScale); - mlx90640->cpAlpha[0] = alphaSP[0]; - mlx90640->cpAlpha[1] = alphaSP[1]; - mlx90640->cpOffset[0] = offsetSP[0]; - mlx90640->cpOffset[1] = offsetSP[1]; + MLX90640->cpAlpha[0] = alphaSP[0]; + MLX90640->cpAlpha[1] = alphaSP[1]; + MLX90640->cpOffset[0] = offsetSP[0]; + MLX90640->cpOffset[1] = offsetSP[1]; } //------------------------------------------------------------------------------ -void MLX90640::ExtractCILCParameters(uint16_t *eeData, paramsMLX90640 *mlx90640) +void MLX90640::ExtractCILCParameters(uint16_t *eeData, paramsMLX90640 *MLX90640) { float ilChessC[3]; uint8_t calibrationModeEE; @@ -1265,15 +1267,15 @@ void MLX90640::ExtractCILCParameters(uint16_t *eeData, paramsMLX90640 *mlx90640) } ilChessC[2] = ilChessC[2] / 8.0f; - mlx90640->calibrationModeEE = calibrationModeEE; - mlx90640->ilChessC[0] = ilChessC[0]; - mlx90640->ilChessC[1] = ilChessC[1]; - mlx90640->ilChessC[2] = ilChessC[2]; + MLX90640->calibrationModeEE = calibrationModeEE; + MLX90640->ilChessC[0] = ilChessC[0]; + MLX90640->ilChessC[1] = ilChessC[1]; + MLX90640->ilChessC[2] = ilChessC[2]; } //------------------------------------------------------------------------------ -int MLX90640::ExtractDeviatingPixels(uint16_t *eeData, paramsMLX90640 *mlx90640) +int MLX90640::ExtractDeviatingPixels(uint16_t *eeData, paramsMLX90640 *MLX90640) { uint16_t pixCnt = 0; uint16_t brokenPixCnt = 0; @@ -1283,21 +1285,21 @@ int MLX90640::ExtractDeviatingPixels(uint16_t *eeData, paramsMLX90640 *mlx90640) for(pixCnt = 0; pixCnt<5; pixCnt++) { - mlx90640->brokenPixels[pixCnt] = 0xFFFF; - mlx90640->outlierPixels[pixCnt] = 0xFFFF; + MLX90640->brokenPixels[pixCnt] = 0xFFFF; + MLX90640->outlierPixels[pixCnt] = 0xFFFF; } pixCnt = 0; - while (pixCnt < MLX90640_PIXEL_NUM && brokenPixCnt < 5 && outlierPixCnt < 5) + while (pixCnt < mlx90640_PIXEL_NUM && brokenPixCnt < 5 && outlierPixCnt < 5) { if(eeData[pixCnt+64] == 0) { - mlx90640->brokenPixels[brokenPixCnt] = pixCnt; + MLX90640->brokenPixels[brokenPixCnt] = pixCnt; brokenPixCnt = brokenPixCnt + 1; } else if((eeData[pixCnt+64] & 0x0001) != 0) { - mlx90640->outlierPixels[outlierPixCnt] = pixCnt; + MLX90640->outlierPixels[outlierPixCnt] = pixCnt; outlierPixCnt = outlierPixCnt + 1; } @@ -1307,15 +1309,15 @@ int MLX90640::ExtractDeviatingPixels(uint16_t *eeData, paramsMLX90640 *mlx90640) if(brokenPixCnt > 4) { - warn = -MLX90640_BROKEN_PIXELS_NUM_ERROR; + warn = -mlx90640_BROKEN_PIXELS_NUM_ERROR; } else if(outlierPixCnt > 4) { - warn = -MLX90640_OUTLIER_PIXELS_NUM_ERROR; + warn = -mlx90640_OUTLIER_PIXELS_NUM_ERROR; } else if((brokenPixCnt + outlierPixCnt) > 4) { - warn = -MLX90640_BAD_PIXELS_NUM_ERROR; + warn = -mlx90640_BAD_PIXELS_NUM_ERROR; } else { @@ -1323,7 +1325,7 @@ int MLX90640::ExtractDeviatingPixels(uint16_t *eeData, paramsMLX90640 *mlx90640) { for(i=pixCnt+1; ibrokenPixels[pixCnt],mlx90640->brokenPixels[i]); + warn = CheckAdjacentPixels(MLX90640->brokenPixels[pixCnt],MLX90640->brokenPixels[i]); if(warn != 0) { return warn; @@ -1335,7 +1337,7 @@ int MLX90640::ExtractDeviatingPixels(uint16_t *eeData, paramsMLX90640 *mlx90640) { for(i=pixCnt+1; ioutlierPixels[pixCnt],mlx90640->outlierPixels[i]); + warn = CheckAdjacentPixels(MLX90640->outlierPixels[pixCnt],MLX90640->outlierPixels[i]); if(warn != 0) { return warn; @@ -1347,7 +1349,7 @@ int MLX90640::ExtractDeviatingPixels(uint16_t *eeData, paramsMLX90640 *mlx90640) { for(i=0; ibrokenPixels[pixCnt],mlx90640->outlierPixels[i]); + warn = CheckAdjacentPixels(MLX90640->brokenPixels[pixCnt],MLX90640->outlierPixels[i]); if(warn != 0) { return warn; diff --git a/src/MLX90640_API.h b/src/MLX90640_API.h index e362c6b..b44f787 100644 --- a/src/MLX90640_API.h +++ b/src/MLX90640_API.h @@ -14,64 +14,71 @@ * limitations under the License. * */ -#ifndef _MLX90640_API_H_ -#define _MLX90640_API_H_ - -#define MLX90640_NO_ERROR 0 -#define MLX90640_I2C_NACK_ERROR 1 -#define MLX90640_I2C_WRITE_ERROR 2 -#define MLX90640_BROKEN_PIXELS_NUM_ERROR 3 -#define MLX90640_OUTLIER_PIXELS_NUM_ERROR 4 -#define MLX90640_BAD_PIXELS_NUM_ERROR 5 -#define MLX90640_ADJACENT_BAD_PIXELS_ERROR 6 -#define MLX90640_EEPROM_DATA_ERROR 7 -#define MLX90640_FRAME_DATA_ERROR 8 -#define MLX90640_MEAS_TRIGGER_ERROR 9 +#ifndef _mlx90640_API_H_ +#define _mlx90640_API_H_ + +#include +#include +#include +#include + +#define mlx90640_DEV_ADDR 0x33 + +#define mlx90640_NO_ERROR 0 +#define mlx90640_I2C_NACK_ERROR 1 +#define mlx90640_I2C_WRITE_ERROR 2 +#define mlx90640_BROKEN_PIXELS_NUM_ERROR 3 +#define mlx90640_OUTLIER_PIXELS_NUM_ERROR 4 +#define mlx90640_BAD_PIXELS_NUM_ERROR 5 +#define mlx90640_ADJACENT_BAD_PIXELS_ERROR 6 +#define mlx90640_EEPROM_DATA_ERROR 7 +#define mlx90640_FRAME_DATA_ERROR 8 +#define mlx90640_MEAS_TRIGGER_ERROR 9 #define BIT_MASK(x) (1UL << (x)) #define REG_MASK(sbit,nbits) ~((~(~0UL << (nbits))) << (sbit)) -#define MLX90640_EEPROM_START_ADDRESS 0x2400 -#define MLX90640_EEPROM_DUMP_NUM 832 -#define MLX90640_PIXEL_DATA_START_ADDRESS 0x0400 -#define MLX90640_PIXEL_NUM 768 -#define MLX90640_LINE_NUM 24 -#define MLX90640_COLUMN_NUM 32 -#define MLX90640_LINE_SIZE 32 -#define MLX90640_COLUMN_SIZE 24 -#define MLX90640_AUX_DATA_START_ADDRESS 0x0700 -#define MLX90640_AUX_NUM 64 -#define MLX90640_STATUS_REG 0x8000 -#define MLX90640_INIT_STATUS_VALUE 0x0030 -#define MLX90640_STAT_FRAME_MASK BIT_MASK(0) -#define MLX90640_GET_FRAME(reg_value) (reg_value & MLX90640_STAT_FRAME_MASK) -#define MLX90640_STAT_DATA_READY_MASK BIT_MASK(3) -#define MLX90640_GET_DATA_READY(reg_value) (reg_value & MLX90640_STAT_DATA_READY_MASK) - -#define MLX90640_CTRL_REG 0x800D -#define MLX90640_CTRL_TRIG_READY_MASK BIT_MASK(15) -#define MLX90640_CTRL_REFRESH_SHIFT 7 -#define MLX90640_CTRL_REFRESH_MASK REG_MASK(MLX90640_CTRL_REFRESH_SHIFT,3) -#define MLX90640_CTRL_RESOLUTION_SHIFT 10 -#define MLX90640_CTRL_RESOLUTION_MASK REG_MASK(MLX90640_CTRL_RESOLUTION_SHIFT,2) -#define MLX90640_CTRL_MEAS_MODE_SHIFT 12 -#define MLX90640_CTRL_MEAS_MODE_MASK BIT_MASK(12) - -#define MLX90640_MS_BYTE_SHIFT 8 -#define MLX90640_MS_BYTE_MASK 0xFF00 -#define MLX90640_LS_BYTE_MASK 0x00FF -#define MLX90640_MS_BYTE(reg16) ((reg16 & MLX90640_MS_BYTE_MASK) >> MLX90640_MS_BYTE_SHIFT) -#define MLX90640_LS_BYTE(reg16) (reg16 & MLX90640_LS_BYTE_MASK) -#define MLX90640_MSBITS_6_MASK 0xFC00 -#define MLX90640_LSBITS_10_MASK 0x03FF -#define MLX90640_NIBBLE1_MASK 0x000F -#define MLX90640_NIBBLE2_MASK 0x00F0 -#define MLX90640_NIBBLE3_MASK 0x0F00 -#define MLX90640_NIBBLE4_MASK 0xF000 -#define MLX90640_NIBBLE1(reg16) ((reg16 & MLX90640_NIBBLE1_MASK)) -#define MLX90640_NIBBLE2(reg16) ((reg16 & MLX90640_NIBBLE2_MASK) >> 4) -#define MLX90640_NIBBLE3(reg16) ((reg16 & MLX90640_NIBBLE3_MASK) >> 8) -#define MLX90640_NIBBLE4(reg16) ((reg16 & MLX90640_NIBBLE4_MASK) >> 12) +#define mlx90640_EEPROM_START_ADDRESS 0x2400 +#define mlx90640_EEPROM_DUMP_NUM 832 +#define mlx90640_PIXEL_DATA_START_ADDRESS 0x0400 +#define mlx90640_PIXEL_NUM 768 +#define mlx90640_LINE_NUM 24 +#define mlx90640_COLUMN_NUM 32 +#define mlx90640_LINE_SIZE 32 +#define mlx90640_COLUMN_SIZE 24 +#define mlx90640_AUX_DATA_START_ADDRESS 0x0700 +#define mlx90640_AUX_NUM 64 +#define mlx90640_STATUS_REG 0x8000 +#define mlx90640_INIT_STATUS_VALUE 0x0030 +#define mlx90640_STAT_FRAME_MASK BIT_MASK(0) +#define mlx90640_GET_FRAME(reg_value) (reg_value & mlx90640_STAT_FRAME_MASK) +#define mlx90640_STAT_DATA_READY_MASK BIT_MASK(3) +#define mlx90640_GET_DATA_READY(reg_value) (reg_value & mlx90640_STAT_DATA_READY_MASK) + +#define mlx90640_CTRL_REG 0x800D +#define mlx90640_CTRL_TRIG_READY_MASK BIT_MASK(15) +#define mlx90640_CTRL_REFRESH_SHIFT 7 +#define mlx90640_CTRL_REFRESH_MASK REG_MASK(mlx90640_CTRL_REFRESH_SHIFT,3) +#define mlx90640_CTRL_RESOLUTION_SHIFT 10 +#define mlx90640_CTRL_RESOLUTION_MASK REG_MASK(mlx90640_CTRL_RESOLUTION_SHIFT,2) +#define mlx90640_CTRL_MEAS_MODE_SHIFT 12 +#define mlx90640_CTRL_MEAS_MODE_MASK BIT_MASK(12) + +#define mlx90640_MS_BYTE_SHIFT 8 +#define mlx90640_MS_BYTE_MASK 0xFF00 +#define mlx90640_LS_BYTE_MASK 0x00FF +#define mlx90640_MS_BYTE(reg16) ((reg16 & mlx90640_MS_BYTE_MASK) >> mlx90640_MS_BYTE_SHIFT) +#define mlx90640_LS_BYTE(reg16) (reg16 & mlx90640_LS_BYTE_MASK) +#define mlx90640_MSBITS_6_MASK 0xFC00 +#define mlx90640_LSBITS_10_MASK 0x03FF +#define mlx90640_NIBBLE1_MASK 0x000F +#define mlx90640_NIBBLE2_MASK 0x00F0 +#define mlx90640_NIBBLE3_MASK 0x0F00 +#define mlx90640_NIBBLE4_MASK 0xF000 +#define mlx90640_NIBBLE1(reg16) ((reg16 & mlx90640_NIBBLE1_MASK)) +#define mlx90640_NIBBLE2(reg16) ((reg16 & mlx90640_NIBBLE2_MASK) >> 4) +#define mlx90640_NIBBLE3(reg16) ((reg16 & mlx90640_NIBBLE3_MASK) >> 8) +#define mlx90640_NIBBLE4(reg16) ((reg16 & mlx90640_NIBBLE4_MASK) >> 12) #define POW2(x) pow(2, (double)x) @@ -79,76 +86,98 @@ #include -typedef struct - { - int16_t kVdd; - int16_t vdd25; - float KvPTAT; - float KtPTAT; - uint16_t vPTAT25; - float alphaPTAT; - int16_t gainEE; - float tgc; - float cpKv; - float cpKta; - uint8_t resolutionEE; - uint8_t calibrationModeEE; - float KsTa; - float ksTo[5]; - int16_t ct[5]; - uint16_t alpha[768]; - uint8_t alphaScale; - int16_t offset[768]; - int8_t kta[768]; - uint8_t ktaScale; - int8_t kv[768]; - uint8_t kvScale; - float cpAlpha[2]; - int16_t cpOffset[2]; - float ilChessC[3]; - uint16_t brokenPixels[5]; - uint16_t outlierPixels[5]; - } paramsMLX90640; - -class MLX90640{ +class MLX90640 : public QObject +{ + Q_OBJECT + public: - int MLX90640_DumpEE(uint8_t slaveAddr, uint16_t *eeData); - int MLX90640_SynchFrame(uint8_t slaveAddr); - int MLX90640_TriggerMeasurement(uint8_t slaveAddr); - int MLX90640_GetFrameData(uint8_t slaveAddr, uint16_t *frameData); - int MLX90640_ExtractParameters(uint16_t *eeData, paramsMLX90640 *mlx90640); - float MLX90640_GetVdd(uint16_t *frameData, const paramsMLX90640 *params); - float MLX90640_GetTa(uint16_t *frameData, const paramsMLX90640 *params); - void MLX90640_GetImage(uint16_t *frameData, const paramsMLX90640 *params, float *result); - void MLX90640_CalculateTo(uint16_t *frameData, const paramsMLX90640 *params, float emissivity, float tr, float *result); - int MLX90640_SetResolution(uint8_t slaveAddr, uint8_t resolution); - int MLX90640_GetCurResolution(uint8_t slaveAddr); - int MLX90640_SetRefreshRate(uint8_t slaveAddr, uint8_t refreshRate); - int MLX90640_GetRefreshRate(uint8_t slaveAddr); - int MLX90640_GetSubPageNumber(uint16_t *frameData); - int MLX90640_GetCurMode(uint8_t slaveAddr); - int MLX90640_SetInterleavedMode(uint8_t slaveAddr); - int MLX90640_SetChessMode(uint8_t slaveAddr); - void MLX90640_BadPixelsCorrection(uint16_t *pixels, float *to, int mode, paramsMLX90640 *params); + typedef struct + { + int16_t kVdd; + int16_t vdd25; + float KvPTAT; + float KtPTAT; + uint16_t vPTAT25; + float alphaPTAT; + int16_t gainEE; + float tgc; + float cpKv; + float cpKta; + uint8_t resolutionEE; + uint8_t calibrationModeEE; + float KsTa; + float ksTo[5]; + int16_t ct[5]; + uint16_t alpha[768]; + uint8_t alphaScale; + int16_t offset[768]; + int8_t kta[768]; + uint8_t ktaScale; + int8_t kv[768]; + uint8_t kvScale; + float cpAlpha[2]; + int16_t cpOffset[2]; + float ilChessC[3]; + uint16_t brokenPixels[5]; + uint16_t outlierPixels[5]; + } paramsMLX90640; + + int mlx90640_DumpEE(uint8_t slaveAddr, uint16_t *eeData); + int mlx90640_SynchFrame(uint8_t slaveAddr); + int mlx90640_TriggerMeasurement(uint8_t slaveAddr); + Q_INVOKABLE int mlx90640_GetFrameData(uint8_t slaveAddr, uint16_t *frameData); + int mlx90640_ExtractParameters(uint16_t *eeData, paramsMLX90640 *MLX90640); + Q_INVOKABLE float mlx90640_GetVdd(uint16_t *frameData, const paramsMLX90640 *params); + Q_INVOKABLE float mlx90640_GetTa(uint16_t *frameData, const paramsMLX90640 *params); + Q_INVOKABLE void mlx90640_GetImage(uint16_t *frameData, const paramsMLX90640 *params); + void mlx90640_CalculateTo(uint16_t *frameData, const paramsMLX90640 *params, float emissivity, float tr, float *result); + Q_INVOKABLE int mlx90640_SetResolution(uint8_t slaveAddr, uint8_t resolution); + int mlx90640_GetCurResolution(uint8_t slaveAddr); + Q_INVOKABLE int mlx90640_SetRefreshRate(uint8_t slaveAddr, uint8_t refreshRate); + int mlx90640_GetRefreshRate(uint8_t slaveAddr); + int mlx90640_GetSubPageNumber(uint16_t *frameData); + int mlx90640_GetCurMode(uint8_t slaveAddr); + Q_INVOKABLE int mlx90640_SetInterleavedMode(uint8_t slaveAddr); + Q_INVOKABLE int mlx90640_SetChessMode(uint8_t slaveAddr); + void mlx90640_BadPixelsCorrection(uint16_t *pixels, float *to, int mode, paramsMLX90640 *params); + + Q_INVOKABLE void fuzzyInit(){ + unsigned char slaveAddress = 0x33; + static uint16_t eeMLX90640[832]; + static uint16_t mlx90640Frame[834]; + paramsMLX90640 mlx90640; + + int status; + status = mlx90640_DumpEE (slaveAddress, eeMLX90640); + //status = mlx90640_ExtractParameters(eeMLX90640, &mlx90640); + //status = mlx90640_GetFrameData (0x33, mlx90640Frame); + //mlx90640_GetImage(mlx90640Frame, &mlx90640); + } + + MLX90640() : imageVect(768){} + + QVector imageVect; protected: - void ExtractVDDParameters(uint16_t *eeData, paramsMLX90640 *mlx90640); - void ExtractPTATParameters(uint16_t *eeData, paramsMLX90640 *mlx90640); - void ExtractGainParameters(uint16_t *eeData, paramsMLX90640 *mlx90640); - void ExtractTgcParameters(uint16_t *eeData, paramsMLX90640 *mlx90640); - void ExtractResolutionParameters(uint16_t *eeData, paramsMLX90640 *mlx90640); - void ExtractKsTaParameters(uint16_t *eeData, paramsMLX90640 *mlx90640); - void ExtractKsToParameters(uint16_t *eeData, paramsMLX90640 *mlx90640); - void ExtractAlphaParameters(uint16_t *eeData, paramsMLX90640 *mlx90640); - void ExtractOffsetParameters(uint16_t *eeData, paramsMLX90640 *mlx90640); - void ExtractKtaPixelParameters(uint16_t *eeData, paramsMLX90640 *mlx90640); - void ExtractKvPixelParameters(uint16_t *eeData, paramsMLX90640 *mlx90640); - void ExtractCPParameters(uint16_t *eeData, paramsMLX90640 *mlx90640); - void ExtractCILCParameters(uint16_t *eeData, paramsMLX90640 *mlx90640); - int ExtractDeviatingPixels(uint16_t *eeData, paramsMLX90640 *mlx90640); + void ExtractVDDParameters(uint16_t *eeData, paramsMLX90640 *MLX90640); + void ExtractPTATParameters(uint16_t *eeData, paramsMLX90640 *MLX90640); + void ExtractGainParameters(uint16_t *eeData, paramsMLX90640 *MLX90640); + void ExtractTgcParameters(uint16_t *eeData, paramsMLX90640 *MLX90640); + void ExtractResolutionParameters(uint16_t *eeData, paramsMLX90640 *MLX90640); + void ExtractKsTaParameters(uint16_t *eeData, paramsMLX90640 *MLX90640); + void ExtractKsToParameters(uint16_t *eeData, paramsMLX90640 *MLX90640); + void ExtractAlphaParameters(uint16_t *eeData, paramsMLX90640 *MLX90640); + void ExtractOffsetParameters(uint16_t *eeData, paramsMLX90640 *MLX90640); + void ExtractKtaPixelParameters(uint16_t *eeData, paramsMLX90640 *MLX90640); + void ExtractKvPixelParameters(uint16_t *eeData, paramsMLX90640 *MLX90640); + void ExtractCPParameters(uint16_t *eeData, paramsMLX90640 *MLX90640); + void ExtractCILCParameters(uint16_t *eeData, paramsMLX90640 *MLX90640); + int ExtractDeviatingPixels(uint16_t *eeData, paramsMLX90640 *MLX90640); int CheckAdjacentPixels(uint16_t pix1, uint16_t pix2); float GetMedian(float *values, int n); int IsPixelBad(uint16_t pixel,paramsMLX90640 *params); int ValidateFrameData(uint16_t *frameData); int ValidateAuxData(uint16_t *auxData); +signals: + void dataReady(); }; #endif diff --git a/src/MLX90640_I2C_Driver.cpp b/src/MLX90640_I2C_Driver.cpp index 39475b4..63d2965 100644 --- a/src/MLX90640_I2C_Driver.cpp +++ b/src/MLX90640_I2C_Driver.cpp @@ -1,38 +1,40 @@ -#include "MLX90640_I2C_Driver.h" +#include "mlx90640_I2C_Driver.h" #include "i2cdriversingleton.h" #include #define DEFAULT_I2C_DEV QString("/dev/i2c-1/") /// -/// \brief MLX90640_I2CInit Setup the I2C lines +/// \brief mlx90640_I2CInit Setup the I2C lines /// -void MLX90640_I2CInit(void){ +void mlx90640_I2CInit(void){ i2cDriverSingleton::getinstance()->tohVddSet(QString("on")); i2cDriverSingleton::getinstance()->i2cProbe(DEFAULT_I2C_DEV); } /// -/// \brief MLX90640_I2CGeneralReset resets the I2C line and devices +/// \brief mlx90640_I2CGeneralReset resets the I2C line and devices /// \return 0 if success /// -int MLX90640_I2CGeneralReset(void){ +int mlx90640_I2CGeneralReset(void){ } /// -/// \brief MLX90640_I2CFreqSet Sets the frequency for the I2C bus +/// \brief mlx90640_I2CFreqSet Sets the frequency for the I2C bus /// \param freq /// -void MLX90640_I2CFreqSet(int freq){ +void mlx90640_I2CFreqSet(int freq){ } -int MLX90640_I2CRead(uint8_t slaveAddr,uint16_t startAddress, uint16_t nMemAddressRead, uint16_t *data){ - i2cDriverSingleton::getinstance()->i2cRead(DEFAULT_I2C_DEV,nMemAddressRead,nMemAddressRead); +int mlx90640_I2CRead(uint8_t slaveAddr,uint16_t startAddress, uint16_t nMemAddressRead, uint16_t *data){ + i2cDriverSingleton::getinstance()->i2cRead(slaveAddr, startAddress, nMemAddressRead, data); + return 0; } -int MLX90640_I2CWrite(uint8_t slaveAddr,uint16_t writeAddress, uint16_t data) +int mlx90640_I2CWrite(uint8_t slaveAddr,uint16_t writeAddress, uint16_t data) { - i2cDriverSingleton::getinstance()->i2cWrite(DEFAULT_I2C_DEV,writeAddress,QString(data)); + i2cDriverSingleton::getinstance()->i2cWrite(slaveAddr, writeAddress, data); + return 0; } diff --git a/src/MLX90640_I2C_Driver.h b/src/MLX90640_I2C_Driver.h index 0a0d613..4b63220 100644 --- a/src/MLX90640_I2C_Driver.h +++ b/src/MLX90640_I2C_Driver.h @@ -14,15 +14,15 @@ * limitations under the License. * */ -#ifndef _MLX90640_I2C_Driver_H_ -#define _MLX90640_I2C_Driver_H_ +#ifndef _mlx90640_I2C_Driver_H_ +#define _mlx90640_I2C_Driver_H_ #include -#include "MLX90640_API.h" +#include "mlx90640_API.h" - extern void MLX90640_I2CInit(void); - extern int MLX90640_I2CGeneralReset(void); - extern int MLX90640_I2CRead(uint8_t slaveAddr,uint16_t startAddress, uint16_t nMemAddressRead, uint16_t *data); - extern int MLX90640_I2CWrite(uint8_t slaveAddr,uint16_t writeAddress, uint16_t data); - extern void MLX90640_I2CFreqSet(int freq); + extern void mlx90640_I2CInit(void); + extern int mlx90640_I2CGeneralReset(void); + extern int mlx90640_I2CWrite(uint8_t slaveAddr,uint16_t writeAddress, uint16_t data); + extern int mlx90640_I2CRead(uint8_t slaveAddr,uint16_t startAddress, uint16_t nMemAddressRead, uint16_t *data); + extern void mlx90640_I2CFreqSet(int freq); #endif diff --git a/src/i2cdriversingleton.cpp b/src/i2cdriversingleton.cpp index aec9caf..32d63c1 100644 --- a/src/i2cdriversingleton.cpp +++ b/src/i2cdriversingleton.cpp @@ -1,6 +1,6 @@ #include "i2cdriversingleton.h" -I2cif* i2cDriverSingleton::instance; //instance declaration for the static variable in the singleton +I2cif* i2cDriverSingleton::instance = nullptr; //instance declaration for the static variable in the singleton I2cif* i2cDriverSingleton::getinstance() { @@ -13,5 +13,6 @@ I2cif* i2cDriverSingleton::getinstance() void i2cDriverSingleton::cleanup(){ if(instance != nullptr){ instance->tohVddSet(QString("off")); + delete instance; } } diff --git a/src/i2cif.cpp b/src/i2cif.cpp index 48721d2..7bebeca 100644 --- a/src/i2cif.cpp +++ b/src/i2cif.cpp @@ -1,5 +1,3 @@ -#include "i2cif.h" - #include "i2cif.h" #include #include @@ -15,6 +13,8 @@ #include #include "conv.h" #include +#include +#define DEFAULT_I2C_DEV QString("/dev/i2c-1/") I2cif::I2cif(QObject *parent) : QObject(parent) @@ -100,6 +100,111 @@ bool I2cif::tohVddGet() * */ +Q_INVOKABLE void I2cif::i2cWrite(const uint8_t &slaveAddr, const uint16_t &writeAddress, const uint16_t &data){ + int file; + char buf[3]; + + QByteArray tmpBa = DEFAULT_I2C_DEV.toUtf8(); + const char* devNameChar = tmpBa.constData(); + + fprintf(stderr, "writing to address %02x: ", slaveAddr); + + if ((file = open (devNameChar, O_RDWR)) < 0) + { + fprintf(stderr,"open error\n"); + emit i2cError(); + return; + } + + if (ioctl(file, I2C_SLAVE, slaveAddr) < 0) + { + close(file); + fprintf(stderr,"ioctl error\n"); + emit i2cError(); + return; + } + + // prepare buffer to write + buf[0] = (writeAddress >> 8) & 0xFF; // writeAddress high byte + buf[1] = writeAddress & 0xFF; // writeAddress low byte + buf[2] = data & 0xFF; // data + + /* write the data */ + if (write(file, buf, sizeof(buf)) != sizeof(buf)) + { + close(file); + fprintf(stderr,"write error\n"); + emit i2cError(); + return; + } + + close(file); + + fprintf(stderr,"write ok\n"); + + emit i2cWriteOk(); + +} + +void I2cif::i2cRead(const uint8_t &slaveAddr, const uint16_t &startAddress, const uint16_t &nMemAddressRead, uint16_t *data) +{ + int file; + char buf[2]; + 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 %d, %s\n",errno, devNameChar); + emit i2cError(); + return; + } + + if (ioctl(file, I2C_SLAVE, slaveAddr) < 0) + { + close(file); + fprintf(stderr,"ioctl error\n"); + emit i2cError(); + return; + } + + /* Read data */ + for (int i = 0; i < nMemAddressRead; i++) + { + /* Write start address */ + buf[0] = ((startAddress + 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 "); + for (int i = 0; i < nMemAddressRead; i++) + { + fprintf(stderr, "%04x ", data[i]); + } + fprintf(stderr, "\n"); + + emit i2cReadResultChanged(); +} + void I2cif::i2cWrite(QString devName, unsigned char address, QString data) { int file; @@ -169,20 +274,42 @@ void I2cif::i2cWrite(QString devName, unsigned char address, QString data) void I2cif::i2cRead(QString devName, unsigned char address, int count) { int file; - char buf[200]; + const int CHUNK_SIZE = 200; + char buf[CHUNK_SIZE]; Conv conv; + int bytesRead = 0; + const int MAX_ATTEMPTS = 3; + int attempt = 0; m_readResult = ""; - //emit i2cReadResultChanged(); QByteArray tmpBa = devName.toUtf8(); const char* devNameChar = tmpBa.constData(); fprintf(stderr, "reading from address %02x count %d\n", address, count); - if ((file = open (devNameChar, O_RDWR)) < 0) + do { - fprintf(stderr,"open error\n"); + if ((file = open (devNameChar, O_RDWR)) < 0) + { + perror("open"); + if (errno == EBUSY) + { + fprintf(stderr, "i2c bus is busy!\n"); + usleep(50000); // wait for 50 ms + continue; + }else{ + fprintf(stderr, "got error: %d\n", errno); + } + emit i2cError(); + return; + } + break; + } while (++attempt < MAX_ATTEMPTS); + + if (attempt == MAX_ATTEMPTS) + { + fprintf(stderr, "Failed to open the device after %d attempts\n", attempt); emit i2cError(); return; } @@ -190,32 +317,41 @@ void I2cif::i2cRead(QString devName, unsigned char address, int count) if (ioctl(file, I2C_SLAVE, address) < 0) { close(file); - fprintf(stderr,"ioctl error\n"); + perror("ioctl"); emit i2cError(); return; } - /* Read data */ - if (read( file, buf, count ) != count) + while(bytesRead < count) { - close(file); - fprintf(stderr,"read error\n"); - emit i2cError(); - return; - } + int chunk = count - bytesRead; + if(chunk > CHUNK_SIZE) + { + chunk = CHUNK_SIZE; + } - close(file); + /* Read data */ + if (read( file, buf, chunk ) != chunk) + { + close(file); + perror("read"); + emit i2cError(); + return; + } - /* copy buf to m_readResult */ - int i; + /* copy buf to m_readResult */ + fprintf(stderr, "read "); + for (int i=0; i #include +#include + class I2cif : public QObject { @@ -20,6 +22,8 @@ public: Q_INVOKABLE void i2cProbe(QString devName); Q_INVOKABLE void i2cWrite(QString devName, unsigned char address, QString data); Q_INVOKABLE void i2cRead(QString devName, unsigned char address, int count); + Q_INVOKABLE void i2cWrite(const uint8_t &slaveAddr,const uint16_t &writeAddress,const uint16_t &data); + Q_INVOKABLE void i2cRead(const uint8_t &slaveAddr,const uint16_t &startAddress, const uint16_t &nMemAddressRead,uint16_t *data); Q_INVOKABLE void i2cWriteThenRead(QString devName, unsigned char address, QString data, int count); Q_INVOKABLE void tohVddSet(QString onOff); diff --git a/src/thermi2c.cpp b/src/thermi2c.cpp index 70fa066..e49b822 100644 --- a/src/thermi2c.cpp +++ b/src/thermi2c.cpp @@ -1,4 +1,8 @@ #ifdef QT_QML_DEBUG +#include "conv.h" +#include "i2cif.h" +#include "mlx90640_API.h" + #include #endif @@ -6,15 +10,9 @@ int main(int argc, char *argv[]) { - // SailfishApp::main() will display "qml/thermi2c.qml", if you need more - // control over initialization, you can use: - // - // - SailfishApp::application(int, char *[]) to get the QGuiApplication * - // - SailfishApp::createView() to get a new QQuickView * instance - // - SailfishApp::pathTo(QString) to get a QUrl to a resource file - // - SailfishApp::pathToMainQml() to get a QUrl to the main QML file - // - // To display the view, call "show()" (will show fullscreen on device). + qmlRegisterType("harbour.i2ctool.I2cif", 1, 0, "I2cif"); + qmlRegisterType("harbour.i2ctool.Conv", 1, 0, "Conv"); + qmlRegisterType("melexis.driver", 1, 0, "MLX90640"); return SailfishApp::main(argc, argv); } diff --git a/thermi2c.pro b/thermi2c.pro index 8e32d65..0903ee7 100644 --- a/thermi2c.pro +++ b/thermi2c.pro @@ -15,8 +15,8 @@ TARGET = thermi2c CONFIG += sailfishapp SOURCES += src/thermi2c.cpp \ - src/MLX90640_API.cpp \ - src/MLX90640_I2C_Driver.cpp \ + src/mlx90640_API.cpp \ + src/mlx90640_I2C_Driver.cpp \ src/conv.cpp \ src/i2cdriversingleton.cpp \ src/i2cif.cpp @@ -44,8 +44,8 @@ CONFIG += sailfishapp_i18n TRANSLATIONS += translations/thermi2c-de.ts HEADERS += \ - src/MLX90640_API.h \ - src/MLX90640_I2C_Driver.h \ + src/mlx90640_API.h \ + src/mlx90640_I2C_Driver.h \ src/conv.h \ src/i2cdriversingleton.h \ src/i2cif.h diff --git a/thermi2c.pro.user b/thermi2c.pro.user index 0583146..4f18fa8 100644 --- a/thermi2c.pro.user +++ b/thermi2c.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -275,7 +275,7 @@ - true + false QmakeProjectManager.MerPrepareTargetStep @@ -303,7 +303,11 @@ true QmakeProjectManager.MerRpmBuildStep - 1 + + true + QmakeProjectManager.MerRpmValidationStep + + 2 Deploy Deploy ProjectExplorer.BuildSteps.Deploy @@ -340,83 +344,6 @@ 3 - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - - 25 - - 1 - true - false - true - - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - - true - C:/Users/Onyxa/Documents/thermi2c - false - -1 - 3 - - 2 - - ProjectExplorer.CustomExecutableRunConfiguration - - false - true - false - true - - dwarf cpu-cycles @@ -486,16 +413,16 @@ 1 - Custom Executable2 - QmakeProjectManager.MerCustomRunConfiguration: - + thermi2c + QmakeProjectManager.MerRunConfiguration:C:/Users/Onyxa/Documents/thermi2c/thermi2c.pro + C:/Users/Onyxa/Documents/thermi2c/thermi2c.pro 1 false true false true - 2 + 1 diff --git a/translations/thermi2c-de.ts b/translations/thermi2c-de.ts index 8f39883..8de5b6e 100644 --- a/translations/thermi2c-de.ts +++ b/translations/thermi2c-de.ts @@ -8,21 +8,6 @@ Mein Cover - - FirstPage - - Show Page 2 - Zur Seite 2 - - - UI Template - UI-Vorlage - - - Hello Sailors - Hallo Matrosen - - SecondPage diff --git a/translations/thermi2c.ts b/translations/thermi2c.ts index 7fc118e..a088806 100644 --- a/translations/thermi2c.ts +++ b/translations/thermi2c.ts @@ -8,21 +8,6 @@ - - FirstPage - - Show Page 2 - - - - UI Template - - - - Hello Sailors - - - SecondPage