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


Java GpioPinListenerDigital类代码示例

本文整理汇总了Java中com.pi4j.io.gpio.event.GpioPinListenerDigital的典型用法代码示例。如果您正苦于以下问题:Java GpioPinListenerDigital类的具体用法?Java GpioPinListenerDigital怎么用?Java GpioPinListenerDigital使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GpioPinListenerDigital类属于com.pi4j.io.gpio.event包,在下文中一共展示了GpioPinListenerDigital类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: SwitchImpl

import com.pi4j.io.gpio.event.GpioPinListenerDigital; //导入依赖的package包/类
public SwitchImpl (final RobotGPIO pi2goGPIO, Pin switchPin){

        button = pi2goGPIO.provisionDigitalInputPin(switchPin, PinPullResistance.PULL_UP);
        //button.setShutdownOptions(Boolean.TRUE, PinState.LOW, PinPullResistance.OFF);
//com.pi4j.io.gpio.exception.InvalidPinModeException: Invalid pin mode on pin [GPIO 14]; cannot setState() when pin mode is [input]
//at com.pi4j.io.gpio.GpioProviderBase.setState(GpioProviderBase.java:180)
//at com.pi4j.io.gpio.RaspiGpioProvider.setState(RaspiGpioProvider.java:150)
//	at com.pi4j.io.gpio.impl.GpioPinImpl.setState(GpioPinImpl.java:325)
//	at com.pi4j.io.gpio.impl.GpioControllerImpl.shutdown(GpioControllerImpl.java:939)
//	at com.pi4j.io.gpio.impl.GpioControllerImpl$ShutdownHook.run(GpioControllerImpl.java:888)

        // create and register gpio pin listeners
        button.addListener((GpioPinListenerDigital) (GpioPinDigitalStateChangeEvent event) -> {
            
            synchronized(this){
                if(event.getState().isLow()) lastLow = System.currentTimeMillis();
                if(event.getState().isHigh()) lastHigh = System.currentTimeMillis();
            }
            
            listeners.stream().forEach((listener) -> {
                listener.changedEvent(event.getState().isLow());
            });
        });
    }
 
开发者ID:fustinoni-net,项目名称:PiRobotPlatform,代码行数:25,代码来源:SwitchImpl.java

示例2: main

import com.pi4j.io.gpio.event.GpioPinListenerDigital; //导入依赖的package包/类
/**
 * Command-line interface.
 * @param args unused here.
 */
public static void main(String[] args) {
    RotaryEncoder rotaryEncoder = new RotaryEncoder(GPIOPin.GPIO_27, GPIOPin.GPIO_28, GPIOPin.GPIO_29);
    
    rotaryEncoder.getGpioPinDigitalInput().addListener((GpioPinListenerDigital)
            (GpioPinDigitalStateChangeEvent event) -> Tools.log(rotaryEncoder.isPressed() ? "rotary pressed" : "rotary released"));
    
    int previousCounterValue = rotaryEncoder.getCounterValue();
    while(true) {
        rotaryEncoder.getEncoderTurn();
        if(previousCounterValue != rotaryEncoder.getCounterValue()) {
            Tools.log(rotaryEncoder.getCounterValue());
            previousCounterValue = rotaryEncoder.getCounterValue();
        }
    }
}
 
开发者ID:Raspoid,项目名称:raspoid,代码行数:20,代码来源:RotaryEncoderExample.java

示例3: FlowMeterFlux

import com.pi4j.io.gpio.event.GpioPinListenerDigital; //导入依赖的package包/类
public FlowMeterFlux(GpioController gpioController, Pin flowMeterPin) {
		this.gpio = gpioController;
		this.pin = flowMeterPin;

		flowMeterEmitter = EmitterProcessor.create();
		flowMeterSink = flowMeterEmitter.connectSink();

		gpioInput = gpio.provisionDigitalInputPin(pin, PinPullResistance.PULL_DOWN);
		gpioInput.addListener(new GpioPinListenerDigital() {
			long counter = 0L;
			@Override
			public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
				counter++;
//				System.out.println(
//						"--> GPIO PIN STATE CHANGE " + event.getPin() + " " + event.getState() + " --> " + counter);
//				if (flowMeterSink.requestedFromDownstream() > 0)
//					System.out.println("--> " + flowMeterSink.emit(counter * MILILITERS_PER_IMPULS));
					flowMeterSink.emit(counter * MILILITERS_PER_IMPULS);
//				else
//					System.err.println("Error: Missed FlowMeter reading because of missing subscriber request.");
			}
		});
	}
 
