__author__ = 'user'

import time
import logging
from threading import Thread, Timer
from .main import ClsPython

logger = logging.getLogger(__name__)

def adjust_led(controller, stop):
    logger.info("[START] adjust_led thread")
    while True:
        if stop():
            controller.set_led("reset", 0)
            break
        pl_distance = controller.get_distance("pl")
        no_pldistance = controller.get_distance("nopl")

        controller.set_led("pl", pl_distance)
        controller.set_led("nopl", no_pldistance)
    logger.info("[FINISH] adjust_led thread")

def image_checker():
    with ClsPython() as cls:
        pl_distance = cls.get_distance("pl")
        no_pldistance = cls.get_distance("nopl")

        cls.set_led("pl", pl_distance)
        cls.set_led("nopl", no_pldistance)

        cls.snap_and_save("pl")
        cls.snap_and_save("nopl")
        cls.snap_and_save("id")


@@ -636,86 +636,198 @@
  pl_
-distance = cls.get_distance(%22pl%22)%0A        no_pldistance = cls.get_distanc
+timeout = time.time() + 2%0A%0A        while time.time() %3C pl_timeout:%0A            pl_distance = cls.get_distance(%22pl%22)%0A            cls.set_led(%22pl%22, pl_distance)%0A            cls.snap_and_sav
 e(%22
-no
 pl%22)
@@ -849,34 +849,166 @@
 et_led(%22
-pl%22, pl_distance)%0A
+reset%22, 0)%0A        nopl_timeout = time.time() + 2%0A%0A        while time.time() %3C nopl_timeout:%0A            no_pldistance = cls.get_distance(%22nopl%22)%0A    
         
@@ -1042,17 +1042,20 @@
 stance)%0A
-%0A
+    
         
@@ -1073,21 +1073,24 @@
 d_save(%22
+no
 pl%22)%0A
+%0A
         
@@ -1108,20 +1108,18 @@
 d_save(%22
-nopl
+id
 %22)%0A     
@@ -1126,28 +1126,28 @@
    cls.s
-nap_and_save(%22id%22
+et_led(%22reset%22, 0
 )%0A%0A

make cls_image_checker to take sample of each camera individually