3232
3333import time
3434import gc
35- import adafruit_esp32spi as esp
3635from micropython import const
3736
3837_the_interface = None # pylint: disable=invalid-name
@@ -92,7 +91,7 @@ def readline(self):
9291 stamp = time .monotonic ()
9392 while b'\r \n ' not in self ._buffer :
9493 # there's no line already in there, read some more
95- avail = min ( _the_interface . socket_available ( self ._socknum ), MAX_PACKET )
94+ avail = self .available ( )
9695 if avail :
9796 self ._buffer += _the_interface .socket_read (self ._socknum , avail )
9897 elif self ._timeout > 0 and time .monotonic () - stamp > self ._timeout :
@@ -108,7 +107,7 @@ def read(self, size=0):
108107 #print("Socket read", size)
109108 if size == 0 : # read as much as we can at the moment
110109 while True :
111- avail = min ( _the_interface . socket_available ( self ._socknum ), MAX_PACKET )
110+ avail = self .available ( )
112111 if avail :
113112 self ._buffer += _the_interface .socket_read (self ._socknum , avail )
114113 else :
@@ -124,7 +123,7 @@ def read(self, size=0):
124123 received = []
125124 while to_read > 0 :
126125 #print("Bytes to read:", to_read)
127- avail = min ( _the_interface . socket_available ( self ._socknum ), MAX_PACKET )
126+ avail = self .available ( )
128127 if avail :
129128 stamp = time .monotonic ()
130129 recv = _the_interface .socket_read (self ._socknum , min (to_read , avail ))
@@ -151,11 +150,13 @@ def settimeout(self, value):
151150 self ._timeout = value
152151
153152 def available (self ):
153+ """Returns how many bytes of data are available to be read (up to the MAX_PACKET length)"""
154154 if self .socknum != NO_SOCKET_AVAIL :
155155 return min (_the_interface .socket_available (self ._socknum ), MAX_PACKET )
156156 return 0
157157
158158 def connected (self ):
159+ """Whether or not we are connected to the socket"""
159160 if self .socknum == NO_SOCKET_AVAIL :
160161 return False
161162 elif self .available ():
@@ -178,6 +179,7 @@ def connected(self):
178179
179180 @property
180181 def socknum (self ):
182+ """The socket number"""
181183 return self ._socknum
182184
183185 def close (self ):
0 commit comments