MODULE Beep;
IMPORT Kernel32, Kernel(* , KernelLog*) ;
CONST
TYPE
Beeper = OBJECT
VAR hz: LONGINT;
beep: BOOLEAN;
PROCEDURE & Init*;
BEGIN
beep := FALSE;
END Init;
PROCEDURE On( hz: LONGINT );
BEGIN
BEGIN {EXCLUSIVE}
SELF.hz := hz; beep := TRUE;
END;
END On;
PROCEDURE Off;
BEGIN
BEGIN {EXCLUSIVE}
beep := FALSE;
END;
END Off;
PROCEDURE Beep;
VAR retBOOL: Kernel32.BOOL;
BEGIN
LOOP
WHILE (beep) DO retBOOL :=Kernel32.Beep( hz, 50 ); END;
BEGIN {EXCLUSIVE}
AWAIT( beep );
END;
END;
END Beep;
BEGIN {ACTIVE}
(*KernelLog.String("Beep:Beeper.Active"); KernelLog.Ln; *) Beep();
END Beeper;
VAR
beep: Beeper;
PROCEDURE Beep*( hz: LONGINT );
VAR s: SET;
BEGIN
IF (hz # 0) THEN
IF beep = NIL THEN NEW( beep ) END;
beep.On( hz )
ELSE
IF beep # NIL THEN beep.Off(); END;
END;
END Beep;
PROCEDURE Test*;
VAR timer: Kernel.Timer;
BEGIN
NEW(timer);
Beep( 2000 ); timer.Sleep(1000); Beep(0);
END Test;
PROCEDURE TestOn*;
BEGIN
Beep( 2000 );
END TestOn;
PROCEDURE TestOff*;
BEGIN
Beep( 0 );
END TestOff;
END Beep.
System.Free Beep ~
Beep.TimerTest
Beep.Test
Beep.TestOn
Beep.TestOff
~