@@ -96,8 +96,8 @@ class MLX90640: # pylint: disable=too-many-instance-attributes
96
96
cpAlpha = [0 ] * 2
97
97
cpOffset = [0 ] * 2
98
98
ilChessC = [0 ] * 3
99
- brokenPixels = [0xFFFF ] * 5
100
- outlierPixels = [0xFFFF ] * 5
99
+ brokenPixels = []
100
+ outlierPixels = []
101
101
cpKta = 0
102
102
cpKv = 0
103
103
@@ -266,6 +266,11 @@ def _CalculateTo(self, frameData, emissivity, tr, result):
266
266
)
267
267
268
268
for pixelNumber in range (768 ):
269
+ if self ._IsPixelBad (pixelNumber ):
270
+ # print("Fixing broken pixel %d" % pixelNumber)
271
+ result [pixelNumber ] = - 273.15
272
+ continue
273
+
269
274
ilPattern = pixelNumber // 32 - (pixelNumber // 64 ) * 2
270
275
chessPattern = ilPattern ^ (pixelNumber - (pixelNumber // 2 ) * 2 )
271
276
conversionPattern = (
@@ -744,30 +749,66 @@ def _ExtractCILCParameters(self):
744
749
self .ilChessC = ilChessC
745
750
746
751
def _ExtractDeviatingPixels (self ):
747
- self .brokenPixels = [0xFFFF ] * 5
748
- self .outlierPixels = [0xFFFF ] * 5
749
-
752
+ # pylint: disable=too-many-branches
750
753
pixCnt = 0
751
- brokenPixCnt = 0
752
- outlierPixCnt = 0
753
754
754
- while (pixCnt < 768 ) and (brokenPixCnt < 5 ) and (outlierPixCnt < 5 ):
755
+ while (
756
+ (pixCnt < 768 )
757
+ and (len (self .brokenPixels ) < 5 )
758
+ and (len (self .outlierPixels ) < 5 )
759
+ ):
755
760
if eeData [pixCnt + 64 ] == 0 :
756
- self .brokenPixels [brokenPixCnt ] = pixCnt
757
- brokenPixCnt += 1
761
+ self .brokenPixels .append (pixCnt )
758
762
elif (eeData [pixCnt + 64 ] & 0x0001 ) != 0 :
759
- self .outlierPixels [outlierPixCnt ] = pixCnt
760
- outlierPixCnt += 1
763
+ self .outlierPixels .append (pixCnt )
761
764
pixCnt += 1
762
765
763
- if brokenPixCnt > 4 :
766
+ if len ( self . brokenPixels ) > 4 :
764
767
raise RuntimeError ("More than 4 broken pixels" )
765
- if outlierPixCnt > 4 :
768
+ if len ( self . outlierPixels ) > 4 :
766
769
raise RuntimeError ("More than 4 outlier pixels" )
767
- if (brokenPixCnt + outlierPixCnt ) > 4 :
770
+ if (len ( self . brokenPixels ) + len ( self . outlierPixels ) ) > 4 :
768
771
raise RuntimeError ("More than 4 faulty pixels" )
769
- # print("Found %d broken pixels, %d outliers" % (brokenPixCnt, outlierPixCnt))
770
- # TODO INCOMPLETE
772
+ # print("Found %d broken pixels, %d outliers"
773
+ # % (len(self.brokenPixels), len(self.outlierPixels)))
774
+
775
+ for brokenPixel1 , brokenPixel2 in self ._UniqueListPairs (self .brokenPixels ):
776
+ if self ._ArePixelsAdjacent (brokenPixel1 , brokenPixel2 ):
777
+ raise RuntimeError ("Adjacent broken pixels" )
778
+
779
+ for outlierPixel1 , outlierPixel2 in self ._UniqueListPairs (self .outlierPixels ):
780
+ if self ._ArePixelsAdjacent (outlierPixel1 , outlierPixel2 ):
781
+ raise RuntimeError ("Adjacent outlier pixels" )
782
+
783
+ for brokenPixel in self .brokenPixels :
784
+ for outlierPixel in self .outlierPixels :
785
+ if self ._ArePixelsAdjacent (brokenPixel , outlierPixel ):
786
+ raise RuntimeError ("Adjacent broken and outlier pixels" )
787
+
788
+ def _UniqueListPairs (self , inputList ):
789
+ # pylint: disable=no-self-use
790
+ for i , listValue1 in enumerate (inputList ):
791
+ for listValue2 in inputList [i + 1 :]:
792
+ yield (listValue1 , listValue2 )
793
+
794
+ def _ArePixelsAdjacent (self , pix1 , pix2 ):
795
+ # pylint: disable=no-self-use
796
+ pixPosDif = pix1 - pix2
797
+
798
+ if - 34 < pixPosDif < - 30 :
799
+ return True
800
+ if - 2 < pixPosDif < 2 :
801
+ return True
802
+ if 30 < pixPosDif < 34 :
803
+ return True
804
+
805
+ return False
806
+
807
+ def _IsPixelBad (self , pixel ):
808
+ if pixel in self .brokenPixels or pixel in self .outlierPixels :
809
+ return True
810
+
811
+ return False
771
812
772
813
def _I2CWriteWord (self , writeAddress , data ):
773
814
cmd = bytearray (4 )
0 commit comments