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


Java GpioPinDigitalStateChangeEvent类代码示例

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


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

示例1: handleGpioPinDigitalStateChangeEvent

import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent; //导入依赖的package包/类
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {

    // display pin state on console
    String state = null;
    if (event.getState() == PinState.HIGH) {
        state = "on";
    } else if (event.getState() == PinState.LOW) {
        state = "off";
    } else {
        System.out.println("problem state = " + state);
        return;
    }
    for (int i = 0; i < addresses.size(); i++) {
        try {
            sendData(command + " " + state, addresses.get(i), port);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

}
 
开发者ID:tsoglani,项目名称:SpeechRaspberrySmartHouse,代码行数:23,代码来源:SH.java

示例2: SwitchImpl

import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent; //导入依赖的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

示例3: main

import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent; //导入依赖的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

示例4: handleGpioPinDigitalStateChangeEvent

import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent; //导入依赖的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

示例5: FlowMeterFlux

import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent; //导入依赖的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

示例6: start

import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent; //导入依赖的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

示例7: setup

import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent; //导入依赖的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

示例8: setup

import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent; //导入依赖的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

示例9: setup

import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent; //导入依赖的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

示例10: setup

import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent; //导入依赖的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

示例11: setup

import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent; //导入依赖的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

示例12: GPIOButton

import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent; //导入依赖的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

示例13: handleGpioPinDigitalStateChangeEvent

import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent; //导入依赖的package包/类
@Override
		public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
			if (event.getState().isLow()) return;
			System.out.println("Print button pressed !");
			System.out.println("Get a frame");
			start = System.currentTimeMillis();
			
			monoimg = new MonochromImageWin();
			monoimg.setPixels(picam.getAFrame());
			
			endCapture = System.currentTimeMillis();

			// print test 
//			testWithFile();
//			testWithUsb();
			picam.close();
			printer.close();
		}
 
开发者ID:pierre-muth,项目名称:selfpi,代码行数:19,代码来源:PrintImage.java

示例14: handleGpioPinDigitalStateChangeEvent

import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent; //导入依赖的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

示例15: handleGpioPinDigitalStateChangeEvent

import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent; //导入依赖的package包/类
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) 
{
    String s;
    PinState state = event.getState();
    if(state == PinState.LOW)
    {
        s = "low: ";
    }
    else
    {
        s = "high: ";
    }
       
    System.out.println("*Photo booth button pin state changed to " + s + state + ".");
}
 
开发者ID:onebeartoe,项目名称:photorama,代码行数:17,代码来源:PhotoBoothButtonTester.java


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