本文整理汇总了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");
}
});
}