// Path: photorama-raspberry-pi-webapp/src/main/java/org/onebeartoe/electronics/photorama/ConfigurationServlet.java
// public static final String CAMERA_KEY = "camera";
// 
// Path: photorama-raspberry-pi/src/main/java/org/onebeartoe/electronics/photorama/PhotoBoothButtonTester.java
// public static final Pin buttonPin = RaspiPin.GPIO_02;


import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalInput;
import com.pi4j.io.gpio.PinPullResistance;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent;
import com.pi4j.io.gpio.event.GpioPinListenerDigital;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import static org.onebeartoe.electronics.photorama.ConfigurationServlet.CAMERA_KEY;
import static org.onebeartoe.electronics.photorama.PhotoBoothButtonTester.buttonPin;
import org.onebeartoe.system.Sleeper;
            Sleeper.sleepo(SNAPSHOT_DELAY);
            camera.takeSnapshot();
        }
    }
    
    @Override
    public void destroy()
    {
        ServletContext servletContext = getServletContext();
        GpioController gpio = (GpioController) servletContext.getAttribute(PHOTO_BOOTH_GPIO_CONTROLLER_KEY);
        gpio.shutdown();
    }
    
    @Override
    public void init() throws ServletException
    {
        super.init();
        
        logger = Logger.getLogger(getClass().getName());
        
        takingSnapshots = false;
        
        ServletContext servletContext = getServletContext();
        GpioController gpio = (GpioController) servletContext.getAttribute(PHOTO_BOOTH_GPIO_CONTROLLER_KEY);
        if(gpio == null)
        {
            System.out.println("*Provisioning GPIO.");
            gpio = GpioFactory.getInstance();
            servletContext.setAttribute(PHOTO_BOOTH_GPIO_CONTROLLER_KEY, gpio);
            
// Path: photorama-raspberry-pi-webapp/src/main/java/org/onebeartoe/electronics/photorama/ConfigurationServlet.java
// public static final String CAMERA_KEY = "camera";
// 
// Path: photorama-raspberry-pi/src/main/java/org/onebeartoe/electronics/photorama/PhotoBoothButtonTester.java
// public static final Pin buttonPin = RaspiPin.GPIO_02;


// Path: photorama-raspberry-pi-webapp/src/main/java/org/onebeartoe/electronics/photorama/PhotoBoothServlet.java
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalInput;
import com.pi4j.io.gpio.PinPullResistance;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent;
import com.pi4j.io.gpio.event.GpioPinListenerDigital;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import static org.onebeartoe.electronics.photorama.ConfigurationServlet.CAMERA_KEY;
import static org.onebeartoe.electronics.photorama.PhotoBoothButtonTester.buttonPin;
import org.onebeartoe.system.Sleeper;

            Sleeper.sleepo(SNAPSHOT_DELAY);
            camera.takeSnapshot();
        }
    }
    
    @Override
    public void destroy()
    {
        ServletContext servletContext = getServletContext();
        GpioController gpio = (GpioController) servletContext.getAttribute(PHOTO_BOOTH_GPIO_CONTROLLER_KEY);
        gpio.shutdown();
    }
    
    @Override
    public void init() throws ServletException
    {
        super.init();
        
        logger = Logger.getLogger(getClass().getName());
        
        takingSnapshots = false;
        
        ServletContext servletContext = getServletContext();
        GpioController gpio = (GpioController) servletContext.getAttribute(PHOTO_BOOTH_GPIO_CONTROLLER_KEY);
        if(gpio == null)
        {
            System.out.println("*Provisioning GPIO.");
            gpio = GpioFactory.getInstance();
            servletContext.setAttribute(PHOTO_BOOTH_GPIO_CONTROLLER_KEY, gpio);
            
            GpioPinDigitalInput photoBoothButton = gpio.provisionDigitalInputPin(buttonPin, 