diff options
-rw-r--r-- | include/xas/drone.h | 5 | ||||
-rw-r--r-- | src/drone.c | 40 |
2 files changed, 45 insertions, 0 deletions
diff --git a/include/xas/drone.h b/include/xas/drone.h index 28929fd..df16040 100644 --- a/include/xas/drone.h +++ b/include/xas/drone.h @@ -116,6 +116,11 @@ int xas_drone_seq_sample(xas_drone *drone, size_t sample_index, struct timeval *now); +int xas_drone_seq_beep(xas_drone *drone, + xas_seq *seq, + enum xas_drone_mood mood, + struct timeval *now); + /* * Methods for drone vocalisations */ diff --git a/src/drone.c b/src/drone.c index b00e492..4fa9ddb 100644 --- a/src/drone.c +++ b/src/drone.c @@ -357,6 +357,46 @@ error_xas_seq_add: return -1; } +int xas_drone_seq_beep(xas_drone *drone, + xas_seq *seq, + enum xas_drone_mood mood, + struct timeval *now) { + static struct timeval duration = { 1, 0 }, + tmp; + + if (xas_seq_add_set_type(seq, + &drone->obj, + *now, + XAS_DRONE_INDEX_BEEP, + mood) < 0) { + goto error_seq; + } + + if (xas_seq_add_event_on(seq, + &drone->obj, + *now, + XAS_DRONE_INDEX_BEEP) < 0) { + goto error_seq; + } + + timeradd(now, &duration, &tmp); + + now->tv_sec = tmp.tv_sec; + now->tv_usec = tmp.tv_usec; + + if (xas_seq_add_event_off(seq, + &drone->obj, + *now, + XAS_DRONE_INDEX_BEEP) < 0) { + goto error_seq; + } + + return 0; + +error_seq: + return -1; +} + int xas_drone_vox_set_voice(xas_drone *drone, const char *voice) { return xas_vox_set_voice(drone->vox, voice); } |