MCPcopy Create free account
hub / github.com/DexterInd/GoPiGo3 / get_sensor_instance

Function get_sensor_instance

Software/Scratch/GoPiGo3Scratch.py:240–260  ·  view source on GitHub ↗

Checks if an instance of the requested sensor already exists for the desired port. If it does, return that one If there's nothing on that port, or there's another sensor, then create the requested sensor and return this new one

(port, sensor_class)

Source from the content-addressed store, hash-verified

238##################################################################
239
240def get_sensor_instance(port, sensor_class):
241 '''
242 Checks if an instance of the requested sensor already exists for
243 the desired port. If it does, return that one
244 If there's nothing on that port, or there's another sensor,
245 then create the requested sensor and return this new one
246 '''
247 try:
248 if known_sensors[port] == None or \
249 isinstance(known_sensors[port], sensor_class) is False:
250 try:
251 known_sensors[port] = sensor_class(port, gpg)
252 except Exception as e:
253 print("get_sensor_instance {}".format(e))
254 known_sensors[port] = None
255 except Exception as e:
256 print("get_sensor_instance 2 {}".format(e))
257 known_sensors[port] = None
258
259 # print(known_sensors[port])
260 return(known_sensors[port])
261
262
263def set_regex_string():

Callers 9

handle_dhtFunction · 0.85
handle_buttonFunction · 0.85
handle_one_servoFunction · 0.85
handle_lightFunction · 0.85
handle_loudnessFunction · 0.85
handle_ledFunction · 0.85
handle_buzzerFunction · 0.85
read_ultrasonicFunction · 0.85
handle_distanceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected