当前位置: 首页>>代码示例>>Java>>正文


Java GpioPin类代码示例

本文整理汇总了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))
}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:20,代码来源:PickToLight.java

示例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;
	}
 
开发者ID:Ardulink,项目名称:Ardulink-1,代码行数:19,代码来源:RaspberryPIConnection.java

示例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))
}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:18,代码来源:PickToLight.java

示例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);
}
   }
 
开发者ID:PoJD,项目名称:hawa,代码行数:21,代码来源:GpioImpl.java

示例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);
                }
            }
        }
    }
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:29,代码来源:MCP23017Binding.java

示例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();
}
 
开发者ID:Ardulink,项目名称:Ardulink-2,代码行数:13,代码来源:PiLink.java

示例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);
}
 
开发者ID:Ardulink,项目名称:Ardulink-2,代码行数:12,代码来源:PiLink.java

示例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();
    }
}
 
开发者ID:marcandreuf,项目名称:sunfounder-sensors-raspi-4j,代码行数:12,代码来源:BaseSketch.java

示例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);
}
 
开发者ID:osgi,项目名称:osgi.iot.contest.sdk,代码行数:15,代码来源:SignalSegmentImpl.java

示例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());
           		}
           	}
           }
           
       });
}
 
开发者ID:osgi,项目名称:osgi.iot.contest.sdk,代码行数:34,代码来源:MicroSwitchSegmentImpl.java

示例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);
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:12,代码来源:Mcp23017Handler.java

示例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);
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:14,代码来源:MCP23017Binding.java

示例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.");
    }
 
开发者ID:uwigem,项目名称:uwigem2017,代码行数:62,代码来源:MCP3424GpioExample.java

示例14: getProvisionedPins

import com.pi4j.io.gpio.GpioPin; //导入依赖的package包/类
@Override
public Collection<GpioPin> getProvisionedPins() {
    return delegate.getProvisionedPins();
}
 
开发者ID:fustinoni-net,项目名称:PiRobotPlatform,代码行数:5,代码来源:BaseRobot.java

示例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);
}
 
开发者ID:fustinoni-net,项目名称:PiRobotPlatform,代码行数:5,代码来源:BaseRobot.java


注:本文中的com.pi4j.io.gpio.GpioPin类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。