1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-06-28 23:29:50 +03:00
iris/source/metronome.ccp
2010-05-10 01:07:17 +02:00

72 lines
2.1 KiB
COBOL

#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"
Iris::Num start ():
Iris::my_parent.init_done ()
Iris::Buzzer buzzer = Iris::my_parent.get_capability <Iris::Buzzer> ()
Iris::Keyboard kbd = Iris::my_parent.get_capability <Iris::Keyboard> ()
Iris::Cap key = Iris::my_receiver.create_capability (0)
kbd.set_cb (key)
// Frequency of the pulse train in millihertz.
unsigned mHz = 1000
// Frequency of single pulses in hertz.
unsigned freq = 1000
bool running (false)
while true:
Iris::wait ()
switch Iris::recv.protected_data.l:
case ~0:
if running:
buzzer.beep (freq, 10, ~0)
Iris::my_receiver.set_alarm (HZ * 1000 / mHz)
break
case 0:
if Iris::recv.data[0].l & Iris::Keyboard::RELEASE:
break
switch Iris::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:
mHz = mHz * 99 / 100
break
case Key::RIGHT:
mHz = mHz * 101 / 100
break
case Key::UP:
mHz = mHz * 11 / 10
break
case Key::DOWN:
mHz = mHz * 9 / 10
break
case Key::P:
running = !running
if running:
Iris::my_receiver.set_alarm (0)
break
break
default:
kdebug ("metronome: huh?\n")
break