コード例 #1
0
    def passiveRecording(self, isNew):
        # first, delete the oldest passive recording
        self.filer.deleteOldestPassive()

        # depending on the given input, either START a new video, or STOP the
        # current one and create a new one
        if (isNew):
            self.filer.log("Beginning passive recording...\n")
            self.camera.startVideo(Filer.makeFileName(0),
                                   self.filer.passivePath)
        else:
            self.filer.log("Splitting passive recording...\n")
            self.camera.stopVideo()
            self.camera.startVideo(Filer.makeFileName(0),
                                   self.filer.passivePath)
コード例 #2
0
    def main(self):
        # start passively recording
        self.passiveRecording(1)

        # termination code: used to help determine why the main loop
        # was broken (could be the power button, could be too hot
        # of a cpu, etc.)
        #   -1  =  not terminated
        #    0  =  CPU is too hot
        #    1  =  power button was pressed
        #    2  =  debug terminate (exit program but keep pi powered on)
        terminateCode = -1

        # --------------- main loop --------------- #
        ticks = 0.0
        tickSeconds = 0.0
        tickPrintRate = 1
        # logs the tickString every 'tickPrintRate' seconds
        terminate = False
        while (not terminate):
            tickOnSecond = tickSeconds.is_integer()
            # write a tick string to be printed to the log
            tickString = "Tick: {t1:9.2f}  |  Running Time: {t2:9.2f}"
            tickString = tickString.format(t1=ticks, t2=int(tickSeconds))
            tickHeader = "[dashcam]  "
            tickHeader += "[LED: " + (str(self.lights.states[0]) + str(
                self.lights.states[1]) + str(self.lights.states[2])) + "]  "
            tickHeader += "[Button: " + (
                str(int(self.buttons.durations[0] * self.TICK_RATE)) + "|" +
                str(int(self.buttons.durations[1] * self.TICK_RATE)) + "]  ")
            tickString = tickHeader + tickString

            # check the CPU temperature (terminate if needed)
            if (tickOnSecond):
                cpuTemp = self.getCPUTemp()
                terminate = cpuTemp > 80.0
                # add to the tick string
                tickString += "  [CPU Temp: " + str(cpuTemp) + "]"
                # if the temperature exceeds the threshold, stop the program
                terminate = cpuTemp > 80
                if (terminate):
                    self.filer.log("CPU running too hot! Shutting down...")
                    terminateCode = 0

            # perform any mode actions needed
            tickString += self.update(ticks, tickSeconds)

            # grab the initial button durations
            powerDuration = self.buttons.durations[0]
            captureDuration = self.buttons.durations[1]
            # call the button-detection methods to update their durations
            self.buttons.isPowerPressed()
            self.buttons.isCapturePressed()

            # check for both buttons being pressed
            if (self.buttons.isPowerPressed()
                    and powerDuration * self.TICK_RATE >= 2.0
                    and self.buttons.isCapturePressed()
                    and captureDuration * self.TICK_RATE >= 2.0):
                # terminate and shut down
                terminate = True
                terminateCode = 1
            # check for power button press
            elif (self.buttons.isPowerPressed()
                  and powerDuration * self.TICK_RATE >= 2.0
                  and not self.buttons.isCapturePressed()):
                # terminate but don't shut down
                terminate = True
                terminateCode = 2
            # check for capture button press (TAKE PICTURE)
            elif (captureDuration * self.TICK_RATE <= 2.0
                  and captureDuration * self.TICK_RATE > 0.0
                  and not self.buttons.isCapturePressed()):
                self.filer.log("Capturing image...")
                # flash LED and take picture
                self.lights.flashLED([1], 2)
                self.camera.takePicture(Filer.makeFileName(1),
                                        self.filer.imagePath)

            # update the camera's overlay text
            if (self.camera.currVideo != None):
                self.camera.updateOverlays(datetime.datetime.now())
                self.camera.currVideo.duration += self.TICK_RATE

            # sleep for one tick rate
            self.camera.picam.wait_recording(self.TICK_RATE)
            # log the tick string
            if (tickSeconds % tickPrintRate == 0):
                self.filer.log(tickString + "\n")
            # increment ticks
            ticks += 1
            tickSeconds += self.TICK_RATE
        # ----------------------------------------- #

        self.filer.log("Terminate Code: " + str(terminateCode) + "\n")
        # check terminate code: shutdown if needed
        if (terminateCode == 0 or terminateCode == 1):
            self.filer.log("Shutting down...\n")
            shutdown_pi(self.lights, [self.buttons, self])

        if (terminateCode == 2):
            # flash LED to show debug terminate
            self.lights.setLED([0, 1], False)
            self.lights.flashLED([0, 1], 5)
            self.filer.log(
                "Terminating dash cam, but keeping Pi powered on...\n")