55`P1AM`
66================================================================================
77
8- Library to interface with P1000 modules using a P1AM-200.
9-
10- * Author(s): Adam Cummick, Tristan Warder, Michael Scott
8+ Library to interface with Productivity1000 modules.
119"""
1210
1311import time
2321__repo__ = "https://github.com/facts-engineering/CircuitPython_P1AM.git"
2422
2523def change_bit (original , bit , state ):
26- """Change value of sepcific bit position"""
24+ """Change value of specific bit position"""
2725 if state :
2826 return original | (1 << bit )
2927
@@ -86,19 +84,24 @@ def read_block(length: int, offset: int, block_type: int):
8684 _p1 .write (msg )
8785 if _spi_timeout ():
8886 with BC_SPI as _p1 :
87+ time .sleep (0.00001 )
8988 _p1 .readinto (data_buf , start = 0 , end = length )
9089 _data_sync ()
9190 data = int .from_bytes (data_buf [0 :length ], byte_order )
9291 return data
9392
94- return False # no respsonse
93+ raise RuntimeError (
94+ "Check External Supply Connection\n No Base Controller Activity"
95+ )
9596
9697
9798def _data_sync (timeout = 0.2 ):
98- """Wait for Base Contorller to update data"""
99+ """Wait for Base Controller to update data"""
99100 start = time .monotonic ()
101+ power_lost = 0
100102 while not ACK .value :
101103 if time .monotonic () - start > timeout :
104+ power_lost += 1
102105 break
103106
104107 start = time .monotonic ()
@@ -109,8 +112,14 @@ def _data_sync(timeout=0.2):
109112 start = time .monotonic ()
110113 while not ACK .value :
111114 if time .monotonic () - start > timeout :
115+ power_lost += 1
112116 break
113117
118+ if power_lost == 2 :
119+ raise RuntimeError (
120+ "Check External Supply Connection\n No Base Controller Activity"
121+ )
122+
114123
115124def _spi_timeout (timeout = 0.200 ):
116125 """Wait for Base Controller to be ready for next transaction"""
@@ -1003,7 +1012,7 @@ def init(self): # pylint: disable=too-many-locals, too-many-statements
10031012
10041013 if _spi_timeout (5 ) is False :
10051014 raise RuntimeError (
1006- "Check External Supply Connection\n " "No Base Controller Activity"
1015+ "Check External Supply Connection\n No Base Controller Activity"
10071016 )
10081017
10091018 while (slots == 0 or slots > 15 ) and retry < 5 :
0 commit comments