All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bidib.wizard.model.status.LightPortStatus Maven / Gradle / Ivy

There is a newer version: 2.0.26
Show newest version
package org.bidib.wizard.model.status;

import org.bidib.jbidibc.messages.enums.LightPortEnum;
import org.bidib.jbidibc.messages.utils.ByteUtils;

public enum LightPortStatus implements BidibStatus {
    // @formatter:off
    ON(LightPortEnum.ON, "on"), OFF(LightPortEnum.OFF, "off"), UP(LightPortEnum.UP, "up"), DOWN(LightPortEnum.DOWN,
        "down"), NEON(LightPortEnum.NEON, "neon"), BLINKA(LightPortEnum.BLINKA, "blinka"), BLINKB(LightPortEnum.BLINKB,
        "blinkb"), FLASHA(LightPortEnum.FLASHA, "flasha"), FLASHB(LightPortEnum.FLASHB, "flashb"), DOUBLEFLASH(
        LightPortEnum.DOUBLEFLASH, "doubleflash"), UNKNOWN(LightPortEnum.UNKNOWN, "unknown"), TEST(LightPortEnum.TEST,
        "test");
    // @formatter:on

    private final LightPortEnum type;

    private final String key;

    LightPortStatus(LightPortEnum type, String key) {
        this.type = type;
        this.key = key;
    }

    @Override
    public LightPortEnum getType() {
        return type;
    }

    @Override
    public String getKey() {
        return key;
    }

    public static LightPortStatus valueOf(LightPortEnum type) {
        LightPortStatus result = null;

        for (LightPortStatus e : values()) {
            if (e.type == type) {
                result = e;
                break;
            }
        }
        if (result == null) {
            throw new IllegalArgumentException("cannot map " + type + " to a light port status");
        }
        return result;
    }

    /**
     * Create the {@code LightPortStatus} from the bidib value.
     * 
     * @param value
     *            the value
     * @return the status
     */
    public static LightPortStatus fromBidibValue(int value) {

        LightPortEnum type = LightPortEnum.valueOf(ByteUtils.getLowByte(value));

        return valueOf(type);
    }

    @Override
    public LightPortStatus[] getValues() {
        return new LightPortStatus[] { ON, OFF, UP, DOWN, NEON, BLINKA, BLINKB, FLASHA, FLASHB, DOUBLEFLASH, TEST };
    }

    @Override
    public LightPortStatus[] getMacroValues() {
        return new LightPortStatus[] { ON, OFF, UP, DOWN, NEON, BLINKA, BLINKB, FLASHA, FLASHB, DOUBLEFLASH };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy