// Note: To make the example code cleaner we do not handle exceptions. Exceptions
  //       you might normally want to catch are described in the documentation
  public static void main(String args[]) throws Exception {
    IPConnection ipcon = new IPConnection(); // Create IP connection
    BrickletTemperature t = new BrickletTemperature(UID, ipcon); // Create device object

    ipcon.connect(HOST, PORT); // Connect to brickd
    // Don't use device before ipcon is connected

    // Get threshold callbacks with a debounce time of 10 seconds (10000ms)
    t.setDebouncePeriod(10000);

    // Add temperature reached listener (parameter has unit °C/100)
    t.addTemperatureReachedListener(
        new BrickletTemperature.TemperatureReachedListener() {
          public void temperatureReached(short temperature) {
            System.out.println("Temperature: " + temperature / 100.0 + " °C");
            System.out.println("It is too hot, we need air conditioning!");
          }
        });

    // Configure threshold for temperature "greater than 30 °C" (unit is °C/100)
    t.setTemperatureCallbackThreshold('>', (short) (30 * 100), (short) 0);

    System.out.println("Press key to exit");
    System.in.read();
    ipcon.disconnect();
  }
  // Note: To make the example code cleaner we do not handle exceptions. Exceptions
  //       you might normally want to catch are described in the documentation
  public static void main(String args[]) throws Exception {
    IPConnection ipcon = new IPConnection(); // Create IP connection
    BrickletColor c = new BrickletColor(UID, ipcon); // Create device object

    ipcon.connect(HOST, PORT); // Connect to brickd
    // Don't use device before ipcon is connected

    // Get threshold callbacks with a debounce time of 10 seconds (10000ms)
    c.setDebouncePeriod(10000);

    // Add color reached listener
    c.addColorReachedListener(
        new BrickletColor.ColorReachedListener() {
          public void colorReached(int r, int g, int b, int c) {
            System.out.println("Color[R]: " + r);
            System.out.println("Color[G]: " + g);
            System.out.println("Color[B]: " + b);
            System.out.println("Color[C]: " + c);
            System.out.println("");
          }
        });

    // Configure threshold for color "greater than 100, 200, 300, 400"
    c.setColorCallbackThreshold('>', 100, 0, 200, 0, 300, 0, 400, 0);

    System.out.println("Press key to exit");
    System.in.read();
    ipcon.disconnect();
  }
Exemplo n.º 3
0
  // Note: To make the examples code cleaner we do not handle exceptions. Exceptions you
  //       might normally want to catch are described in the documentation
  public static void main(String args[]) throws Exception {
    IPConnection ipcon = new IPConnection(); // Create IP connection
    BrickMaster master = new BrickMaster(UID, ipcon); // Create device object

    ipcon.connect(host, port); // Connect to brickd
    // Don't use device before ipcon is connected

    // Get voltage and current from stack (in mV/mA)
    int voltage = master.getStackVoltage();
    int current = master.getStackCurrent();

    System.out.println("Stack Voltage: " + voltage / 1000.0 + " V");
    System.out.println("Stack Current: " + current / 1000.0 + " A");

    System.console().readLine("Press key to exit\n");
    ipcon.disconnect();
  }
Exemplo n.º 4
0
  public static void main(String args[]) {
    ipcon = new IPConnection();

    while (true) {
      try {
        ipcon.connect(HOST, PORT);
        break;
      } catch (java.net.UnknownHostException e) {
      } catch (java.io.IOException e) {
      } catch (com.tinkerforge.AlreadyConnectedException e) {
      }

      try {
        Thread.sleep(1000);
      } catch (InterruptedException ei) {
      }
    }

    smokeListener = new SmokeListener(ipcon);
    ipcon.addEnumerateListener(smokeListener);
    ipcon.addConnectedListener(smokeListener);

    while (true) {
      try {
        ipcon.enumerate();
        break;
      } catch (com.tinkerforge.NotConnectedException e) {
      }

      try {
        Thread.sleep(1000);
      } catch (InterruptedException ei) {
      }
    }

    try {
      System.out.println("Press key to exit");
      System.in.read();
    } catch (java.io.IOException e) {
    }

    try {
      ipcon.disconnect();
    } catch (com.tinkerforge.NotConnectedException e) {
    }
  }
