package ev3dev.actuators.ev3;

import ev3dev.hardware.EV3DevDevice;
import ev3dev.hardware.EV3DevPlatform;
import ev3dev.utils.Sysfs;
import lejos.hardware.LED;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class EV3Led extends EV3DevDevice implements LED {

    /**
     * Directions of the LED.
     */
    public enum Direction {
        LEFT,
        RIGHT
    }

    private static final Logger log = LoggerFactory.getLogger(EV3Led.class);

    public static final int LEFT = 0;
    public static final int RIGHT = 1;

    private final Direction direction;

    private final String LED_RED;
    private final String LED_GREEN;

    /**
     * Create an EV3LED object associated with the LED of the specified direction.
     *
     * @param direction the direction of the LED, either {@link Direction#LEFT} or {@link Direction#RIGHT}.
     * @throws RuntimeException if LED feature is not supported on the current platform.
     */
    public EV3Led(final Direction direction) {
        checkPlatform();

        if (direction == null) {
            log.error("You are not specifying any button.");
            throw new IllegalArgumentException("You are not specifying any button.");
        }

        this.direction = direction;

        if (direction == Direction.LEFT) {
            LED_RED = ev3DevProperties.getProperty("ev3.led.left.red");
            LED_GREEN = ev3DevProperties.getProperty("ev3.led.left.green");
        } else {
            LED_RED = ev3DevProperties.getProperty("ev3.led.right.red");
            LED_GREEN = ev3DevProperties.getProperty("ev3.led.right.green");
        }
    }

    /**
     * Creates an EV3LED object associated with the LED of the specified direction.
     *
     * @param button the direction of the LED, should be either {@link #LEFT} or {@link #RIGHT}.
     * @throws RuntimeException if LED feature is not supported on the current platform.
     * @deprecated Use {@link #EV3Led(Direction)} instead.
     */
    public EV3Led(final int button) {
        checkPlatform();

        if (button == LEFT) {
            LED_RED = ev3DevProperties.getProperty("ev3.led.left.red");
            LED_GREEN = ev3DevProperties.getProperty("ev3.led.left.green");
            direction = Direction.LEFT;
        } else if (button == RIGHT) {
            LED_RED = ev3DevProperties.getProperty("ev3.led.right.red");
            LED_GREEN = ev3DevProperties.getProperty("ev3.led.right.green");
            direction = Direction.RIGHT;
        } else {
            log.error("You are not specifying any button.");
            throw new IllegalArgumentException("You are not specifying any button.");
        }

    }

    /**
     * Checks if the current platform support this feature.
     *
     * @throws RuntimeException if this feature is not supported on the current platform.
     */
    private void checkPlatform() {
        if (!CURRENT_PLATFORM.equals(EV3DevPlatform.EV3BRICK)) {
            log.error("This actuator is specific of: {}", EV3DevPlatform.EV3BRICK);
            throw new RuntimeException("This actuator is specific of: " + EV3DevPlatform.EV3BRICK);
        }
    }

    //TODO Add Enums for patterns

    /**
     * 0: turn off button lights
     * 1/2/3: static light green/red/yellow
     * 4/5/6: normal blinking light green/red/yellow
     * 7/8/9: fast blinking light green/red/yellow
     * >9: same as 9.
     *
     * @param pattern
     */
    @Override
    public void setPattern(final int pattern) {
        //Off
        if (pattern == 0) {
            Sysfs.writeInteger(LED_RED, 0);
            Sysfs.writeInteger(LED_GREEN, 0);
        } else if (pattern == 1) {
            Sysfs.writeInteger(LED_RED, 0);
            Sysfs.writeInteger(LED_GREEN, 255);
        } else if (pattern == 2) {
            Sysfs.writeInteger(LED_RED, 255);
            Sysfs.writeInteger(LED_GREEN, 0);
        } else if (pattern == 3) {
            Sysfs.writeInteger(LED_RED, 255);
            Sysfs.writeInteger(LED_GREEN, 255);
        } else if (pattern > 3) {
            log.debug("This feature is not implemented");
        }
    }

    public Direction getDirection() {
        return direction;
    }
}
@@ -212,16 +212,149 @@
 ctory;%0A%0A
+/**%0A * This class provides methods for interacting with the LEDs on the EV3Brick.%0A * %3Cp%3E%0A * %3Ci%3EOnly EV3Bricks are supported.%3C/i%3E%0A */%0A
 public c
@@ -3332,48 +3332,256 @@
   * 
-0: turn off button lights%0A     *
+Sets the pattern of light to be shown with this LED.%0A     *%0A     * @param pattern the pattern to show with this LED.%0A     *                %3Cp%3E%0A     *                0: Turns off the LED light;%0A     *                %3Cp%3E%0A     *               
  1/2/3: 
 stat
@@ -3580,21 +3580,15 @@
 /3: 
-s
+S
 tatic 
-light 
 gree
@@ -3603,23 +3603,71 @@
 llow
+ light;
 %0A     *
+                %3Cp%3E%0A     *               
  4/5/6: 
 norm
@@ -3662,17 +3662,17 @@
  4/5/6: 
-n
+N
 ormal bl
@@ -3670,38 +3670,32 @@
 Normal blinking 
-light 
 green/red/yellow
@@ -3698,23 +3698,95 @@
 llow
-%0A     *
+ light, %3Ci%3Enot implemented%3C/i%3E;%0A     *                %3Cp%3E%0A     *               
  7/8/9: 
 fast
@@ -3781,17 +3781,17 @@
  7/8/9: 
-f
+F
 ast blin
@@ -3795,22 +3795,16 @@
 linking 
-light 
 green/re
@@ -3815,59 +3815,39 @@
 llow
-%0A     * %3E9: same as 9.%0A     *%0A     * @param pattern
+ light, %3Ci%3Enot implemented%3C/i%3E.
 %0A   
@@ -4533,24 +4533,215 @@
    %7D%0A    %7D%0A%0A
+    /**%0A     * Returns the direction of the LED associated with this object.%0A     *%0A     * @return the direction of the LED, either %7B@link Direction#LEFT%7D or %7B@link Direction#RIGHT%7D.%0A     */%0A
     public D

Complete documentation for EV3Led.java