001package com.pi4j.wiringpi;
002
003/*
004 * #%L
005 * **********************************************************************
006 * ORGANIZATION  :  Pi4J
007 * PROJECT       :  Pi4J :: Java Library (Core)
008 * FILENAME      :  GpioInterruptEvent.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.EventObject;
032
033/**
034 * <p> This class provides the event object for GPIO interrupt state changes. </p>
035 * 
036 * <p>
037 * Before using the Pi4J library, you need to ensure that the Java VM in configured with access to
038 * the following system libraries:
039 * <ul>
040 * <li>pi4j</li>
041 * <li>wiringPi</li>
042 * </ul>
043 * <blockquote> This library depends on the wiringPi native system library.</br> (developed by
044 * Gordon Henderson @ <a href="https://projects.drogon.net/">https://projects.drogon.net/</a>)
045 * </blockquote>
046 * </p>
047 * 
048 * @see <a href="http://www.pi4j.com/">http://www.pi4j.com/</a>
049 * @author Robert Savage (<a
050 *         href="http://www.savagehomeautomation.com">http://www.savagehomeautomation.com</a>)
051 */
052public class GpioInterruptEvent extends EventObject {
053
054    private static final long serialVersionUID = 1L;
055    private int pin;
056    private boolean state;
057
058    /**
059     * <h1>Default event constructor</h1>
060     * 
061     * @param obj Ignore this parameter
062     * @param pin GPIO pin number (not header pin number; not wiringPi pin number)
063     * @param state New GPIO pin state.
064     */
065    public GpioInterruptEvent(Object obj, int pin, boolean state) {
066        super(obj);
067        this.pin = pin;
068        this.state = state;
069    }
070
071    /**
072     * Get the pin number that changed and raised this event.
073     * 
074     * @return GPIO pin number (not header pin number; not wiringPi pin number)
075     */
076    public int getPin() {
077        return pin;
078    }
079
080    /**
081     * Get the new pin state raised in this event.
082     * 
083     * @return GPIO pin state (HIGH=true, LOW=false)
084     */
085    public boolean getState() {
086        return state;
087    }
088
089    /**
090     * Get the new pin state value raised in this event.
091     * 
092     * @return GPIO pin state (HIGH=1, LOW=0)
093     */
094    public int getStateValue() {
095        return (state == true) ? 1 : 0;
096    }
097}