001package com.pi4j.io.gpio.trigger; 002 003/* 004 * #%L 005 * ********************************************************************** 006 * ORGANIZATION : Pi4J 007 * PROJECT : Pi4J :: Java Library (Core) 008 * FILENAME : GpioToggleStateTrigger.java 009 * 010 * This file is part of the Pi4J project. More information about 011 * this project can be found here: http://www.pi4j.com/ 012 * ********************************************************************** 013 * %% 014 * Copyright (C) 2012 - 2013 Pi4J 015 * %% 016 * Licensed under the Apache License, Version 2.0 (the "License"); 017 * you may not use this file except in compliance with the License. 018 * You may obtain a copy of the License at 019 * 020 * http://www.apache.org/licenses/LICENSE-2.0 021 * 022 * Unless required by applicable law or agreed to in writing, software 023 * distributed under the License is distributed on an "AS IS" BASIS, 024 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 025 * See the License for the specific language governing permissions and 026 * limitations under the License. 027 * #L% 028 */ 029 030 031import java.util.List; 032 033import com.pi4j.io.gpio.GpioPin; 034import com.pi4j.io.gpio.GpioPinDigitalOutput; 035import com.pi4j.io.gpio.PinState; 036 037public class GpioToggleStateTrigger extends GpioTriggerBase { 038 039 private final GpioPinDigitalOutput targetPin; 040 041 public GpioToggleStateTrigger(GpioPinDigitalOutput targetPin) { 042 super(); 043 this.targetPin = targetPin; 044 } 045 046 public GpioToggleStateTrigger(PinState state, GpioPinDigitalOutput targetPin) { 047 super(state); 048 this.targetPin = targetPin; 049 } 050 051 public GpioToggleStateTrigger(GpioPin pin, PinState state, GpioPinDigitalOutput targetPin) { 052 super(state); 053 this.targetPin = targetPin; 054 } 055 056 public GpioToggleStateTrigger(GpioPin pin, PinState[] states, GpioPinDigitalOutput targetPin) { 057 super(states); 058 this.targetPin = targetPin; 059 } 060 061 public GpioToggleStateTrigger(GpioPin pin, List<PinState> states, GpioPinDigitalOutput targetPin) { 062 super(states); 063 this.targetPin = targetPin; 064 } 065 066 public GpioToggleStateTrigger(GpioPin[] pins, PinState[] states, GpioPinDigitalOutput targetPin) { 067 super(states); 068 this.targetPin = targetPin; 069 } 070 071 public GpioToggleStateTrigger(List<GpioPin> pins, List<PinState> states, GpioPinDigitalOutput targetPin) { 072 super(states); 073 this.targetPin = targetPin; 074 } 075 076 public GpioPinDigitalOutput getTargetPin() { 077 return targetPin; 078 } 079 080 @Override 081 public void invoke(GpioPin pin, PinState state) { 082 if (targetPin != null) { 083 targetPin.toggle(); 084 } 085 } 086}