55import sys
66import threading
77import time
8+ import logging
89
910from smbus2 import SMBus
1011
2324 "USER_FUNC" + str (i + 1 ) for i in range (0 , 15 )
2425]
2526
27+ _LOGGER = logging .getLogger (__name__ )
2628
2729class PiJuiceInterface (object ):
2830 def __init__ (self , bus = 1 , address = 0x14 ):
@@ -82,13 +84,15 @@ def _Write(self):
8284
8385 def _DoTransfer (self , oper ):
8486 self .force = True if (self .t is not None and self .t .is_alive ()) else None
87+ #_LOGGER.debug(f"_DoTransfer force={self.force}")
8588 self .t = threading .Thread (target = oper , args = ())
8689 self .t .start ()
8790
8891 # wait for transfer to finish or timeout
8992 self .t .join (timeout = 0.1 )
9093
9194 r_code = not (self .comError or self .t .is_alive ())
95+ #_LOGGER.debug(f"_DoTransfer return code={r_code}")
9296 return r_code
9397
9498 def ReadData (self , cmd , length ):
@@ -101,6 +105,7 @@ def ReadData(self, cmd, length):
101105 return {"error" : "COMMUNICATION_ERROR" }
102106
103107 d = self .d
108+ _LOGGER .info ("ReadData cmd 0x%x= %s %x (%x)" , cmd , d , d [- 1 ], self ._GetChecksum (d [0 :- 1 ]))
104109 if self ._GetChecksum (d [0 :- 1 ]) != d [- 1 ]:
105110 # With n+1 byte data (n data bytes and 1 checksum byte) sometimes the
106111 # MSbit of the first received data byte is 0 while it should be 1. So we
@@ -109,6 +114,8 @@ def ReadData(self, cmd, length):
109114 if self ._GetChecksum (d [0 :- 1 ]) == d [- 1 ]:
110115 del d [- 1 ]
111116 return {"data" : d , "error" : "NO_ERROR" }
117+ _LOGGER .info (
118+ "ReadData cmd 0x%x= %x (%x)" , cmd , d , self ._GetChecksum (d [0 :- 1 ]))
112119 return {"error" : "DATA_CORRUPTED" }
113120 del d [- 1 ]
114121 return {"data" : d , "error" : "NO_ERROR" }
0 commit comments