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 - 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.EnumSet; 032 033import com.pi4j.io.gpio.Pin; 034import com.pi4j.io.gpio.PinMode; 035import com.pi4j.io.gpio.PinPullResistance; 036 037public class PinImpl implements Pin { 038 039 private final int address; 040 private final String name ; 041 private final String provider; 042 private final EnumSet<PinPullResistance> supportedPinPullResistance; 043 private final EnumSet<PinMode> supportedPinModes; 044 045 public PinImpl(String provider, int address, String name, EnumSet<PinMode> modes, EnumSet<PinPullResistance> pullResistance) { 046 this.provider = provider; 047 this.address = address; 048 this.name = name; 049 this.supportedPinModes = modes; 050 this.supportedPinPullResistance = pullResistance; 051 } 052 053 public PinImpl(String provider, int address, String name, EnumSet<PinMode> modes) { 054 this(provider, address, name, modes, null); 055 } 056 057 @Override 058 public int getAddress() { 059 return address; 060 } 061 062 @Override 063 public String getName() { 064 return name; 065 } 066 067 @Override 068 public String getProvider() { 069 return provider; 070 } 071 072 @Override 073 public String toString() { 074 return name; 075 } 076 077 @Override 078 public EnumSet<PinMode> getSupportedPinModes() { 079 if (supportedPinModes == null) { 080 return EnumSet.noneOf(PinMode.class); 081 } 082 return supportedPinModes; 083 } 084 085 @Override 086 public EnumSet<PinPullResistance> getSupportedPinPullResistance() { 087 if (supportedPinPullResistance == null) { 088 return EnumSet.noneOf(PinPullResistance.class); 089 } 090 return supportedPinPullResistance; 091 } 092}