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

Commit 8b85a9a

Browse files
committed
Add conversion specifiers for sound alerts
1 parent 260a85a commit 8b85a9a

4 files changed

Lines changed: 38 additions & 6 deletions

File tree

doc/motionplus_config.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,17 @@ <h3><a name="conversion_specifiers"></a>Conversion Specifiers</h3>
671671
</tr>
672672
<tr>
673673
<td bgcolor="#edf4f9" >%{ver}</a> </td>
674-
<td bgcolor="#edf4f9" >The version of MotionPlus</a> </td>
674+
<td bgcolor="#edf4f9" >version of MotionPlus</a> </td>
675+
<td bgcolor="#edf4f9" >%{trig_nbr}</a> </td>
676+
<td bgcolor="#edf4f9" >sound alert number that was triggered</a> </td>
677+
<td bgcolor="#edf4f9" >%{trig_nm}</a> </td>
678+
<td bgcolor="#edf4f9" >sound alert name that was triggered</a> </td>
675679
</tr>
680+
<tr>
681+
<td bgcolor="#edf4f9" >%{trig_freq}</a> </td>
682+
<td bgcolor="#edf4f9" >frequency that triggered the sound alert</a> </td>
683+
</tr>
684+
676685
</tbody>
677686
</table>
678687
</div>

src/motionplus.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@ struct ctx_snd_info {
379379
int buffer_size;
380380
int frames;
381381
std::string pulse_server;
382+
std::string trig_freq;
383+
std::string trig_nbr;
384+
std::string trig_nm;
382385
};
383386

384387
struct ctx_dev {

src/sound.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,6 @@ static void snd_check_alerts(ctx_dev *snd)
758758
float pImaginaryNbr;
759759
float pIntensity;
760760
bool trigger;
761-
std::string pcmd;
762761
std::list<ctx_snd_alert>::iterator it;
763762
struct timespec trig_ts;
764763

@@ -826,10 +825,10 @@ static void snd_check_alerts(ctx_dev *snd)
826825
, it->volume_level, chkcnt
827826
, info->vol_max);
828827
if (snd->conf->on_sound_alert != "") {
829-
pcmd = snd->conf->on_sound_alert;
830-
pcmd = pcmd + " " + std::to_string(it->alert_id);
831-
pcmd = pcmd + " " + std::to_string(freq_value);
832-
util_exec_command(snd, pcmd.c_str(), NULL, 0);
828+
info->trig_freq =std::to_string(freq_value);
829+
info->trig_nbr = std::to_string(it->alert_id);
830+
info->trig_nm = it->alert_nm;
831+
util_exec_command(snd, snd->conf->on_sound_alert.c_str(), NULL, 0);
833832
}
834833
}
835834
}

src/util.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,27 @@ static void mystrftime_long (const ctx_dev *cam,
335335
return;
336336
}
337337

338+
if (SPECIFIERWORD("trig_freq")) {
339+
if (cam->snd_info != NULL) {
340+
snprintf (out, PATH_MAX, "%*s", width, cam->snd_info->trig_freq.c_str() );
341+
}
342+
return;
343+
}
344+
345+
if (SPECIFIERWORD("trig_nbr")) {
346+
if (cam->snd_info != NULL) {
347+
snprintf (out, PATH_MAX, "%*s", width, cam->snd_info->trig_nbr.c_str() );
348+
}
349+
return;
350+
}
351+
352+
if (SPECIFIERWORD("trig_nm")) {
353+
if (cam->snd_info != NULL) {
354+
snprintf (out, PATH_MAX, "%*s", width, cam->snd_info->trig_nm.c_str() );
355+
}
356+
return;
357+
}
358+
338359

339360
// Not a valid modifier keyword. Log the error and ignore.
340361
MOTPLS_LOG(ERR, TYPE_ALL, NO_ERRNO,

0 commit comments

Comments
 (0)