Skip to content
This repository was archived by the owner on Apr 5, 2025. It is now read-only.

Commit 56c6599

Browse files
committed
Revise process for manually requested pause. Closes #199
1 parent 4bf8177 commit 56c6599

File tree

11 files changed

+113
-38
lines changed

11 files changed

+113
-38
lines changed

doc/motionplus_config.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,9 @@ <h3><a name="device_tmo"></a>device_tmo</h3>
832832
<h3><a name="pause"></a>pause</h3>
833833
<ul>
834834
<li> Values: Boolean | Default: false </li>
835-
Pause detection at start up.
835+
<li> Values: on, off, schedule | Default: schedule</li>
836+
Use 'on' and 'off' to pause or enable motion detection respectively. Use
837+
'schedule' to allow the schedule process to pause or enable detection.
836838
</ul>
837839
<p></p>
838840

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

850852
<div>
@@ -2444,7 +2446,7 @@ <h3><a name="webcontrol_actions"></a> webcontrol_actions </h3>
24442446
Comma separated list of the actions=values to allow and show on the web control page. The
24452447
following parameters are recognized.
24462448
<ul>
2447-
<li> pause: Applies for both Pause and Unpause actions</li>
2449+
<li> pause: Applies for Pause On, Pause Off and Pause schedule actions</li>
24482450
<li> event: Applies for both Start Event and End Event actions</li>
24492451
<li> snapshot</li>
24502452
<li> camera_add</li>

doc/motionplus_examples.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,9 @@ <h3><a name="webcontrol_pages"></a>Webcontrol pages</h3>
308308
<li><code>eventstart</code>Start an event</li>
309309
<li><code>eventend</code>End an event</li>
310310
<li><code>snapshot</code>Invoke a snapshot</li>
311-
<li><code>pause</code>Pause motion detection</li>
312-
<li><code>unpause</code>Unpause motion detection</li>
311+
<li><code>pause_on</code>Pause motion detection</li>
312+
<li><code>pause_off</code>Enable motion detection</li>
313+
<li><code>pause_schedule</code>Allow schedule to pause or enable motion detection</li>
313314
<li><code>restart</code>Restart camera</li>
314315
<li><code>stop</code>Stop camera</li>
315316
<li><code>config_write</code>Write out the configuration to file. User account running Motionplus must have write access to directory</li>

src/camera.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -637,14 +637,15 @@ void cls_camera::init_values()
637637
movie_passthrough = false;
638638
}
639639

640-
user_pause = false;
641-
if (app->user_pause) {
642-
user_pause = true;
643-
} else if (cfg->pause) {
644-
user_pause = true;
640+
if (app->user_pause == "on") {
641+
user_pause = "on";
642+
} else {
643+
user_pause = cfg->pause;
644+
}
645+
if (user_pause == "on") {
646+
pause = true;
645647
}
646648

647-
pause = user_pause;
648649
v4l2cam = nullptr;
649650
netcam = nullptr;
650651
netcam_high = nullptr;
@@ -1814,11 +1815,15 @@ void cls_camera::check_schedule()
18141815
return;
18151816
}
18161817