开发者ID:iproduct,项目名称:course-social-robotics,代码行数:24,代码来源:FlowMeterFlux.java

示例4: start

import com.pi4j.io.gpio.event.GpioPinListenerDigital; //导入依赖的package包/类
@Override
public void start() {
	
	bufferZeroInterrupt.addListener(new GpioPinListenerDigital() {	    	 
    	  
		@Override
           public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
			// display pin state on console
               
			//System.out.println(" --> MESSAGE RECEIVED: " + event.getPin() + " = " + event.getState());
               
               if(event.getState() == PinState.LOW) {
               	
               	//Message is in RX0
               	manager.submitRead(readBufferZero());
               }
           }
       });
}
 
开发者ID:pglotfel,项目名称:ithinkican,代码行数:20,代码来源:MCP2515.java

示例5: setup

import com.pi4j.io.gpio.event.GpioPinListenerDigital; //导入依赖的package包/类
@Override
protected void setup(String[] args) {
    wiringPiSetup();
    ledPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01);        
    sigPin = gpio.provisionDigitalInputPin(RaspiPin.GPIO_00, PinPullResistance.PULL_DOWN);        
    sigPin.addListener(new GpioPinListenerDigital() {
        @Override
        public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
            if(event.getState().isLow()){
                logger.debug("Magic cup connected.");
                ledPin.high();
            }else{
                ledPin.low();
            }
        }
        
    });
    logger.debug("Magic cup sensor ready!");        
}
 
开发者ID:marcandreuf,项目名称:sunfounder-sensors-raspi-4j,代码行数:20,代码来源:Ex29_MagicCupListener.java

示例6: setup

import com.pi4j.io.gpio.event.GpioPinListenerDigital; //导入依赖的package包/类
@Override
protected void setup(String[] args) {
    wiringPiSetup();
    ledPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01);        
    tiltSwitch = gpio.provisionDigitalInputPin(RaspiPin.GPIO_00, PinPullResistance.PULL_DOWN);        
    tiltSwitch.addListener(new GpioPinListenerDigital() {
        @Override
        public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
            logger.debug("Tilt state: "+event.getState());
            if(event.getState().isHigh()){
                ledPin.high();
            }else{
                ledPin.low();
            }
        }            
    });
    logger.debug("Tilt switch sensor ready!"); 
}
 
开发者ID:marcandreuf,项目名称:sunfounder-sensors-raspi-4j,代码行数:19,代码来源:Ex15_TiltSwitchListener.java

示例7: setup

import com.pi4j.io.gpio.event.GpioPinListenerDigital; //导入依赖的package包/类
@Override
protected void setup(String[] args) {
    wiringPiSetup();
    ledPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01);        
    lightBreakPin = gpio.provisionDigitalInputPin(RaspiPin.GPIO_00, PinPullResistance.PULL_DOWN);        
    lightBreakPin.addListener(new GpioPinListenerDigital() {
        @Override
        public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
            if(event.getState().isHigh()){
                logger.debug("Light beam is broken");
                ledPin.high();
            }else{
                ledPin.low();
            }
        }
        
    });
    logger.debug("Light break ready!");        
}
 
开发者ID:marcandreuf,项目名称:sunfounder-sensors-raspi-4j,代码行数:20,代码来源:Ex14_LightBreakListener.java

示例8: setup

