1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-07-03 01:13:18 +03:00
iris/boot-programs/metronome.ccp

73 lines
2.1 KiB
Plaintext
Raw Normal View History

2009-10-10 02:31:10 +03:00
#pypp 0
// Iris: micro-kernel for a capability-based operating system.
// boot-programs/metronome.ccp: Userspace program.
// Copyright 2009 Bas Wijnen <wijnen@debian.org>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "devices.hh"
#include "keys.hh"
Kernel::Num start ():
2009-12-26 15:17:06 +02:00
Kernel::schedule ()
2009-10-10 02:31:10 +03:00
kdebug ("metronome started\n")
Buzzer buzzer = Kernel::my_parent.get_device <Buzzer> ()
Keyboard kbd = Kernel::my_parent.get_device <Keyboard> ()
Kernel::Cap key = Kernel::my_receiver.create_capability (0)
kbd.set_cb (key)
2009-10-31 10:32:23 +02:00
// Frequency of the pulse train in millihertz.
2009-10-10 02:31:10 +03:00
unsigned mHz = 1000
2009-10-31 10:32:23 +02:00
// Frequency of single pulses in hertz.
2009-10-10 02:31:10 +03:00
unsigned freq = 1000
2009-10-31 10:32:23 +02:00
bool running (false)
2009-10-10 02:31:10 +03:00
while true:
Kernel::wait ()
switch Kernel::recv.protected_data.l:
case ~0:
if running:
buzzer.beep (freq, 10, ~0)
Kernel::my_receiver.set_alarm (HZ * 1000 / mHz)
break
case 0:
if Kernel::recv.data[0].l & Keyboard::RELEASE:
break
switch Kernel::recv.data[0].l:
case Key::VOLUME_UP:
freq = freq * 11 / 10
break
case Key::VOLUME_DOWN:
freq = freq * 9 / 10
break
case Key::LEFT:
2009-10-31 10:32:23 +02:00
mHz = mHz * 99 / 100
2009-10-10 02:31:10 +03:00
break
case Key::RIGHT:
2009-10-31 10:32:23 +02:00
mHz = mHz * 101 / 100
2009-10-10 02:31:10 +03:00
break
case Key::UP:
mHz = mHz * 11 / 10
break
case Key::DOWN:
mHz = mHz * 9 / 10
break
case Key::P:
running = !running
if running:
2009-10-31 10:32:23 +02:00
Kernel::my_receiver.set_alarm (0)
2009-10-10 02:31:10 +03:00
break
break
default:
kdebug ("huh?\n")
break