Exemplo n.º 5
0
  public static void main(String[] args) throws Exception {

    IPConnection ip = new IPConnection("localhost", 4223);

    BrickletLinearPoti poti = new BrickletLinearPoti("bxs");
    final BrickletLCD20x4 lcd = new BrickletLCD20x4("bfL");
    final BrickletDistanceIR dist = new BrickletDistanceIR("aUM");

    ip.addDevice(lcd);
    ip.addDevice(poti);
    ip.addDevice(dist);

    poti.setPositionCallbackPeriod(500L);
    lcd.clearDisplay();
    lcd.backlightOn();
    lcd.writeLine((short) 0, (short) 0, "Tinkering /w LinPoti");

    poti.addListener(
        new BrickletLinearPoti.PositionListener() {

          @Override
          public void position(int position) {
            System.out.println("Position: " + position);
            lcd.writeLine((short) 1, (short) 0, "Position: " + position + "   ");
          }
        });

    dist.setDistanceCallbackPeriod(2000);
    dist.addListener(
        new BrickletDistanceIR.DistanceListener() {
          @Override
          public void distance(int distance) {
            System.out.println("Distance: " + distance);
            lcd.writeLine((short) 2, (short) 0, "Distance: " + distance + "   ");
          }
        });

    System.in.read();

    ip.destroy();
  }
  // Note: To make the example code cleaner we do not handle exceptions. Exceptions you
  //       might normally want to catch are described in the documentation
  public static void main(String args[]) throws Exception {
    IPConnection ipcon = new IPConnection(); // Create IP connection
    BrickletIndustrialDigitalIn4 idi4 =
        new BrickletIndustrialDigitalIn4(UID, ipcon); // Create device object

    ipcon.connect(HOST, PORT); // Connect to brickd
    // Don't use device before ipcon is connected

    // Add and implement listener for interrupt (called if pin 0 changes)
    idi4.addInterruptListener(
        new BrickletIndustrialDigitalIn4.InterruptListener() {
          public void interrupt(int interruptMask, int valueMask) {
            System.out.println("Interrupt by: " + Integer.toBinaryString(interruptMask));
            System.out.println("Value: " + Integer.toBinaryString(valueMask));
          }
        });

    // Enable interrupt on pin 0
    idi4.setInterrupt(1 << 0);

    System.out.println("Press key to exit");
    System.in.read();
    ipcon.disconnect();
  }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 @Override
 public boolean eIsSet(int featureID) {
   switch (featureID) {
     case ModelPackage.MBRICKLET_DUST_DETECTOR__LOGGER:
       return LOGGER_EDEFAULT == null ? logger != null : !LOGGER_EDEFAULT.equals(logger);
     case ModelPackage.MBRICKLET_DUST_DETECTOR__UID:
       return UID_EDEFAULT == null ? uid != null : !UID_EDEFAULT.equals(uid);
     case ModelPackage.MBRICKLET_DUST_DETECTOR__POLL:
       return poll != POLL_EDEFAULT;
     case ModelPackage.MBRICKLET_DUST_DETECTOR__ENABLED_A:
       return ENABLED_A_EDEFAULT == null ? enabledA != null : !ENABLED_A_EDEFAULT.equals(enabledA);
     case ModelPackage.MBRICKLET_DUST_DETECTOR__TINKERFORGE_DEVICE:
       return tinkerforgeDevice != null;
     case ModelPackage.MBRICKLET_DUST_DETECTOR__IP_CONNECTION:
       return IP_CONNECTION_EDEFAULT == null
           ? ipConnection != null
           : !IP_CONNECTION_EDEFAULT.equals(ipConnection);
     case ModelPackage.MBRICKLET_DUST_DETECTOR__CONNECTED_UID:
       return CONNECTED_UID_EDEFAULT == null
           ? connectedUid != null
           : !CONNECTED_UID_EDEFAULT.equals(connectedUid);
     case ModelPackage.MBRICKLET_DUST_DETECTOR__POSITION:
       return position != POSITION_EDEFAULT;
     case ModelPackage.MBRICKLET_DUST_DETECTOR__DEVICE_IDENTIFIER:
       return deviceIdentifier != DEVICE_IDENTIFIER_EDEFAULT;
     case ModelPackage.MBRICKLET_DUST_DETECTOR__NAME:
       return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
     case ModelPackage.MBRICKLET_DUST_DETECTOR__BRICKD:
       return getBrickd() != null;
     case ModelPackage.MBRICKLET_DUST_DETECTOR__SENSOR_VALUE:
       return sensorValue != null;
     case ModelPackage.MBRICKLET_DUST_DETECTOR__TF_CONFIG:
       return tfConfig != null;
     case ModelPackage.MBRICKLET_DUST_DETECTOR__CALLBACK_PERIOD:
       return callbackPeriod != CALLBACK_PERIOD_EDEFAULT;
     case ModelPackage.MBRICKLET_DUST_DETECTOR__DEVICE_TYPE:
       return DEVICE_TYPE_EDEFAULT == null
           ? deviceType != null
           : !DEVICE_TYPE_EDEFAULT.equals(deviceType);
     case ModelPackage.MBRICKLET_DUST_DETECTOR__THRESHOLD:
       return THRESHOLD_EDEFAULT == null
           ? threshold != null
           : !THRESHOLD_EDEFAULT.equals(threshold);
   }
   return super.eIsSet(featureID);
 }
