mirror of
git://projects.qi-hardware.com/iris.git
synced 2024-11-05 06:43:44 +02:00
74 lines
1.4 KiB
COBOL
74 lines
1.4 KiB
COBOL
#pypp 0
|
|
#include <iris.hh>
|
|
#include <ui.hh>
|
|
|
|
enum Ins:
|
|
TOTAL_TIME
|
|
START
|
|
NUM_INS
|
|
|
|
enum Outs:
|
|
CURRENT_TIME
|
|
ALARM
|
|
NUM_OUTS
|
|
|
|
typedef UI <NUM_INS, NUM_OUTS> ui_t
|
|
static ui_t ui
|
|
static ui_t::in <unsigned> total_time
|
|
static ui_t::in_event do_start
|
|
static ui_t::out <unsigned> current_time
|
|
static ui_t::out_event do_alarm
|
|
|
|
static bool ticking
|
|
|
|
static void event (unsigned code):
|
|
switch code:
|
|
case TOTAL_TIME:
|
|
break
|
|
case START:
|
|
current_time = total_time
|
|
if !ticking:
|
|
if !current_time:
|
|
do_alarm ()
|
|
else:
|
|
ticking = true
|
|
Iris::my_receiver.set_alarm (HZ)
|
|
break
|
|
default:
|
|
Iris::panic (0, "invalid event for alarm clock")
|
|
|
|
Iris::Num start ():
|
|
ticking = false;
|
|
Iris::Cap ui_cap = Iris::my_receiver.create_capability (0)
|
|
ui.init (ui_cap.copy ());
|
|
Iris::free_cap (ui_cap)
|
|
total_time.init ()
|
|
do_start.init ()
|
|
current_time.init ()
|
|
do_alarm.init ()
|
|
ui.add_in (&total_time, TOTAL_TIME);
|
|
ui.add_in (&do_start, START);
|
|
ui.add_out (¤t_time, CURRENT_TIME);
|
|
ui.add_out (&do_alarm, ALARM);
|
|
Iris::my_parent.init_done ()
|
|
|
|
while true:
|
|
Iris::wait ()
|
|
switch Iris::recv.protected_data.l:
|
|
case ~0:
|
|
// alarm.
|
|
if current_time:
|
|
current_time = current_time - 1
|
|
if !current_time:
|
|
do_alarm ()
|
|
ticking = false
|
|
else:
|
|
// TODO: use rtc for scheduling an event.
|
|
Iris::my_receiver.set_alarm (HZ)
|
|
continue
|
|
case 0:
|
|
// ui event.
|
|
if !ui.event (&event):
|
|
// Exit request.
|
|
return 0
|