import com.pi4j.io.gpio.event.GpioPinListenerDigital; //导入依赖的package包/类
@Override
protected void setup(String[] args) {
    super.setup(args);
    if(args.length == 1){
        device_fileName = args[0];         
    }else{
        throw new RuntimeException(
                "Please provide a device file name from "
                        +Ex16_Ds18b20.W1_DEVICES_PATH);
    }
    ledRed = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_03);
    ledGreen = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04);
    ledBlue = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_05);
    beep = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_08);
    joyStick_Z = gpio.provisionDigitalInputPin(RaspiPin.GPIO_06, PinPullResistance.PULL_UP);
    joyStick_Z.addListener(new GpioPinListenerDigital() {
        @Override
        public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent gpdsce) {
            sys_state = PinState.LOW;
            logger.debug("interrupt occur !");
        }
    });
    sys_state = PinState.HIGH;
    logger.debug("Temperature monitor ready!");                
}
 
开发者ID:marcandreuf,项目名称:sunfounder-sensors-raspi-4j,代码行数:26,代码来源:Ex30_TempMonitor.java

示例9: setup

import com.pi4j.io.gpio.event.GpioPinListenerDigital; //导入依赖的package包/类
@Override
protected void setup(String[] args) {
    wiringPiSetup();
    ledPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01);        
    myButton = gpio.provisionDigitalInputPin(RaspiPin.GPIO_00, PinPullResistance.PULL_DOWN);        
    myButton.addListener(new GpioPinListenerDigital() {
        @Override
        public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
            if(event.getState().isLow()){
                logger.debug("Button is pressed");
                ledPin.toggle();
            }
        }
        
    });
    logger.debug("Button sensor ready!");    
}
 
开发者ID:marcandreuf,项目名称:sunfounder-sensors-raspi-4j,代码行数:18,代码来源:Ex13_ButtonListener.java

示例10: startListenDigitalPin

import com.pi4j.io.gpio.event.GpioPinListenerDigital; //导入依赖的package包/类
private boolean startListenDigitalPin(MessageParsedInfo messageParsedInfo) {
	int pinNum    = (Integer)messageParsedInfo.getParsedValues()[0];
	
	GpioPinListenerDigital listener = digitalListeners.get(pinNum);
	if(listener == null) {
		listener = createDigitalListener(pinNum);
		GpioPinDigitalInput pin = (GpioPinDigitalInput)getPin(pinNum);
		pin.setMode(PinMode.DIGITAL_INPUT);
		pin.setPullResistance(PinPullResistance.PULL_DOWN);
		
		digitalListeners.put(pinNum, listener);
		pin.addListener(listener);
	}
	
	return true;
}
 
开发者ID:Ardulink,项目名称:Ardulink-1,代码行数:17,代码来源:RaspberryPIConnection.java

示例11: GPIOButton

import com.pi4j.io.gpio.event.GpioPinListenerDigital; //导入依赖的package包/类
/**
 * Constructing a software representation of an GPIO connected hardware
 * button.
 * 
 * @param pin
 *            the GPIO pin that the button is connected to.
 */
public GPIOButton(Pin pin) {
	// create gpio controller
	final GpioController gpio = GpioFactory.getInstance();

	// provision gpio pin as an input pin with its internal pull down
	// resistor enabled
	final GpioPinDigitalInput myButton = gpio.provisionDigitalInputPin(pin, PinPullResistance.PULL_DOWN);

	// register an anonymous listener with the pi4j library to connect to
	// our internal listeners.
	myButton.addListener(new GpioPinListenerDigital() {

		@Override
		public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
			event.getState();
			if (event.getState() == PinState.HIGH) {
				setState(ButtonState.ON);
			} else {
				setState(ButtonState.OFF);
			}
		}
	});
}
 
开发者ID:SebiGo,项目名称:BrewControlServer,代码行数:31,代码来源:GPIOButton.java

示例12: initializePins