Exemplo n.º 8
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 @Override
 public boolean eIsSet(int featureID) {
   switch (featureID) {
     case ModelPackage.MBRICKLET_LED_STRIP__COLOR:
       return COLOR_EDEFAULT == null ? color != null : !COLOR_EDEFAULT.equals(color);
     case ModelPackage.MBRICKLET_LED_STRIP__LOGGER:
       return LOGGER_EDEFAULT == null ? logger != null : !LOGGER_EDEFAULT.equals(logger);
     case ModelPackage.MBRICKLET_LED_STRIP__UID:
       return UID_EDEFAULT == null ? uid != null : !UID_EDEFAULT.equals(uid);
     case ModelPackage.MBRICKLET_LED_STRIP__POLL:
       return poll != POLL_EDEFAULT;
     case ModelPackage.MBRICKLET_LED_STRIP__ENABLED_A:
       return ENABLED_A_EDEFAULT == null ? enabledA != null : !ENABLED_A_EDEFAULT.equals(enabledA);
     case ModelPackage.MBRICKLET_LED_STRIP__TINKERFORGE_DEVICE:
       return tinkerforgeDevice != null;
     case ModelPackage.MBRICKLET_LED_STRIP__IP_CONNECTION:
       return IP_CONNECTION_EDEFAULT == null
           ? ipConnection != null
           : !IP_CONNECTION_EDEFAULT.equals(ipConnection);
     case ModelPackage.MBRICKLET_LED_STRIP__CONNECTED_UID:
       return CONNECTED_UID_EDEFAULT == null
           ? connectedUid != null
           : !CONNECTED_UID_EDEFAULT.equals(connectedUid);
     case ModelPackage.MBRICKLET_LED_STRIP__POSITION:
       return position != POSITION_EDEFAULT;
     case ModelPackage.MBRICKLET_LED_STRIP__DEVICE_IDENTIFIER:
       return deviceIdentifier != DEVICE_IDENTIFIER_EDEFAULT;
     case ModelPackage.MBRICKLET_LED_STRIP__NAME:
       return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
     case ModelPackage.MBRICKLET_LED_STRIP__BRICKD:
       return getBrickd() != null;
     case ModelPackage.MBRICKLET_LED_STRIP__TF_CONFIG:
       return tfConfig != null;
     case ModelPackage.MBRICKLET_LED_STRIP__MSUBDEVICES:
       return msubdevices != null && !msubdevices.isEmpty();
     case ModelPackage.MBRICKLET_LED_STRIP__DEVICE_TYPE:
       return DEVICE_TYPE_EDEFAULT == null
           ? deviceType != null
           : !DEVICE_TYPE_EDEFAULT.equals(deviceType);
     case ModelPackage.MBRICKLET_LED_STRIP__COLOR_MAPPING:
       return COLOR_MAPPING_EDEFAULT == null
           ? colorMapping != null
           : !COLOR_MAPPING_EDEFAULT.equals(colorMapping);
   }
   return super.eIsSet(featureID);
 }
