本文整理汇总了Java中com.pi4j.io.gpio.GpioPin类的典型用法代码示例。如果您正苦于以下问题:Java GpioPin类的具体用法?Java GpioPin怎么用?Java GpioPin使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GpioPin类属于com.pi4j.io.gpio包,在下文中一共展示了GpioPin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleGpioPinDigitalStateChangeEvent
import com.pi4j.io.gpio.GpioPin; //导入依赖的package包/类
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
// display pin state on console
System.out.println(" --> GPIO PIN STATE CHANGE: " + event.getPin() + " [" + event.getPin().getName() + "]" + " = " + event.getState());
GpioPin pin = event.getPin();
/*
* if (pin.getName().equals("GPIO 0")) {
* modules.get("01").blinkOff("ok"); } else if
* (pin.getName().equals("GPIO 1")) { modules.get("02").blinkOff("ok");
* } else if (pin.getName().equals("GPIO 2")) {
* modules.get("03").blinkOff("ok"); } else if
* (pin.getName().equals("GPIO 3")) { modules.get("04").blinkOff("ok");
* }
*/
// if (pin.getName().equals(anObject))
}
示例2: getPin
import com.pi4j.io.gpio.GpioPin; //导入依赖的package包/类
private GpioPin getPin(int address) {
GpioPin retvalue = null;
Collection<GpioPin> provisioned = gpioController.getProvisionedPins();
for (GpioPin gpioPin : provisioned) {
if(gpioPin.getPin().getAddress() == address) {
retvalue = gpioPin;
break;
}
}
if(retvalue == null) {
retvalue = gpioController.provisionPin(RaspiPin.getPinByName("GPIO " + address), PinMode.DIGITAL_OUTPUT);
}
return retvalue;
}
示例3: handleGpioPinDigitalStateChangeEvent
import com.pi4j.io.gpio.GpioPin; //导入依赖的package包/类
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
// display pin state on console
System.out.println(" --> GPIO PIN STATE CHANGE: " + event.getPin() + " [" + event.getPin().getName() + "]" + " = " + event.getState());
GpioPin pin = event.getPin();
log.info("GPIOPin: {}", pin);
/*
* if (pin.getName().equals("GPIO 0")) { modules.get("01").blinkOff("ok"); }
* else if (pin.getName().equals("GPIO 1")) {
* modules.get("02").blinkOff("ok"); } else if (pin.getName().equals(
* "GPIO 2")) { modules.get("03").blinkOff("ok"); } else if
* (pin.getName().equals("GPIO 3")) { modules.get("04").blinkOff("ok"); }
*/
// if (pin.getName().equals(anObject))
}
示例4: destroy
import com.pi4j.io.gpio.GpioPin; //导入依赖的package包/类
@Override
public void destroy() throws Exception {
LOG.info("Cleaning up in GpioImpl: Shutting down and unprovisioning...");
try {
if (LOG.isDebugEnabled()) {
LOG.debug("Shutting down...");
}
// this should also unexport and reset states
shutdown();
if (LOG.isDebugEnabled()) {
LOG.debug("Done. Unprovisioning pins: " + getProvisionedPins());
}
unprovisionPin(getProvisionedPins().toArray(new GpioPin[] {}));
if (LOG.isDebugEnabled()) {
LOG.debug("Done. ");
}
} catch (Exception e) {
LOG.warn("Unable to cleanup GPIO...", e);
}
}
示例5: internalReceiveCommand
import com.pi4j.io.gpio.GpioPin; //导入依赖的package包/类
/**
* @{inheritDoc}
*/
@Override
protected void internalReceiveCommand(String itemName, Command command) {
// the code being executed when a command was sent on the openHAB
// event bus goes here. This method is only called if one of the
// BindingProviders provide a binding for the given 'itemName'.
logger.debug("internalReceiveCommand({},{}) is called!", itemName, command);
// the configuration is guaranteed not to be null, because the component
// definition has the configuration-policy set to require. If set to
// 'optional' then the configuration may be null
if (command instanceof OnOffType) {
final OnOffType switchCommand = (OnOffType) command;
for (MCP23017BindingProvider provider : this.providers) {
if (provider.providesBindingFor(itemName)) {
GpioPin pin = gpioPins.get(itemName);
if (switchCommand == OnOffType.OFF) {
gpio.setState(PinState.LOW, (GpioPinDigitalOutput) pin);
} else if (switchCommand == OnOffType.ON) {
gpio.setState(PinState.HIGH, (GpioPinDigitalOutput) pin);
}
}
}
}
}
示例6: stopListening
import com.pi4j.io.gpio.GpioPin; //导入依赖的package包/类
@Override
public long stopListening(Pin pin) throws IOException {
GpioPin gpioPin = getOrCreate(pin.pinNum(), pi4jInputMode(pin));
List<GpioPinListener> list = listeners.asMap().get(gpioPin);
if (list != null) {
for (GpioPinListener gpioPinListener : list) {
gpioPin.removeListener(gpioPinListener);
listeners.remove(gpioPin, gpioPinListener);
}
}
return MessageIdHolders.NO_ID.getId();
}
示例7: getOrCreate
import com.pi4j.io.gpio.GpioPin; //导入依赖的package包/类
private GpioPin getOrCreate(int address, PinMode pinMode) {
for (GpioPin gpioPin : gpioController.getProvisionedPins()) {
com.pi4j.io.gpio.Pin pin = gpioPin.getPin();
if (pin.getAddress() == address) {
checkState(pin.getSupportedPinModes().contains(pinMode),
"Pin %s does not provide %s", pin, pinMode);
return gpioPin;
}
}
return create(address, pinMode);
}
示例8: tearDown
import com.pi4j.io.gpio.GpioPin; //导入依赖的package包/类
protected void tearDown() {
logger.debug("Shutting down gpio.");
if(gpio != null){
for(GpioPin pin : gpio.getProvisionedPins()){
if(pin.getMode().equals(PinMode.DIGITAL_OUTPUT)){
pin.setShutdownOptions(true, PinState.LOW, PinPullResistance.OFF);
}
}
gpio.shutdown();
}
}
示例9: setup
import com.pi4j.io.gpio.GpioPin; //导入依赖的package包/类
private GpioPinDigitalOutput setup(String name) {
Pin pin = RaspiPin.getPinByName(name);
if (pin == null) {
info("Pin<{}> is null", name);
return null;
}
for (GpioPin e : gpio.getProvisionedPins()) {
if (e.getPin().equals(pin)) {
gpio.unprovisionPin(e);
break;
}
}
return this.gpio.provisionDigitalOutputPin(pin);
}
示例10: activate
import com.pi4j.io.gpio.GpioPin; //导入依赖的package包/类
@Activate
void activate(Config config) {
this.config = config;
Pin pin = RaspiPin.getPinByName(config.pin());
if ( pin == null) {
System.out.println("Pin is " + config.pin() + " is null");
}
for (GpioPin e : gpio.getProvisionedPins()) {
if (e.getPin().equals(pin)) {
gpio.unprovisionPin(e);
break;
}
}
GpioPinDigitalInput microSwitch = gpio.provisionDigitalInputPin(pin, PinPullResistance.PULL_DOWN);
microSwitch.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
// display pin state on console
if(event.getState() == PinState.LOW){
if (System.currentTimeMillis() > debounce) {
System.out.println("RFID triggered at controller "+config.controller_id());
debounce = System.currentTimeMillis() + 1000L;
trigger(config.rfid());
}
else {
System.out.println("ignored RFID triggered at controller "+config.controller_id());
}
}
}
});
}
示例11: handleGpioPinDigitalStateChangeEvent
import com.pi4j.io.gpio.GpioPin; //导入依赖的package包/类
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
GpioPin pin = event.getPin();
OpenClosedType state = OpenClosedType.CLOSED;
if (event.getState() == PinState.LOW) {
state = OpenClosedType.OPEN;
}
ChannelUID channelForPin = pinStateHolder.getChannelForInputPin((GpioPinDigitalInput) pin);
logger.debug("updating channel {} with state {}", channelForPin, state);
updateState(channelForPin, state);
}
示例12: handleGpioPinDigitalStateChangeEvent
import com.pi4j.io.gpio.GpioPin; //导入依赖的package包/类
/**
* @{inheritDoc}
*/
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
GpioPin pin = event.getPin();
OpenClosedType state = OpenClosedType.CLOSED; // Assume we are high...
if (event.getState() == PinState.LOW) { // To err is human...
state = OpenClosedType.OPEN;
}
this.eventPublisher.postUpdate(pin.getName(), state);
logger.debug("GPIO pin state change: {} = {}", pin, state);
}
示例13: main
import com.pi4j.io.gpio.GpioPin; //导入依赖的package包/类
public static void main(String args[]) throws InterruptedException, UnsupportedBusNumberException, IOException {
System.out.println("<--Pi4J--> MCP3424 GPIO Example ... started.");
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// create custom MCP3424 GPIO provider
final MCP3424GpioProvider provider = new MCP3424GpioProvider(I2CBus.BUS_1, 0x6C, 18, 1);
// provision gpio input pins from MCP3424
GpioPinAnalogInput inputs[] = { gpio.provisionAnalogInputPin(provider, MCP3424Pin.GPIO_CH0, "Channel-0"),
gpio.provisionAnalogInputPin(provider, MCP3424Pin.GPIO_CH1, "Channel-1"),
gpio.provisionAnalogInputPin(provider, MCP3424Pin.GPIO_CH2, "Channel-2"),
gpio.provisionAnalogInputPin(provider, MCP3424Pin.GPIO_CH3, "Channel-3") };
// Define the amount that the ADC input conversion value must change before
// a 'GpioPinAnalogValueChangeEvent' is raised. This is used to prevent unnecessary
// event dispatching for an analog input that may have an acceptable or expected
// range of value drift.
provider.setEventThreshold(0, inputs); // all inputs; alternatively you can set thresholds on each input discretely
// Print current analog input conversion values from each input channel
for(GpioPinAnalogInput input : inputs){
System.out.print("<INITIAL VALUE> [" + input.getName() + "] : RAW VALUE = " + input.getValue());
System.out.println(" -> " + provider.getAnalogValue(input.getPin()) + " V");
}
// create and register gpio pin listener
gpio.addListener(new GpioPinListenerAnalog() {
@Override
public void handleGpioPinAnalogValueChangeEvent(GpioPinAnalogValueChangeEvent event) {
// get pin
GpioPin pin = event.getPin();
// get RAW value
double value = event.getValue();
// get Volt value
double analog = provider.getAnalogValue(pin.getPin());
// display output
System.out.print("<CHANGED VALUE> [" + pin + "] : RAW VALUE = " + value);
System.out.println(" -> " + analog + " V");
}
}, inputs);
provider.setMonitorInterval(50);
provider.setMonitorEnabled(true);
// Keep this sample program running for 10 minutes
for (int count = 0; count < 600; count++) {
Thread.sleep(1000);
}
// stop all GPIO activity/threads by shutting down the GPIO controller
// (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks)
gpio.shutdown();
System.out.println("<--Pi4J--> Exiting MCP3424 GPIO Example.");
}
示例14: getProvisionedPins
import com.pi4j.io.gpio.GpioPin; //导入依赖的package包/类
@Override
public Collection<GpioPin> getProvisionedPins() {
return delegate.getProvisionedPins();
}
示例15: provisionPin
import com.pi4j.io.gpio.GpioPin; //导入依赖的package包/类
@Override
public GpioPin provisionPin(GpioProvider provider, Pin pin, PinMode mode) {
return delegate.provisionPin(provider, pin, mode);
}