@@ -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
@@ -744,30 +744,57 @@ def _ExtractCILCParameters(self):
744
744
self .ilChessC = ilChessC
745
745
746
746
def _ExtractDeviatingPixels (self ):
747
- self .brokenPixels = [0xFFFF ] * 5
748
- self .outlierPixels = [0xFFFF ] * 5
749
-
750
747
pixCnt = 0
751
- brokenPixCnt = 0
752
- outlierPixCnt = 0
753
748
754
- while (pixCnt < 768 ) and (brokenPixCnt < 5 ) and (outlierPixCnt < 5 ):
749
+ while (
750
+ (pixCnt < 768 )
751
+ and (len (self .brokenPixels ) < 5 )
752
+ and (len (self .outlierPixels ) < 5 )
753
+ ):
755
754
if eeData [pixCnt + 64 ] == 0 :
756
- self .brokenPixels [brokenPixCnt ] = pixCnt
757
- brokenPixCnt += 1
755
+ self .brokenPixels .append (pixCnt )
758
756
elif (eeData [pixCnt + 64 ] & 0x0001 ) != 0 :
759
- self .outlierPixels [outlierPixCnt ] = pixCnt
760
- outlierPixCnt += 1
757
+ self .outlierPixels .append (pixCnt )
761
758
pixCnt += 1
762
759
763
- if brokenPixCnt > 4 :
760
+ if len ( self . brokenPixels ) > 4 :
764
761
raise RuntimeError ("More than 4 broken pixels" )
765
- if outlierPixCnt > 4 :
762
+ if len ( self . outlierPixels ) > 4 :
766
763
raise RuntimeError ("More than 4 outlier pixels" )
767
- if (brokenPixCnt + outlierPixCnt ) > 4 :
764
+ if (len ( self . brokenPixels ) + len ( self . outlierPixels ) ) > 4 :
768
765
raise RuntimeError ("More than 4 faulty pixels" )
769
- # print("Found %d broken pixels, %d outliers" % (brokenPixCnt, outlierPixCnt))
770
- # TODO INCOMPLETE
766
+ # print("Found %d broken pixels, %d outliers"
767
+ # % (len(self.brokenPixels), len(self.outlierPixels)))
768
+
769
+ for brokenPixel1 , brokenPixel2 in self ._UniqueListPairs (self .brokenPixels ):
770
+ if self ._ArePixelsAdjacent (brokenPixel1 , brokenPixel2 ):
771
+ raise RuntimeError ("Adjacent broken pixels" )
772
+
773
+ for outlierPixel1 , outlierPixel2 in self ._UniqueListPairs (self .outlierPixels ):
774
+ if self ._ArePixelsAdjacent (outlierPixel1 , outlierPixel2 ):
775
+ raise RuntimeError ("Adjacent outlier pixels" )
776
+
777
+ for brokenPixel in self .brokenPixels :
778
+ for outlierPixel in self .outlierPixels :
779
+ if self ._ArePixelsAdjacent (brokenPixel , outlierPixel ):
780
+ raise RuntimeError ("Adjacent broken and outlier pixels" )
781
+
782
+ def _UniqueListPairs (self , inputList ):
783
+ for i , listValue1 in enumerate (inputList ):
784
+ for listValue2 in inputList [i + 1 :]:
785
+ yield (listValue1 , listValue2 )
786
+
787
+ def _ArePixelsAdjacent (self , pix1 , pix2 ):
788
+ pixPosDif = pix1 - pix2
789
+
790
+ if pixPosDif > - 34 and pixPosDif < - 30 :
791
+ return True
792
+ if pixPosDif > - 2 and pixPosDif < 2 :
793
+ return True
794
+ if pixPosDif > 30 and pixPosDif < 34 :
795
+ return True
796
+
797
+ return False
771
798
772
799
def _I2CWriteWord (self , writeAddress , data ):
773
800
cmd = bytearray (4 )
0 commit comments