![JAR search and dependency download from the Maven repository](/logo.png)
com.pi4j.io.spi.SpiChipSelect Maven / Gradle / Ivy
package com.pi4j.io.spi;
/*
* #%L
* **********************************************************************
* ORGANIZATION : Pi4J
* PROJECT : Pi4J :: LIBRARY :: Java Library (CORE)
* FILENAME : SpiChipSelect.java
*
* This file is part of the Pi4J project. More information about
* this project can be found here: https://pi4j.com/
* **********************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
/**
* SpiChipSelect class.
*
* @author Robert Savage (http://www.savagehomeautomation.com)
* @version $Id: $Id
*/
public enum SpiChipSelect {
CS_0(0), CS_1(1), CS_2(2);
private final int address;
private SpiChipSelect(int address) {
this.address = address;
}
/**
* Getter for the field chipSelect
.
*
* @return a int.
*/
public int getChipSelect() {
return address;
}
/**
* getByNumber.
*
* @param address a short.
* @return a {@link SpiChipSelect} object.
*/
public static SpiChipSelect getByNumber(short address){
return getByNumber((int)address);
}
/**
* getByNumber.
*
* @param address a int.
* @return a {@link SpiChipSelect} object.
*/
public static SpiChipSelect getByNumber(int address){
for(var item : SpiChipSelect.values()){
if(item.getChipSelect() == address){
return item;
}
}
return null;
}
/**
* parse.
*
* @param bus a {@link String} object.
* @return a {@link SpiChipSelect} object.
*/
public static SpiChipSelect parse(String bus) {
if(bus.equalsIgnoreCase("0")) return SpiChipSelect.CS_0;
if(bus.equalsIgnoreCase("1")) return SpiChipSelect.CS_1;
if(bus.equalsIgnoreCase("2")) return SpiChipSelect.CS_2;
return Spi.DEFAULT_CHIP_SELECT;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy