示例#1
0
 def __init__(self,
              rst=None,
              address=BNO055_ADDRESS_A,
              i2c=None,
              gpio=None,
              serial_port=None,
              serial_timeout_sec=5,
              **kwargs):
     # If reset pin is provided save it and a reference to provided GPIO
     # bus (or the default system GPIO bus if none is provided).
     self._rst = rst
     if self._rst is not None:
         if gpio is None:
             import Adafruit_GPIO as GPIO
             #gpio = GPIO.get_platform_gpio()
             print 'Setup as Pi'
             gpio = GPIO.set_platform_gpio_rpi()
         self._gpio = gpio
         # Setup the reset pin as an output at a high level.
         self._gpio.setup(self._rst, GPIO.OUT)
         self._gpio.set_high(self._rst)
         # Wait a 650 milliseconds in case setting the reset high reset the chip.
         time.sleep(0.65)
     self._serial = None
     self._i2c_device = None
     if serial_port is not None:
         # Use serial communication if serial_port name is provided.
         # Open the serial port at 115200 baud, 8N1.  Add a 5 second timeout
         # to prevent hanging if device is disconnected.
         self._serial = serial.Serial(serial_port,
                                      115200,
                                      timeout=serial_timeout_sec,
                                      writeTimeout=serial_timeout_sec)
     else:
         # Use I2C if no serial port is provided.
         # Assume we're using platform's default I2C bus if none is specified.
         if i2c is None:
             import Adafruit_GPIO.I2C as I2C
             i2c = I2C
         # Save a reference to the I2C device instance for later communication.
         self._i2c_device = i2c.get_i2c_device(address, **kwargs)