Exemple #1
0
  /**
   * Instantiate an I2cDeviceClient instance in the indicated device with the indicated initial
   * window of registers being read.
   *
   * @param i2cDevice the device we are to be a client of
   * @param i2cAddr8Bit its 8 bit i2cAddress
   * @param autoClose if true, the device client will automatically close when the associated
   *     SynchronousOpMode stops
   */
  public I2cDeviceClient(
      II2cDevice i2cDevice, int i2cAddr8Bit, boolean autoClose, IStopActionRegistrar registrar) {
    i2cDevice.setI2cAddr(i2cAddr8Bit);

    this.i2cDevice = i2cDevice;
    this.callback = new Callback();
    this.callbackThread = null;
    this.callbackThreadOriginalPriority = 0; // not known
    this.callbackThreadPriorityBoost = 0; // no boost
    this.hardwareCycleCount = 0;
    this.loggingEnabled = false;
    this.loggingTag = String.format("I2cDeviceClient(%s)", i2cDevice.getDeviceName());
    ;
    this.timeSinceLastHeartbeat = new ElapsedTime();
    this.timeSinceLastHeartbeat.reset();
    this.msHeartbeatInterval = 0;
    this.heartbeatAction = null;

    this.readCache = this.i2cDevice.getI2cReadCache();
    this.readCacheLock = this.i2cDevice.getI2cReadCacheLock();
    this.writeCache = this.i2cDevice.getI2cWriteCache();
    this.writeCacheLock = this.i2cDevice.getI2cWriteCacheLock();

    this.readWindow = null;
    this.readWindowActuallyRead = null;
    this.readWindowSentToController = null;
    this.readWindowChanged = false;
    this.readWindowSentToControllerInitialized = false;

    this.nanoTimeReadCacheValid = 0;
    this.readCacheStatus = READ_CACHE_STATUS.IDLE;
    this.writeCacheStatus = WRITE_CACHE_STATUS.IDLE;
    this.modeCacheStatus = MODE_CACHE_STATUS.IDLE;

    if (autoClose) {
      if (registrar == null) registrar = SynchronousOpMode.getStopActionRegistrar();
      if (registrar != null) {
        registrar.registerActionOnStop(
            new IAction() {
              @Override
              public void doAction() {
                I2cDeviceClient.this.close();
              }
            });
      }
    }

    this.i2cDevice.registerForI2cPortReadyCallback(this.callback);
  }