001package com.pi4j.io.gpio;
002
003import java.util.EnumSet;
004
005/*
006 * #%L
007 * **********************************************************************
008 * ORGANIZATION  :  Pi4J
009 * PROJECT       :  Pi4J :: Java Library (Core)
010 * FILENAME      :  PinMode.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 - 2013 Pi4J
017 * %%
018 * Licensed under the Apache License, Version 2.0 (the "License");
019 * you may not use this file except in compliance with the License.
020 * You may obtain a copy of the License at
021 * 
022 *      http://www.apache.org/licenses/LICENSE-2.0
023 * 
024 * Unless required by applicable law or agreed to in writing, software
025 * distributed under the License is distributed on an "AS IS" BASIS,
026 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
027 * See the License for the specific language governing permissions and
028 * limitations under the License.
029 * #L%
030 */
031
032/**
033 * Pin edge definition.
034 *
035 * @author Robert Savage (<a
036 *         href="http://www.savagehomeautomation.com">http://www.savagehomeautomation.com</a>)
037 */
038public enum PinMode {
039
040    DIGITAL_INPUT(0, "input", PinDirection.IN), 
041    DIGITAL_OUTPUT(1, "output", PinDirection.OUT),
042    PWM_OUTPUT(2, "pwm_output", PinDirection.OUT),
043    ANALOG_INPUT(3, "analog_input", PinDirection.IN), 
044    ANALOG_OUTPUT(4, "analog_output", PinDirection.OUT);
045
046    private final int value;
047    private final String name;
048    private final PinDirection direction;
049
050    private PinMode(int value, String name, PinDirection direction) {
051        this.value = value;
052        this.name = name;
053        this.direction = direction;
054    }
055
056    public int getValue() {
057        return value;
058    }
059
060    public String getName() {
061        return name;
062    }
063
064    public PinDirection getDirection() {
065        return direction;
066    }
067    
068    @Override
069    public String toString() {
070        return name.toUpperCase();        
071    }    
072    
073    public static EnumSet<PinMode> allDigital() {
074        return EnumSet.of(PinMode.DIGITAL_INPUT, PinMode.DIGITAL_OUTPUT);
075    }    
076
077    public static EnumSet<PinMode> allAnalog() {
078        return EnumSet.of(PinMode.ANALOG_INPUT, PinMode.ANALOG_OUTPUT);
079    }    
080
081    public static EnumSet<PinMode> all() {
082        return EnumSet.of(PinMode.DIGITAL_INPUT, PinMode.DIGITAL_OUTPUT, 
083                          PinMode.ANALOG_INPUT, PinMode.ANALOG_OUTPUT,
084                          PinMode.PWM_OUTPUT);
085    }    
086
087    public static EnumSet<PinMode> allInputs() {
088        return EnumSet.of(PinMode.DIGITAL_INPUT, PinMode.ANALOG_INPUT);
089    }    
090
091    public static EnumSet<PinMode> allOutput() {
092        return EnumSet.of(PinMode.DIGITAL_OUTPUT, 
093                          PinMode.ANALOG_OUTPUT,
094                          PinMode.PWM_OUTPUT);
095    }        
096}