Examples of GPIOPin


Examples of com.pi4j.io.gpio.GpioPin

                throw new GpioPinExistsException(pin);
            }
        }

        // create new GPIO pin instance
        GpioPin gpioPin = new GpioPinImpl(this, provider, pin);

        // set the gpio pin name
        if (name != null) {
            gpioPin.setName(name);
        }

        // export this pin
        gpioPin.export(mode);

        // add this new pin instance to the managed collection
        pins.add(gpioPin);

        // return new new pin instance
View Full Code Here

Examples of com.pi4j.io.gpio.GpioPin

    public void unprovisionPin(GpioPin... pin) {
        if (pin == null || pin.length == 0) {
            throw new IllegalArgumentException("Missing pin argument.");
        }
        for (int index = (pin.length-1); index >= 0; index--) {
            GpioPin p  = pin[index];
           
            // ensure the requested pin has been provisioned
            if (!pins.contains(p)) {
                throw new GpioPinNotProvisionedException(p.getPin());
            }
            // remove all listeners and triggers
            if (p instanceof GpioPinInput) {
                ((GpioPinInput)p).removeAllListeners();
                ((GpioPinInput)p).removeAllTriggers();
View Full Code Here

Examples of org.openhab.io.gpio.GPIOPin

    if (gpio != null) {
      try {
        if (registryLock.readLock().tryLock(REGISTRYLOCK_TIMEOUT, REGISTRYLOCK_TIMEOUT_UNITS)) {
          try {
            GPIOPin gpioPin = (GPIOPin) registry.get(itemName);

            if (gpioPin != null) {
              if (command == OnOffType.ON) {
                gpioPin.setValue(GPIOPin.VALUE_HIGH);
              } else {
                gpioPin.setValue(GPIOPin.VALUE_LOW);
              }
            }
          } catch (IOException e) {
            logger.error("Error occured while changing pin state for item " + itemName + ", exception: " + e.getMessage());
            return;
View Full Code Here

Examples of org.openhab.io.gpio.GPIOPin

      /* The item configuration was changed */

      try {
        if (registryLock.writeLock().tryLock(REGISTRYLOCK_TIMEOUT, REGISTRYLOCK_TIMEOUT_UNITS)) {
          try {
            GPIOPin gpioPin = (GPIOPin) registry.get(itemName);

            /* Existing or new item */
            if (gpioPin != null) {

              /* Pin number change requires deletion of old and creation of new backend object */
              if (gpioPin.getPinNumber() != provider.getPinNumber(itemName)) {
                deleteItem(itemName);
                newItem(provider, itemName);
              } else {
                int newActiveLow = provider.getActiveLow(itemName);
                int currentDirection = gpioPin.getDirection();
                int newDirection = provider.getDirection(itemName);

                if (newActiveLow != gpioPin.getActiveLow()) {
                  gpioPin.setActiveLow(newActiveLow);
                }

                if (newDirection != currentDirection) {
                  if (currentDirection == GPIOPin.DIRECTION_IN) {
                    /* Tracking interrupts on output pins is meaningless */
                    gpioPin.removeEventHandler(this);
                  }
                  gpioPin.setDirection(newDirection);
                  if (newDirection == GPIOPin.DIRECTION_IN) {
                    gpioPin.setEdgeDetection(GPIOPin.EDGEDETECTION_BOTH);
                    gpioPin.addEventHandler(this);
                  }
                }

                /* Debouncing is valid only for input pins */
                if (newDirection == GPIOPin.DIRECTION_IN) {
                  long currentDebounceInterval = gpioPin.getDebounceInterval();
                  long defaultDebounceInterval = gpio.getDefaultDebounceInterval();
                  long newDebounceInterval = provider.getDebounceInterval(itemName);

                  /* If debounceInterval isn't configured its value is GPIOBindingProvider.DEBOUNCEINTERVAL_UNDEFINED */
                  if (newDebounceInterval != GPIOBindingProvider.DEBOUNCEINTERVAL_UNDEFINED) {
                    if (newDebounceInterval != currentDebounceInterval) {
                      gpioPin.setDebounceInterval(newDebounceInterval);
                    }
                  } else {
                    /* Revert back to default if was set before and after then deleted */
                    if (currentDebounceInterval != defaultDebounceInterval) {
                      gpioPin.setDebounceInterval(defaultDebounceInterval);
                    }
                  }                 
                }
              }
            } else {
View Full Code Here

Examples of org.openhab.io.gpio.GPIOPin

  private void newItem(GPIOBindingProvider provider, String itemName) {

    try {
      int direction;

      GPIOPin gpioPin = gpio.reservePin(provider.getPinNumber(itemName));

      gpioPin.setActiveLow(provider.getActiveLow(itemName));

      direction = provider.getDirection(itemName);
      gpioPin.setDirection(direction);

      /* Edge detection and debouncing are valid only for input pins */
      if (direction == GPIOPin.DIRECTION_IN) {
        long debounceInterval = provider.getDebounceInterval(itemName);

        gpioPin.setEdgeDetection(GPIOPin.EDGEDETECTION_BOTH);

        /* If debounceInterval isn't configured its value is GPIOBindingProvider.DEBOUNCEINTERVAL_UNDEFINED */
        if (debounceInterval != GPIOBindingProvider.DEBOUNCEINTERVAL_UNDEFINED) {
          gpioPin.setDebounceInterval(debounceInterval);
        }
      }

      /* Register the pin */
      try {
        if (registryLock.writeLock().tryLock(REGISTRYLOCK_TIMEOUT, REGISTRYLOCK_TIMEOUT_UNITS)) {
          try {
            registry.put(itemName, gpioPin);
          } finally {
            registryLock.writeLock().unlock();
          }
        } else {
          logger.error("Item " + itemName + " hasn't been inserted into the registry, timeout expired while waiting for registry lock");
          return;
        }
      } catch (InterruptedException e) {
        logger.error("Item " + itemName + " hasn't been inserted into the registry, thread was interrupted while waiting for registry lock");
        return;
      }

      /* Set initial item state */
      if (direction == GPIOPin.DIRECTION_IN) {

        /* Item type 'Contact' */
        if (gpioPin.getValue() == GPIOPin.VALUE_HIGH) {
          eventPublisher.postUpdate(itemName, OpenClosedType.OPEN);
        } else {
          eventPublisher.postUpdate(itemName, OpenClosedType.CLOSED);
        }
      } else {

        /* Item type 'Switch' */
        if (gpioPin.getValue() == GPIOPin.VALUE_HIGH) {
          eventPublisher.postUpdate(itemName, OnOffType.ON);
        } else {
          eventPublisher.postUpdate(itemName, OnOffType.OFF);
        }
      }

      /* The item is of type 'Contact', register for state change notifications */
      if (direction == GPIOPin.DIRECTION_IN) {
        gpioPin.addEventHandler(this);
      }
    } catch (Exception e) {
      logger.error("Error occured while creating backend object for item " +itemName + ", exception: "+ e.getMessage());
    }
  }
View Full Code Here

Examples of org.openhab.io.gpio.GPIOPin

    try {
      if (registryLock.writeLock().tryLock(REGISTRYLOCK_TIMEOUT, REGISTRYLOCK_TIMEOUT_UNITS)) {
        try {

          /* Remove the item from registry */
          GPIOPin gpioPin = (GPIOPin) registry.remove(itemName);

          /* Release the backend object */
          if (gpioPin != null) {
            try {
              gpio.releasePin(gpioPin);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.