void ttyd(void) { Message m; int i; lock(); for (i = 0; i < NR_TTY; i ++) { hal_register(ttynames[i], TTY, i); } unlock(); while (1) { receive(ANY, &m); if (m.src == MSG_HWINTR) { switch (m.type) { case MSG_TTY_GETKEY: readkey(); break; case MSG_TTY_UPDATE: update_banner(); break; } } else { DevMessage *msg; switch(m.type) { case MSG_DEVRD: read_request((DevMessage*)&m); break; case MSG_DEVWR: msg = (DevMessage*)&m; if (msg->dev_id >= 0 && msg->dev_id < NR_TTY) { int i; for (i = 0; i < msg->count; i ++) { consl_writec(&ttys[msg->dev_id], ((char*)msg->buf)[i]); } consl_sync(&ttys[msg->dev_id]); } m.type = msg->count; send(m.src, &m); break; } } } }
int main() { struct Timer fps; time_t current; struct tm *current_tm; struct Banner date_banner = { .string = date_string, .offset = 0 }; if (LCD_Init() != 0) { printf("Error initializing LCD\n"); return 1; } LCD_SetBacklight(1); for (;;) { timer_start(&fps); current = time(NULL); current_tm = localtime(¤t); string_print_date(date_string, current_tm); LCD_Clear(); draw_clock_frame(); draw_time(current_tm); update_banner(&date_banner); draw_banner(&date_banner, 0); draw_banner(&date_banner, 38); LCD_Display(); if (timer_get_msecs(&fps) < 1000 / FRAMES_PER_SECOND) { usleep(1000 * ( 1000 / FRAMES_PER_SECOND ) - timer_get_msecs(&fps)); } } return 0; }