本文整理匯總了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");
}
示例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);
});
});
}
示例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");
}
});
}
示例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");
}
});
}
示例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");
}
});
}