Revise process for manually requested pause. Closes #199

This commit is contained in:
Mr-Dave
2024-12-15 16:20:26 -07:00
parent 6d94019c88
commit 24bf2caa26
11 changed files with 112 additions and 37 deletions

View File

@@ -832,7 +832,9 @@
<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>
@@ -844,7 +846,7 @@
<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>
@@ -2444,7 +2446,7 @@
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>

View File

@@ -308,8 +308,9 @@
<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>

View File

@@ -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;
@@ -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;
}
@@ -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;

View File

@@ -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;

View File

@@ -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 },
@@ -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;
pause = "schedule";
} else if (pact == PARM_ACT_SET) {
edit_set_bool(pause, parm);
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"));
@@ -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 '?':

View File

@@ -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;

View File

@@ -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;

View File

@@ -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")) {

View File

@@ -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 += "}";
}

View File

@@ -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;
@@ -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;
@@ -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";
}
}
@@ -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();

View File

@@ -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();