001package com.pi4j.io.gpio.impl;
002
003/*
004 * #%L
005 * **********************************************************************
006 * ORGANIZATION  :  Pi4J
007 * PROJECT       :  Pi4J :: Java Library (Core)
008 * FILENAME      :  PinImpl.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 - 2015 Pi4J
015 * %%
016 * This program is free software: you can redistribute it and/or modify
017 * it under the terms of the GNU Lesser General Public License as
018 * published by the Free Software Foundation, either version 3 of the
019 * License, or (at your option) any later version.
020 * 
021 * This program is distributed in the hope that it will be useful,
022 * but WITHOUT ANY WARRANTY; without even the implied warranty of
023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
024 * GNU General Lesser Public License for more details.
025 * 
026 * You should have received a copy of the GNU General Lesser Public
027 * License along with this program.  If not, see
028 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
029 * #L%
030 */
031
032
033import java.util.EnumSet;
034
035import com.pi4j.io.gpio.Pin;
036import com.pi4j.io.gpio.PinMode;
037import com.pi4j.io.gpio.PinPullResistance;
038
039public class PinImpl implements Pin {
040
041    private final int address;
042    private final String name ;
043    private final String provider;
044    private final EnumSet<PinPullResistance> supportedPinPullResistance;
045    private final EnumSet<PinMode> supportedPinModes;
046
047    public PinImpl(String provider, int address, String name, EnumSet<PinMode> modes, EnumSet<PinPullResistance> pullResistance) {
048        this.provider = provider;
049        this.address = address;
050        this.name = name;
051        this.supportedPinModes = modes;
052        this.supportedPinPullResistance = pullResistance;
053    }
054
055    public PinImpl(String provider, int address, String name, EnumSet<PinMode> modes) {
056        this(provider, address, name, modes, null);
057    }
058    
059    @Override
060    public int getAddress() {
061        return address;
062    }
063    
064    @Override
065    public String getName() {
066        return name;
067    }
068
069    @Override
070    public String getProvider() {
071        return provider;
072    }
073    
074    @Override
075    public String toString() {
076        return name;
077    }
078
079    @Override
080    public EnumSet<PinMode> getSupportedPinModes() {
081        if (supportedPinModes == null) {
082            return EnumSet.noneOf(PinMode.class);
083        }
084        return supportedPinModes;
085    }
086
087    @Override
088    public EnumSet<PinPullResistance> getSupportedPinPullResistance() {
089        if (supportedPinPullResistance == null) {
090            return EnumSet.noneOf(PinPullResistance.class);
091        }
092        return supportedPinPullResistance;
093    }
094}