[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[debian-users:07150] Re: beep control?
佐野@浜松です。笹山さんこんにちは。
> コンソールのビープ音を制御するコマンドってないでしょうか。音
> の高さと長さが変えられれば、とりあえず用は足りるんですが。
> モニターなしのホストで、haltの前に鳴らすとかしたいので、Xが
> 必要なのとかはダメです。できればパッケージに入ってるといいの
> ですが、ソースでも可です。
たしか昔、 fj.* だったかで見かけたソースコードが
ありますが、こんなので使えますでしょうか ?
注意点として、 root 特権が無いと ioctl を拒絶されるので
 root で実行する必要があります。
 mktone の引数を換えることで、高さと長さを変更できると
思うので、 main() を変更して argc, argv を使うように
すればいかがでしょう。(試してはいないです。すみません。)
--- begin --- cut off --- begin --- cut off ---
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/kd.h>
#include <sys/param.h>
int cons_fd = -1;
#define PC_CLOCK 1193180
int mktone(double hz, int ms)
{
    int tick;
    if (cons_fd < 0) {
        cons_fd = open("/dev/tty0", O_WRONLY);
        if (cons_fd < 0)
            return cons_fd;
    }
    tick = (int) (PC_CLOCK / hz);
    if (ioctl(cons_fd, KDMKTONE, (ms << 16) | (tick & 0xffff)) < 0)
        return -1;
    return 0;
}
int
main(void)
{
    mktone(440, 1000);
    if (cons_fd != -1)
        close(cons_fd);
    return 0;
}
--- end --- cut off --- end --- cut off ---
-- 
 <sano@xxxxxxxxxxxxxxxxxxxxxxxxxx> : Taketoshi Sano (佐野 武俊)