package com.rasppi;

import com.pi4j.io.gpio.*;

/**
 * Created with IntelliJ IDEA.
 * User: jerome
 * Date: 9/02/2014
 * Time: 4:25 PM
 * To change this template use File | Settings | File Templates.
 */
public class LightController {

    private static GpioController gpio = null;
    private static GpioPinDigitalOutput redLightPin = null;
    private static GpioPinDigitalOutput greenLightPin = null;
    private static LightController instance = null;
    private static boolean green = false;
    private static boolean red = false;

    // Configure GPIO.
    private LightController(){
//        gpio = GpioFactory.getInstance();
//        redLightPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04, "RED", PinState.HIGH); // Off state
//        greenLightPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_06, "GREEN", PinState.HIGH); // Off state
    }

    public static LightController getLightControllerInstance(){
        if (instance == null){
            instance = new LightController();
        }

        return instance;
    }

    public void toggleGreen(){
        this.green = !green;
        System.out.println(green);
    }

    public void toggleRed(){
        this.red = !red;
        System.out.println(red);
    }

    public void startBlinking(){
        System.out.println("Blinking");
    }

    public void stopBlinking(){
        System.out.println("Stopped Blinking");
    }

    public void switchOffAll(){
        System.out.println("Switching off");
    }

    public void stop(){
        System.out.println("Stopped");
//        gpio.shutdown();
    }
}

@@ -532,16 +532,61 @@
 = false;
+%0A    private static boolean blinking = false;
 %0A%0A    //
@@ -633,18 +633,16 @@
 ller()%7B%0A
-//
         
@@ -675,18 +675,16 @@
 ance();%0A
-//
         
@@ -782,18 +782,16 @@
 f state%0A
-//
         
@@ -1111,24 +1111,56 @@
 gleGreen()%7B%0A
+        greenLightPin.toggle();%0A
         this
@@ -1243,24 +1243,54 @@
 oggleRed()%7B%0A
+        redLightPin.toggle();%0A
         this
@@ -1387,241 +1387,687 @@
     
-System.out.println(%22Blinking%22);%0A    %7D%0A%0A    public void stopBlinking()%7B%0A        System.out.println(%22Stopped Blinking%22);%0A    %7D%0A%0A    public void switchOffAll()%7B%0A        System.out.println(%22Switching off%22);%0A    %7D%0A%0A    public void stop()%7B
+if (!blinking)%7B%0A            redLightPin.pulse(1000);%0A            greenLightPin.blink(1000);%0A            blinking = true;%0A        %7D%0A        System.out.println(%22Blinking%22);%0A    %7D%0A%0A    public void stopBlinking()%7B%0A        if (blinking)%7B%0A            redLightPin.clearProperties();%0A            greenLightPin.clearProperties();%0A        %7D%0A        blinking = false;%0A        System.out.println(%22Stopped Blinking%22);%0A    %7D%0A%0A    public void switchOffAll()%7B%0A        redLightPin.clearProperties();%0A        greenLightPin.clearProperties();%0A        System.out.println(%22Switching off%22);%0A    %7D%0A%0A    public void stop()%7B%0A        redLightPin.clearProperties();%0A        greenLightPin.clearProperties();
 %0A   
@@ -2102,18 +2102,16 @@
 pped%22);%0A
-//
         

Enable gpio events