Beispiel #1
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated NOT
  */
 public void fetchSensorValue() {
   try {
     int resistance = tinkerforgeDevice.getResistance();
     DecimalValue value = Tools.calculate(resistance);
     setSensorValue(value);
   } catch (TimeoutException e) {
     TinkerforgeErrorHandler.handleError(this, TinkerforgeErrorHandler.TF_TIMEOUT_EXCEPTION, e);
   } catch (NotConnectedException e) {
     TinkerforgeErrorHandler.handleError(
         this, TinkerforgeErrorHandler.TF_NOT_CONNECTION_EXCEPTION, e);
   }
 }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated NOT
  */
 @Override
 public void fetchDigitalValue() {
   HighLowValue pinValue = HighLowValue.UNDEF;
   try {
     pinValue = extractValue(getMbrick().getTinkerforgeDevice().getPort(getPort()));
     setDigitalState(pinValue);
   } catch (TimeoutException e) {
     TinkerforgeErrorHandler.handleError(this, TinkerforgeErrorHandler.TF_TIMEOUT_EXCEPTION, e);
   } catch (NotConnectedException e) {
     TinkerforgeErrorHandler.handleError(
         this, TinkerforgeErrorHandler.TF_NOT_CONNECTION_EXCEPTION, e);
   }
 }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated NOT
  */
 @Override
 public void enable() {
   logger.debug("{} enable called on DigitalActor", LoggerConstants.TFINIT);
   if (tfConfig != null) {
     if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("defaultState"))) {
       logger.debug("{} setDefaultState: {}", LoggerConstants.TFINIT, tfConfig.getDefaultState());
       setDefaultState(tfConfig.getDefaultState());
     }
     if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("keepOnReconnect"))) {
       logger.debug(
           "{} keepOnReconnect: {}", LoggerConstants.TFINIT, tfConfig.isKeepOnReconnect());
       setKeepOnReconnect(tfConfig.isKeepOnReconnect());
     }
   }
   String defaultState = getDefaultState();
   try {
     // there seems to be no interrupt support in the upstream api
     if (getMbrick().getBrickd().isReconnected() && isKeepOnReconnect()) {
       logger.debug(
           "{} reconnected: no new port configuration set for {}",
           LoggerConstants.TFINIT,
           getSubId());
     } else if (defaultState == null || defaultState.equals("keep")) {
       logger.debug("{} keep: no new port configuration set", LoggerConstants.TFINIT);
     } else if (defaultState.equals("true")) {
       logger.debug("{} setPortconfiguration to state: true", LoggerConstants.TFINIT);
       getMbrick()
           .getTinkerforgeDevice()
           .setPortConfiguration(getPort(), (short) mask, BrickletIO16.DIRECTION_OUT, true);
     } else if (defaultState.equals("false")) {
       logger.debug("{} setPortconfiguration to state: false", LoggerConstants.TFINIT);
       getMbrick()
           .getTinkerforgeDevice()
           .setPortConfiguration(getPort(), (short) mask, BrickletIO16.DIRECTION_OUT, false);
     }
     fetchDigitalValue();
   } catch (TimeoutException e) {
     TinkerforgeErrorHandler.handleError(this, TinkerforgeErrorHandler.TF_TIMEOUT_EXCEPTION, e);
   } catch (NotConnectedException e) {
     TinkerforgeErrorHandler.handleError(
         this, TinkerforgeErrorHandler.TF_NOT_CONNECTION_EXCEPTION, e);
   }
 }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated NOT
  */
 @Override
 public void turnDigital(HighLowValue digitalState) {
   BrickletIO16 brickletIO16 = getMbrick().getTinkerforgeDevice();
   try {
     if (digitalState == HighLowValue.HIGH) {
       brickletIO16.setSelectedValues(getPort(), (short) mask, (short) mask);
     } else if (digitalState == HighLowValue.LOW) {
       brickletIO16.setSelectedValues(getPort(), (short) mask, (short) 0);
     } else {
       logger.error("{} unkown digitalState {}", LoggerConstants.TFMODELUPDATE, digitalState);
     }
     setDigitalState(digitalState);
   } catch (TimeoutException e) {
     TinkerforgeErrorHandler.handleError(this, TinkerforgeErrorHandler.TF_TIMEOUT_EXCEPTION, e);
   } catch (NotConnectedException e) {
     TinkerforgeErrorHandler.handleError(
         this, TinkerforgeErrorHandler.TF_NOT_CONNECTION_EXCEPTION, e);
   }
 }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated NOT
  */
 @Override
 public void enable() {
   if (tfConfig != null) {
     if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("sampleRate"))) {
       Short sampleRate = tfConfig.getSampleRate();
       logger.debug("sampleRate {}", sampleRate);
       setSampleRate(sampleRate);
     }
   }
   try {
     tinkerforgeDevice = new BrickletIndustrialDualAnalogIn(getUid(), getIpConnection());
     tinkerforgeDevice.setSampleRate(getSampleRate());
   } catch (TimeoutException e) {
     TinkerforgeErrorHandler.handleError(this, TinkerforgeErrorHandler.TF_TIMEOUT_EXCEPTION, e);
   } catch (NotConnectedException e) {
     TinkerforgeErrorHandler.handleError(
         this, TinkerforgeErrorHandler.TF_NOT_CONNECTION_EXCEPTION, e);
   }
 }
