import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; import enroute.hw.io.pi.api.DHT11; import osgi.enroute.commands.annotation.Command; @Component(service = TemperatureCommand.class) public class TemperatureCommand { private DHT11 dht11; @Activate public void activate() { dht11 = new DHT11(); } @Command(scope = "temperature", name = "get", description = "Get current temperature") public String getCurrentTemperature() { double temperature = dht11.getTemperature(); return "Current temperature: " + temperature + "°C"; } @Command(scope = "temperature", name = "get-humidity", description = "Get current humidity") public String getCurrentHumidity() { double humidity = dht11.getHumidity(); return "Current humidity: " + humidity + "%"; } } temperature:get temperature:get-humidity


上一篇:
下一篇:
切换中文