# import tty # import select import time import os import math from I2C_mutex import Mutex import easysensors try: from di_sensors import easy_distance_sensor except ImportError as e: # It is quite possible to use the GPG3 without having the di_sensors repo installed pass except Exception as e: print("Importing di_sensors error: {}".format(e)) mutex = Mutex(debug=False) hardware_connected = True try: import gopigo3 except ImportError: hardware_connected = False print("Cannot import gopigo3 library") except Exception as e: hardware_connected = False print("Unknown issue while importing gopigo3") print(e) # try: # from line_follower import line_sensor # from line_follower import scratch_line
import sys # import tty # import select import time try: import gopigo except: pass # import os # the following libraries may or may not be installed # nor needed from I2C_mutex import Mutex mutex = Mutex() def _ifMutexAcquire(mutex_enabled = False): """ Acquires the I2C if the ``use_mutex`` parameter of the constructor was set to ``True``. """ if mutex_enabled: mutex.acquire() def _ifMutexRelease(mutex_enabled = False): """ Releases the I2C if the ``use_mutex`` parameter of the constructor was set to ``True``. """ if mutex_enabled: mutex.release()
#################################################### # This file tests the mutex class # Run it in parallel with text_heavy_mutext_2.py # in order to verify that mutex is functional. # This one acquires and releases every 5 seconds # the other one is every half second #################################################### import time from I2C_mutex import Mutex import fcntl mutex = Mutex(debug=True) DexterLockI2C_handle = open('/run/lock/DexterLockI2C') while True: try: mutex.acquire() time.sleep(5) mutex.release() except KeyboardInterrupt: mutex.release() exit() except Exception as e: print(e)