Skip to content

Commit

Permalink
Add auto camera on/off function
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Tidey committed Oct 24, 2015
1 parent 276a311 commit 448c47f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Web based interface for controlling the Raspberry Pi Camera, includes motion detection, time lapse, and image and video recording.
Current version 6.0.11
Current version 6.0.12
All information on this project can be found here: http://www.raspberrypi.org/forums/viewtopic.php?f=43&t=63276

The wiki page can be found here:
Expand Down
2 changes: 1 addition & 1 deletion www/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
define('LBASE_DIR',dirname(__FILE__));
//Global defines and utility functions
// version string
define('APP_VERSION', 'v6.0.11');
define('APP_VERSION', 'v6.0.12');

// name of this application
define('APP_NAME', 'RPi Cam Control');
Expand Down
26 changes: 25 additions & 1 deletion www/schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
define('SCHEDULE_PURGESPACEMODE', 'PurgeSpace_ModeEx');
define('SCHEDULE_PURGESPACELEVEL', 'PurgeSpace_Level');
define('SCHEDULE_AUTOCAPTUREINTERVAL', 'AutoCapture_Interval');
define('SCHEDULE_AUTOCAMERAINTERVAL', 'AutoCamera_Interval');
define('SCHEDULE_COMMANDSON', 'Commands_On');
define('SCHEDULE_COMMANDSOFF', 'Commands_Off');
define('SCHEDULE_MODES', 'Modes');
Expand Down Expand Up @@ -191,6 +192,7 @@ function initPars() {
SCHEDULE_MAXCAPTURE => '0',
SCHEDULE_DAYMODE => '1',
SCHEDULE_AUTOCAPTUREINTERVAL => '0',
SCHEDULE_AUTOCAMERAINTERVAL => '0',
SCHEDULE_TIMES => array("09:00","10:00","11:00","12:00","13:00","14:00"),
SCHEDULE_COMMANDSON => array("ca 1","","","ca 1","","","","","","",""),
SCHEDULE_COMMANDSOFF => array("ca 0","","","ca 0","","","","","","",""),
Expand Down Expand Up @@ -645,6 +647,7 @@ function mainCLI() {
$pollTime = $schedulePars[SCHEDULE_CMDPOLL];
$slowPoll = 0;
$managechecktime = time();
$autocameratime =$managechecktime;
$modechecktime = $managechecktime;
if ($schedulePars[SCHEDULE_AUTOCAPTUREINTERVAL] > $schedulePars[SCHEDULE_MAXCAPTURE] ) {
$autocapturetime = $managechecktime;
Expand All @@ -653,7 +656,7 @@ function mainCLI() {
$autocapturetime = 0;
$autocapture = 0;
}

$lastStatusTime = filemtime(BASE_DIR . "/status_mjpeg.txt");
while($timeoutMax == 0 || $timeout < $timeoutMax) {
usleep($pollTime * 1000000);
//Check for incoming motion capture requests
Expand Down Expand Up @@ -745,6 +748,27 @@ function mainCLI() {
writeLog("Autocapture request.");
$autocapture = 1;
}
//Check for auto camera on/off based on status update timing (active browser)
if (($schedulePars[SCHEDULE_AUTOCAMERAINTERVAL] > 0) && $timenow > $autocameratime) {
// 2 seconds between tests to allow time for commands to take effect
$autocameratime = $timenow + 2;
clearstatcache();
$modTime = filemtime(BASE_DIR . "/status_mjpeg.txt");
if (file_get_contents(BASE_DIR . "/status_mjpeg.txt") == 'halted') {
if ($modTime > $lastStatusTime) {
writeLog("autocamera startup");
sendCmds('ru 1');
}
} else {
if (($timenow - $modTime) > $schedulePars[SCHEDULE_AUTOCAMERAINTERVAL]) {
writeLog("autocamera shutdown");
sendCmds('md 0;ru 0');
$lastStatusTime = $timenow + $schedulePars[SCHEDULE_AUTOCAMERAINTERVAL];
} else {
$lastStatusTime = $timenow;
}
}
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions www/status_mjpeg.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
if($file_content != $_GET["last"]) break;
usleep(100000);
}
touch("status_mjpeg.txt");
echo $file_content;

?>

0 comments on commit 448c47f

Please sign in to comment.