Skip to content

Commit

Permalink
Revise process for manually requested pause. Closes #199
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Dave committed Dec 15, 2024
1 parent 4bf8177 commit 56c6599
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 38 deletions.
8 changes: 5 additions & 3 deletions doc/motionplus_config.html
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,9 @@ <h3><a name="device_tmo"></a>device_tmo</h3>
<h3><a name="pause"></a>pause</h3>
<ul>
<li> Values: Boolean | Default: false </li>
Pause detection at start up.
<li> Values: on, off, schedule | Default: schedule</li>
Use 'on' and 'off' to pause or enable motion detection respectively. Use
'schedule' to allow the schedule process to pause or enable detection.
</ul>
<p></p>

Expand All @@ -844,7 +846,7 @@ <h3><a name="schedule_params"></a>schedule_params</h3>
<ul>
<p></p>
This parameter specifies the time of the day that Motionplus will perform
motion detection.
motion detection. To use this, the pause parameter must be set to schedule.
<p></p>

<div>
Expand Down Expand Up @@ -2444,7 +2446,7 @@ <h3><a name="webcontrol_actions"></a> webcontrol_actions </h3>
Comma separated list of the actions=values to allow and show on the web control page. The
following parameters are recognized.
<ul>
<li> pause: Applies for both Pause and Unpause actions</li>
<li> pause: Applies for Pause On, Pause Off and Pause schedule actions</li>
<li> event: Applies for both Start Event and End Event actions</li>
<li> snapshot</li>
<li> camera_add</li>
Expand Down
5 changes: 3 additions & 2 deletions doc/motionplus_examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,9 @@ <h3><a name="webcontrol_pages"></a>Webcontrol pages</h3>
<li><code>eventstart</code>Start an event</li>
<li><code>eventend</code>End an event</li>
<li><code>snapshot</code>Invoke a snapshot</li>
<li><code>pause</code>Pause motion detection</li>
<li><code>unpause</code>Unpause motion detection</li>
<li><code>pause_on</code>Pause motion detection</li>
<li><code>pause_off</code>Enable motion detection</li>
<li><code>pause_schedule</code>Allow schedule to pause or enable motion detection</li>
<li><code>restart</code>Restart camera</li>
<li><code>stop</code>Stop camera</li>
<li><code>config_write</code>Write out the configuration to file. User account running Motionplus must have write access to directory</li>
Expand Down
21 changes: 13 additions & 8 deletions src/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,14 +637,15 @@ void cls_camera::init_values()
movie_passthrough = false;
}

user_pause = false;
if (app->user_pause) {
user_pause = true;
} else if (cfg->pause) {
user_pause = true;
if (app->user_pause == "on") {
user_pause = "on";
} else {
user_pause = cfg->pause;
}
if (user_pause == "on") {
pause = true;
}

pause = user_pause;
v4l2cam = nullptr;
netcam = nullptr;
netcam_high = nullptr;
Expand Down Expand Up @@ -1814,11 +1815,15 @@ void cls_camera::check_schedule()
return;
}