Exemplo n.º 9
0
  public void connected(short connectedReason) {
    if (connectedReason == IPConnection.CONNECT_REASON_AUTO_RECONNECT) {
      System.out.println("Auto Reconnect");

      while (true) {
        try {
          ipcon.enumerate();
          break;
        } catch (com.tinkerforge.NotConnectedException e) {
        }

        try {
          Thread.sleep(1000);
        } catch (InterruptedException ei) {
        }
      }
    }
  }
 // THIS METHOD IS AUTOMATICALLY CALLED IN THE BACKGROUND:
 @Override
 protected boolean createKeys(final List<DeviceIdentifier> list) {
   try {
     ipc = new IPConnection(host, port);
     ipc.enumerate(
         new IPConnection.EnumerateListener() {
           @Override
           public void enumerate(String uid, String name, short stackID, boolean isNew) {
             if (isNew) {
               list.add(new DeviceIdentifier(name, uid, stackID));
             } else {
               refresh(false);
             }
           }
         });
   } catch (IOException ex) {
   }
   return true;
 }
  @Before
  public void before(TestContext context) {
    String uid = "tem";
    String host = "localhost";
    int port = 1234;
    JsonObject emuconfig =
        new JsonObject()
            .put(
                "devices",
                new JsonArray()
                    .add(
                        new JsonObject()
                            .put("type", "BrickletTemperature")
                            .put("uid", uid)
                            .put("enabled", true)));
    System.out.println(emuconfig.encodePrettily());
    DeploymentOptions deploymentOptions = new DeploymentOptions().setConfig(emuconfig);

    vertx = Vertx.vertx();
    Async async = context.async();
    vertx.deployVerticle(
        "org.m1theo.tfemulator.Brickd",
        deploymentOptions,
        res -> {
          async.complete();
        });
    ipcon = new IPConnection(); // Create IP connection
    try {
      try {
        Thread.sleep(100);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      ipcon.connect(host, port);
    } catch (AlreadyConnectedException | IOException e) {
      context.fail(e);
    }
    device = new BrickletTemperature(uid, ipcon);
  }
  @Override
  protected Node[] createNodesForKey(DeviceIdentifier model) {
    ArrayList<Node> nodes = new ArrayList<>();
    try {
      Device device = null;
      DeviceIdentifier tmpDM = model;
      String cutted = tmpDM.getName().substring(0, tmpDM.getName().trim().length() - 4).trim();
      switch (cutted) {
        case "Ambient Light Bricklet":
          device = new BrickletAmbientLight(tmpDM.getUid());
          nodes.add(new AmbientLightNode(device));
          break;
        case "AnalogIn Bricklet":
          device = new BrickletAnalogIn(tmpDM.getUid());
          break;
        case "AnalogOut Bricklet":
          device = new BrickletAnalogOut(tmpDM.getUid());
          break;
        case "Buzzer Bricklet":
          device = new BrickletPiezoBuzzer(tmpDM.getUid());
          break;
        case "Current12 Bricklet":
          device = new BrickletCurrent12(tmpDM.getUid());
          break;
        case "Current25 Bricklet":
          device = new BrickletCurrent25(tmpDM.getUid());
          break;
        case "DC Brick":
          device = new BrickDC(tmpDM.getUid());
          break;
        case "Distance IR Bricklet":
          device = new BrickletDistanceIR(tmpDM.getUid());
          nodes.add(new DistanceIRNode(device));
          break;
        case "Humidity Bricklet":
          device = new BrickletHumidity(tmpDM.getUid());
          break;
        case "IMU Brick":
          device = new BrickIMU(tmpDM.getUid());
          break;
        case "IO-16 Bricklet":
          BrickletIO16 io16 = new BrickletIO16(tmpDM.getUid());
          device = io16;
          nodes.add(new IO16Node(io16));
          break;
        case "IO-4 Bricklet":
          device = new BrickletIO4(tmpDM.getUid());
          break;
        case "Joystick Bricklet":
          device = new BrickletJoystick(tmpDM.getUid());
          break;
        case "LCD 16x2 Bricklet":
          device = new BrickletLCD16x2(tmpDM.getUid());
          break;
        case "LCD 20x4 Bricklet":
          device = new BrickletLCD20x4(tmpDM.getUid());
          nodes.add(new LCD2044Node(device));
          break;
        case "Master Brick":
          BrickMaster bm = new BrickMaster(tmpDM.getUid());
          device = bm;
          nodes.add(new BrickMasterNode(bm));
          break;
        case "Linear Poti Bricklet":
          BrickletLinearPoti blp = new BrickletLinearPoti(tmpDM.getUid());
          device = blp;
          nodes.add(new LinearPotiNode(blp));
          break;
        case "Rotary Poti Bricklet":
          device = new BrickletRotaryPoti(tmpDM.getUid());
          break;
        case "Relay Dual Bricklet":
          device = new BrickletDualRelay(tmpDM.getUid());
          break;
        case "Servo Brick":
          device = new BrickServo(tmpDM.getUid());
          break;
        case "Stepper Brick":
          device = new BrickStepper(tmpDM.getUid());
          break;
        case "Temperature AmbientBricklet":
          device = new BrickletTemperature(tmpDM.getUid());
          break;
        case "Temperature IR Bricklet":
          device = new BrickletTemperatureIR(tmpDM.getUid());
          break;
        case "Voltage Bricklet":
          device = new BrickletVoltage(tmpDM.getUid());
          break;
        case "Chibi Extension":
        case "StepDown Brick":
        case "RS485 Extension":
      }

      try {
        if (device != null) {
          ipc.addDevice(device);
        }
      } catch (TimeoutException ex) {
        Exceptions.printStackTrace(ex);
      }

      model.setDeviceType(device);
    } catch (IntrospectionException ex) {
      Exceptions.printStackTrace(ex);
    }
    return (nodes.toArray(new Node[nodes.size()]));
  }