001package com.pi4j.io.gpio.trigger; 002 003/* 004 * #%L 005 * ********************************************************************** 006 * ORGANIZATION : Pi4J 007 * PROJECT : Pi4J :: Java Library (Core) 008 * FILENAME : GpioTriggerBase.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; 032import java.util.Vector; 033 034import com.pi4j.io.gpio.GpioPin; 035import com.pi4j.io.gpio.PinState; 036 037public abstract class GpioTriggerBase implements GpioTrigger { 038 039 private List<PinState> states = new Vector<PinState>(); 040 041 public GpioTriggerBase() { 042 addPinState(PinState.allStates()); 043 } 044 045 public GpioTriggerBase(PinState state) { 046 addPinState(state); 047 } 048 049 public GpioTriggerBase(PinState[] states) { 050 addPinState(states); 051 } 052 053 public GpioTriggerBase(List<PinState> states) { 054 addPinState(states); 055 } 056 057 public void addPinState(PinState... state) { 058 if (state == null || state.length == 0) { 059 throw new IllegalArgumentException("Missing pin state argument."); 060 } 061 for (PinState s : state) { 062 if (!states.contains(s)) { 063 states.add(s); 064 } 065 } 066 } 067 068 public void addPinState(List<? extends PinState> states) { 069 for (PinState state : states) { 070 addPinState(state); 071 } 072 } 073 074 public boolean hasPinState(PinState state) { 075 return states.contains(state); 076 } 077 078 public abstract void invoke(GpioPin pin, PinState state); 079}