import com.pi4j.io.gpio.event.GpioPinListenerDigital; //导入依赖的package包/类
private static GpioPinDigitalInput[] initializePins(int mapping[], GpioController gpioController,
                                                    final RelayStateChangedListener listener) {
  final GpioPinDigitalInput[] pins = new GpioPinDigitalInput[mapping.length];
  for (int i = 0; i < mapping.length; ++i) {
    pins[i] = gpioController.provisionDigitalInputPin(Pins.GPIO_PIN[mapping[i]],
        PinPullResistance.PULL_UP);
    final int relayNum = i;
    pins[i].addListener((GpioPinListenerDigital) event -> {
      listener.onRelayStateChanged(relayNum, event.getState() == PinState.LOW);
    });

    // Tell the listener about the current state before change events are
    // received.
    listener.onRelayStateChanged(relayNum, pins[i].getState() == PinState.LOW);
  }
  return pins;
}
 
开发者ID:shaeberling,项目名称:winston,代码行数:18,代码来源:ReedControllerImpl.java

示例13: testRemoveListener

import com.pi4j.io.gpio.event.GpioPinListenerDigital; //导入依赖的package包/类
@Test
public void testRemoveListener() {
  ReedController.RelayStateChangedListener mMockListener = mock(ReedController
      .RelayStateChangedListener.class);
  mReedController.addListener(mMockListener);

  ArgumentCaptor<GpioPinListenerDigital> pinOneListenerCaptor = ArgumentCaptor.forClass
      (GpioPinListenerDigital.class);
  verify(mMockPins[0], times(1)).addListener(pinOneListenerCaptor.capture());

  reset(mMockListener);
  // Fire a fake HIGH event on the first pin.
  pinOneListenerCaptor.getValue().handleGpioPinDigitalStateChangeEvent(
      createMockChangeEvent(PinState.HIGH));
  verify(mMockListener, times(1)).onRelayStateChanged(0, false);

  reset(mMockListener);

  mReedController.removeListener(mMockListener);
  // Fire a fake LOW event on the first pin after removing listener.
  pinOneListenerCaptor.getValue().handleGpioPinDigitalStateChangeEvent(
      createMockChangeEvent(PinState.LOW));
  verify(mMockListener, never()).onRelayStateChanged(eq(0), anyBoolean());
}
 
开发者ID:shaeberling,项目名称:winston,代码行数:25,代码来源:ReedControllerImplTest.java

示例14: GarageDoorMotionService

import com.pi4j.io.gpio.event.GpioPinListenerDigital; //导入依赖的package包/类
public GarageDoorMotionService(GarageDoorController theController)
{
	super(theController);
	GpioController aGPIOFactory = GpioFactory.getInstance();
	myStatusPin = aGPIOFactory.provisionDigitalInputPin(kMotionPin, PinPullResistance.PULL_DOWN);
	myStatusPin.addListener(new GpioPinListenerDigital()
	{
		/**
		 * Listen for status changes, inform the status service we're working so it won't auto
		 * close the door.
		 *
		 * @param theEvent
		 */
		@Override
		public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent theEvent)
		{
			if (isMotionDetected() && (System.currentTimeMillis() - myLastTime) > kDelay)
			{
				myLastTime = System.currentTimeMillis();
				myLogger.warning("Motion detected!");
				getController().getStatusService().resetOpenTime();
			}
		}
	});
}
 
开发者ID:bigboxer23,项目名称:PiGarage,代码行数:26,代码来源:GarageDoorMotionService.java

示例15: setupPin

import com.pi4j.io.gpio.event.GpioPinListenerDigital; //导入依赖的package包/类
private void setupPin() {
if (isInitiated()) {
    gpioInputPin.addListener(new GpioPinListenerDigital() {
	@Override
	public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
	    if (LOG.isDebugEnabled()) {
		LOG.debug(this + ": detected change on pin " + event.getPin() + ". Value = " + event.getState());
	    }
	    notifyObservers(translate(event.getState()).isHigh());
	}
    });

    gpioInputPin.setShutdownOptions(true);
} else {
    LOG.warn(this + ": init failed before, not setting up any GPIO listener nor any shutdown options.");
}
   }
 
开发者ID:PoJD,项目名称:hawa,代码行数:18,代码来源:GpioObservableSensor.java


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