當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。