File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3030# Protocol limits
3131MAX_WRITE_CHUNK = const (30 )
3232SECTOR_SIZE = const (256 )
33+ MAX_SECTORS = const (32768 )
3334FILENAME_LEN = const (8 )
3435EXT_LEN = const (3 )
Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ def busy(self):
5555 """Return True if flash is busy."""
5656 return bool (self ._status () & STATUS_BUSY )
5757
58- def _wait_busy (self , timeout_ms = 1000 ):
58+ def _wait_busy (self , timeout_ms = 30000 ):
5959 """Poll busy bit until clear. Raises OSError on timeout."""
6060 elapsed = 0
6161 while self .busy ():
@@ -114,6 +114,10 @@ def write(self, data):
114114 buf [i ] = 0
115115 self .i2c .writeto (self .address , buf )
116116 offset += chunk_len
117+ self ._wait_busy ()
118+ err = self ._error ()
119+ if err :
120+ raise OSError ("DAPLink Flash write error: 0x{:02X}" .format (err ))
117121 return length
118122
119123 def write_line (self , text ):
@@ -152,12 +156,16 @@ def read(self, length=None):
152156 """
153157 result = bytearray ()
154158 sector = 0
155- while True :
159+ while sector < MAX_SECTORS :
156160 data = self .read_sector (sector )
157161 for i in range (SECTOR_SIZE ):
158- if data [i ] == 0xFF :
159- return bytes (result )
160- result .append (data [i ])
161- if length is not None and len (result ) >= length :
162- return bytes (result )
162+ if length is not None :
163+ result .append (data [i ])
164+ if len (result ) >= length :
165+ return bytes (result )
166+ else :
167+ if data [i ] == 0xFF :
168+ return bytes (result )
169+ result .append (data [i ])
163170 sector += 1
171+ return bytes (result )
Original file line number Diff line number Diff line change 7575 hum_sum += h
7676 pres_sum += p
7777
78- if t < temp_min :
79- temp_min = t
80- if t > temp_max :
81- temp_max = t
82- if h < hum_min :
83- hum_min = h
84- if h > hum_max :
85- hum_max = h
86- if p < pres_min :
87- pres_min = p
88- if p > pres_max :
89- pres_max = p
78+ temp_min = min (temp_min , t )
79+ temp_max = max (temp_max , t )
80+ hum_min = min (hum_min , h )
81+ hum_max = max (hum_max , h )
82+ pres_min = min (pres_min , p )
83+ pres_max = max (pres_max , p )
9084
9185 count += 1
9286
You can’t perform that action at this time.
0 commit comments