001package com.pi4j.io.serial;
002
003/*
004 * #%L
005 * **********************************************************************
006 * ORGANIZATION  :  Pi4J
007 * PROJECT       :  Pi4J :: Java Library (Core)
008 * FILENAME      :  Baud.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 - 2016 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
032import java.util.Enumeration;
033
034public enum Baud {
035
036    _50(com.pi4j.jni.Serial.BAUD_RATE_50),
037    _75(com.pi4j.jni.Serial.BAUD_RATE_75),
038    _110(com.pi4j.jni.Serial.BAUD_RATE_110),
039    _134(com.pi4j.jni.Serial.BAUD_RATE_134),
040    _150(com.pi4j.jni.Serial.BAUD_RATE_150),
041    _200(com.pi4j.jni.Serial.BAUD_RATE_200),
042    _300(com.pi4j.jni.Serial.BAUD_RATE_300),
043    _600(com.pi4j.jni.Serial.BAUD_RATE_600),
044    _1200(com.pi4j.jni.Serial.BAUD_RATE_1200),
045    _1800(com.pi4j.jni.Serial.BAUD_RATE_1800),
046    _2400(com.pi4j.jni.Serial.BAUD_RATE_2400),
047    _4800(com.pi4j.jni.Serial.BAUD_RATE_4800),
048    _9600(com.pi4j.jni.Serial.BAUD_RATE_9600),
049    _19200(com.pi4j.jni.Serial.BAUD_RATE_19200),
050    _38400(com.pi4j.jni.Serial.BAUD_RATE_38400),
051    _57600(com.pi4j.jni.Serial.BAUD_RATE_57600),
052    _115200(com.pi4j.jni.Serial.BAUD_RATE_115200),
053    _230400(com.pi4j.jni.Serial.BAUD_RATE_230400);
054
055    private int baud = 0;
056
057    private Baud(int baud){
058        this.baud = baud;
059    }
060
061    public int getValue(){
062        return this.baud;
063    }
064
065    public static Baud getInstance(int baud_rate){
066        for(Baud b : Baud.values()){
067            if(b.getValue() == baud_rate){
068                return b;
069            }
070        }
071        return null;
072    }
073}