Malexis 90640 sensor

Dependencies:   mbed

Committer:
withboobs
Date:
Fri Apr 20 17:26:01 2018 +0000
Revision:
4:b9ae79d80127
Parent:
1:3f763d28c1be
nothing to say;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
withboobs 0:99e98f131071 1
withboobs 0:99e98f131071 2 #include <MLX90640_I2C_Driver.h>
withboobs 0:99e98f131071 3 #include <MLX90640_API.h>
withboobs 0:99e98f131071 4 #include <math.h>
withboobs 0:99e98f131071 5
withboobs 0:99e98f131071 6 void ExtractVDDParameters(uint16_t *eeData, paramsMLX90640 *mlx90640);
withboobs 0:99e98f131071 7 void ExtractPTATParameters(uint16_t *eeData, paramsMLX90640 *mlx90640);
withboobs 0:99e98f131071 8 void ExtractGainParameters(uint16_t *eeData, paramsMLX90640 *mlx90640);
withboobs 0:99e98f131071 9 void ExtractTgcParameters(uint16_t *eeData, paramsMLX90640 *mlx90640);
withboobs 0:99e98f131071 10 void ExtractResolutionParameters(uint16_t *eeData, paramsMLX90640 *mlx90640);
withboobs 0:99e98f131071 11 void ExtractKsTaParameters(uint16_t *eeData, paramsMLX90640 *mlx90640);
withboobs 0:99e98f131071 12 void ExtractKsToParameters(uint16_t *eeData, paramsMLX90640 *mlx90640);
withboobs 0:99e98f131071 13 void ExtractAlphaParameters(uint16_t *eeData, paramsMLX90640 *mlx90640);
withboobs 0:99e98f131071 14 void ExtractOffsetParameters(uint16_t *eeData, paramsMLX90640 *mlx90640);
withboobs 0:99e98f131071 15 void ExtractKtaPixelParameters(uint16_t *eeData, paramsMLX90640 *mlx90640);
withboobs 0:99e98f131071 16 void ExtractKvPixelParameters(uint16_t *eeData, paramsMLX90640 *mlx90640);
withboobs 0:99e98f131071 17 void ExtractCPParameters(uint16_t *eeData, paramsMLX90640 *mlx90640);
withboobs 0:99e98f131071 18 void ExtractCILCParameters(uint16_t *eeData, paramsMLX90640 *mlx90640);
withboobs 0:99e98f131071 19 int ExtractDeviatingPixels(uint16_t *eeData, paramsMLX90640 *mlx90640);
withboobs 0:99e98f131071 20 int CheckAdjacentPixels(uint16_t pix1, uint16_t pix2);
withboobs 0:99e98f131071 21 int CheckEEPROMValid(uint16_t *eeData);
withboobs 0:99e98f131071 22
withboobs 0:99e98f131071 23
withboobs 0:99e98f131071 24 int MLX90640_DumpEE(uint8_t slaveAddr, uint16_t *eeData)
withboobs 0:99e98f131071 25 {
withboobs 0:99e98f131071 26 return MLX90640_I2CRead(slaveAddr, 0x2400, 832, eeData);
withboobs 0:99e98f131071 27 }
withboobs 0:99e98f131071 28
withboobs 0:99e98f131071 29 int MLX90640_GetFrameData(uint8_t slaveAddr, uint16_t *frameData)
withboobs 0:99e98f131071 30 {
withboobs 0:99e98f131071 31 uint16_t dataReady = 1;
withboobs 0:99e98f131071 32 uint16_t controlRegister1;
withboobs 0:99e98f131071 33 uint16_t statusRegister;
withboobs 0:99e98f131071 34 int error = 1;
withboobs 0:99e98f131071 35 uint8_t cnt = 0;
withboobs 0:99e98f131071 36
withboobs 0:99e98f131071 37 dataReady = 0;
withboobs 0:99e98f131071 38 while(dataReady == 0)
withboobs 0:99e98f131071 39 {
withboobs 0:99e98f131071 40 error = MLX90640_I2CRead(slaveAddr, 0x8000, 1, &statusRegister);
withboobs 0:99e98f131071 41 if(error != 0)
withboobs 0:99e98f131071 42 {
withboobs 0:99e98f131071 43 return error;
withboobs 0:99e98f131071 44 }
withboobs 0:99e98f131071 45 dataReady = statusRegister & 0x0008;
withboobs 0:99e98f131071 46 }
withboobs 0:99e98f131071 47
withboobs 0:99e98f131071 48 while(dataReady != 0 && cnt < 5)
withboobs 0:99e98f131071 49 {
withboobs 0:99e98f131071 50 error = MLX90640_I2CWrite(slaveAddr, 0x8000, 0x0030);
withboobs 0:99e98f131071 51 if(error == -1)
withboobs 0:99e98f131071 52 {
withboobs 0:99e98f131071 53 return error;
withboobs 0:99e98f131071 54 }
withboobs 0:99e98f131071 55
withboobs 0:99e98f131071 56 error = MLX90640_I2CRead(slaveAddr, 0x0400, 832, frameData);
withboobs 0:99e98f131071 57 if(error != 0)
withboobs 0:99e98f131071 58 {
withboobs 0:99e98f131071 59 return error;
withboobs 0:99e98f131071 60 }
withboobs 0:99e98f131071 61
withboobs 0:99e98f131071 62 error = MLX90640_I2CRead(slaveAddr, 0x8000, 1, &statusRegister);
withboobs 0:99e98f131071 63 if(error != 0)
withboobs 0:99e98f131071 64 {
withboobs 0:99e98f131071 65 return error;
withboobs 0:99e98f131071 66 }
withboobs 0:99e98f131071 67 dataReady = statusRegister & 0x0008;
withboobs 0:99e98f131071 68 cnt = cnt + 1;
withboobs 0:99e98f131071 69 }
withboobs 0:99e98f131071 70
withboobs 0:99e98f131071 71 if(cnt > 4)
withboobs 0:99e98f131071 72 {
withboobs 0:99e98f131071 73 return -8;
withboobs 0:99e98f131071 74 }
withboobs 0:99e98f131071 75
withboobs 0:99e98f131071 76 error = MLX90640_I2CRead(slaveAddr, 0x800D, 1, &controlRegister1);
withboobs 0:99e98f131071 77 frameData[832] = controlRegister1;
withboobs 0:99e98f131071 78 frameData[833] = statusRegister & 0x0007;
withboobs 0:99e98f131071 79
withboobs 0:99e98f131071 80 if(error != 0)
withboobs 0:99e98f131071 81 {
withboobs 0:99e98f131071 82 return error;
withboobs 0:99e98f131071 83 }
withboobs 0:99e98f131071 84
withboobs 0:99e98f131071 85 return frameData[833];
withboobs 0:99e98f131071 86 }
withboobs 0:99e98f131071 87
withboobs 0:99e98f131071 88 int MLX90640_ExtractParameters(uint16_t *eeData, paramsMLX90640 *mlx90640)
withboobs 0:99e98f131071 89 {
withboobs 0:99e98f131071 90 int error = CheckEEPROMValid(eeData);
withboobs 0:99e98f131071 91
withboobs 0:99e98f131071 92 if(error == 0)
withboobs 0:99e98f131071 93 {
withboobs 0:99e98f131071 94 ExtractVDDParameters(eeData, mlx90640);
withboobs 0:99e98f131071 95 ExtractPTATParameters(eeData, mlx90640);
withboobs 0:99e98f131071 96 ExtractGainParameters(eeData, mlx90640);
withboobs 0:99e98f131071 97 ExtractTgcParameters(eeData, mlx90640);
withboobs 0:99e98f131071 98 ExtractResolutionParameters(eeData, mlx90640);
withboobs 0:99e98f131071 99 ExtractKsTaParameters(eeData, mlx90640);
withboobs 0:99e98f131071 100 ExtractKsToParameters(eeData, mlx90640);
withboobs 0:99e98f131071 101 ExtractAlphaParameters(eeData, mlx90640);
withboobs 0:99e98f131071 102 ExtractOffsetParameters(eeData, mlx90640);
withboobs 0:99e98f131071 103 ExtractKtaPixelParameters(eeData, mlx90640);
withboobs 0:99e98f131071 104 ExtractKvPixelParameters(eeData, mlx90640);
withboobs 0:99e98f131071 105 ExtractCPParameters(eeData, mlx90640);
withboobs 0:99e98f131071 106 ExtractCILCParameters(eeData, mlx90640);
withboobs 0:99e98f131071 107 error = ExtractDeviatingPixels(eeData, mlx90640);
withboobs 0:99e98f131071 108 }
withboobs 0:99e98f131071 109
withboobs 0:99e98f131071 110 return error;
withboobs 0:99e98f131071 111
withboobs 0:99e98f131071 112 }
withboobs 0:99e98f131071 113
withboobs 0:99e98f131071 114 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 115
withboobs 0:99e98f131071 116 int MLX90640_SetResolution(uint8_t slaveAddr, uint8_t resolution)
withboobs 0:99e98f131071 117 {
withboobs 0:99e98f131071 118 uint16_t controlRegister1;
withboobs 0:99e98f131071 119 int value;
withboobs 0:99e98f131071 120 int error;
withboobs 0:99e98f131071 121
withboobs 0:99e98f131071 122 value = (resolution & 0x03) << 10;
withboobs 0:99e98f131071 123
withboobs 0:99e98f131071 124 error = MLX90640_I2CRead(slaveAddr, 0x800D, 1, &controlRegister1);
withboobs 0:99e98f131071 125
withboobs 0:99e98f131071 126 if(error == 0)
withboobs 0:99e98f131071 127 {
withboobs 0:99e98f131071 128 value = (controlRegister1 & 0xF3FF) | value;
withboobs 0:99e98f131071 129 error = MLX90640_I2CWrite(slaveAddr, 0x800D, value);
withboobs 0:99e98f131071 130 }
withboobs 0:99e98f131071 131
withboobs 0:99e98f131071 132 return error;
withboobs 0:99e98f131071 133 }
withboobs 0:99e98f131071 134
withboobs 0:99e98f131071 135 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 136
withboobs 0:99e98f131071 137 int MLX90640_GetCurResolution(uint8_t slaveAddr)
withboobs 0:99e98f131071 138 {
withboobs 0:99e98f131071 139 uint16_t controlRegister1;
withboobs 0:99e98f131071 140 int resolutionRAM;
withboobs 0:99e98f131071 141 int error;
withboobs 0:99e98f131071 142
withboobs 0:99e98f131071 143 error = MLX90640_I2CRead(slaveAddr, 0x800D, 1, &controlRegister1);
withboobs 0:99e98f131071 144 if(error != 0)
withboobs 0:99e98f131071 145 {
withboobs 0:99e98f131071 146 return error;
withboobs 0:99e98f131071 147 }
withboobs 0:99e98f131071 148 resolutionRAM = (controlRegister1 & 0x0C00) >> 10;
withboobs 0:99e98f131071 149
withboobs 0:99e98f131071 150 return resolutionRAM;
withboobs 0:99e98f131071 151 }
withboobs 0:99e98f131071 152
withboobs 0:99e98f131071 153 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 154
withboobs 0:99e98f131071 155 int MLX90640_SetRefreshRate(uint8_t slaveAddr, uint8_t refreshRate)
withboobs 0:99e98f131071 156 {
withboobs 0:99e98f131071 157 uint16_t controlRegister1;
withboobs 0:99e98f131071 158 int value;
withboobs 0:99e98f131071 159 int error;
withboobs 0:99e98f131071 160
withboobs 0:99e98f131071 161 value = (refreshRate & 0x07)<<7;
withboobs 0:99e98f131071 162
withboobs 0:99e98f131071 163 error = MLX90640_I2CRead(slaveAddr, 0x800D, 1, &controlRegister1);
withboobs 0:99e98f131071 164 if(error == 0)
withboobs 0:99e98f131071 165 {
withboobs 0:99e98f131071 166 value = (controlRegister1 & 0xFC7F) | value;
withboobs 0:99e98f131071 167 error = MLX90640_I2CWrite(slaveAddr, 0x800D, value);
withboobs 0:99e98f131071 168 }
withboobs 0:99e98f131071 169
withboobs 0:99e98f131071 170 return error;
withboobs 0:99e98f131071 171 }
withboobs 0:99e98f131071 172
withboobs 0:99e98f131071 173 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 174
withboobs 0:99e98f131071 175 int MLX90640_GetRefreshRate(uint8_t slaveAddr)
withboobs 0:99e98f131071 176 {
withboobs 0:99e98f131071 177 uint16_t controlRegister1;
withboobs 0:99e98f131071 178 int refreshRate;
withboobs 0:99e98f131071 179 int error;
withboobs 0:99e98f131071 180
withboobs 0:99e98f131071 181 error = MLX90640_I2CRead(slaveAddr, 0x800D, 1, &controlRegister1);
withboobs 0:99e98f131071 182 if(error != 0)
withboobs 0:99e98f131071 183 {
withboobs 0:99e98f131071 184 return error;
withboobs 0:99e98f131071 185 }
withboobs 0:99e98f131071 186 refreshRate = (controlRegister1 & 0x0380) >> 7;
withboobs 0:99e98f131071 187
withboobs 0:99e98f131071 188 return refreshRate;
withboobs 0:99e98f131071 189 }
withboobs 0:99e98f131071 190
withboobs 0:99e98f131071 191 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 192
withboobs 0:99e98f131071 193 int MLX90640_SetInterleavedMode(uint8_t slaveAddr)
withboobs 0:99e98f131071 194 {
withboobs 0:99e98f131071 195 uint16_t controlRegister1;
withboobs 0:99e98f131071 196 int value;
withboobs 0:99e98f131071 197 int error;
withboobs 0:99e98f131071 198
withboobs 0:99e98f131071 199 error = MLX90640_I2CRead(slaveAddr, 0x800D, 1, &controlRegister1);
withboobs 0:99e98f131071 200
withboobs 0:99e98f131071 201 if(error == 0)
withboobs 0:99e98f131071 202 {
withboobs 0:99e98f131071 203 value = (controlRegister1 & 0xEFFF);
withboobs 0:99e98f131071 204 error = MLX90640_I2CWrite(slaveAddr, 0x800D, value);
withboobs 0:99e98f131071 205 }
withboobs 0:99e98f131071 206
withboobs 0:99e98f131071 207 return error;
withboobs 0:99e98f131071 208 }
withboobs 0:99e98f131071 209
withboobs 0:99e98f131071 210 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 211
withboobs 0:99e98f131071 212 int MLX90640_SetChessMode(uint8_t slaveAddr)
withboobs 0:99e98f131071 213 {
withboobs 0:99e98f131071 214 uint16_t controlRegister1;
withboobs 0:99e98f131071 215 int value;
withboobs 0:99e98f131071 216 int error;
withboobs 0:99e98f131071 217
withboobs 0:99e98f131071 218 error = MLX90640_I2CRead(slaveAddr, 0x800D, 1, &controlRegister1);
withboobs 0:99e98f131071 219
withboobs 0:99e98f131071 220 if(error == 0)
withboobs 0:99e98f131071 221 {
withboobs 0:99e98f131071 222 value = (controlRegister1 | 0x1000);
withboobs 0:99e98f131071 223 error = MLX90640_I2CWrite(slaveAddr, 0x800D, value);
withboobs 0:99e98f131071 224 }
withboobs 0:99e98f131071 225
withboobs 0:99e98f131071 226 return error;
withboobs 0:99e98f131071 227 }
withboobs 0:99e98f131071 228
withboobs 0:99e98f131071 229 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 230
withboobs 0:99e98f131071 231 int MLX90640_GetCurMode(uint8_t slaveAddr)
withboobs 0:99e98f131071 232 {
withboobs 0:99e98f131071 233 uint16_t controlRegister1;
withboobs 0:99e98f131071 234 int modeRAM;
withboobs 0:99e98f131071 235 int error;
withboobs 0:99e98f131071 236
withboobs 0:99e98f131071 237 error = MLX90640_I2CRead(slaveAddr, 0x800D, 1, &controlRegister1);
withboobs 0:99e98f131071 238 if(error != 0)
withboobs 0:99e98f131071 239 {
withboobs 0:99e98f131071 240 return error;
withboobs 0:99e98f131071 241 }
withboobs 0:99e98f131071 242 modeRAM = (controlRegister1 & 0x1000) >> 12;
withboobs 0:99e98f131071 243
withboobs 0:99e98f131071 244 return modeRAM;
withboobs 0:99e98f131071 245 }
withboobs 0:99e98f131071 246
withboobs 0:99e98f131071 247 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 248
withboobs 0:99e98f131071 249 void MLX90640_CalculateTo(uint16_t *frameData, paramsMLX90640 *params, float emissivity, float tr, float *result)
withboobs 0:99e98f131071 250 {
withboobs 0:99e98f131071 251 float vdd;
withboobs 0:99e98f131071 252 float ta;
withboobs 0:99e98f131071 253 float ta4;
withboobs 0:99e98f131071 254 float tr4;
withboobs 0:99e98f131071 255 float taTr;
withboobs 0:99e98f131071 256 float gain;
withboobs 0:99e98f131071 257 float irDataCP[2];
withboobs 0:99e98f131071 258 float irData;
withboobs 0:99e98f131071 259 float alphaCompensated;
withboobs 0:99e98f131071 260 uint8_t mode;
withboobs 0:99e98f131071 261 int8_t ilPattern;
withboobs 0:99e98f131071 262 int8_t chessPattern;
withboobs 0:99e98f131071 263 int8_t pattern;
withboobs 0:99e98f131071 264 int8_t conversionPattern;
withboobs 0:99e98f131071 265 float Sx;
withboobs 0:99e98f131071 266 float To;
withboobs 0:99e98f131071 267 float alphaCorrR[4];
withboobs 0:99e98f131071 268 int8_t range;
withboobs 0:99e98f131071 269
withboobs 0:99e98f131071 270
withboobs 0:99e98f131071 271 vdd = MLX90640_GetVdd(frameData, params);
withboobs 0:99e98f131071 272 ta = MLX90640_GetTa(frameData, params);
withboobs 1:3f763d28c1be 273 ta4 = powf((ta + 273.15f), 4.0f);
withboobs 1:3f763d28c1be 274 tr4 = powf((tr + 273.15f), 4.0f);
withboobs 0:99e98f131071 275 taTr = tr4 - (tr4-ta4)/emissivity;
withboobs 0:99e98f131071 276
withboobs 1:3f763d28c1be 277 alphaCorrR[0] = 1.0f / (1.0f + params->ksTo[0] * 40.0f);
withboobs 1:3f763d28c1be 278 alphaCorrR[1] = 1.0f ;
withboobs 1:3f763d28c1be 279 alphaCorrR[2] = (1.0f + params->ksTo[2] * params->ct[2]);
withboobs 0:99e98f131071 280 alphaCorrR[3] = alphaCorrR[2] * (1 + params->ksTo[3] * (params->ct[3] - params->ct[2]));
withboobs 0:99e98f131071 281
withboobs 0:99e98f131071 282 //------------------------- Gain calculation -----------------------------------
withboobs 0:99e98f131071 283 gain = frameData[778];
withboobs 0:99e98f131071 284 if(gain > 32767)
withboobs 0:99e98f131071 285 {
withboobs 1:3f763d28c1be 286 gain = gain - 65536.0f;
withboobs 0:99e98f131071 287 }
withboobs 0:99e98f131071 288
withboobs 0:99e98f131071 289 gain = params->gainEE / gain;
withboobs 0:99e98f131071 290
withboobs 0:99e98f131071 291 //------------------------- To calculation -------------------------------------
withboobs 0:99e98f131071 292 mode = (frameData[832] & 0x1000) >> 5;
withboobs 0:99e98f131071 293
withboobs 0:99e98f131071 294 irDataCP[0] = frameData[776];
withboobs 0:99e98f131071 295 irDataCP[1] = frameData[808];
withboobs 0:99e98f131071 296 for( int i = 0; i < 2; i++)
withboobs 0:99e98f131071 297 {
withboobs 0:99e98f131071 298 if(irDataCP[i] > 32767)
withboobs 0:99e98f131071 299 {
withboobs 0:99e98f131071 300 irDataCP[i] = irDataCP[i] - 65536;
withboobs 0:99e98f131071 301 }
withboobs 0:99e98f131071 302 irDataCP[i] = irDataCP[i] * gain;
withboobs 0:99e98f131071 303 }
withboobs 1:3f763d28c1be 304 irDataCP[0] = irDataCP[0] - params->cpOffset[0] * (1.0f + params->cpKta * (ta - 25.0f)) * (1.0f + params->cpKv * (vdd - 3.3f));
withboobs 0:99e98f131071 305 if( mode == params->calibrationModeEE)
withboobs 0:99e98f131071 306 {
withboobs 1:3f763d28c1be 307 irDataCP[1] = irDataCP[1] - params->cpOffset[1] * (1.0f + params->cpKta * (ta - 25.0f)) * (1.0f + params->cpKv * (vdd - 3.3f));
withboobs 0:99e98f131071 308 }
withboobs 0:99e98f131071 309 else
withboobs 0:99e98f131071 310 {
withboobs 1:3f763d28c1be 311 irDataCP[1] = irDataCP[1] - (params->cpOffset[1] + params->ilChessC[0]) * (1.0f + params->cpKta * (ta - 25.0f)) * (1.0f + params->cpKv * (vdd - 3.3f));
withboobs 0:99e98f131071 312 }
withboobs 0:99e98f131071 313
withboobs 0:99e98f131071 314 for( int pixelNumber = 0; pixelNumber < 768; pixelNumber++)
withboobs 0:99e98f131071 315 {
withboobs 0:99e98f131071 316 ilPattern = int((pixelNumber) / 32) - int(int((pixelNumber) / 32) / 2) * 2;
withboobs 0:99e98f131071 317 chessPattern = ilPattern ^ (pixelNumber - int(pixelNumber/2)*2);
withboobs 0:99e98f131071 318 conversionPattern = (int((pixelNumber - 2) / 4) - int((pixelNumber - 1) / 4) + int((pixelNumber + 1) / 4) - int((pixelNumber) / 4)) * (1 - 2 * ilPattern);
withboobs 0:99e98f131071 319
withboobs 0:99e98f131071 320 if(mode == 0)
withboobs 0:99e98f131071 321 {
withboobs 0:99e98f131071 322 pattern = ilPattern;
withboobs 0:99e98f131071 323 }
withboobs 0:99e98f131071 324 else
withboobs 0:99e98f131071 325 {
withboobs 0:99e98f131071 326 pattern = chessPattern;
withboobs 0:99e98f131071 327 }
withboobs 0:99e98f131071 328
withboobs 0:99e98f131071 329 if(pattern == frameData[833])
withboobs 0:99e98f131071 330 {
withboobs 0:99e98f131071 331 irData = frameData[pixelNumber];
withboobs 0:99e98f131071 332 if(irData > 32767)
withboobs 0:99e98f131071 333 {
withboobs 0:99e98f131071 334 irData = irData - 65536;
withboobs 0:99e98f131071 335 }
withboobs 0:99e98f131071 336 irData = irData * gain;
withboobs 0:99e98f131071 337
withboobs 1:3f763d28c1be 338 irData = irData - params->offset[pixelNumber]*(1 + params->kta[pixelNumber]*(ta - 25.0f))*(1.0f + params->kv[pixelNumber]*(vdd - 3.3f));
withboobs 0:99e98f131071 339 if(mode != params->calibrationModeEE)
withboobs 0:99e98f131071 340 {
withboobs 0:99e98f131071 341 irData = irData + params->ilChessC[2] * (2 * ilPattern - 1) - params->ilChessC[1] * conversionPattern;
withboobs 0:99e98f131071 342 }
withboobs 0:99e98f131071 343
withboobs 0:99e98f131071 344 irData = irData / emissivity;
withboobs 0:99e98f131071 345
withboobs 0:99e98f131071 346 irData = irData - params->tgc * ((1-pattern) * irDataCP[0] + pattern * irDataCP[1]);
withboobs 0:99e98f131071 347
withboobs 0:99e98f131071 348 alphaCompensated = (params->alpha[pixelNumber] - params->tgc * ((1-pattern) * params->cpAlpha[0] + pattern * params->cpAlpha[1])) * (1 + params->KsTa * (ta - 25));
withboobs 0:99e98f131071 349
withboobs 0:99e98f131071 350 Sx = pow((double)alphaCompensated, (double)3) * (irData + alphaCompensated * taTr);
withboobs 0:99e98f131071 351 Sx = sqrt(sqrt(Sx)) * params->ksTo[1];
withboobs 0:99e98f131071 352
withboobs 1:3f763d28c1be 353 To = sqrt(sqrt(irData/(alphaCompensated * (1 - params->ksTo[1] * 273.15f) + Sx) + taTr)) - 273.15f;
withboobs 0:99e98f131071 354
withboobs 0:99e98f131071 355 if(To < params->ct[1])
withboobs 0:99e98f131071 356 {
withboobs 0:99e98f131071 357 range = 0;
withboobs 0:99e98f131071 358 }
withboobs 0:99e98f131071 359 else if(To < params->ct[2])
withboobs 0:99e98f131071 360 {
withboobs 0:99e98f131071 361 range = 1;
withboobs 0:99e98f131071 362 }
withboobs 0:99e98f131071 363 else if(To < params->ct[3])
withboobs 0:99e98f131071 364 {
withboobs 0:99e98f131071 365 range = 2;
withboobs 0:99e98f131071 366 }
withboobs 0:99e98f131071 367 else
withboobs 0:99e98f131071 368 {
withboobs 0:99e98f131071 369 range = 3;
withboobs 0:99e98f131071 370 }
withboobs 0:99e98f131071 371
withboobs 1:3f763d28c1be 372 To = sqrt(sqrt(irData / (alphaCompensated * alphaCorrR[range] * (1 + params->ksTo[range] * (To - params->ct[range]))) + taTr));
withboobs 0:99e98f131071 373 result[pixelNumber] = To;
withboobs 0:99e98f131071 374 }
withboobs 0:99e98f131071 375 }
withboobs 0:99e98f131071 376 }
withboobs 0:99e98f131071 377
withboobs 0:99e98f131071 378 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 379
withboobs 0:99e98f131071 380 void MLX90640_GetImage(uint16_t *frameData, paramsMLX90640 *params, float *result)
withboobs 0:99e98f131071 381 {
withboobs 0:99e98f131071 382 float vdd;
withboobs 0:99e98f131071 383 float ta;
withboobs 0:99e98f131071 384 float gain;
withboobs 0:99e98f131071 385 float irDataCP[2];
withboobs 0:99e98f131071 386 float irData;
withboobs 0:99e98f131071 387 float alphaCompensated;
withboobs 0:99e98f131071 388 uint8_t mode;
withboobs 0:99e98f131071 389 int8_t ilPattern;
withboobs 0:99e98f131071 390 int8_t chessPattern;
withboobs 0:99e98f131071 391 int8_t pattern;
withboobs 0:99e98f131071 392 int8_t conversionPattern;
withboobs 0:99e98f131071 393 float image;
withboobs 0:99e98f131071 394
withboobs 0:99e98f131071 395 vdd = MLX90640_GetVdd(frameData, params);
withboobs 0:99e98f131071 396 ta = MLX90640_GetTa(frameData, params);
withboobs 0:99e98f131071 397
withboobs 0:99e98f131071 398 //------------------------- Gain calculation -----------------------------------
withboobs 0:99e98f131071 399 gain = frameData[778];
withboobs 0:99e98f131071 400 if(gain > 32767)
withboobs 0:99e98f131071 401 {
withboobs 0:99e98f131071 402 gain = gain - 65536;
withboobs 0:99e98f131071 403 }
withboobs 0:99e98f131071 404
withboobs 0:99e98f131071 405 gain = params->gainEE / gain;
withboobs 0:99e98f131071 406
withboobs 0:99e98f131071 407 //------------------------- Image calculation -------------------------------------
withboobs 0:99e98f131071 408 mode = (frameData[832] & 0x1000) >> 5;
withboobs 0:99e98f131071 409
withboobs 0:99e98f131071 410 irDataCP[0] = frameData[776];
withboobs 0:99e98f131071 411 irDataCP[1] = frameData[808];
withboobs 0:99e98f131071 412 for( int i = 0; i < 2; i++)
withboobs 0:99e98f131071 413 {
withboobs 0:99e98f131071 414 if(irDataCP[i] > 32767)
withboobs 0:99e98f131071 415 {
withboobs 0:99e98f131071 416 irDataCP[i] = irDataCP[i] - 65536;
withboobs 0:99e98f131071 417 }
withboobs 0:99e98f131071 418 irDataCP[i] = irDataCP[i] * gain;
withboobs 0:99e98f131071 419 }
withboobs 1:3f763d28c1be 420 irDataCP[0] = irDataCP[0] - params->cpOffset[0] * (1.0f + params->cpKta * (ta - 25.0f)) * (1.0f + params->cpKv * (vdd - 3.3f));
withboobs 0:99e98f131071 421 if( mode == params->calibrationModeEE)
withboobs 0:99e98f131071 422 {
withboobs 1:3f763d28c1be 423 irDataCP[1] = irDataCP[1] - params->cpOffset[1] * (1.0f + params->cpKta * (ta - 25.0f)) * (1.0f + params->cpKv * (vdd - 3.3f));
withboobs 0:99e98f131071 424 }
withboobs 0:99e98f131071 425 else
withboobs 0:99e98f131071 426 {
withboobs 1:3f763d28c1be 427 irDataCP[1] = irDataCP[1] - (params->cpOffset[1] + params->ilChessC[0]) * (1.0f + params->cpKta * (ta - 25.0f)) * (1 + params->cpKv * (vdd - 3.3f));
withboobs 0:99e98f131071 428 }
withboobs 0:99e98f131071 429
withboobs 0:99e98f131071 430 for( int pixelNumber = 0; pixelNumber < 768; pixelNumber++)
withboobs 0:99e98f131071 431 {
withboobs 0:99e98f131071 432 ilPattern = int((pixelNumber) / 32) - int(int((pixelNumber) / 32) / 2) * 2;
withboobs 0:99e98f131071 433 chessPattern = ilPattern ^ (pixelNumber - int(pixelNumber/2)*2);
withboobs 0:99e98f131071 434 conversionPattern = (int((pixelNumber - 2) / 4) - int((pixelNumber - 1) / 4) + int((pixelNumber + 1) / 4) - int((pixelNumber) / 4)) * (1 - 2 * ilPattern);
withboobs 0:99e98f131071 435
withboobs 0:99e98f131071 436 if(mode == 0)
withboobs 0:99e98f131071 437 {
withboobs 0:99e98f131071 438 pattern = ilPattern;
withboobs 0:99e98f131071 439 }
withboobs 0:99e98f131071 440 else
withboobs 0:99e98f131071 441 {
withboobs 0:99e98f131071 442 pattern = chessPattern;
withboobs 0:99e98f131071 443 }
withboobs 0:99e98f131071 444
withboobs 0:99e98f131071 445 if(pattern == frameData[833])
withboobs 0:99e98f131071 446 {
withboobs 0:99e98f131071 447 irData = frameData[pixelNumber];
withboobs 0:99e98f131071 448 if(irData > 32767)
withboobs 0:99e98f131071 449 {
withboobs 0:99e98f131071 450 irData = irData - 65536;
withboobs 0:99e98f131071 451 }
withboobs 0:99e98f131071 452 irData = irData * gain;
withboobs 0:99e98f131071 453
withboobs 1:3f763d28c1be 454 irData = irData - params->offset[pixelNumber]*(1 + params->kta[pixelNumber]*(ta - 25.0f))*(1.0f + params->kv[pixelNumber]*(vdd - 3.3f));
withboobs 0:99e98f131071 455 if(mode != params->calibrationModeEE)
withboobs 0:99e98f131071 456 {
withboobs 0:99e98f131071 457 irData = irData + params->ilChessC[2] * (2 * ilPattern - 1) - params->ilChessC[1] * conversionPattern;
withboobs 0:99e98f131071 458 }
withboobs 0:99e98f131071 459
withboobs 0:99e98f131071 460 irData = irData - params->tgc * ((1-pattern) * irDataCP[0] + pattern * irDataCP[1]);
withboobs 0:99e98f131071 461
withboobs 0:99e98f131071 462 alphaCompensated = (params->alpha[pixelNumber] - params->tgc * ((1-pattern) * params->cpAlpha[0] + pattern * params->cpAlpha[1]));
withboobs 0:99e98f131071 463
withboobs 0:99e98f131071 464 image = irData/alphaCompensated;
withboobs 0:99e98f131071 465
withboobs 0:99e98f131071 466 result[pixelNumber] = image;
withboobs 0:99e98f131071 467 }
withboobs 0:99e98f131071 468 }
withboobs 0:99e98f131071 469 }
withboobs 0:99e98f131071 470
withboobs 0:99e98f131071 471 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 472
withboobs 0:99e98f131071 473 float MLX90640_GetVdd(uint16_t *frameData, paramsMLX90640 *params)
withboobs 0:99e98f131071 474 {
withboobs 0:99e98f131071 475 float vdd;
withboobs 0:99e98f131071 476 float resolutionCorrection;
withboobs 0:99e98f131071 477 //int resolution;
withboobs 0:99e98f131071 478 int resolutionRAM;
withboobs 0:99e98f131071 479
withboobs 0:99e98f131071 480 vdd = frameData[810];
withboobs 0:99e98f131071 481 if(vdd > 32767)
withboobs 0:99e98f131071 482 {
withboobs 0:99e98f131071 483 vdd = vdd - 65536;
withboobs 0:99e98f131071 484 }
withboobs 0:99e98f131071 485 resolutionRAM = (frameData[832] & 0x0C00) >> 10;
withboobs 1:3f763d28c1be 486 resolutionCorrection = powf(2.0f, (float)params->resolutionEE) / powf(2.0f, (float)resolutionRAM);
withboobs 1:3f763d28c1be 487 vdd = (resolutionCorrection * vdd - params->vdd25) / params->kVdd + 3.3f;
withboobs 0:99e98f131071 488
withboobs 0:99e98f131071 489 return vdd;
withboobs 0:99e98f131071 490 }
withboobs 0:99e98f131071 491
withboobs 0:99e98f131071 492 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 493
withboobs 0:99e98f131071 494 float MLX90640_GetTa(uint16_t *frameData, paramsMLX90640 *params)
withboobs 0:99e98f131071 495 {
withboobs 0:99e98f131071 496 float ptat;
withboobs 0:99e98f131071 497 float ptatArt;
withboobs 0:99e98f131071 498 float vdd;
withboobs 0:99e98f131071 499 float ta;
withboobs 0:99e98f131071 500
withboobs 0:99e98f131071 501 vdd = MLX90640_GetVdd(frameData, params);
withboobs 0:99e98f131071 502
withboobs 0:99e98f131071 503 ptat = frameData[800];
withboobs 0:99e98f131071 504 if(ptat > 32767)
withboobs 0:99e98f131071 505 {
withboobs 0:99e98f131071 506 ptat = ptat - 65536;
withboobs 0:99e98f131071 507 }
withboobs 0:99e98f131071 508
withboobs 0:99e98f131071 509 ptatArt = frameData[768];
withboobs 0:99e98f131071 510 if(ptatArt > 32767)
withboobs 0:99e98f131071 511 {
withboobs 0:99e98f131071 512 ptatArt = ptatArt - 65536;
withboobs 0:99e98f131071 513 }
withboobs 1:3f763d28c1be 514 ptatArt = (ptat / (ptat * params->alphaPTAT + ptatArt)) * powf(2.0f, 18.0f);
withboobs 0:99e98f131071 515
withboobs 1:3f763d28c1be 516 ta = (ptatArt / (1.0f + params->KvPTAT * (vdd - 3.3f)) - params->vPTAT25);
withboobs 1:3f763d28c1be 517 ta = ta / params->KtPTAT + 25.0f;
withboobs 0:99e98f131071 518
withboobs 0:99e98f131071 519 return ta;
withboobs 0:99e98f131071 520 }
withboobs 0:99e98f131071 521
withboobs 0:99e98f131071 522 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 523
withboobs 0:99e98f131071 524 int MLX90640_GetSubPageNumber(uint16_t *frameData)
withboobs 0:99e98f131071 525 {
withboobs 0:99e98f131071 526 return frameData[833];
withboobs 0:99e98f131071 527
withboobs 0:99e98f131071 528 }
withboobs 0:99e98f131071 529
withboobs 0:99e98f131071 530 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 531
withboobs 0:99e98f131071 532 void ExtractVDDParameters(uint16_t *eeData, paramsMLX90640 *mlx90640)
withboobs 0:99e98f131071 533 {
withboobs 0:99e98f131071 534 int16_t kVdd;
withboobs 0:99e98f131071 535 int16_t vdd25;
withboobs 0:99e98f131071 536
withboobs 0:99e98f131071 537 kVdd = eeData[51];
withboobs 0:99e98f131071 538
withboobs 0:99e98f131071 539 kVdd = (eeData[51] & 0xFF00) >> 8;
withboobs 0:99e98f131071 540 if(kVdd > 127)
withboobs 0:99e98f131071 541 {
withboobs 0:99e98f131071 542 kVdd = kVdd - 256;
withboobs 0:99e98f131071 543 }
withboobs 0:99e98f131071 544 kVdd = 32 * kVdd;
withboobs 0:99e98f131071 545 vdd25 = eeData[51] & 0x00FF;
withboobs 0:99e98f131071 546 vdd25 = ((vdd25 - 256) << 5) - 8192;
withboobs 0:99e98f131071 547
withboobs 0:99e98f131071 548 mlx90640->kVdd = kVdd;
withboobs 0:99e98f131071 549 mlx90640->vdd25 = vdd25;
withboobs 0:99e98f131071 550 }
withboobs 0:99e98f131071 551
withboobs 0:99e98f131071 552 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 553
withboobs 0:99e98f131071 554 void ExtractPTATParameters(uint16_t *eeData, paramsMLX90640 *mlx90640)
withboobs 0:99e98f131071 555 {
withboobs 0:99e98f131071 556 float KvPTAT;
withboobs 0:99e98f131071 557 float KtPTAT;
withboobs 0:99e98f131071 558 int16_t vPTAT25;
withboobs 0:99e98f131071 559 int16_t alphaPTAT;
withboobs 0:99e98f131071 560
withboobs 0:99e98f131071 561 KvPTAT = (eeData[50] & 0xFC00) >> 10;
withboobs 0:99e98f131071 562 if(KvPTAT > 31)
withboobs 0:99e98f131071 563 {
withboobs 0:99e98f131071 564 KvPTAT = KvPTAT - 64;
withboobs 0:99e98f131071 565 }
withboobs 0:99e98f131071 566 KvPTAT = KvPTAT/4096;
withboobs 0:99e98f131071 567
withboobs 0:99e98f131071 568 KtPTAT = eeData[50] & 0x03FF;
withboobs 0:99e98f131071 569 if(KtPTAT > 511)
withboobs 0:99e98f131071 570 {
withboobs 0:99e98f131071 571 KtPTAT = KtPTAT - 1024;
withboobs 0:99e98f131071 572 }
withboobs 0:99e98f131071 573 KtPTAT = KtPTAT/8;
withboobs 0:99e98f131071 574
withboobs 0:99e98f131071 575 vPTAT25 = eeData[49];
withboobs 0:99e98f131071 576
withboobs 0:99e98f131071 577 alphaPTAT = ((eeData[16] & 0xF000) >> 14) + 8;
withboobs 0:99e98f131071 578
withboobs 0:99e98f131071 579 mlx90640->KvPTAT = KvPTAT;
withboobs 0:99e98f131071 580 mlx90640->KtPTAT = KtPTAT;
withboobs 0:99e98f131071 581 mlx90640->vPTAT25 = vPTAT25;
withboobs 0:99e98f131071 582 mlx90640->alphaPTAT = alphaPTAT;
withboobs 0:99e98f131071 583 }
withboobs 0:99e98f131071 584
withboobs 0:99e98f131071 585 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 586
withboobs 0:99e98f131071 587 void ExtractGainParameters(uint16_t *eeData, paramsMLX90640 *mlx90640)
withboobs 0:99e98f131071 588 {
withboobs 0:99e98f131071 589 int16_t gainEE;
withboobs 0:99e98f131071 590
withboobs 0:99e98f131071 591 gainEE = eeData[48];
withboobs 0:99e98f131071 592 if(gainEE > 32767)
withboobs 0:99e98f131071 593 {
withboobs 0:99e98f131071 594 gainEE = gainEE -65536;
withboobs 0:99e98f131071 595 }
withboobs 0:99e98f131071 596
withboobs 0:99e98f131071 597 mlx90640->gainEE = gainEE;
withboobs 0:99e98f131071 598 }
withboobs 0:99e98f131071 599
withboobs 0:99e98f131071 600 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 601
withboobs 0:99e98f131071 602 void ExtractTgcParameters(uint16_t *eeData, paramsMLX90640 *mlx90640)
withboobs 0:99e98f131071 603 {
withboobs 0:99e98f131071 604 float tgc;
withboobs 0:99e98f131071 605 tgc = eeData[60] & 0x00FF;
withboobs 0:99e98f131071 606 if(tgc > 127)
withboobs 0:99e98f131071 607 {
withboobs 0:99e98f131071 608 tgc = tgc - 256;
withboobs 0:99e98f131071 609 }
withboobs 0:99e98f131071 610 tgc = tgc / 32.0f;
withboobs 0:99e98f131071 611
withboobs 0:99e98f131071 612 mlx90640->tgc = tgc;
withboobs 0:99e98f131071 613 }
withboobs 0:99e98f131071 614
withboobs 0:99e98f131071 615 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 616
withboobs 0:99e98f131071 617 void ExtractResolutionParameters(uint16_t *eeData, paramsMLX90640 *mlx90640)
withboobs 0:99e98f131071 618 {
withboobs 0:99e98f131071 619 uint8_t resolutionEE;
withboobs 0:99e98f131071 620 resolutionEE = (eeData[56] & 0x3000) >> 12;
withboobs 0:99e98f131071 621
withboobs 0:99e98f131071 622 mlx90640->resolutionEE = resolutionEE;
withboobs 0:99e98f131071 623 }
withboobs 0:99e98f131071 624
withboobs 0:99e98f131071 625 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 626
withboobs 0:99e98f131071 627 void ExtractKsTaParameters(uint16_t *eeData, paramsMLX90640 *mlx90640)
withboobs 0:99e98f131071 628 {
withboobs 0:99e98f131071 629 float KsTa;
withboobs 0:99e98f131071 630 KsTa = (eeData[60] & 0xFF00) >> 8;
withboobs 0:99e98f131071 631 if(KsTa > 127)
withboobs 0:99e98f131071 632 {
withboobs 0:99e98f131071 633 KsTa = KsTa -256;
withboobs 0:99e98f131071 634 }
withboobs 0:99e98f131071 635 KsTa = KsTa / 8192.0f;
withboobs 0:99e98f131071 636
withboobs 0:99e98f131071 637 mlx90640->KsTa = KsTa;
withboobs 0:99e98f131071 638 }
withboobs 0:99e98f131071 639
withboobs 0:99e98f131071 640 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 641
withboobs 0:99e98f131071 642 void ExtractKsToParameters(uint16_t *eeData, paramsMLX90640 *mlx90640)
withboobs 0:99e98f131071 643 {
withboobs 0:99e98f131071 644 int KsToScale;
withboobs 0:99e98f131071 645 int8_t step;
withboobs 0:99e98f131071 646
withboobs 0:99e98f131071 647 step = ((eeData[63] & 0x3000) >> 12) * 10;
withboobs 0:99e98f131071 648
withboobs 0:99e98f131071 649 mlx90640->ct[0] = -40;
withboobs 0:99e98f131071 650 mlx90640->ct[1] = 0;
withboobs 0:99e98f131071 651 mlx90640->ct[2] = (eeData[63] & 0x00F0) >> 4;
withboobs 0:99e98f131071 652 mlx90640->ct[3] = (eeData[63] & 0x0F00) >> 8;
withboobs 0:99e98f131071 653
withboobs 0:99e98f131071 654 mlx90640->ct[2] = mlx90640->ct[2]*step;
withboobs 0:99e98f131071 655 mlx90640->ct[3] = mlx90640->ct[2] + mlx90640->ct[3]*step;
withboobs 0:99e98f131071 656
withboobs 0:99e98f131071 657 KsToScale = (eeData[63] & 0x000F) + 8;
withboobs 0:99e98f131071 658 KsToScale = 1 << KsToScale;
withboobs 0:99e98f131071 659
withboobs 0:99e98f131071 660 mlx90640->ksTo[0] = eeData[61] & 0x00FF;
withboobs 0:99e98f131071 661 mlx90640->ksTo[1] = (eeData[61] & 0xFF00) >> 8;
withboobs 0:99e98f131071 662 mlx90640->ksTo[2] = eeData[62] & 0x00FF;
withboobs 0:99e98f131071 663 mlx90640->ksTo[3] = (eeData[62] & 0xFF00) >> 8;
withboobs 0:99e98f131071 664
withboobs 0:99e98f131071 665
withboobs 0:99e98f131071 666 for(int i = 0; i < 4; i++)
withboobs 0:99e98f131071 667 {
withboobs 0:99e98f131071 668 if(mlx90640->ksTo[i] > 127)
withboobs 0:99e98f131071 669 {
withboobs 0:99e98f131071 670 mlx90640->ksTo[i] = mlx90640->ksTo[i] -256;
withboobs 0:99e98f131071 671 }
withboobs 0:99e98f131071 672 mlx90640->ksTo[i] = mlx90640->ksTo[i] / KsToScale;
withboobs 0:99e98f131071 673 }
withboobs 0:99e98f131071 674 }
withboobs 0:99e98f131071 675
withboobs 0:99e98f131071 676 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 677
withboobs 0:99e98f131071 678 void ExtractAlphaParameters(uint16_t *eeData, paramsMLX90640 *mlx90640)
withboobs 0:99e98f131071 679 {
withboobs 0:99e98f131071 680 int accRow[24];
withboobs 0:99e98f131071 681 int accColumn[32];
withboobs 0:99e98f131071 682 int p = 0;
withboobs 0:99e98f131071 683 int alphaRef;
withboobs 0:99e98f131071 684 uint8_t alphaScale;
withboobs 0:99e98f131071 685 uint8_t accRowScale;
withboobs 0:99e98f131071 686 uint8_t accColumnScale;
withboobs 0:99e98f131071 687 uint8_t accRemScale;
withboobs 0:99e98f131071 688
withboobs 0:99e98f131071 689
withboobs 0:99e98f131071 690 accRemScale = eeData[32] & 0x000F;
withboobs 0:99e98f131071 691 accColumnScale = (eeData[32] & 0x00F0) >> 4;
withboobs 0:99e98f131071 692 accRowScale = (eeData[32] & 0x0F00) >> 8;
withboobs 0:99e98f131071 693 alphaScale = ((eeData[32] & 0xF000) >> 12) + 30;
withboobs 0:99e98f131071 694 alphaRef = eeData[33];
withboobs 0:99e98f131071 695
withboobs 0:99e98f131071 696 for(int i = 0; i < 6; i++)
withboobs 0:99e98f131071 697 {
withboobs 0:99e98f131071 698 p = i * 4;
withboobs 0:99e98f131071 699 accRow[p + 0] = (eeData[34 + i] & 0x000F);
withboobs 0:99e98f131071 700 accRow[p + 1] = (eeData[34 + i] & 0x00F0) >> 4;
withboobs 0:99e98f131071 701 accRow[p + 2] = (eeData[34 + i] & 0x0F00) >> 8;
withboobs 0:99e98f131071 702 accRow[p + 3] = (eeData[34 + i] & 0xF000) >> 12;
withboobs 0:99e98f131071 703 }
withboobs 0:99e98f131071 704
withboobs 0:99e98f131071 705 for(int i = 0; i < 24; i++)
withboobs 0:99e98f131071 706 {
withboobs 0:99e98f131071 707 if (accRow[i] > 7)
withboobs 0:99e98f131071 708 {
withboobs 0:99e98f131071 709 accRow[i] = accRow[i] - 16;
withboobs 0:99e98f131071 710 }
withboobs 0:99e98f131071 711 }
withboobs 0:99e98f131071 712
withboobs 0:99e98f131071 713 for(int i = 0; i < 8; i++)
withboobs 0:99e98f131071 714 {
withboobs 0:99e98f131071 715 p = i * 4;
withboobs 0:99e98f131071 716 accColumn[p + 0] = (eeData[40 + i] & 0x000F);
withboobs 0:99e98f131071 717 accColumn[p + 1] = (eeData[40 + i] & 0x00F0) >> 4;
withboobs 0:99e98f131071 718 accColumn[p + 2] = (eeData[40 + i] & 0x0F00) >> 8;
withboobs 0:99e98f131071 719 accColumn[p + 3] = (eeData[40 + i] & 0xF000) >> 12;
withboobs 0:99e98f131071 720 }
withboobs 0:99e98f131071 721
withboobs 0:99e98f131071 722 for(int i = 0; i < 32; i ++)
withboobs 0:99e98f131071 723 {
withboobs 0:99e98f131071 724 if (accColumn[i] > 7)
withboobs 0:99e98f131071 725 {
withboobs 0:99e98f131071 726 accColumn[i] = accColumn[i] - 16;
withboobs 0:99e98f131071 727 }
withboobs 0:99e98f131071 728 }
withboobs 0:99e98f131071 729
withboobs 0:99e98f131071 730 for(int i = 0; i < 24; i++)
withboobs 0:99e98f131071 731 {
withboobs 0:99e98f131071 732 for(int j = 0; j < 32; j ++)
withboobs 0:99e98f131071 733 {
withboobs 0:99e98f131071 734 p = 32 * i +j;
withboobs 0:99e98f131071 735 mlx90640->alpha[p] = (eeData[64 + p] & 0x03F0) >> 4;
withboobs 0:99e98f131071 736 if (mlx90640->alpha[p] > 31)
withboobs 0:99e98f131071 737 {
withboobs 0:99e98f131071 738 mlx90640->alpha[p] = mlx90640->alpha[p] - 64;
withboobs 0:99e98f131071 739 }
withboobs 0:99e98f131071 740 mlx90640->alpha[p] = mlx90640->alpha[p]*(1 << accRemScale);
withboobs 0:99e98f131071 741 mlx90640->alpha[p] = (alphaRef + (accRow[i] << accRowScale) + (accColumn[j] << accColumnScale) + mlx90640->alpha[p]);
withboobs 0:99e98f131071 742 mlx90640->alpha[p] = mlx90640->alpha[p] / pow(2,(double)alphaScale);
withboobs 0:99e98f131071 743 }
withboobs 0:99e98f131071 744 }
withboobs 0:99e98f131071 745 }
withboobs 0:99e98f131071 746
withboobs 0:99e98f131071 747 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 748
withboobs 0:99e98f131071 749 void ExtractOffsetParameters(uint16_t *eeData, paramsMLX90640 *mlx90640)
withboobs 0:99e98f131071 750 {
withboobs 0:99e98f131071 751 int occRow[24];
withboobs 0:99e98f131071 752 int occColumn[32];
withboobs 0:99e98f131071 753 int p = 0;
withboobs 0:99e98f131071 754 int16_t offsetRef;
withboobs 0:99e98f131071 755 uint8_t occRowScale;
withboobs 0:99e98f131071 756 uint8_t occColumnScale;
withboobs 0:99e98f131071 757 uint8_t occRemScale;
withboobs 0:99e98f131071 758
withboobs 0:99e98f131071 759
withboobs 0:99e98f131071 760 occRemScale = (eeData[16] & 0x000F);
withboobs 0:99e98f131071 761 occColumnScale = (eeData[16] & 0x00F0) >> 4;
withboobs 0:99e98f131071 762 occRowScale = (eeData[16] & 0x0F00) >> 8;
withboobs 0:99e98f131071 763 offsetRef = eeData[17];
withboobs 0:99e98f131071 764 if (offsetRef > 32767)
withboobs 0:99e98f131071 765 {
withboobs 0:99e98f131071 766 offsetRef = offsetRef - 65536;
withboobs 0:99e98f131071 767 }
withboobs 0:99e98f131071 768
withboobs 0:99e98f131071 769 for(int i = 0; i < 6; i++)
withboobs 0:99e98f131071 770 {
withboobs 0:99e98f131071 771 p = i * 4;
withboobs 0:99e98f131071 772 occRow[p + 0] = (eeData[18 + i] & 0x000F);
withboobs 0:99e98f131071 773 occRow[p + 1] = (eeData[18 + i] & 0x00F0) >> 4;
withboobs 0:99e98f131071 774 occRow[p + 2] = (eeData[18 + i] & 0x0F00) >> 8;
withboobs 0:99e98f131071 775 occRow[p + 3] = (eeData[18 + i] & 0xF000) >> 12;
withboobs 0:99e98f131071 776 }
withboobs 0:99e98f131071 777
withboobs 0:99e98f131071 778 for(int i = 0; i < 24; i++)
withboobs 0:99e98f131071 779 {
withboobs 0:99e98f131071 780 if (occRow[i] > 7)
withboobs 0:99e98f131071 781 {
withboobs 0:99e98f131071 782 occRow[i] = occRow[i] - 16;
withboobs 0:99e98f131071 783 }
withboobs 0:99e98f131071 784 }
withboobs 0:99e98f131071 785
withboobs 0:99e98f131071 786 for(int i = 0; i < 8; i++)
withboobs 0:99e98f131071 787 {
withboobs 0:99e98f131071 788 p = i * 4;
withboobs 0:99e98f131071 789 occColumn[p + 0] = (eeData[24 + i] & 0x000F);
withboobs 0:99e98f131071 790 occColumn[p + 1] = (eeData[24 + i] & 0x00F0) >> 4;
withboobs 0:99e98f131071 791 occColumn[p + 2] = (eeData[24 + i] & 0x0F00) >> 8;
withboobs 0:99e98f131071 792 occColumn[p + 3] = (eeData[24 + i] & 0xF000) >> 12;
withboobs 0:99e98f131071 793 }
withboobs 0:99e98f131071 794
withboobs 0:99e98f131071 795 for(int i = 0; i < 32; i ++)
withboobs 0:99e98f131071 796 {
withboobs 0:99e98f131071 797 if (occColumn[i] > 7)
withboobs 0:99e98f131071 798 {
withboobs 0:99e98f131071 799 occColumn[i] = occColumn[i] - 16;
withboobs 0:99e98f131071 800 }
withboobs 0:99e98f131071 801 }
withboobs 0:99e98f131071 802
withboobs 0:99e98f131071 803 for(int i = 0; i < 24; i++)
withboobs 0:99e98f131071 804 {
withboobs 0:99e98f131071 805 for(int j = 0; j < 32; j ++)
withboobs 0:99e98f131071 806 {
withboobs 0:99e98f131071 807 p = 32 * i +j;
withboobs 0:99e98f131071 808 mlx90640->offset[p] = (eeData[64 + p] & 0xFC00) >> 10;
withboobs 0:99e98f131071 809 if (mlx90640->offset[p] > 31)
withboobs 0:99e98f131071 810 {
withboobs 0:99e98f131071 811 mlx90640->offset[p] = mlx90640->offset[p] - 64;
withboobs 0:99e98f131071 812 }
withboobs 0:99e98f131071 813 mlx90640->offset[p] = mlx90640->offset[p]*(1 << occRemScale);
withboobs 0:99e98f131071 814 mlx90640->offset[p] = (offsetRef + (occRow[i] << occRowScale) + (occColumn[j] << occColumnScale) + mlx90640->offset[p]);
withboobs 0:99e98f131071 815 }
withboobs 0:99e98f131071 816 }
withboobs 0:99e98f131071 817 }
withboobs 0:99e98f131071 818
withboobs 0:99e98f131071 819 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 820
withboobs 0:99e98f131071 821 void ExtractKtaPixelParameters(uint16_t *eeData, paramsMLX90640 *mlx90640)
withboobs 0:99e98f131071 822 {
withboobs 0:99e98f131071 823 int p = 0;
withboobs 0:99e98f131071 824 int8_t KtaRC[4];
withboobs 0:99e98f131071 825 int8_t KtaRoCo;
withboobs 0:99e98f131071 826 int8_t KtaRoCe;
withboobs 0:99e98f131071 827 int8_t KtaReCo;
withboobs 0:99e98f131071 828 int8_t KtaReCe;
withboobs 0:99e98f131071 829 uint8_t ktaScale1;
withboobs 0:99e98f131071 830 uint8_t ktaScale2;
withboobs 0:99e98f131071 831 uint8_t split;
withboobs 0:99e98f131071 832
withboobs 0:99e98f131071 833 KtaRoCo = (eeData[54] & 0xFF00) >> 8;
withboobs 0:99e98f131071 834 if (KtaRoCo > 127)
withboobs 0:99e98f131071 835 {
withboobs 0:99e98f131071 836 KtaRoCo = KtaRoCo - 256;
withboobs 0:99e98f131071 837 }
withboobs 0:99e98f131071 838 KtaRC[0] = KtaRoCo;
withboobs 0:99e98f131071 839
withboobs 0:99e98f131071 840 KtaReCo = (eeData[54] & 0x00FF);
withboobs 0:99e98f131071 841 if (KtaReCo > 127)
withboobs 0:99e98f131071 842 {
withboobs 0:99e98f131071 843 KtaReCo = KtaReCo - 256;
withboobs 0:99e98f131071 844 }
withboobs 0:99e98f131071 845 KtaRC[2] = KtaReCo;
withboobs 0:99e98f131071 846
withboobs 0:99e98f131071 847 KtaRoCe = (eeData[55] & 0xFF00) >> 8;
withboobs 0:99e98f131071 848 if (KtaRoCe > 127)
withboobs 0:99e98f131071 849 {
withboobs 0:99e98f131071 850 KtaRoCe = KtaRoCe - 256;
withboobs 0:99e98f131071 851 }
withboobs 0:99e98f131071 852 KtaRC[1] = KtaRoCe;
withboobs 0:99e98f131071 853
withboobs 0:99e98f131071 854 KtaReCe = (eeData[55] & 0x00FF);
withboobs 0:99e98f131071 855 if (KtaReCe > 127)
withboobs 0:99e98f131071 856 {
withboobs 0:99e98f131071 857 KtaReCe = KtaReCe - 256;
withboobs 0:99e98f131071 858 }
withboobs 0:99e98f131071 859 KtaRC[3] = KtaReCe;
withboobs 0:99e98f131071 860
withboobs 0:99e98f131071 861 ktaScale1 = ((eeData[56] & 0x00F0) >> 4) + 8;
withboobs 0:99e98f131071 862 ktaScale2 = (eeData[56] & 0x000F);
withboobs 0:99e98f131071 863
withboobs 0:99e98f131071 864 for(int i = 0; i < 24; i++)
withboobs 0:99e98f131071 865 {
withboobs 0:99e98f131071 866 for(int j = 0; j < 32; j ++)
withboobs 0:99e98f131071 867 {
withboobs 0:99e98f131071 868 p = 32 * i +j;
withboobs 0:99e98f131071 869 split = 2*(int(p/32) - int(int(p/32)/2)*2) + p%2;
withboobs 0:99e98f131071 870 mlx90640->kta[p] = (eeData[64 + p] & 0x000E) >> 1;
withboobs 0:99e98f131071 871 if (mlx90640->kta[p] > 3)
withboobs 0:99e98f131071 872 {
withboobs 0:99e98f131071 873 mlx90640->kta[p] = mlx90640->kta[p] - 8;
withboobs 0:99e98f131071 874 }
withboobs 0:99e98f131071 875 mlx90640->kta[p] = mlx90640->kta[p] * (1 << ktaScale2);
withboobs 0:99e98f131071 876 mlx90640->kta[p] = KtaRC[split] + mlx90640->kta[p];
withboobs 0:99e98f131071 877 mlx90640->kta[p] = mlx90640->kta[p] / pow(2,(double)ktaScale1);
withboobs 0:99e98f131071 878 }
withboobs 0:99e98f131071 879 }
withboobs 0:99e98f131071 880 }
withboobs 0:99e98f131071 881
withboobs 0:99e98f131071 882 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 883
withboobs 0:99e98f131071 884 void ExtractKvPixelParameters(uint16_t *eeData, paramsMLX90640 *mlx90640)
withboobs 0:99e98f131071 885 {
withboobs 0:99e98f131071 886 int p = 0;
withboobs 0:99e98f131071 887 int8_t KvT[4];
withboobs 0:99e98f131071 888 int8_t KvRoCo;
withboobs 0:99e98f131071 889 int8_t KvRoCe;
withboobs 0:99e98f131071 890 int8_t KvReCo;
withboobs 0:99e98f131071 891 int8_t KvReCe;
withboobs 0:99e98f131071 892 uint8_t kvScale;
withboobs 0:99e98f131071 893 uint8_t split;
withboobs 0:99e98f131071 894
withboobs 0:99e98f131071 895 KvRoCo = (eeData[52] & 0xF000) >> 12;
withboobs 0:99e98f131071 896 if (KvRoCo > 7)
withboobs 0:99e98f131071 897 {
withboobs 0:99e98f131071 898 KvRoCo = KvRoCo - 16;
withboobs 0:99e98f131071 899 }
withboobs 0:99e98f131071 900 KvT[0] = KvRoCo;
withboobs 0:99e98f131071 901
withboobs 0:99e98f131071 902 KvReCo = (eeData[52] & 0x0F00) >> 8;
withboobs 0:99e98f131071 903 if (KvReCo > 7)
withboobs 0:99e98f131071 904 {
withboobs 0:99e98f131071 905 KvReCo = KvReCo - 16;
withboobs 0:99e98f131071 906 }
withboobs 0:99e98f131071 907 KvT[2] = KvReCo;
withboobs 0:99e98f131071 908
withboobs 0:99e98f131071 909 KvRoCe = (eeData[52] & 0x00F0) >> 4;
withboobs 0:99e98f131071 910 if (KvRoCe > 7)
withboobs 0:99e98f131071 911 {
withboobs 0:99e98f131071 912 KvRoCe = KvRoCe - 16;
withboobs 0:99e98f131071 913 }
withboobs 0:99e98f131071 914 KvT[1] = KvRoCe;
withboobs 0:99e98f131071 915
withboobs 0:99e98f131071 916 KvReCe = (eeData[52] & 0x000F);
withboobs 0:99e98f131071 917 if (KvReCe > 7)
withboobs 0:99e98f131071 918 {
withboobs 0:99e98f131071 919 KvReCe = KvReCe - 16;
withboobs 0:99e98f131071 920 }
withboobs 0:99e98f131071 921 KvT[3] = KvReCe;
withboobs 0:99e98f131071 922
withboobs 0:99e98f131071 923 kvScale = (eeData[56] & 0x0F00) >> 8;
withboobs 0:99e98f131071 924
withboobs 0:99e98f131071 925
withboobs 0:99e98f131071 926 for(int i = 0; i < 24; i++)
withboobs 0:99e98f131071 927 {
withboobs 0:99e98f131071 928 for(int j = 0; j < 32; j ++)
withboobs 0:99e98f131071 929 {
withboobs 0:99e98f131071 930 p = 32 * i +j;
withboobs 0:99e98f131071 931 split = 2*(int(p/32) - int(int(p/32)/2)*2) + p%2;
withboobs 0:99e98f131071 932 mlx90640->kv[p] = KvT[split];
withboobs 0:99e98f131071 933 mlx90640->kv[p] = mlx90640->kv[p] / pow(2,(double)kvScale);
withboobs 0:99e98f131071 934 }
withboobs 0:99e98f131071 935 }
withboobs 0:99e98f131071 936 }
withboobs 0:99e98f131071 937
withboobs 0:99e98f131071 938 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 939
withboobs 0:99e98f131071 940 void ExtractCPParameters(uint16_t *eeData, paramsMLX90640 *mlx90640)
withboobs 0:99e98f131071 941 {
withboobs 0:99e98f131071 942 float alphaSP[2];
withboobs 0:99e98f131071 943 int16_t offsetSP[2];
withboobs 0:99e98f131071 944 float cpKv;
withboobs 0:99e98f131071 945 float cpKta;
withboobs 0:99e98f131071 946 uint8_t alphaScale;
withboobs 0:99e98f131071 947 uint8_t ktaScale1;
withboobs 0:99e98f131071 948 uint8_t kvScale;
withboobs 0:99e98f131071 949
withboobs 0:99e98f131071 950 alphaScale = ((eeData[32] & 0xF000) >> 12) + 27;
withboobs 0:99e98f131071 951
withboobs 0:99e98f131071 952 offsetSP[0] = (eeData[58] & 0x03FF);
withboobs 0:99e98f131071 953 if (offsetSP[0] > 511)
withboobs 0:99e98f131071 954 {
withboobs 0:99e98f131071 955 offsetSP[0] = offsetSP[0] - 1024;
withboobs 0:99e98f131071 956 }
withboobs 0:99e98f131071 957
withboobs 0:99e98f131071 958 offsetSP[1] = (eeData[58] & 0xFC00) >> 10;
withboobs 0:99e98f131071 959 if (offsetSP[1] > 31)
withboobs 0:99e98f131071 960 {
withboobs 0:99e98f131071 961 offsetSP[1] = offsetSP[1] - 64;
withboobs 0:99e98f131071 962 }
withboobs 0:99e98f131071 963 offsetSP[1] = offsetSP[1] + offsetSP[0];
withboobs 0:99e98f131071 964
withboobs 0:99e98f131071 965 alphaSP[0] = (eeData[57] & 0x03FF);
withboobs 0:99e98f131071 966 if (alphaSP[0] > 511)
withboobs 0:99e98f131071 967 {
withboobs 0:99e98f131071 968 alphaSP[0] = alphaSP[0] - 1024;
withboobs 0:99e98f131071 969 }
withboobs 0:99e98f131071 970 alphaSP[0] = alphaSP[0] / pow(2,(double)alphaScale);
withboobs 0:99e98f131071 971
withboobs 0:99e98f131071 972 alphaSP[1] = (eeData[57] & 0xFC00) >> 10;
withboobs 0:99e98f131071 973 if (alphaSP[1] > 31)
withboobs 0:99e98f131071 974 {
withboobs 0:99e98f131071 975 alphaSP[1] = alphaSP[1] - 64;
withboobs 0:99e98f131071 976 }
withboobs 0:99e98f131071 977 alphaSP[1] = (1 + alphaSP[1]/128) * alphaSP[0];
withboobs 0:99e98f131071 978
withboobs 0:99e98f131071 979 cpKta = (eeData[59] & 0x00FF);
withboobs 0:99e98f131071 980 if (cpKta > 127)
withboobs 0:99e98f131071 981 {
withboobs 0:99e98f131071 982 cpKta = cpKta - 256;
withboobs 0:99e98f131071 983 }
withboobs 0:99e98f131071 984 ktaScale1 = ((eeData[56] & 0x00F0) >> 4) + 8;
withboobs 0:99e98f131071 985 mlx90640->cpKta = cpKta / pow(2,(double)ktaScale1);
withboobs 0:99e98f131071 986
withboobs 0:99e98f131071 987 cpKv = (eeData[59] & 0xFF00) >> 8;
withboobs 0:99e98f131071 988 if (cpKv > 127)
withboobs 0:99e98f131071 989 {
withboobs 0:99e98f131071 990 cpKv = cpKv - 256;
withboobs 0:99e98f131071 991 }
withboobs 0:99e98f131071 992 kvScale = (eeData[56] & 0x0F00) >> 8;
withboobs 0:99e98f131071 993 mlx90640->cpKv = cpKv / pow(2,(double)kvScale);
withboobs 0:99e98f131071 994
withboobs 0:99e98f131071 995 mlx90640->cpAlpha[0] = alphaSP[0];
withboobs 0:99e98f131071 996 mlx90640->cpAlpha[1] = alphaSP[1];
withboobs 0:99e98f131071 997 mlx90640->cpOffset[0] = offsetSP[0];
withboobs 0:99e98f131071 998 mlx90640->cpOffset[1] = offsetSP[1];
withboobs 0:99e98f131071 999 }
withboobs 0:99e98f131071 1000
withboobs 0:99e98f131071 1001 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 1002
withboobs 0:99e98f131071 1003 void ExtractCILCParameters(uint16_t *eeData, paramsMLX90640 *mlx90640)
withboobs 0:99e98f131071 1004 {
withboobs 0:99e98f131071 1005 float ilChessC[3];
withboobs 0:99e98f131071 1006 uint8_t calibrationModeEE;
withboobs 0:99e98f131071 1007
withboobs 0:99e98f131071 1008 calibrationModeEE = (eeData[10] & 0x0800) >> 4;
withboobs 0:99e98f131071 1009 calibrationModeEE = calibrationModeEE ^ 0x80;
withboobs 0:99e98f131071 1010
withboobs 0:99e98f131071 1011 ilChessC[0] = (eeData[53] & 0x003F);
withboobs 0:99e98f131071 1012 if (ilChessC[0] > 31)
withboobs 0:99e98f131071 1013 {
withboobs 0:99e98f131071 1014 ilChessC[0] = ilChessC[0] - 64;
withboobs 0:99e98f131071 1015 }
withboobs 0:99e98f131071 1016 ilChessC[0] = ilChessC[0] / 16.0f;
withboobs 0:99e98f131071 1017
withboobs 0:99e98f131071 1018 ilChessC[1] = (eeData[53] & 0x07C0) >> 6;
withboobs 0:99e98f131071 1019 if (ilChessC[1] > 15)
withboobs 0:99e98f131071 1020 {
withboobs 0:99e98f131071 1021 ilChessC[1] = ilChessC[1] - 32;
withboobs 0:99e98f131071 1022 }
withboobs 0:99e98f131071 1023 ilChessC[1] = ilChessC[1] / 2.0f;
withboobs 0:99e98f131071 1024
withboobs 0:99e98f131071 1025 ilChessC[2] = (eeData[53] & 0xF800) >> 11;
withboobs 0:99e98f131071 1026 if (ilChessC[2] > 15)
withboobs 0:99e98f131071 1027 {
withboobs 0:99e98f131071 1028 ilChessC[2] = ilChessC[2] - 32;
withboobs 0:99e98f131071 1029 }
withboobs 0:99e98f131071 1030 ilChessC[2] = ilChessC[2] / 8.0f;
withboobs 0:99e98f131071 1031
withboobs 0:99e98f131071 1032 mlx90640->calibrationModeEE = calibrationModeEE;
withboobs 0:99e98f131071 1033 mlx90640->ilChessC[0] = ilChessC[0];
withboobs 0:99e98f131071 1034 mlx90640->ilChessC[1] = ilChessC[1];
withboobs 0:99e98f131071 1035 mlx90640->ilChessC[2] = ilChessC[2];
withboobs 0:99e98f131071 1036 }
withboobs 0:99e98f131071 1037
withboobs 0:99e98f131071 1038 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 1039
withboobs 0:99e98f131071 1040 int ExtractDeviatingPixels(uint16_t *eeData, paramsMLX90640 *mlx90640)
withboobs 0:99e98f131071 1041 {
withboobs 0:99e98f131071 1042 uint16_t pixCnt = 0;
withboobs 0:99e98f131071 1043 uint16_t brokenPixCnt = 0;
withboobs 0:99e98f131071 1044 uint16_t outlierPixCnt = 0;
withboobs 0:99e98f131071 1045 int warn = 0;
withboobs 0:99e98f131071 1046 int i;
withboobs 0:99e98f131071 1047
withboobs 0:99e98f131071 1048 for(pixCnt = 0; pixCnt<5; pixCnt++)
withboobs 0:99e98f131071 1049 {
withboobs 0:99e98f131071 1050 mlx90640->brokenPixels[pixCnt] = 0xFFFF;
withboobs 0:99e98f131071 1051 mlx90640->outlierPixels[pixCnt] = 0xFFFF;
withboobs 0:99e98f131071 1052 }
withboobs 0:99e98f131071 1053
withboobs 0:99e98f131071 1054 pixCnt = 0;
withboobs 0:99e98f131071 1055 while (pixCnt < 768 && brokenPixCnt < 5 && outlierPixCnt < 5)
withboobs 0:99e98f131071 1056 {
withboobs 0:99e98f131071 1057 if(eeData[pixCnt+64] == 0)
withboobs 0:99e98f131071 1058 {
withboobs 0:99e98f131071 1059 mlx90640->brokenPixels[brokenPixCnt] = pixCnt;
withboobs 0:99e98f131071 1060 brokenPixCnt = brokenPixCnt + 1;
withboobs 0:99e98f131071 1061 }
withboobs 0:99e98f131071 1062 else if((eeData[pixCnt+64] & 0x0001) != 0)
withboobs 0:99e98f131071 1063 {
withboobs 0:99e98f131071 1064 mlx90640->outlierPixels[outlierPixCnt] = pixCnt;
withboobs 0:99e98f131071 1065 outlierPixCnt = outlierPixCnt + 1;
withboobs 0:99e98f131071 1066 }
withboobs 0:99e98f131071 1067
withboobs 0:99e98f131071 1068 pixCnt = pixCnt + 1;
withboobs 0:99e98f131071 1069
withboobs 0:99e98f131071 1070 }
withboobs 0:99e98f131071 1071
withboobs 0:99e98f131071 1072 if(brokenPixCnt > 4)
withboobs 0:99e98f131071 1073 {
withboobs 0:99e98f131071 1074 warn = -3;
withboobs 0:99e98f131071 1075 }
withboobs 0:99e98f131071 1076 else if(outlierPixCnt > 4)
withboobs 0:99e98f131071 1077 {
withboobs 0:99e98f131071 1078 warn = -4;
withboobs 0:99e98f131071 1079 }
withboobs 0:99e98f131071 1080 else if((brokenPixCnt + outlierPixCnt) > 4)
withboobs 0:99e98f131071 1081 {
withboobs 0:99e98f131071 1082 warn = -5;
withboobs 0:99e98f131071 1083 }
withboobs 0:99e98f131071 1084 else
withboobs 0:99e98f131071 1085 {
withboobs 0:99e98f131071 1086 for(pixCnt=0; pixCnt<brokenPixCnt; pixCnt++)
withboobs 0:99e98f131071 1087 {
withboobs 0:99e98f131071 1088 for(i=pixCnt+1; i<brokenPixCnt; i++)
withboobs 0:99e98f131071 1089 {
withboobs 0:99e98f131071 1090 warn = CheckAdjacentPixels(mlx90640->brokenPixels[pixCnt],mlx90640->brokenPixels[i]);
withboobs 0:99e98f131071 1091 if(warn != 0)
withboobs 0:99e98f131071 1092 {
withboobs 0:99e98f131071 1093 return warn;
withboobs 0:99e98f131071 1094 }
withboobs 0:99e98f131071 1095 }
withboobs 0:99e98f131071 1096 }
withboobs 0:99e98f131071 1097
withboobs 0:99e98f131071 1098 for(pixCnt=0; pixCnt<outlierPixCnt; pixCnt++)
withboobs 0:99e98f131071 1099 {
withboobs 0:99e98f131071 1100 for(i=pixCnt+1; i<outlierPixCnt; i++)
withboobs 0:99e98f131071 1101 {
withboobs 0:99e98f131071 1102 warn = CheckAdjacentPixels(mlx90640->outlierPixels[pixCnt],mlx90640->outlierPixels[i]);
withboobs 0:99e98f131071 1103 if(warn != 0)
withboobs 0:99e98f131071 1104 {
withboobs 0:99e98f131071 1105 return warn;
withboobs 0:99e98f131071 1106 }
withboobs 0:99e98f131071 1107 }
withboobs 0:99e98f131071 1108 }
withboobs 0:99e98f131071 1109
withboobs 0:99e98f131071 1110 for(pixCnt=0; pixCnt<brokenPixCnt; pixCnt++)
withboobs 0:99e98f131071 1111 {
withboobs 0:99e98f131071 1112 for(i=0; i<outlierPixCnt; i++)
withboobs 0:99e98f131071 1113 {
withboobs 0:99e98f131071 1114 warn = CheckAdjacentPixels(mlx90640->brokenPixels[pixCnt],mlx90640->outlierPixels[i]);
withboobs 0:99e98f131071 1115 if(warn != 0)
withboobs 0:99e98f131071 1116 {
withboobs 0:99e98f131071 1117 return warn;
withboobs 0:99e98f131071 1118 }
withboobs 0:99e98f131071 1119 }
withboobs 0:99e98f131071 1120 }
withboobs 0:99e98f131071 1121
withboobs 0:99e98f131071 1122 }
withboobs 0:99e98f131071 1123
withboobs 0:99e98f131071 1124
withboobs 0:99e98f131071 1125 return warn;
withboobs 0:99e98f131071 1126
withboobs 0:99e98f131071 1127 }
withboobs 0:99e98f131071 1128
withboobs 0:99e98f131071 1129 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 1130
withboobs 0:99e98f131071 1131 int CheckAdjacentPixels(uint16_t pix1, uint16_t pix2)
withboobs 0:99e98f131071 1132 {
withboobs 0:99e98f131071 1133 int pixPosDif;
withboobs 0:99e98f131071 1134
withboobs 0:99e98f131071 1135 pixPosDif = pix1 - pix2;
withboobs 0:99e98f131071 1136 if(pixPosDif > -34 && pixPosDif < -30)
withboobs 0:99e98f131071 1137 {
withboobs 0:99e98f131071 1138 return -6;
withboobs 0:99e98f131071 1139 }
withboobs 0:99e98f131071 1140 if(pixPosDif > -2 && pixPosDif < 2)
withboobs 0:99e98f131071 1141 {
withboobs 0:99e98f131071 1142 return -6;
withboobs 0:99e98f131071 1143 }
withboobs 0:99e98f131071 1144 if(pixPosDif > 30 && pixPosDif < 34)
withboobs 0:99e98f131071 1145 {
withboobs 0:99e98f131071 1146 return -6;
withboobs 0:99e98f131071 1147 }
withboobs 0:99e98f131071 1148
withboobs 0:99e98f131071 1149 return 0;
withboobs 0:99e98f131071 1150 }
withboobs 0:99e98f131071 1151
withboobs 0:99e98f131071 1152 //------------------------------------------------------------------------------
withboobs 0:99e98f131071 1153
withboobs 0:99e98f131071 1154 int CheckEEPROMValid(uint16_t *eeData)
withboobs 0:99e98f131071 1155 {
withboobs 0:99e98f131071 1156 int deviceSelect;
withboobs 0:99e98f131071 1157 deviceSelect = eeData[10] & 0x0040;
withboobs 0:99e98f131071 1158 if(deviceSelect == 0)
withboobs 0:99e98f131071 1159 {
withboobs 0:99e98f131071 1160 return 0;
withboobs 0:99e98f131071 1161 }
withboobs 0:99e98f131071 1162
withboobs 0:99e98f131071 1163 return -7;
withboobs 1:3f763d28c1be 1164 }