1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-11-17 10:30:37 +02:00
iris/userspace/application/alarm.ccp
2013-05-14 18:30:50 -04:00

55 lines
1.7 KiB
COBOL

#pypp 0
// vim: set filetype=cpp : //
#include <iris.hh>
#include <devices.hh>
enum captypes:
CONTROL = 1
KBD
INTERRUPT
Iris::Num start ():
unsigned *screen = (unsigned *)0x40000000
Iris::RTC rtc = Iris::my_parent.get_capability <Iris::RTC> ()
Iris::Display display = Iris::my_parent.get_capability <Iris::Display> ()
display.map_fb ((unsigned)screen)
Iris::Font font = Iris::my_parent.get_capability <Iris::Font> ()
font.set_display (display)
Iris::Keyboard keyboard = Iris::my_parent.get_capability <Iris::Keyboard> ()
Iris::Cap cap = Iris::my_receiver.create_capability (KBD)
keyboard.set_cb (cap.copy ())
Iris::free_cap (cap)
Iris::Buzzer buzzer = Iris::my_parent.get_capability <Iris::Buzzer> ()
Iris::Event self = Iris::my_receiver.create_capability (CONTROL)
Iris::my_parent.provide_capability <Iris::Event> (self)
cap = Iris::my_receiver.create_capability (INTERRUPT)
Iris::my_parent.init_done ()
while true:
Iris::wait ()
switch Iris::recv.protected_data.l:
case INTERRUPT:
// RTC alarm interrupt.
if Iris::recv.data[0].l == ~0:
// Not a real interrupt, just an abort notification.
continue
font.printf ("alarm: RTC alarm interrupt\n")
break
case CONTROL:
// Store callback
font.printf ("alarm: control event\n")
break
case KBD:
if Iris::recv.data[0].l & Iris::Keyboard::RELEASE:
// Key release.
Iris::poweroff ()
else:
// Key press.
unsigned time = rtc.get_time ()
rtc.set_alarm (time + 5, cap)
unsigned alarm = rtc.get_alarm ()
unsigned enabled = Iris::recv.data[1].l
font.printf ("Debug: %d %d %d\n", time, alarm, enabled)
break
default:
Iris::panic (Iris::recv.protected_data.l, "invalid request for alarm")