1817-
if (user_pause) {
1818+
if (user_pause == "on") {
18181819
pause = true;
18191820
return;
1821+
} else if (user_pause == "off") {
1822+
pause = false;
1823+
return;
18201824
}
18211825

1826+
18221827
if (schedule.size() == 0) {
18231828
return;
18241829
}
@@ -2011,7 +2016,7 @@ cls_camera::cls_camera(cls_motapp *p_app)
20112016
pipe = -1;
20122017
mpipe = -1;
20132018
pause = false;
2014-
user_pause = false;
2019+
user_pause = "schedule";
20152020
missing_frame_counter = -1;
20162021
schedule.clear();
20172022
cleandir = nullptr;

src/camera.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class cls_camera {
185185
int pipe;
186186
int mpipe;
187187
bool pause;
188-
bool user_pause;
188+
std::string user_pause;
189189
int missing_frame_counter;
190190

191191
uint64_t info_diff_tot;

src/conf.cpp

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ ctx_parm config_parms[] = {
4848
{"device_name", PARM_TYP_STRING, PARM_CAT_01, PARM_LEVEL_LIMITED },
4949
{"device_id", PARM_TYP_INT, PARM_CAT_01, PARM_LEVEL_LIMITED },
5050
{"device_tmo", PARM_TYP_INT, PARM_CAT_01, PARM_LEVEL_LIMITED },
51-
{"pause", PARM_TYP_BOOL, PARM_CAT_01, PARM_LEVEL_LIMITED },
51+
{"pause", PARM_TYP_LIST, PARM_CAT_01, PARM_LEVEL_LIMITED },
5252
{"schedule_params", PARM_TYP_STRING, PARM_CAT_01, PARM_LEVEL_LIMITED },
5353
{"cleandir_params", PARM_TYP_STRING, PARM_CAT_01, PARM_LEVEL_LIMITED },
5454
{"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)
688688
void cls_config::edit_pause(std::string &parm, enum PARM_ACT pact)
689689
{
690690
if (pact == PARM_ACT_DFLT) {
691-
pause = false;
692-
} else if (pact == PARM_ACT_SET) {
693-
edit_set_bool(pause, parm);
691+
pause = "schedule";
692+
} else if (pact == PARM_ACT_SET) {
693+
if ((parm == "schedule") ||
694+
(parm == "1") || (parm == "yes") ||
695+
(parm == "on") || (parm == "true") ||
696+
(parm == "0") || (parm == "no") ||
697+
(parm == "off") || (parm == "false")) {
698+
if ((parm == "schedule") || (parm == "on") || (parm == "off")) {
699+
pause = parm;
700+
} else if ((parm == "1") || (parm == "yes") || (parm == "true")) {
701+
MOTPLS_LOG(WRN, TYPE_ALL, NO_ERRNO
702+
, _("Old type specified for pause %s. Use 'on' instead")
703+
,parm.c_str());
704+
pause = "on";
705+
} else if ((parm == "0") || (parm == "no") || (parm == "false")) {
706+
MOTPLS_LOG(WRN, TYPE_ALL, NO_ERRNO
707+
, _("Old type specified for pause %s. Use 'off' instead")
708+
,parm.c_str());
709+
pause = "off";
710+
}
711+
} else {
712+
MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid pause %s"),parm.c_str());
713+
}
694714
} else if (pact == PARM_ACT_GET) {
695-
edit_get_bool(parm, pause);
715+
parm = pause;
716+
} else if (pact == PARM_ACT_LIST) {
717+
parm = "[";
718+
parm = parm + "\"schedule\",\"on\",\"off\"";
719+
parm = parm + "]";
696720
}
697721
return;
698722
MOTPLS_LOG(DBG, TYPE_ALL, NO_ERRNO,"%s:%s","pause",_("pause"));
@@ -3668,7 +3692,7 @@ void cls_config::cmdline()
36683692
edit_set("log_file", optarg);
36693693
break;
36703694
case 'm':
3671-
app->user_pause = true;
3695+
app->user_pause = "on";
36723696
break;
36733697
case 'h':
36743698
case '?':

src/conf.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
int watchdog_tmo;
111111
int watchdog_kill;
112112
int device_tmo;
113-
bool pause;
113+
std::string pause;
114114
std::string schedule_params;
115115
std::string cleandir_params;
116116

src/motionplus.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class cls_motapp {
189189

190190
int argc;
191191
char **argv;
192-
bool user_pause;
192+
std::string user_pause;
193193

194194
cls_config *conf_src;
195195
cls_config *cfg;

src/webu_html.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -689,12 +689,16 @@ void cls_webu_html::script_assign_actions()
689689
(itm->param_value == "on")) {
690690
webua->resp_page +=
691691
" html_actions += \"<a onclick=\\\"send_action(\";\n"
692-
" html_actions += \"'pause');\\\">\";\n"
693-
" html_actions += \"Pause</a>\\n\";\n\n"
692+
" html_actions += \"'pause_on');\\\">\";\n"
693+
" html_actions += \"Pause On</a>\\n\";\n\n"
694694

695695
" html_actions += \"<a onclick=\\\"send_action(\";\n"
696-
" html_actions += \"'unpause');\\\">\";\n"
697-
" html_actions += \"Unpause</a>\\n\";\n\n"
696+
" html_actions += \"'pause_off');\\\">\";\n"
697+
" html_actions += \"Pause Off</a>\\n\";\n\n"
698+
699+
" html_actions += \"<a onclick=\\\"send_action(\";\n"
700+
" html_actions += \"'pause_schedule');\\\">\";\n"
701+
" html_actions += \"Pause Schedule</a>\\n\";\n\n"
698702
;
699703
} else if ((itm->param_name == "camera_add") &&
700704
(itm->param_value == "on")) {

src/webu_json.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ void cls_webu_json::status_vars(int indx_cam)
408408
webua->resp_page += ",\"pause\":false";
409409
}
410410

411+
webua->resp_page += ",\"user_pause\":\"" + cam->user_pause +"\"";
412+
411413
webua->resp_page += "}";
412414
}
413415

src/webu_post.cpp

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,7 @@ void cls_webu_post::action_snapshot()
251251

252252
}
253253

254-
/* Process the pause action */
255-
void cls_webu_post::action_pause()
254+
void cls_webu_post::action_pause_on()
256255
{
257256
int indx;
258257

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

270269
if (webua->device_id == 0) {
271270
for (indx=0; indx<app->cam_cnt; indx++) {
272-
app->cam_list[indx]->user_pause = true;
271+
app->cam_list[indx]->user_pause = "on";
273272
}
274273
} else {
275-
app->cam_list[webua->camindx]->user_pause = true;
274+
app->cam_list[webua->camindx]->user_pause = "on";
276275
}
277276

278277
}
279278

280-
/* Process the unpause action */
281-
void cls_webu_post::action_unpause()
279+
void cls_webu_post::action_pause_off()
282280
{
283281
int indx;
284282

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

296294
if (webua->device_id == 0) {
297295
for (indx=0; indx<app->cam_cnt; indx++) {
298-
app->cam_list[indx]->user_pause = false;
296+
app->cam_list[indx]->user_pause = "off";
299297
}
300298
} else {
301-
app->cam_list[webua->camindx]->user_pause = false;
299+
app->cam_list[webua->camindx]->user_pause = "off";
300+
}
301+
302+
}
303+
304+
void cls_webu_post::action_pause_schedule()
305+
{
306+
int indx;
307+
308+
for (indx=0;indx<webu->wb_actions->params_cnt;indx++) {
309+
if (webu->wb_actions->params_array[indx].param_name == "pause") {
310+
if (webu->wb_actions->params_array[indx].param_value == "off") {
311+
MOTPLS_LOG(INF, TYPE_ALL, NO_ERRNO, "Pause action disabled");
312+
return;
313+
} else {
314+
break;
315+
}
316+
}
317+
}
318+
319+
if (webua->device_id == 0) {
320+
for (indx=0; indx<app->cam_cnt; indx++) {
321+
app->cam_list[indx]->user_pause = "schedule";
322+
}
323+
} else {
324+
app->cam_list[webua->camindx]->user_pause = "schedule";
302325
}
303326

304327
}
@@ -738,10 +761,23 @@ void cls_webu_post::process_actions()
738761
action_snapshot();
739762

740763
} else if (post_cmd == "pause") {
741-
action_pause();
764+
MOTPLS_LOG(NTC, TYPE_STREAM, NO_ERRNO
765+
, _("pause action deprecated. Use pause_on"));
766+
action_pause_on();
742767

743768
} else if (post_cmd == "unpause") {
744-
action_unpause();
769+
MOTPLS_LOG(NTC, TYPE_STREAM, NO_ERRNO
770+
, _("unpause action deprecated. Use pause_off"));
771+
action_pause_off();
772+
773+
} else if (post_cmd == "pause_on") {
774+
action_pause_on();
775+
776+
} else if (post_cmd == "pause_off") {
777+
action_pause_off();
778+
779+
} else if (post_cmd == "pause_schedule") {
780+
action_pause_schedule();
745781

746782
} else if (post_cmd == "restart") {
747783
action_restart();

0 commit comments

Comments
 (0)