当前位置: 首页>>代码示例>>Java>>正文


Java W1Master类代码示例

本文整理汇总了Java中com.pi4j.io.w1.W1Master的典型用法代码示例。如果您正苦于以下问题:Java W1Master类的具体用法?Java W1Master怎么用?Java W1Master使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


W1Master类属于com.pi4j.io.w1包,在下文中一共展示了W1Master类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.pi4j.io.w1.W1Master; //导入依赖的package包/类
public static void main(String args[]) throws InterruptedException, IOException {
    //W1Master w1Master = new W1Master("C:\\work\\pi4j\\pi4j-device\\target\\test-classes\\w1\\sys\\bus\\w1\\devices");
    W1Master w1Master = new W1Master();

    System.out.println(w1Master);

    for (TemperatureSensor device : w1Master.getDevices(TemperatureSensor.class)) {
        System.out.printf("%-20s %3.1f°C %3.1f°F\n", device.getName(), device.getTemperature(),
                device.getTemperature(TemperatureScale.FARENHEIT));
    }

    System.out.println("Exiting W1TempExample");
}
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:14,代码来源:W1TempExample.java

示例2: start

import com.pi4j.io.w1.W1Master; //导入依赖的package包/类
@Override
public void start(Future<Void> fut) throws Exception {

    // Sensors
    sensors.put(1, null);
    sensors.put(2, null);

    // W1 Bus init
    W1Master w1Master = new W1Master();

    // Get DS18B20 Temp device objects
    for (TemperatureSensor device : w1Master.getDevices(TemperatureSensor.class)) {
        if (device.getName().contains("28-0000062d006a")) sensor1 = device;
        if (device.getName().contains("28-0000062d1425")) sensor2 = device;
    }

    // Read the 2 temp sensors "immediately"
    readTemp(event -> {
        log.info("Temp sensor reading finished");
        fut.complete();
    });
    // .. and continue refreshing the 2 temp. sensors every minute
    vertx.setPeriodic(2000, event -> {
        readTemp(event1 -> {
            log.info("Temp sensor reading finished");
            // JSON message construction
            JsonObject msg = new JsonObject();
            msg.put("sensor1", sensors.get(1));
            msg.put("sensor2", sensors.get(2));
            // Message publishing
            vertx.eventBus().publish("sensors-temp", msg);
        });
    });

}
 
开发者ID:lhuet,项目名称:vertxOnRpiAndOdroid,代码行数:36,代码来源:Ds18b20Verticle.java

示例3: start

import com.pi4j.io.w1.W1Master; //导入依赖的package包/类
@Override
public void start(Future<Void> fut) throws Exception {

    // Sensors
    sensors.put(1, null);
    sensors.put(2, null);

    // W1 Bus init
    W1Master w1Master = new W1Master();

    // Get DS18B20 Temp device objects
    for (TemperatureSensor device : w1Master.getDevices(TemperatureSensor.class)) {
        if (device.getName().contains("28-0000062d006a")) sensor1 = device;
        if (device.getName().contains("28-0000062d1425")) sensor2 = device;
    }

    // Read the 2 temp sensors "immediately"
    readTemp(event -> fut.complete());
    // .. and continue refreshing the 2 temp. sensors every minute
    vertx.setPeriodic(2000, event -> {
        readTemp(event1 -> log.info("Temp sensor reading ok : " + sensors.get(1) + " / " + sensors.get(2)));
    });

    // Handler to serve the sensors values on the vertx event loop
    MessageConsumer<String> dhwConsumer = vertx.eventBus().consumer("sensor-temp");
    dhwConsumer.handler(event -> {
        String sensorId = event.body();
        if (sensorId.equals("1")) {
            event.reply(sensors.get(1));
        }
        else if (sensorId.equals("2")) {
            event.reply(sensors.get(2));
        }
        else {
            event.fail(-1, "Bad sensor Id");
        }
    });

}
 
开发者ID:lhuet,项目名称:vertxOnRpiAndOdroid,代码行数:40,代码来源:Ds18b20Verticle.java

示例4: start

import com.pi4j.io.w1.W1Master; //导入依赖的package包/类
@Override
public void start(Future<Void> fut) throws Exception {

    // Sensors
    sensors.put(1, null);
    sensors.put(2, null);

    // W1 Bus init
    W1Master w1Master = new W1Master();

    // Get DS18B20 Temp device objects
    for (TemperatureSensor device : w1Master.getDevices(TemperatureSensor.class)) {
        if (device.getName().contains("28-0000062d006a")) sensor1 = device;
        if (device.getName().contains("28-0000062d1425")) sensor2 = device;
    }

    // Read the 2 temp sensors "immediately"
    readTemp(event -> fut.complete());
    // .. and continue refreshing the 2 temp. sensors every minute
    vertx.setPeriodic(2000, event -> {
        readTemp(event1 -> {
            log.info("Temp sensor reading ok : " + sensors.get(1) + " / " + sensors.get(2));
            // Broadcast message
            vertx.eventBus().publish("sensors-temp-publish", new JsonObject().put("sensor1", sensors.get(1))
                                                                             .put("sensor2", sensors.get(2)));
        });
    });

    // Handler to serve the sensors values on the vertx event loop
    MessageConsumer<String> dhwConsumer = vertx.eventBus().consumer("sensor-temp");
    dhwConsumer.handler(event -> {
        String sensorId = event.body();
        if (sensorId.equals("1")) {
            event.reply(sensors.get(1));
        }
        else if (sensorId.equals("2")) {
            event.reply(sensors.get(2));
        }
        else {
            event.fail(-1, "Bad sensor Id");
        }
    });

}
 
开发者ID:lhuet,项目名称:vertxOnRpiAndOdroid,代码行数:45,代码来源:Ds18b20Verticle.java

示例5: start

import com.pi4j.io.w1.W1Master; //导入依赖的package包/类
@Override
public void start(Future<Void> fut) throws Exception {

    // Sensors
    sensors.put(1, null);
    sensors.put(2, null);

    // W1 Bus init
    W1Master w1Master = new W1Master();

    // Get DS18B20 Temp device objects
    for (TemperatureSensor device : w1Master.getDevices(TemperatureSensor.class)) {
        if (device.getName().contains("28-0000062d006a")) sensor1 = device;
        if (device.getName().contains("28-0000062d1425")) sensor2 = device;
    }

    // Read the 2 temp sensors "immediately"
    readTemp(event -> {
        log.info("Temp sensor reading finished");
        fut.complete();
    });
    // .. and continue refreshing the 2 temp. sensors every minute
    vertx.setPeriodic(2000, event -> {
        readTemp(event1 -> log.info("Temp sensor reading finished"));
    });

    // Handler to serve the sensors values on the vertx event loop
    MessageConsumer<String> dhwConsumer = vertx.eventBus().consumer("sensor-temp");
    dhwConsumer.handler(event -> {
        String sensorId = event.body();
        if (sensorId.equals("1")) {
            event.reply(sensors.get(1));
        }
        else if (sensorId.equals("2")) {
            event.reply(sensors.get(2));
        }
        else {
            event.fail(-1, "Bad sensor Id");
        }
    });

}
 
开发者ID:lhuet,项目名称:vertxOnRpiAndOdroid,代码行数:43,代码来源:Ds18b20Verticle.java


注:本文中的com.pi4j.io.w1.W1Master类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。