1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-07-01 03:44:32 +03:00
iris/source/metronome.ccp

72 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"
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)
2009-10-10 02:31:10 +03:00
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:
Iris::wait ()
switch Iris::recv.protected_data.l:
2009-10-10 02:31:10 +03:00
case ~0:
if running:
buzzer.beep (freq, 10, ~0)
Iris::my_receiver.set_alarm (HZ * 1000 / mHz)
2009-10-10 02:31:10 +03:00
break
case 0:
if Iris::recv.data[0].l & Iris::Keyboard::RELEASE:
2009-10-10 02:31:10 +03:00
break
switch Iris::recv.data[0].l:
2009-10-10 02:31:10 +03:00
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:
Iris::my_receiver.set_alarm (0)
2009-10-10 02:31:10 +03:00
break
break
default:
2009-12-27 01:12:35 +02:00
kdebug ("metronome: huh?\n")
2009-10-10 02:31:10 +03:00
break