def main(self):
     det = Dosimeter(**self.LEDS)  # Initialise dosimeter object from dosimeter.py
     det.activatePin(self.led_power)
     sleep_time = 300
     if self.args.test:
         sleep_time = 10 # seconds
     while True: # Run until error or KeyboardInterrupt (Ctrl + C)
         p = Process(target = det.ping, args=(self.led_network,))
         p.start()
         p.join() # Will block main thread execution until ping succeeds, else blinks in parallel
         GPIO.remove_event_detect(SIG_PIN)
         GPIO.add_event_detect(SIG_PIN, GPIO.FALLING, callback = det.updateCount_basic, bouncetime=1)
         sleep(sleep_time)
         self.getAndSendData(det = det, sleep_time = sleep_time) # time in seconds
Пример #2
0
    def main(self):
        # Initialise dosimeter object from dosimeter.py
        det = Dosimeter(max_accumulation_time_sec=3600, **self.LEDS)
        det.activatePin(self.led_power)
        sleep_time = 300
        if self.args.test:
            sleep_time = 30  # seconds
        dt = datetime.timedelta(seconds=sleep_time)

        # now we are keeping track of our accumulation time intervals
        #   in this block, not in Dosimeter
        curStart = datetime.datetime.now()
        curEnd = curStart + dt
        timeCheckFactor = 30

        while True:
            # Run until error or KeyboardInterrupt (Ctrl + C)
            p = Process(target=det.ping, args=(self.led_network,))
            p.start()
            p.join()
            # p.join() will block main thread execution until ping succeeds,
            #   else blinks in parallel
            GPIO.remove_event_detect(SIG_PIN)
            GPIO.add_event_detect(
                SIG_PIN, GPIO.FALLING, callback=det.updateCount_basic,
                bouncetime=1)
            while datetime.datetime.now() < curEnd:
                # Wait until the accumulation time interval is up
                # If timeCheckFactor==1, then the intervals of the while True
                #   loop would slowly get out of sync with the start/end times,
                #   due to the additional processing time for commands before
                #   and after the sleep command.
                sleep(sleep_time / timeCheckFactor)
            self.getAndSendData(det, curStart, curEnd)  # time in sec
            curStart = curEnd + datetime.timedelta(seconds=0)   # copy
            curEnd = curEnd + dt