1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-11-04 23:34:04 +02:00
iris/source/gui.ccp

269 lines
5.0 KiB
Plaintext
Raw Normal View History

#pypp 0
#include <iris.hh>
#include <devices.hh>
#include <keys.hh>
// Interface: two way, started by ui.
// From ui to application.
// ~0: request reset.
// ~1: set reply cap; send current state.
// inum: event (with optional value) for input number num.
// From application to ui.
// onum: event (with optional value) for output number num.
// For now, the code is hardwired to the alarm clock interface.
enum outs:
CURRENT_TIME
ALARM
enum ins:
TOTAL_TIME
START
static Iris::Display display
static Iris::Buzzer buzzer
static unsigned *framebuffer
2010-05-15 19:42:17 +03:00
static unsigned alarming
enum PD:
UI
KBD
static char const *chardef =
".###.."
"#...#."
"#...#."
"#...#."
"#...#."
"#...#."
".###.."
"......"
"..#..."
"..#..."
"..#..."
"..#..."
"..#..."
"..#..."
"..#..."
"......"
".###.."
"#...#."
"....#."
"...#.."
"..#..."
".#...."
"#####."
"......"
".###.."
"#...#."
"....#."
"..##.."
"....#."
"#...#."
".###.."
"......"
"#...#."
"#...#."
"#...#."
"#####."
"....#."
"....#."
"....#."
"......"
"#####."
"#....."
"####.."
"....#."
"....#."
"....#."
"####.."
"......"
"....#."
"...#.."
"..#..."
".###.."
"#...#."
"#...#."
".###.."
"......"
"#####."
"....#."
"...#.."
"..#..."
".#...."
"#....."
"#....."
"......"
".###.."
"#...#."
"#...#."
".###.."
"#...#."
"#...#."
".###.."
"......"
".###.."
"#...#."
"#...#."
".###.."
"..#..."
".#...."
"#....."
"......"
"......"
"......"
"..#..."
"......"
"......"
"..#..."
"......"
"......"
static void draw_pixel (unsigned x, unsigned y, bool set):
for unsigned ty = 0; ty < 8; ++ty:
for unsigned tx = 0; tx < 8; ++tx:
framebuffer[320 * (y + ty) + x + tx] = (set ? 0xffffff : 0x000000)
static void draw_num (bool upper, unsigned x0, unsigned d):
for unsigned y = 0; y < 8; ++y:
for unsigned x = 0; x < 6; ++x:
draw_pixel (x * 10 + 10 + x0 * 60, y * 10 + (upper ? 30 : 50 + 80), chardef[(d * 8 + y) * 6 + x] == '#')
static void draw_time (bool upper, unsigned time):
unsigned min = time / 60
time %= 60
if min >= 100:
min = 99
time = 99
draw_num (upper, 0, min / 10)
draw_num (upper, 1, min % 10)
draw_num (upper, 3, time / 10)
draw_num (upper, 4, time % 10)
2010-05-15 19:42:17 +03:00
static void do_alarm ():
static unsigned tune[] = { 4, 6, 6, 5, 7, 7 }
if ++alarming > sizeof (tune) / sizeof (*tune):
alarming = 1
buzzer.beep (tune[alarming - 1] * 220, 300, ~0)
Iris::my_receiver.set_alarm (HZ / 3)
Iris::Num start ():
display = Iris::my_parent.get_capability <Iris::Display> ()
Iris::Setting bright = Iris::my_parent.get_capability <Iris::Setting> ()
Iris::Keyboard keyboard = Iris::my_parent.get_capability <Iris::Keyboard> ()
buzzer = Iris::my_parent.get_capability <Iris::Buzzer> ()
Iris::UI app = Iris::my_parent.get_capability <Iris::UI> ()
2010-05-15 19:42:17 +03:00
framebuffer = (unsigned *)0x15000
Iris::Caps fb = display.map_fb ((unsigned)framebuffer)
2010-05-15 19:42:17 +03:00
unsigned screen_max = bright.get_range ()
bright.set (0)
bool screen_on = false
Iris::Cap cb = Iris::my_receiver.create_capability (UI)
app.get_state (cb.copy ())
Iris::free_cap (cb)
2010-05-15 19:42:17 +03:00
cb = Iris::my_receiver.create_capability (KBD)
keyboard.set_cb (cb.copy ())
Iris::free_cap (cb)
2010-05-15 19:42:17 +03:00
draw_num (false, 2, 10)
draw_num (true, 2, 10)
2010-05-15 19:42:17 +03:00
unsigned total_time = 0
2010-05-15 19:42:17 +03:00
alarming = 0
2010-07-10 21:14:54 +03:00
Iris::my_parent.init_done ()
while true:
Iris::wait ()
switch Iris::recv.protected_data.l:
2010-05-15 19:42:17 +03:00
case ~0:
// Alarm.
if alarming:
do_alarm ()
break
case UI:
switch Iris::recv.data[0].l:
case CURRENT_TIME:
draw_time (false, Iris::recv.data[1].l)
break
case ALARM:
2010-05-15 19:42:17 +03:00
do_alarm ()
break
case TOTAL_TIME | Iris::UI::INPUT:
total_time = Iris::recv.data[1].l
draw_time (true, total_time)
break
case START | Iris::UI::INPUT:
break
break
case KBD:
if Iris::recv.data[0].l & Iris::Keyboard::RELEASE:
break
2010-05-15 19:42:17 +03:00
alarming = 0
switch Iris::recv.data[0].l:
case Key::VOLUME_UP:
total_time += 60
draw_time (true, total_time)
app.event (TOTAL_TIME, total_time)
break
case Key::VOLUME_DOWN:
if total_time < 60:
total_time = 0
else:
total_time -= 60
draw_time (true, total_time)
app.event (TOTAL_TIME, total_time)
break
case Key::UP:
total_time += 10
draw_time (true, total_time)
app.event (TOTAL_TIME, total_time)
break
case Key::DOWN:
if total_time < 10:
total_time = 0
else:
total_time -= 10
draw_time (true, total_time)
app.event (TOTAL_TIME, total_time)
break
case Key::LEFT:
if total_time < 1:
total_time = 0
else:
total_time -= 1
draw_time (true, total_time)
app.event (TOTAL_TIME, total_time)
break
case Key::RIGHT:
total_time += 1
draw_time (true, total_time)
app.event (TOTAL_TIME, total_time)
break
case Key::ENTER:
app.event (START)
2010-05-15 19:42:17 +03:00
break
case Key::BACKSPACE:
screen_on = !screen_on
if screen_on:
bright.set (screen_max)
else:
bright.set (0)
break