Root/userspace/application/metronome.ccp

1#pypp 0
2// Iris: micro-kernel for a capability-based operating system.
3// boot-programs/metronome.ccp: Userspace program.
4// Copyright 2009 Bas Wijnen <wijnen@debian.org>
5//
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19#include "devices.hh"
20#include "keys.hh"
21
22Iris::Num start ():
23    Iris::my_parent.init_done ()
24    Iris::Buzzer buzzer = Iris::my_parent.get_capability <Iris::Buzzer> ()
25    Iris::Keyboard kbd = Iris::my_parent.get_capability <Iris::Keyboard> ()
26    Iris::Cap key = Iris::my_receiver.create_capability (0)
27    kbd.set_cb (key)
28    // Frequency of the pulse train in millihertz.
29    unsigned mHz = 1000
30    // Frequency of single pulses in hertz.
31    unsigned freq = 1000
32    bool running (false)
33    while true:
34        Iris::wait ()
35        switch Iris::recv.protected_data.l:
36            case ~0:
37                if running:
38                    buzzer.beep (freq, 10, ~0)
39                    Iris::my_receiver.set_alarm (HZ * 1000 / mHz)
40                break
41            case 0:
42                if Iris::recv.data[0].l & Iris::Keyboard::RELEASE:
43                    break
44                switch Iris::recv.data[0].l:
45                    case Key::VOLUME_UP:
46                        freq = freq * 11 / 10
47                        break
48                    case Key::VOLUME_DOWN:
49                        freq = freq * 9 / 10
50                        break
51                    case Key::LEFT:
52                        mHz = mHz * 99 / 100
53                        break
54                    case Key::RIGHT:
55                        mHz = mHz * 101 / 100
56                        break
57                    case Key::UP:
58                        mHz = mHz * 11 / 10
59                        break
60                    case Key::DOWN:
61                        mHz = mHz * 9 / 10
62                        break
63                    case Key::P:
64                        running = !running
65                        if running:
66                            Iris::my_receiver.set_alarm (0)
67                        break
68                break
69            default:
70                kdebug ("metronome: huh?\n")
71                break
72

Archive Download this file

Branches:
master



interactive