1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-29 07:17:35 +00:00

Kernel+Userland: Add option for duration of /dev/beep producing sound

This commit is contained in:
Liav A 2023-08-25 20:26:18 +03:00 committed by Tim Schumacher
parent 1b00618fd9
commit 26f96d2a42
6 changed files with 13 additions and 5 deletions

View file

@ -149,12 +149,12 @@ namespace Core::System {
#ifdef AK_OS_SERENITY
ErrorOr<void> beep(u16 tone)
ErrorOr<void> beep(u16 tone, u16 milliseconds_duration)
{
static Optional<int> beep_fd;
if (!beep_fd.has_value())
beep_fd = TRY(Core::System::open("/dev/beep"sv, O_RDWR));
BeepInstruction instruction { tone };
BeepInstruction instruction { tone, milliseconds_duration };
TRY(Core::System::write(beep_fd.value(), Span<u8 const>(&instruction, sizeof(BeepInstruction))));
return {};
}

View file

@ -51,7 +51,7 @@
namespace Core::System {
#ifdef AK_OS_SERENITY
ErrorOr<void> beep(u16 tone = 440);
ErrorOr<void> beep(u16 tone = 440, u16 milliseconds_duration = 200);
ErrorOr<void> pledge(StringView promises, StringView execpromises = {});
ErrorOr<void> unveil(StringView path, StringView permissions);
ErrorOr<void> unveil_after_exec(StringView path, StringView permissions);

View file

@ -11,9 +11,11 @@
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
Optional<size_t> tone;
Optional<size_t> milliseconds_duration;
Core::ArgsParser args_parser;
args_parser.add_option(tone, "Beep tone", "beep-tone", 'f', "Beep tone (frequency in Hz)");
args_parser.add_option(milliseconds_duration, "Duration", "duration", 'n', "Duration (in milliseconds)");
args_parser.parse(arguments);
TRY(Core::System::beep(tone.value_or(440)));
TRY(Core::System::beep(tone.value_or(440), milliseconds_duration.value_or(200)));
return 0;
}