package com.uxxu.konashi.lib.util;

import com.uxxu.konashi.lib.Konashi;
import com.uxxu.konashi.lib.KonashiUtils;

import java.util.Arrays;

/**
 * Created by izumin on 9/18/15.
 */
public final class PwmUtils {
    private PwmUtils() {
        throw new AssertionError("constructor of the utility class should not be called");
    }

    public static boolean isValidPin(int pin) {
        return (pin >= Konashi.PIO0) && (pin <= Konashi.PIO2);
    }

    public static boolean isValidMode(int mode) {
        return (mode == Konashi.PWM_ENABLE) || (mode == Konashi.PWM_DISABLE)
                || (mode == Konashi.PWM_ENABLE_LED_MODE);
    }

    public static boolean isValidPeriod(int period, int duty) {
        return duty <= period;
    }

    public static boolean isValidDuty(int duty, int period) {
        return duty <= period;
    }

    public static boolean isValidDutyRatio(float dutyRatio) {
        return dutyRatio >= 0.0 && dutyRatio <= 100.0;
    }

    public static int getPwmDuty(byte[] value) {
        byte[] bytes = Arrays.copyOfRange(value, 1, value.length);
        return KonashiUtils.bytes2int(bytes);
    }

    public static int getPwmPeriod(byte[] value) {
        byte[] bytes = Arrays.copyOfRange(value, 1, value.length);
        return KonashiUtils.bytes2int(bytes);
    }
}
@@ -710,32 +710,65 @@
 %0A        return 
+(period %3E= 0) && (duty %3E= 0) && (
 duty %3C= period;%0A
@@ -757,32 +757,33 @@
  (duty %3C= period
+)
 ;%0A    %7D%0A%0A    pub
@@ -852,30 +852,43 @@
  return 
-duty %3C= period
+isValidPeriod(period, duty)
 ;%0A    %7D%0A

Fix PwmUtils.isValid{Period,Duty}