001package com.pi4j.io.gpio;
002
003import com.pi4j.wiringpi.GpioInterruptListener;
004
005/*
006 * #%L
007 * **********************************************************************
008 * ORGANIZATION  :  Pi4J
009 * PROJECT       :  Pi4J :: Java Library (Core)
010 * FILENAME      :  RaspiGpioProvider.java
011 *
012 * This file is part of the Pi4J project. More information about
013 * this project can be found here:  http://www.pi4j.com/
014 * **********************************************************************
015 * %%
016 * Copyright (C) 2012 - 2016 Pi4J
017 * %%
018 * This program is free software: you can redistribute it and/or modify
019 * it under the terms of the GNU Lesser General Public License as
020 * published by the Free Software Foundation, either version 3 of the
021 * License, or (at your option) any later version.
022 *
023 * This program is distributed in the hope that it will be useful,
024 * but WITHOUT ANY WARRANTY; without even the implied warranty of
025 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
026 * GNU General Lesser Public License for more details.
027 *
028 * You should have received a copy of the GNU General Lesser Public
029 * License along with this program.  If not, see
030 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
031 * #L%
032 */
033
034/**
035 * Raspberry PI {@link GpioProvider} implementation.
036 *
037 * @author Robert Savage (<a
038 *         href="http://www.savagehomeautomation.com">http://www.savagehomeautomation.com</a>)
039 */
040@SuppressWarnings("unused")
041public class RaspiGpioProvider extends WiringPiGpioProviderBase implements GpioProvider, GpioInterruptListener {
042
043    public static final String NAME = "RaspberryPi GPIO Provider";
044
045    /**
046     * Default Constructor
047     */
048    public RaspiGpioProvider() {
049        // set wiringPi interface for internal use
050        // we will use the (default) WiringPi pin number scheme with the wiringPi library
051        this(RaspiPinNumberingScheme.DEFAULT_PIN_NUMBERING);
052    }
053
054    /**
055     * Alternate Constructor allowing user ot override default pin numbering scheme
056     *
057     * @param pinNumberingScheme
058     */
059    public RaspiGpioProvider(RaspiPinNumberingScheme pinNumberingScheme) {
060        // set wiringPi interface for internal use
061        switch(pinNumberingScheme){
062            case BROADCOM_PIN_NUMBERING: {
063                // we will use the raw/direct Broadcom GPIO pin number scheme with the wiringPi library
064                com.pi4j.wiringpi.Gpio.wiringPiSetupGpio();
065                break;
066            }
067            case DEFAULT_PIN_NUMBERING: {
068                // we will use the WiringPi pin number scheme with the wiringPi library
069                com.pi4j.wiringpi.Gpio.wiringPiSetup();
070                break;
071            }
072            default: {
073                throw new RuntimeException("Unsupported pin numbering scheme: " + pinNumberingScheme.name());
074            }
075        }
076    }
077
078    @Override
079    public String getName() {
080        return NAME;
081    }
082}