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: https://www.pi4j.com/ 014 * ********************************************************************** 015 * %% 016 * Copyright (C) 2012 - 2021 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 * Pin edge definition. 036 * 037 * @author Robert Savage (<a 038 * href="http://www.savagehomeautomation.com">http://www.savagehomeautomation.com</a>) 039 */ 040public enum PinMode { 041 042 DIGITAL_INPUT(0, "input", PinDirection.IN), 043 DIGITAL_OUTPUT(1, "output", PinDirection.OUT), 044 PWM_OUTPUT(2, "pwm_output", PinDirection.OUT), 045 GPIO_CLOCK(3, "gpio_clock", PinDirection.OUT), 046 SOFT_PWM_OUTPUT(4, "soft_pwm_output", PinDirection.OUT), 047 SOFT_TONE_OUTPUT(5, "soft_tone_output", PinDirection.OUT), 048 PWM_TONE_OUTPUT(6, "pwm_tone_output", PinDirection.OUT), 049 ANALOG_INPUT(998, "analog_input", PinDirection.IN), 050 ANALOG_OUTPUT(999, "analog_output", PinDirection.OUT); 051 052 private final int value; 053 private final String name; 054 private final PinDirection direction; 055 056 private PinMode(int value, String name, PinDirection direction) { 057 this.value = value; 058 this.name = name; 059 this.direction = direction; 060 } 061 062 public int getValue() { 063 return value; 064 } 065 066 public String getName() { 067 return name; 068 } 069 070 public PinDirection getDirection() { 071 return direction; 072 } 073 074 @Override 075 public String toString() { 076 return name.toUpperCase(); 077 } 078 079 public static EnumSet<PinMode> allDigital() { 080 return EnumSet.of(PinMode.DIGITAL_INPUT, PinMode.DIGITAL_OUTPUT); 081 } 082 083 public static EnumSet<PinMode> allAnalog() { 084 return EnumSet.of(PinMode.ANALOG_INPUT, PinMode.ANALOG_OUTPUT); 085 } 086 087 public static EnumSet<PinMode> all() { 088 return EnumSet.of(PinMode.DIGITAL_INPUT, PinMode.DIGITAL_OUTPUT, 089 PinMode.ANALOG_INPUT, PinMode.ANALOG_OUTPUT, 090 PinMode.PWM_OUTPUT); 091 } 092 093 public static EnumSet<PinMode> allInputs() { 094 return EnumSet.of(PinMode.DIGITAL_INPUT, PinMode.ANALOG_INPUT); 095 } 096 097 public static EnumSet<PinMode> allOutput() { 098 return EnumSet.of(PinMode.DIGITAL_OUTPUT, 099 PinMode.ANALOG_OUTPUT, 100 PinMode.PWM_OUTPUT); 101 } 102}