Beispiel #6
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated NOT
  */
 public void enable() {
   tinkerforgeDevice = getMbrick().getTinkerforgeDevice();
   if (tfConfig != null) {
     if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("threshold"))) {
       setThreshold(tfConfig.getThreshold());
     }
     if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("callbackPeriod"))) {
       setCallbackPeriod(tfConfig.getCallbackPeriod());
     }
   }
   try {
     tinkerforgeDevice.setResistanceCallbackPeriod(getCallbackPeriod());
     listener = new ResistanceListener();
     tinkerforgeDevice.addResistanceListener(listener);
     fetchSensorValue();
   } catch (TimeoutException e) {
     TinkerforgeErrorHandler.handleError(this, TinkerforgeErrorHandler.TF_TIMEOUT_EXCEPTION, e);
   } catch (NotConnectedException e) {
     TinkerforgeErrorHandler.handleError(
         this, TinkerforgeErrorHandler.TF_NOT_CONNECTION_EXCEPTION, e);
   }
 }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated NOT
  */
 @Override
 public void enable() {
   if (tfConfig != null) {
     if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("threshold"))) {
       setThreshold(tfConfig.getThreshold());
     }
     if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("callbackPeriod"))) {
       setCallbackPeriod(tfConfig.getCallbackPeriod());
     }
   }
   try {
     tinkerforgeDevice = new BrickletDustDetector(getUid(), getIpConnection());
     tinkerforgeDevice.setDustDensityCallbackPeriod(getCallbackPeriod());
     listener = new DustDensityListener();
     tinkerforgeDevice.addDustDensityListener(listener);
     fetchSensorValue();
   } catch (TimeoutException e) {
     TinkerforgeErrorHandler.handleError(this, TinkerforgeErrorHandler.TF_TIMEOUT_EXCEPTION, e);
   } catch (NotConnectedException e) {
     TinkerforgeErrorHandler.handleError(
         this, TinkerforgeErrorHandler.TF_NOT_CONNECTION_EXCEPTION, e);
   }
 }
  /**
   *
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated NOT
   */
  @Override
  public void setSelectedColor(HSBType color, DeviceOptions opts) {
    logger.debug("setSelectedColor called");
    // ColorMapping may be overridden by itemConfiguration
    char[] colorMapping = getColorMapping().toCharArray();
    String leds = null;

    // handle options
    if (opts != null) {
      if (opts.containsKey(COLOR_MAPPING)) {
        logger.debug("custom color mapping {} ", opts.getOption(COLOR_MAPPING));
        colorMapping = opts.getOption(COLOR_MAPPING).toCharArray();
      }
      if (opts.containsKey(LEDS)) {
        leds = opts.getOption(LEDS).trim();
        logger.debug("leds: {}", leds);
      }
    }
    if (leds == null || leds.length() == 0) {
      logger.error("\"leds\" option missing or empty, items configuration has to be fixed!");
      return;
    }

    // get the rgb values from HSBType
    Color rgbColor = color.toColor();
    short red = (short) rgbColor.getRed();
    short green = (short) rgbColor.getGreen();
    short blue = (short) rgbColor.getBlue();
    logger.debug("rgb is: {}:{}:{}", red, green, blue);

    // construct the values for the setRGBValues call
    HashMap<Character, short[]> colorMap = new HashMap<Character, short[]>(3);
    short[] reds = {red, red, red, red, red, red, red, red, red, red, red, red, red, red, red, red};
    short[] greens = {
      green, green, green, green, green, green, green, green, green, green, green, green, green,
      green, green, green
    };
    short[] blues = {
      blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue
    };
    colorMap.put('r', reds);
    colorMap.put('g', greens);
    colorMap.put('b', blues);
    LedList ledList = Tools.parseLedString(leds);

    try {
      if (ledList.hasLedRanges()) {
        Map<Integer, Short> ledRanges = ledList.getLedRanges();
        for (Integer led : ledRanges.keySet()) {
          tinkerforgeDevice.setRGBValues(
              led,
              ledRanges.get(led),
              colorMap.get(colorMapping[0]),
              colorMap.get(colorMapping[1]),
              colorMap.get(colorMapping[2]));
        }
      }
      if (ledList.hasLeds()) {
        for (Integer led : ledList.getLedNumbers()) {
          tinkerforgeDevice.setRGBValues(
              led,
              (short) 1,
              colorMap.get(colorMapping[0]),
              colorMap.get(colorMapping[1]),
              colorMap.get(colorMapping[2]));
        }
      }
      setColor(new HSBValue(color));
    } catch (TimeoutException e) {
      TinkerforgeErrorHandler.handleError(this, TinkerforgeErrorHandler.TF_TIMEOUT_EXCEPTION, e);
    } catch (NotConnectedException e) {
      TinkerforgeErrorHandler.handleError(
          this, TinkerforgeErrorHandler.TF_NOT_CONNECTION_EXCEPTION, e);
    }
  }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated NOT
  */
 @Override
 public void enable() {
   logger.trace("enabling");
   int chipType = BrickletLEDStrip.CHIP_TYPE_WS2801;
   int frameDuration = 100;
   Long clockFrequency = null;
   tinkerforgeDevice = new BrickletLEDStrip(getUid(), getIpConnection());
   if (tfConfig != null) {
     if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("chiptype"))) {
       String chipTypeString = tfConfig.getChiptype();
       if (chipTypeString.equalsIgnoreCase("ws2801")) {
         chipType = BrickletLEDStrip.CHIP_TYPE_WS2801;
       } else if (chipTypeString.equalsIgnoreCase("ws2811")) {
         chipType = BrickletLEDStrip.CHIP_TYPE_WS2811;
       } else if (chipTypeString.equalsIgnoreCase("ws2812")) {
         chipType = BrickletLEDStrip.CHIP_TYPE_WS2812;
       } else {
         logger.error("Unknown ChipType {}", chipTypeString);
         // TODO raise configuration error
       }
     }
     if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("frameduration"))) {
       frameDuration = tfConfig.getFrameduration();
     }
     if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("clockfrequency"))) {
       clockFrequency = tfConfig.getClockfrequency();
     }
     // config Handling for ColorMapping must be before adding the
     // subdevices because subdevices use the ColorMapping
     if (tfConfig.eIsSet(
         tfConfig
             .eClass()
             .getEStructuralFeature(ModelPackage.LED_STRIP_CONFIGURATION__COLOR_MAPPING))) {
       colorMapping = tfConfig.getColorMapping();
     }
     if (tfConfig.eIsSet(
         tfConfig
             .eClass()
             .getEStructuralFeature(ModelPackage.LED_STRIP_CONFIGURATION__SUB_DEVICES))) {
       String[] subdevices = tfConfig.getSubDevices().trim().split("\\s+");
       for (String subId : subdevices) {
         addSubdevice(subId);
       }
     }
   }
   logger.debug("chipType is {}", chipType);
   logger.debug("frameDuration is {}", frameDuration);
   logger.debug("colorMapping is {}", colorMapping);
   try {
     tinkerforgeDevice.setChipType(chipType);
     tinkerforgeDevice.setFrameDuration(frameDuration);
     if (clockFrequency != null) {
       logger.debug("clockFrequency is {}", clockFrequency);
       tinkerforgeDevice.setClockFrequency(clockFrequency);
     } else {
       logger.debug("clockFrequency is not set");
     }
   } catch (TimeoutException e) {
     TinkerforgeErrorHandler.handleError(this, TinkerforgeErrorHandler.TF_TIMEOUT_EXCEPTION, e);
   } catch (NotConnectedException e) {
     TinkerforgeErrorHandler.handleError(
         this, TinkerforgeErrorHandler.TF_NOT_CONNECTION_EXCEPTION, e);
   }
 }