Skip to content

Commit

Permalink
Add looping
Browse files Browse the repository at this point in the history
  • Loading branch information
calebchalmers committed Mar 20, 2024
1 parent 000ab3d commit d2a70d7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion ut-robomaster/src/subsystems/sound/command_play_sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ void CommandPlaySound::initialize()

void CommandPlaySound::execute()
{
if (read_index >= sound.data_length) return;
if (read_index >= sound.data_length)
{
if (!loop) return;
read_index -= sound.data_length;
}

if (timer.execute())
{
Expand Down
8 changes: 7 additions & 1 deletion ut-robomaster/src/subsystems/sound/command_play_sound.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ using tap::arch::MilliTimeout;
class CommandPlaySound : public tap::control::Command
{
public:
CommandPlaySound(src::Drivers *drivers, SoundSubsystem *subsystem, Sound sound)
CommandPlaySound(
src::Drivers *drivers,
SoundSubsystem *subsystem,
Sound sound,
bool loop = false)
: drivers(drivers),
subsystem(subsystem),
sound(sound),
loop(loop),
timer()
{
addSubsystemRequirement(subsystem);
Expand All @@ -44,6 +49,7 @@ class CommandPlaySound : public tap::control::Command
Sound sound;

int read_index = 0;
bool loop = false;
MilliTimeout timer;
}; // class CommandPlaySound
} // namespace commands

0 comments on commit d2a70d7

Please sign in to comment.