package jp.co.bizreach.camp;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.File;

@Component
public class OmiyageOiteokimashitaMail {

	private static final Log log = LogFactory.getLog(OmiyageOiteokimashitaMail.class);

	@Autowired
	private CameraImage cameraImage;

	@Autowired
	private SendMail sendMail;

	@Autowired
	private SshLogic sshLogic;

	@Scheduled(fixedDelay = 2000)
	public void execute() {

		// FIXME このへんにボタンが押された状態であることを判定する処理を追加

		sshLogic.countDown();
		cameraImage.getLatestImage().ifPresent(imageFile -> {
			sendMail.send(imageFile);
		});
	}
}

@@ -324,27 +324,152 @@
 ct;%0A
-import java.io.File
+%0Aimport java.io.BufferedReader;%0Aimport java.io.File;%0Aimport java.io.FileNotFoundException;%0Aimport java.io.FileReader;%0Aimport java.io.IOException
 ;%0A%0A@
@@ -833,16 +833,46 @@
 %E3%81%99%E3%82%8B%E5%87%A6%E7%90%86%E3%82%92%E8%BF%BD%E5%8A%A0%0A
+%09%09if (!isSwichOn()) return;%0A%09%09
 %0A%09%09sshLo
@@ -981,11 +981,458 @@
 %09%09%7D);%0A%09%7D
+%0A%0A%09public boolean isSwichOn() %7B%0A%09%09try %7B%0A%09%09%09File file = new File(%22/sys/class/gpio/gpio2/value%22);%0A%09%09%09BufferedReader br = new BufferedReader(new FileReader(file));%0A%0A%09%09%09String str = br.readLine();%0A%09%09%09if (str != null) %7B%0A%09%09%09%09if (str.equals(%221%22)) %7B%0A%09%09%09%09%09br.close();%0A%09%09%09%09%09return true;%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%09br.close();%0A%09%09%09%0A%09%09%7D catch (FileNotFoundException e) %7B%0A%09%09%09System.out.println(e);%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09System.out.println(e);%0A%09%09%7D%0A%09%09return false;%0A%09%7D
 %0A%7D%0A

add isSwichOn