mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-21 18:15:58 +00:00
Kernel+Userland: Add support for using the PCSpeaker with various tones
This commit is contained in:
parent
2d27c98659
commit
11a7e21c2a
|
@ -12,6 +12,10 @@ $ beep
|
||||||
|
|
||||||
beep allows the user to beep the PC speaker.
|
beep allows the user to beep the PC speaker.
|
||||||
|
|
||||||
|
## Options
|
||||||
|
|
||||||
|
* `-f|--beep-tone`: Beep tone (frequency in Hz)
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
If the user disabled the usage of PC speaker in the kernel commandline, the program
|
If the user disabled the usage of PC speaker in the kernel commandline, the program
|
||||||
|
@ -20,7 +24,10 @@ will fail to use the PC speaker.
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
# Use beep with default tone
|
||||||
$ beep
|
$ beep
|
||||||
|
# Use beep with tone of 1000Hz
|
||||||
|
$ beep -f 1000
|
||||||
```
|
```
|
||||||
|
|
||||||
## See also
|
## See also
|
||||||
|
|
|
@ -291,7 +291,7 @@ public:
|
||||||
ErrorOr<FlatPtr> sys$emuctl();
|
ErrorOr<FlatPtr> sys$emuctl();
|
||||||
ErrorOr<FlatPtr> sys$yield();
|
ErrorOr<FlatPtr> sys$yield();
|
||||||
ErrorOr<FlatPtr> sys$sync();
|
ErrorOr<FlatPtr> sys$sync();
|
||||||
ErrorOr<FlatPtr> sys$beep();
|
ErrorOr<FlatPtr> sys$beep(int tone);
|
||||||
ErrorOr<FlatPtr> sys$get_process_name(Userspace<char*> buffer, size_t buffer_size);
|
ErrorOr<FlatPtr> sys$get_process_name(Userspace<char*> buffer, size_t buffer_size);
|
||||||
ErrorOr<FlatPtr> sys$set_process_name(Userspace<char const*> user_name, size_t user_name_length);
|
ErrorOr<FlatPtr> sys$set_process_name(Userspace<char const*> user_name, size_t user_name_length);
|
||||||
ErrorOr<FlatPtr> sys$create_inode_watcher(u32 flags);
|
ErrorOr<FlatPtr> sys$create_inode_watcher(u32 flags);
|
||||||
|
|
|
@ -12,13 +12,15 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
ErrorOr<FlatPtr> Process::sys$beep()
|
ErrorOr<FlatPtr> Process::sys$beep(int tone)
|
||||||
{
|
{
|
||||||
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
||||||
if (!kernel_command_line().is_pc_speaker_enabled())
|
if (!kernel_command_line().is_pc_speaker_enabled())
|
||||||
return ENODEV;
|
return ENODEV;
|
||||||
|
if (tone < 20 || tone > 20000)
|
||||||
|
return EINVAL;
|
||||||
#if ARCH(X86_64)
|
#if ARCH(X86_64)
|
||||||
PCSpeaker::tone_on(440);
|
PCSpeaker::tone_on(tone);
|
||||||
auto result = Thread::current()->sleep(Time::from_nanoseconds(200'000'000));
|
auto result = Thread::current()->sleep(Time::from_nanoseconds(200'000'000));
|
||||||
PCSpeaker::tone_off();
|
PCSpeaker::tone_off();
|
||||||
if (result.was_interrupted())
|
if (result.was_interrupted())
|
||||||
|
|
|
@ -924,9 +924,9 @@ int gettid()
|
||||||
return cached_tid;
|
return cached_tid;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sysbeep()
|
int sysbeep(int tone)
|
||||||
{
|
{
|
||||||
int rc = syscall(SC_beep);
|
int rc = syscall(SC_beep, tone);
|
||||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ int get_process_name(char* buffer, int buffer_size);
|
||||||
int set_process_name(char const* name, size_t name_length);
|
int set_process_name(char const* name, size_t name_length);
|
||||||
void dump_backtrace(void);
|
void dump_backtrace(void);
|
||||||
int fsync(int fd);
|
int fsync(int fd);
|
||||||
int sysbeep(void);
|
int sysbeep(int tone);
|
||||||
int gettid(void);
|
int gettid(void);
|
||||||
int getpagesize(void);
|
int getpagesize(void);
|
||||||
pid_t fork(void);
|
pid_t fork(void);
|
||||||
|
|
|
@ -132,9 +132,9 @@ namespace Core::System {
|
||||||
|
|
||||||
#ifdef AK_OS_SERENITY
|
#ifdef AK_OS_SERENITY
|
||||||
|
|
||||||
ErrorOr<void> beep()
|
ErrorOr<void> beep(Optional<size_t> tone)
|
||||||
{
|
{
|
||||||
auto rc = ::sysbeep();
|
auto rc = ::sysbeep(tone.value_or(440));
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
return Error::from_syscall("beep"sv, -errno);
|
return Error::from_syscall("beep"sv, -errno);
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
namespace Core::System {
|
namespace Core::System {
|
||||||
|
|
||||||
#ifdef AK_OS_SERENITY
|
#ifdef AK_OS_SERENITY
|
||||||
ErrorOr<void> beep();
|
ErrorOr<void> beep(Optional<size_t> tone);
|
||||||
ErrorOr<void> pledge(StringView promises, StringView execpromises = {});
|
ErrorOr<void> pledge(StringView promises, StringView execpromises = {});
|
||||||
ErrorOr<void> unveil(StringView path, StringView permissions);
|
ErrorOr<void> unveil(StringView path, StringView permissions);
|
||||||
ErrorOr<void> unveil_after_exec(StringView path, StringView permissions);
|
ErrorOr<void> unveil_after_exec(StringView path, StringView permissions);
|
||||||
|
|
|
@ -1067,7 +1067,7 @@ void TerminalWidget::beep()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (m_bell_mode == BellMode::AudibleBeep) {
|
if (m_bell_mode == BellMode::AudibleBeep) {
|
||||||
sysbeep();
|
sysbeep(440);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_visual_beep_timer->restart(200);
|
m_visual_beep_timer->restart(200);
|
||||||
|
|
|
@ -4,11 +4,16 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/System.h>
|
#include <LibCore/System.h>
|
||||||
#include <LibMain/Main.h>
|
#include <LibMain/Main.h>
|
||||||
|
|
||||||
ErrorOr<int> serenity_main(Main::Arguments)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
TRY(Core::System::beep());
|
Optional<size_t> tone;
|
||||||
|
Core::ArgsParser args_parser;
|
||||||
|
args_parser.add_option(tone, "Beep tone", "beep-tone", 'f', "Beep tone (frequency in Hz)");
|
||||||
|
args_parser.parse(arguments);
|
||||||
|
TRY(Core::System::beep(tone));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue