package ev3dev.hardware;

import ev3dev.hardware.EV3DevPlatformsImpl;
import ev3dev.hardware.EV3DevScreenInfo;
import lejos.hardware.port.MotorPort;
import lejos.hardware.port.Port;
import lejos.hardware.port.SensorPort;

import java.util.Properties;

public class EV3DevPlatforms {
    private static EV3DevPlatformsImpl globalInstance = null;
    private EV3DevPlatformsImpl instance = null;

    public EV3DevPlatforms() {
        synchronized(EV3DevPlatforms.class) {
            if (globalInstance == null) {
                globalInstance = new EV3DevPlatformsImpl();
            }
        }
        instance = globalInstance;
    }

    public EV3DevPlatforms(EV3DevPlatform platform) {
        instance = new EV3DevPlatformsImpl(platform);
    }

    public EV3DevPlatform getPlatform() {
        return instance.getPlatform();
    }

    public String getMotorPort(final Port port) {

        //TODO Pending to review in detail
        //return instance.getMotorPort(port);


        final EV3DevPropertyLoader ev3DevPropertyLoader = new EV3DevPropertyLoader();
        final Properties ev3DevProperties = ev3DevPropertyLoader.getEV3DevProperties();

        if(getPlatform().equals(EV3DevPlatform.EV3BRICK)){

            if(port.equals(MotorPort.A)){
                return ev3DevProperties.getProperty("ev3.motor.port.a");
            }else if(port.equals(MotorPort.B)){
                return ev3DevProperties.getProperty("ev3.motor.port.b");
            }else if(port.equals(MotorPort.C)){
                return ev3DevProperties.getProperty("ev3.motor.port.c");
            }else if(port.equals(MotorPort.D)){
                return ev3DevProperties.getProperty("ev3.motor.port.d");
            }

        } else if(getPlatform().equals(EV3DevPlatform.BRICKPI)) {

            if (port.equals(MotorPort.A)) {
                return ev3DevProperties.getProperty("brickpi.motor.port.a");
            } else if (port.equals(MotorPort.B)) {
                return ev3DevProperties.getProperty("brickpi.motor.port.b");
            } else if (port.equals(MotorPort.C)) {
                return ev3DevProperties.getProperty("brickpi.motor.port.c");
            } else if (port.equals(MotorPort.D)) {
                return ev3DevProperties.getProperty("brickpi.motor.port.d");
            }

        } else if(getPlatform().equals(EV3DevPlatform.BRICKPI3)) {

            if (port.equals(MotorPort.A)) {
                return ev3DevProperties.getProperty("brickpi3.motor.port.a");
            } else if (port.equals(MotorPort.B)) {
                return ev3DevProperties.getProperty("brickpi3.motor.port.b");
            } else if (port.equals(MotorPort.C)) {
                return ev3DevProperties.getProperty("brickpi3.motor.port.c");
            } else if (port.equals(MotorPort.D)) {
                return ev3DevProperties.getProperty("brickpi3.motor.port.d");
            }

        } else {

            if (port.equals(MotorPort.A)) {
                return ev3DevProperties.getProperty("pistorms.motor.port.a");
            } else if (port.equals(MotorPort.B)) {
                return ev3DevProperties.getProperty("pistorms.motor.port.b");
            } else if (port.equals(MotorPort.C)) {
                return ev3DevProperties.getProperty("pistorms.motor.port.c");
            } else if (port.equals(MotorPort.D)) {
                return ev3DevProperties.getProperty("pistorms.motor.port.d");
            }

        }

        throw new RuntimeException("Bad port used");
    }

    public String getSensorPort(final Port port) {
        return instance.getSensorPort(port);
    }

    public EV3DevScreenInfo getFramebufferInfo() {
        return instance.getFramebufferInfo();
    }

    public String getProperty(String base) {
        return instance.getProperty(base);
    }

}

@@ -882,25 +882,24 @@
 ort port) %7B%0A
-%0A
         //TO
@@ -900,23 +900,14 @@
   //
+ 
 TODO
- Pending to
+:
  rev
@@ -928,18 +928,16 @@
         
-//
 return i
@@ -968,2523 +968,8 @@
 t);%0A
-%0A%0A        final EV3DevPropertyLoader ev3DevPropertyLoader = new EV3DevPropertyLoader();%0A        final Properties ev3DevProperties = ev3DevPropertyLoader.getEV3DevProperties();%0A%0A        if(getPlatform().equals(EV3DevPlatform.EV3BRICK))%7B%0A%0A            if(port.equals(MotorPort.A))%7B%0A                return ev3DevProperties.getProperty(%22ev3.motor.port.a%22);%0A            %7Delse if(port.equals(MotorPort.B))%7B%0A                return ev3DevProperties.getProperty(%22ev3.motor.port.b%22);%0A            %7Delse if(port.equals(MotorPort.C))%7B%0A                return ev3DevProperties.getProperty(%22ev3.motor.port.c%22);%0A            %7Delse if(port.equals(MotorPort.D))%7B%0A                return ev3DevProperties.getProperty(%22ev3.motor.port.d%22);%0A            %7D%0A%0A        %7D else if(getPlatform().equals(EV3DevPlatform.BRICKPI)) %7B%0A%0A            if (port.equals(MotorPort.A)) %7B%0A                return ev3DevProperties.getProperty(%22brickpi.motor.port.a%22);%0A            %7D else if (port.equals(MotorPort.B)) %7B%0A                return ev3DevProperties.getProperty(%22brickpi.motor.port.b%22);%0A            %7D else if (port.equals(MotorPort.C)) %7B%0A                return ev3DevProperties.getProperty(%22brickpi.motor.port.c%22);%0A            %7D else if (port.equals(MotorPort.D)) %7B%0A                return ev3DevProperties.getProperty(%22brickpi.motor.port.d%22);%0A            %7D%0A%0A        %7D else if(getPlatform().equals(EV3DevPlatform.BRICKPI3)) %7B%0A%0A            if (port.equals(MotorPort.A)) %7B%0A                return ev3DevProperties.getProperty(%22brickpi3.motor.port.a%22);%0A            %7D else if (port.equals(MotorPort.B)) %7B%0A                return ev3DevProperties.getProperty(%22brickpi3.motor.port.b%22);%0A            %7D else if (port.equals(MotorPort.C)) %7B%0A                return ev3DevProperties.getProperty(%22brickpi3.motor.port.c%22);%0A            %7D else if (port.equals(MotorPort.D)) %7B%0A                return ev3DevProperties.getProperty(%22brickpi3.motor.port.d%22);%0A            %7D%0A%0A        %7D else %7B%0A%0A            if (port.equals(MotorPort.A)) %7B%0A                return ev3DevProperties.getProperty(%22pistorms.motor.port.a%22);%0A            %7D else if (port.equals(MotorPort.B)) %7B%0A                return ev3DevProperties.getProperty(%22pistorms.motor.port.b%22);%0A            %7D else if (port.equals(MotorPort.C)) %7B%0A                return ev3DevProperties.getProperty(%22pistorms.motor.port.c%22);%0A            %7D else if (port.equals(MotorPort.D)) %7B%0A                return ev3DevProperties.getProperty(%22pistorms.motor.port.d%22);%0A            %7D%0A%0A        %7D%0A%0A        throw new RuntimeException(%22Bad port used%22);%0A
     

Return back to caching variant of motor get port