本文整理汇总了Java中com.pi4j.io.gpio.PinMode类的典型用法代码示例。如果您正苦于以下问题:Java PinMode类的具体用法?Java PinMode怎么用?Java PinMode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PinMode类属于com.pi4j.io.gpio包,在下文中一共展示了PinMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.pi4j.io.gpio.PinMode; //导入依赖的package包/类
public void init(){
try {
_gpioController = GpioFactory.getInstance();
_i2cbus = I2CFactory.getInstance(I2CBus.BUS_1);
_temperatureSensor = _i2cbus.getDevice(0x40);
_lightActuator = _gpioController.provisionDigitalMultipurposePin(RaspiPin.GPIO_00, "led", PinMode.DIGITAL_OUTPUT);
_lightActuator.setShutdownOptions(true); // unexport on shutdown
// monitor temperature changes
// every change of more than 0.1C will notify SensorChangedListeners
_scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
_handle = _scheduledThreadPoolExecutor.scheduleAtFixedRate(temperatureReader, 0, 100, TimeUnit.MILLISECONDS);
} catch (IOException e) {
log.error("An error occurred whilst trying to read temperature from GPIO Pins.");
}
}
示例2: testNotMagneticFieldInteraction
import com.pi4j.io.gpio.PinMode; //导入依赖的package包/类
@Test
public void testNotMagneticFieldInteraction() throws InterruptedException {
prepareMockedPins();
when(mocked_ADC_DIO.getState()).thenReturn(PinState.LOW);
sketch.setup(NO_ARGS);
sketch.setSketchInterruption();
sketch.loop();
verify(mocked_ADC_DIO, times(2)).setMode(PinMode.DIGITAL_OUTPUT);
verify(mocked_ADC_CS).low();
verify(mocked_ADC_CLK, times(20)).low();
verify(mocked_ADC_CLK, times(19)).high();
verify(mocked_ADC_DIO, times(2)).high();
verify(mocked_ADC_DIO).low();
verify(mocked_ADC_DIO).setMode(PinMode.DIGITAL_INPUT);
verify(mocked_ADC_CS).high();
}
示例3: testNotMagneticFieldInteraction
import com.pi4j.io.gpio.PinMode; //导入依赖的package包/类
@Test
@Category(SlowTest.class)
public void testNotMagneticFieldInteraction() throws InterruptedException {
prepareMockedPins();
when(mocked_ADC_DIO.getState()).thenReturn(PinState.LOW);
sketch.setup(NO_ARGS);
sketch.setSketchInterruption();
sketch.loop();
verify(mocked_ADC_DIO).setMode(PinMode.DIGITAL_OUTPUT);
verify(mocked_ADC_CS).low();
verify(mocked_ADC_CLK, times(20)).low();
verify(mocked_ADC_CLK, times(19)).high();
verify(mocked_ADC_DIO, times(2)).high();
verify(mocked_ADC_DIO).low();
verify(mocked_ADC_DIO).setMode(PinMode.DIGITAL_INPUT);
verify(mocked_ADC_CS).high();
}
示例4: sendPowerPinSwitch
import com.pi4j.io.gpio.PinMode; //导入依赖的package包/类
private boolean sendPowerPinSwitch(MessageParsedInfo messageParsedInfo) {
int pinNum = (Integer)messageParsedInfo.getParsedValues()[0];
int power = (Integer)messageParsedInfo.getParsedValues()[1];
GpioPinDigitalOutput pin = (GpioPinDigitalOutput)getPin(pinNum);
pin.setMode(PinMode.DIGITAL_OUTPUT);
if(power == IProtocol.LOW) {
pin.low();
} else {
pin.high();
}
return true;
}
示例5: startListenDigitalPin
import com.pi4j.io.gpio.PinMode; //导入依赖的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;
}
示例6: startListenAnalogPin
import com.pi4j.io.gpio.PinMode; //导入依赖的package包/类
private boolean startListenAnalogPin(MessageParsedInfo messageParsedInfo) {
int pinNum = (Integer)messageParsedInfo.getParsedValues()[0];
GpioPinListenerAnalog listener = analogListeners.get(pinNum);
if(listener == null) {
listener = createAnalogListener(pinNum);
GpioPinAnalogInput pin = (GpioPinAnalogInput)getPin(pinNum);
pin.setMode(PinMode.ANALOG_INPUT);
pin.setPullResistance(PinPullResistance.PULL_DOWN);
analogListeners.put(pinNum, listener);
pin.addListener(listener);
}
return true;
}
示例7: getPin
import com.pi4j.io.gpio.PinMode; //导入依赖的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;
}
示例8: run
import com.pi4j.io.gpio.PinMode; //导入依赖的package包/类
@Override
public void run() {
setCurrentValue(mReadValuePercent);
mPin.setMode(PinMode.DIGITAL_OUTPUT);
mPin.setState(PinState.LOW);
try {
Thread.sleep(mSleepTimeoutMillis);
} catch (InterruptedException e) {
LOG.info("Interrupted.");
return;
}
// If no read-out happened, we want to fall back to zero. It means, that the resistance of
// the photo cell was so high such that it wasn't able to flip the state of the capacitor
// at all.
mReadValuePercent = 0;
mLastStartTimeNanos = System.nanoTime();
mPin.setMode(PinMode.DIGITAL_INPUT);
}
示例9: traduzirPinoPi4J
import com.pi4j.io.gpio.PinMode; //导入依赖的package包/类
private GrappaPin traduzirPinoPi4J(Integer endereco,GpioPinDigital original) {
GrappaPin resultado = new GrappaPin();
resultado.setValue(
original.isHigh() ? 1 : 0
);
resultado.setType(
PinMode.DIGITAL_INPUT.equals(original.getMode()) ? PinType.INPUT : PinType.OUTPUT
);
if(this.mapeamento.possuiMapeamento(endereco) && this.mapeamento.buscarPino(endereco).hasRegistredServices()){
resultado.setServicos(this.mapeamento.buscarPino(endereco).getServicos());
}
if(this.mapeamento.getPosicaoPinoMonitor() != null
&& this.mapeamento.getPosicaoPinoMonitor().equals(endereco)){
resultado.setType(PinType.MONITOR);
}
return resultado;
}
示例10: GpioControl
import com.pi4j.io.gpio.PinMode; //导入依赖的package包/类
@Inject
public GpioControl(Gpio gpio, GpioProvider provider, String name, Pin pin) {
this.name = name;
LOG.info("Creating " + this + " connected to pin " + pin);
this.gpioPin = gpio.provisionDigitalMultipurposePin(provider, pin, PinMode.DIGITAL_OUTPUT);
setupPin();
this.low = new Runnable() {
public void run() {
gpioPin.low();
}
};
this.high = new Runnable() {
public void run() {
gpioPin.high();
}
};
this.toggle = new Runnable() {
public void run() {
gpioPin.toggle();
}
};
}
示例11: testRealGpioDisabledNoGpioInvocation
import com.pi4j.io.gpio.PinMode; //导入依赖的package包/类
@Test
public void testRealGpioDisabledNoGpioInvocation() {
new NonStrictExpectations() {
{
gpio.provisionDigitalMultipurposePin(null, withEqual(pin), withEqual(PinMode.DIGITAL_OUTPUT));
result = output;
// regardless what we do, it is switched off once ...
output.low();
times = 1;
output.high();
maxTimes = 0;
output.toggle();
maxTimes = 0;
}
};
control = new GpioControl(gpio, "testControl", pin);
control.disable();
control.switchOn();
control.switchOff();
control.switchOff();
control.switchOff();
control.toggleSwitch();
assertFalse(control.isEnabled());
}
示例12: testSetEnabledFalseAlsoSwitchesOff
import com.pi4j.io.gpio.PinMode; //导入依赖的package包/类
@Test
public void testSetEnabledFalseAlsoSwitchesOff() {
new NonStrictExpectations() {
{
gpio.provisionDigitalMultipurposePin(null, withEqual(pin), withEqual(PinMode.DIGITAL_OUTPUT));
result = output;
output.low();
times = 1;
}
};
control = new GpioControl(gpio, "testControl", pin);
control.setEnabled(false);
assertFalse(control.isEnabled());
}
示例13: testEnabledSwitchedOnControlIsSwitchedOn
import com.pi4j.io.gpio.PinMode; //导入依赖的package包/类
@Test
public void testEnabledSwitchedOnControlIsSwitchedOn() {
new NonStrictExpectations() {
{
gpio.provisionDigitalMultipurposePin(null, withEqual(pin), withEqual(PinMode.DIGITAL_OUTPUT));
result = output;
output.high();
times = 1;
output.isHigh();
result = true;
}
};
control = new GpioControl(gpio, "testControl", pin);
control.switchOn();
assertTrue(control.isSwitchedOn());
}
示例14: Hcsr04Impl
import com.pi4j.io.gpio.PinMode; //导入依赖的package包/类
public Hcsr04Impl (final RobotGPIO pi2goGPIO, final Pin echo, final Pin trigger){
echoPin = echo.getAddress();
triggerPin = trigger.getAddress();
pi2goGPIO.export(PinMode.DIGITAL_INPUT,pi2goGPIO.provisionDigitalInputPin(echo));
pi2goGPIO.export(PinMode.DIGITAL_OUTPUT,pi2goGPIO.provisionDigitalOutputPin(trigger));
}
示例15: getOrCreate
import com.pi4j.io.gpio.PinMode; //导入依赖的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);
}