private PinState getStateA(Pin pin){ // determine pin address int pinAddress = pin.getAddress() - GPIO_A_OFFSET; // determine pin state PinState state = (currentStatesA & pinAddress) == pinAddress ? PinState.HIGH : PinState.LOW; // cache state getPinCache(pin).setState(state); return state; }
private PinState getStateB(Pin pin){ // determine pin address int pinAddress = pin.getAddress() - GPIO_B_OFFSET; // determine pin state PinState state = (currentStatesB & pinAddress) == pinAddress ? PinState.HIGH : PinState.LOW; // cache state getPinCache(pin).setState(state); return state; }
private PinState getStateA(Pin pin){ // determine pin address int pinAddress = pin.getAddress() - GPIO_A_OFFSET; // determine pin state PinState state = (currentStatesA & pinAddress) == pinAddress ? PinState.HIGH : PinState.LOW; // cache state getPinCache(pin).setState(state); return state; }
private PinState getStateB(Pin pin){ // determine pin address int pinAddress = pin.getAddress() - GPIO_B_OFFSET; // determine pin state PinState state = (currentStatesB & pinAddress) == pinAddress ? PinState.HIGH : PinState.LOW; // cache state getPinCache(pin).setState(state); return state; }
private PinState getStateA(Pin pin){ // determine pin address int pinAddress = pin.getAddress() - GPIO_A_OFFSET; // determine pin state PinState state = (currentStatesA & pinAddress) == pinAddress ? PinState.HIGH : PinState.LOW; // cache state getPinCache(pin).setState(state); return state; }
public void setState(Pin pin, PinState state) { // cache pin state getPinCache(pin).setState(state); // dispatch event dispatchPinDigitalStateChangeEvent(pin, state); }
private PinState getStateB(Pin pin){ // determine pin address int pinAddress = pin.getAddress() - GPIO_B_OFFSET; // determine pin state PinState state = (currentStatesB & pinAddress) == pinAddress ? PinState.HIGH : PinState.LOW; // cache state getPinCache(pin).setState(state); return state; }
getPinCache(pin).setState(newState); currentStates.set(index, pinStates.get(index));
@Override public PinState getState(Pin pin) { // call super method to perform validation on pin PinState result = super.getState(pin); // determine pin address int pinAddress = pin.getAddress(); // determine pin state result = (currentStates & pinAddress) == pinAddress ? PinState.HIGH : PinState.LOW; // cache state getPinCache(pin).setState(result); return result; }
public PCF8574GpioProvider(I2CBus bus, int address) throws IOException { // set reference to I2C communications bus instance this.bus = bus; // create I2C device instance device = bus.getDevice(address); // set all default pin cache states to match documented chip power up states for (Pin pin : PCF8574Pin.ALL) { getPinCache(pin).setState(PinState.HIGH); currentStates.set(pin.getAddress(), true); } // start monitoring thread monitor = new PCF8574GpioProvider.GpioStateMonitor(device); monitor.start(); }
private void evaluatePinForChangeA(Pin pin, int state) { if (getPinCache(pin).isExported()) { // determine pin address int pinAddress = pin.getAddress() - GPIO_A_OFFSET; if ((state & pinAddress) != (currentStatesA & pinAddress)) { PinState newState = (state & pinAddress) == pinAddress ? PinState.HIGH : PinState.LOW; // cache state getPinCache(pin).setState(newState); // determine and cache state value for pin bit if (newState.isHigh()) { currentStatesA |= pinAddress; } else { currentStatesA &= ~pinAddress; } // change detected for INPUT PIN // System.out.println("<<< CHANGE >>> " + pin.getName() + " : " + state); dispatchPinChangeEvent(pin.getAddress(), newState); } } }
private void evaluatePinForChange(Pin pin, int state) { if (getPinCache(pin).isExported()) { // determine pin address int pinAddress = pin.getAddress(); if ((state & pinAddress) != (currentStates & pinAddress)) { PinState newState = (state & pinAddress) == pinAddress ? PinState.HIGH : PinState.LOW; // cache state getPinCache(pin).setState(newState); // determine and cache state value for pin bit if (newState.isHigh()) { currentStates |= pinAddress; } else { currentStates &= ~pinAddress; } // change detected for INPUT PIN // System.out.println("<<< CHANGE >>> " + pin.getName() + " : " + state); dispatchPinChangeEvent(pin.getAddress(), newState); } } }
private void evaluatePinForChangeB(Pin pin, int state) { if (getPinCache(pin).isExported()) { // determine pin address int pinAddress = pin.getAddress() - GPIO_B_OFFSET; if ((state & pinAddress) != (currentStatesB & pinAddress)) { PinState newState = (state & pinAddress) == pinAddress ? PinState.HIGH : PinState.LOW; // cache state getPinCache(pin).setState(newState); // determine and cache state value for pin bit if (newState.isHigh()) { currentStatesB |= pinAddress; } else { currentStatesB &= ~pinAddress; } // change detected for INPUT PIN // System.out.println("<<< CHANGE >>> " + pin.getName() + " : " + state); dispatchPinChangeEvent(pin.getAddress(), newState); } } }
private void evaluatePinForChangeA(Pin pin, int state) { if (getPinCache(pin).isExported()) { // determine pin address int pinAddress = pin.getAddress() - GPIO_A_OFFSET; if ((state & pinAddress) != (currentStatesA & pinAddress)) { PinState newState = (state & pinAddress) == pinAddress ? PinState.HIGH : PinState.LOW; // cache state getPinCache(pin).setState(newState); // determine and cache state value for pin bit if (newState.isHigh()) { currentStatesA |= pinAddress; } else { currentStatesA &= ~pinAddress; } // change detected for INPUT PIN // System.out.println("<<< CHANGE >>> " + pin.getName() + " : " + state); dispatchPinChangeEvent(pin.getAddress(), newState); } } }
private void evaluatePinForChangeB(Pin pin, int state) { if (getPinCache(pin).isExported()) { // determine pin address int pinAddress = pin.getAddress() - GPIO_B_OFFSET; if ((state & pinAddress) != (currentStatesB & pinAddress)) { PinState newState = (state & pinAddress) == pinAddress ? PinState.HIGH : PinState.LOW; // cache state getPinCache(pin).setState(newState); // determine and cache state value for pin bit if (newState.isHigh()) { currentStatesB |= pinAddress; } else { currentStatesB &= ~pinAddress; } // change detected for INPUT PIN // System.out.println("<<< CHANGE >>> " + pin.getName() + " : " + state); dispatchPinChangeEvent(pin.getAddress(), newState); } } }
private void evaluatePinForChangeA(Pin pin, int state) { if (getPinCache(pin).isExported()) { // determine pin address int pinAddress = pin.getAddress() - GPIO_A_OFFSET; if ((state & pinAddress) != (currentStatesA & pinAddress)) { PinState newState = (state & pinAddress) == pinAddress ? PinState.HIGH : PinState.LOW; // cache state getPinCache(pin).setState(newState); // determine and cache state value for pin bit if (newState.isHigh()) { currentStatesA |= pinAddress; } else { currentStatesA &= ~pinAddress; } // change detected for INPUT PIN // System.out.println("<<< CHANGE >>> " + pin.getName() + " : " + state); dispatchPinChangeEvent(pin.getAddress(), newState); } } }
private void evaluatePinForChangeB(Pin pin, int state) { if (getPinCache(pin).isExported()) { // determine pin address int pinAddress = pin.getAddress() - GPIO_B_OFFSET; if ((state & pinAddress) != (currentStatesB & pinAddress)) { PinState newState = (state & pinAddress) == pinAddress ? PinState.HIGH : PinState.LOW; // cache state getPinCache(pin).setState(newState); // determine and cache state value for pin bit if (newState.isHigh()) { currentStatesB |= pinAddress; } else { currentStatesB &= ~pinAddress; } // change detected for INPUT PIN // System.out.println("<<< CHANGE >>> " + pin.getName() + " : " + state); dispatchPinChangeEvent(pin.getAddress(), newState); } } }
@Override public void setState(Pin pin, PinState state) { if (!hasPin(pin)) { throw new InvalidPinException(pin); } GpioProviderPinCache pinCache = getPinCache(pin); // only permit invocation on pins set to DIGITAL_OUTPUT modes if (pinCache.getMode() != PinMode.DIGITAL_OUTPUT) { throw new InvalidPinModeException(pin, "Invalid pin mode on pin [" + pin.getName() + "]; cannot setState() when pin mode is [" + pinCache.getMode().getName() + "]"); } // for digital output pins, we will echo the event feedback dispatchPinDigitalStateChangeEvent(pin, state); // cache pin state pinCache.setState(state); }
@Override public void setState(Pin pin, PinState state) { if (!hasPin(pin)) { throw new InvalidPinException(pin); } GpioProviderPinCache pinCache = getPinCache(pin); // only permit invocation on pins set to DIGITAL_OUTPUT modes if (pinCache.getMode() != PinMode.DIGITAL_OUTPUT) { throw new InvalidPinModeException(pin, "Invalid pin mode on pin [" + pin.getName() + "]; cannot setState() when pin mode is [" + pinCache.getMode().getName() + "]"); } // for digital output pins, we will echo the event feedback dispatchPinDigitalStateChangeEvent(pin, state); // cache pin state pinCache.setState(state); }