package de.ctdo.bunti.dmx;

public final class DMX {

    public static final int DMX_CHANNEL_INDEX_MAX = 512;
    public static final int DMX_CHANNEL_INDEX_MIN = 1;
    public static final int DMX_CHANNEL_VALUE_MAX = 255;
    public static final int DMX_CHANNEL_VALUE_MIN = 0;

    /**
     * Offset by which startaddress differs from DMX512 data location
     */
    public static final int DMX_STARTADDRESS_OFFSET = 1;


    private DMX() {

    }

    /**
     * Checks the DMX Value boundaries
     *
     * @param value the DMX channel value to sanitize
     * @return A valid DMX512 channel value
     */
    public static int sanitizeDMXValue(int value) {
        if (value < DMX_CHANNEL_VALUE_MIN) {
            return DMX_CHANNEL_VALUE_MIN;
        }
        if (value > DMX_CHANNEL_VALUE_MAX) {
            return DMX_CHANNEL_VALUE_MAX;
        }
        return value;
    }

    /**
     * Checks the DMX Channel boundaries
     *
     * @param channel The channel to check
     * @return True if channel is valid. Otherwise false.
     */
    public static boolean checkChannelBoundaries(int channel) {
        return (channel >= DMX_CHANNEL_INDEX_MIN && channel <= DMX_CHANNEL_INDEX_MAX);
    }


}