if (user_pause) {
if (user_pause == "on") {
pause = true;
return;
} else if (user_pause == "off") {
pause = false;
return;
}


if (schedule.size() == 0) {
return;
}
Expand Down Expand Up @@ -2011,7 +2016,7 @@ cls_camera::cls_camera(cls_motapp *p_app)
pipe = -1;
mpipe = -1;
pause = false;
user_pause = false;
user_pause = "schedule";
missing_frame_counter = -1;
schedule.clear();
cleandir = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class cls_camera {
int pipe;
int mpipe;
bool pause;
bool user_pause;
std::string user_pause;
int missing_frame_counter;

uint64_t info_diff_tot;
Expand Down
36 changes: 30 additions & 6 deletions src/conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ ctx_parm config_parms[] = {
{"device_name", PARM_TYP_STRING, PARM_CAT_01, PARM_LEVEL_LIMITED },
{"device_id", PARM_TYP_INT, PARM_CAT_01, PARM_LEVEL_LIMITED },
{"device_tmo", PARM_TYP_INT, PARM_CAT_01, PARM_LEVEL_LIMITED },
{"pause", PARM_TYP_BOOL, PARM_CAT_01, PARM_LEVEL_LIMITED },
{"pause", PARM_TYP_LIST, PARM_CAT_01, PARM_LEVEL_LIMITED },
{"schedule_params", PARM_TYP_STRING, PARM_CAT_01, PARM_LEVEL_LIMITED },
{"cleandir_params", PARM_TYP_STRING, PARM_CAT_01, PARM_LEVEL_LIMITED },
{"target_dir", PARM_TYP_STRING, PARM_CAT_01, PARM_LEVEL_ADVANCED },
Expand Down Expand Up @@ -688,11 +688,35 @@ void cls_config::edit_device_tmo(std::string &parm, enum PARM_ACT pact)
void cls_config::edit_pause(std::string &parm, enum PARM_ACT pact)
{
if (pact == PARM_ACT_DFLT) {
pause = false;
} else if (pact == PARM_ACT_SET) {
edit_set_bool(pause, parm);
pause = "schedule";
} else if (pact == PARM_ACT_SET) {
if ((parm == "schedule") ||
(parm == "1") || (parm == "yes") ||
(parm == "on") || (parm == "true") ||
(parm == "0") || (parm == "no") ||
(parm == "off") || (parm == "false")) {
if ((parm == "schedule") || (parm == "on") || (parm == "off")) {
pause = parm;
} else if ((parm == "1") || (parm == "yes") || (parm == "true")) {
MOTPLS_LOG(WRN, TYPE_ALL, NO_ERRNO
, _("Old type specified for pause %s. Use 'on' instead")
,parm.c_str());
pause = "on";
} else if ((parm == "0") || (parm == "no") || (parm == "false")) {
MOTPLS_LOG(WRN, TYPE_ALL, NO_ERRNO
, _("Old type specified for pause %s. Use 'off' instead")
,parm.c_str());
pause = "off";
}
} else {
MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid pause %s"),parm.c_str());
}
} else if (pact == PARM_ACT_GET) {
edit_get_bool(parm, pause);
parm = pause;
} else if (pact == PARM_ACT_LIST) {
parm = "[";
parm = parm + "\"schedule\",\"on\",\"off\"";
parm = parm + "]";
}
return;
MOTPLS_LOG(DBG, TYPE_ALL, NO_ERRNO,"%s:%s","pause",_("pause"));
Expand Down Expand Up @@ -3668,7 +3692,7 @@ void cls_config::cmdline()
edit_set("log_file", optarg);
break;
case 'm':
app->user_pause = true;
app->user_pause = "on";
break;
case 'h':
case '?':
Expand Down
2 changes: 1 addition & 1 deletion src/conf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
int watchdog_tmo;
int watchdog_kill;
int device_tmo;
bool pause;
std::string pause;
std::string schedule_params;
std::string cleandir_params;

Expand Down
2 changes: 1 addition & 1 deletion src/motionplus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class cls_motapp {

int argc;
char **argv;
bool user_pause;
std::string user_pause;

cls_config *conf_src;
cls_config *cfg;
Expand Down
12 changes: 8 additions & 4 deletions src/webu_html.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,12 +689,16 @@ void cls_webu_html::script_assign_actions()
(itm->param_value == "on")) {
webua->resp_page +=
" html_actions += \"<a onclick=\\\"send_action(\";\n"
" html_actions += \"'pause');\\\">\";\n"
" html_actions += \"Pause</a>\\n\";\n\n"
" html_actions += \"'pause_on');\\\">\";\n"
" html_actions += \"Pause On</a>\\n\";\n\n"

" html_actions += \"<a onclick=\\\"send_action(\";\n"
" html_actions += \"'unpause');\\\">\";\n"
" html_actions += \"Unpause</a>\\n\";\n\n"
" html_actions += \"'pause_off');\\\">\";\n"
" html_actions += \"Pause Off</a>\\n\";\n\n"

" html_actions += \"<a onclick=\\\"send_action(\";\n"
" html_actions += \"'pause_schedule');\\\">\";\n"
" html_actions += \"Pause Schedule</a>\\n\";\n\n"
;
} else if ((itm->param_name == "camera_add") &&
(itm->param_value == "on")) {
Expand Down
2 changes: 2 additions & 0 deletions src/webu_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ void cls_webu_json::status_vars(int indx_cam)
webua->resp_page += ",\"pause\":false";
}

webua->resp_page += ",\"user_pause\":\"" + cam->user_pause +"\"";

webua->resp_page += "}";
}

Expand Down
56 changes: 46 additions & 10 deletions src/webu_post.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ void cls_webu_post::action_snapshot()

}

/* Process the pause action */
void cls_webu_post::action_pause()
void cls_webu_post::action_pause_on()
{
int indx;

Expand All @@ -269,16 +268,15 @@ void cls_webu_post::action_pause()

if (webua->device_id == 0) {
for (indx=0; indx<app->cam_cnt; indx++) {
app->cam_list[indx]->user_pause = true;
app->cam_list[indx]->user_pause = "on";
}
} else {
app->cam_list[webua->camindx]->user_pause = true;
app->cam_list[webua->camindx]->user_pause = "on";
}

}

/* Process the unpause action */
void cls_webu_post::action_unpause()
void cls_webu_post::action_pause_off()
{
int indx;

Expand All @@ -295,10 +293,35 @@ void cls_webu_post::action_unpause()

if (webua->device_id == 0) {
for (indx=0; indx<app->cam_cnt; indx++) {
app->cam_list[indx]->user_pause = false;
app->cam_list[indx]->user_pause = "off";
}
} else {
app->cam_list[webua->camindx]->user_pause = false;
app->cam_list[webua->camindx]->user_pause = "off";
}

}

void cls_webu_post::action_pause_schedule()
{
int indx;

for (indx=0;indx<webu->wb_actions->params_cnt;indx++) {
if (webu->wb_actions->params_array[indx].param_name == "pause") {
if (webu->wb_actions->params_array[indx].param_value == "off") {
MOTPLS_LOG(INF, TYPE_ALL, NO_ERRNO, "Pause action disabled");
return;
} else {
break;
}
}
}

if (webua->device_id == 0) {
for (indx=0; indx<app->cam_cnt; indx++) {
app->cam_list[indx]->user_pause = "schedule";
}
} else {
app->cam_list[webua->camindx]->user_pause = "schedule";
}

}
Expand Down Expand Up @@ -738,10 +761,23 @@ void cls_webu_post::process_actions()
action_snapshot();

} else if (post_cmd == "pause") {
action_pause();
MOTPLS_LOG(NTC, TYPE_STREAM, NO_ERRNO
, _("pause action deprecated. Use pause_on"));
action_pause_on();

} else if (post_cmd == "unpause") {
action_unpause();
MOTPLS_LOG(NTC, TYPE_STREAM, NO_ERRNO
, _("unpause action deprecated. Use pause_off"));
action_pause_off();

} else if (post_cmd == "pause_on") {
action_pause_on();

} else if (post_cmd == "pause_off") {
action_pause_off();

} else if (post_cmd == "pause_schedule") {
action_pause_schedule();

} else if (post_cmd == "restart") {
action_restart();
Expand Down
5 changes: 3 additions & 2 deletions src/webu_post.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@
void action_eventend();
void action_eventstart();
void action_snapshot();
void action_pause();
void action_unpause();
void action_pause_on();
void action_pause_off();
void action_pause_schedule();
void action_restart();
void action_stop();
void action_user();
Expand Down

0 comments on commit 56c6599

Please sign in to comment.