// 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();
  }
예제 #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();
  }
예제 #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) {
    }
  }
  @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);
  }
  // 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();
  }