#pypp 0 // Iris: micro-kernel for a capability-based operating system. // boot-programs/metronome.ccp: Userspace program. // Copyright 2009 Bas Wijnen // // 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 . #include "devices.hh" #include "keys.hh" Kernel::Num start (): kdebug ("metronome started\n") Buzzer buzzer = Kernel::my_parent.get_device () Keyboard kbd = Kernel::my_parent.get_device () Kernel::Cap key = Kernel::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: 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: 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: Kernel::my_receiver.set_alarm (0) break break default: kdebug ("huh?\n") break