#pypp 0 #include #include #include // 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 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) static void beep (): buzzer.beep (4 * 440, 1000, ~0) Iris::Num start (): Iris::my_parent.init_done () display = Iris::my_parent.get_capability () Iris::Setting bright = Iris::my_parent.get_capability () Iris::Keyboard keyboard = Iris::my_parent.get_capability () buzzer = Iris::my_parent.get_capability () Iris::UI app = Iris::my_parent.get_capability () Iris::Cap cb = Iris::my_receiver.create_capability (UI) framebuffer = (unsigned *)0x15000 Iris::Caps fb = display.map_fb ((unsigned)framebuffer) bright.set (bright.get_range ()) app.get_state (cb.copy ()) Iris::free_cap (cb) cb = Iris::my_receiver.create_capability (KBD) keyboard.set_cb (cb.copy ()) Iris::free_cap (cb) draw_num (false, 2, 10) draw_num (true, 2, 10) unsigned total_time = 0 while true: Iris::wait () switch Iris::recv.protected_data.l: case UI: switch Iris::recv.data[0].l: case CURRENT_TIME: draw_time (false, Iris::recv.data[1].l) break case ALARM: beep () 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 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)