2 * pslash - a lightweight framebuffer splashscreen for embedded devices.
4 * Copyright (c) 2006 Matthew Allum <mallum@o-hand.com>
6 * Parts of this file ( fifo handling ) based on 'usplash' copyright
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
22 #include "psplash-hand-img.h"
23 #include "psplash-bar-img.h"
24 #include "radeon-font.h"
29 psplash_exit (int signum)
33 psplash_console_reset ();
37 psplash_draw_msg (PSplashFB *fb, const char *msg)
41 psplash_fb_text_size (fb, &w, &h, &radeon_font, msg);
43 DBG("displaying '%s' %ix%i\n", msg, w, h);
47 psplash_fb_draw_rect (fb,
49 fb->height - (fb->height/6) - h,
54 psplash_fb_draw_text (fb,
56 fb->height - (fb->height/6) - h,
63 psplash_draw_progress (PSplashFB *fb, int value)
65 int x, y, width, height;
68 x = ((fb->width - BAR_IMG_WIDTH)/2) + 4 ;
69 y = fb->height - (fb->height/6) + 4;
70 width = BAR_IMG_WIDTH - 8;
71 height = BAR_IMG_HEIGHT - 8;
73 value = CLAMP(value,0,100);
75 DBG("total w: %i, val :%i, w: %i",
76 width, value, (value * width) / 100);
78 psplash_fb_draw_rect (fb, x, y,
79 (value * width) / 100,
80 height, 0x6d, 0x6d, 0x70);
84 parse_command (PSplashFB *fb, char *string, int length)
89 parsed = strlen(string)+1;
91 DBG("got cmd %s", string);
93 if (strcmp(string,"QUIT") == 0)
96 command = strtok(string," ");
98 if (!strcmp(command,"PROGRESS"))
100 psplash_draw_progress (fb, atoi(strtok(NULL,"\0")));
102 else if (!strcmp(command,"MSG"))
104 psplash_draw_msg (fb, strtok(NULL,"\0"));
106 else if (!strcmp(command,"QUIT"))
115 psplash_main (PSplashFB *fb, int pipe_fd, int timeout)
127 FD_ZERO(&descriptors);
128 FD_SET(pipe_fd, &descriptors);
135 err = select(pipe_fd+1, &descriptors, NULL, NULL, &tv);
137 err = select(pipe_fd+1, &descriptors, NULL, NULL, NULL);
148 length += read (pipe_fd, end, sizeof(command) - (end - command));
152 /* Reopen to see if there's anything more for us */
154 pipe_fd = open(PSPLASH_FIFO,O_RDONLY|O_NONBLOCK);
158 if (command[length-1] == '\0')
160 if (parse_command(fb, command, strlen(command)))
165 end = &command[length];
170 FD_ZERO(&descriptors);
171 FD_SET(pipe_fd,&descriptors);
178 main (int argc, char** argv)
181 int pipe_fd, i = 0, angle = 0;
183 bool disable_console_switch = FALSE;
185 signal(SIGHUP, psplash_exit);
186 signal(SIGINT, psplash_exit);
187 signal(SIGQUIT, psplash_exit);
191 if (!strcmp(argv[i],"-n") || !strcmp(argv[i],"--no-console-switch"))
193 disable_console_switch = TRUE;
197 if (!strcmp(argv[i],"-a") || !strcmp(argv[i],"--angle"))
199 if (++i > argc) goto fail;
200 angle = atoi(argv[i]);
206 "Usage: %s [-n|--no-console-switch] [-a|--angle <0|90|180|270>]\n",
211 tmpdir = getenv("TMPDIR");
218 if (mkfifo(PSPLASH_FIFO, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP))
227 pipe_fd = open (PSPLASH_FIFO,O_RDONLY|O_NONBLOCK);
235 if (!disable_console_switch)
236 psplash_console_switch ();
238 if ((fb = psplash_fb_new(angle)) == NULL)
241 /* Clear the background with #ecece1 */
242 psplash_fb_draw_rect (fb, 0, 0, fb->width, fb->height, 0xec, 0xec, 0xe1);
244 /* Draw the OH logo */
245 psplash_fb_draw_image (fb,
246 (fb->width - HAND_IMG_WIDTH)/2,
247 (fb->height - HAND_IMG_HEIGHT)/2,
250 HAND_IMG_BYTES_PER_PIXEL,
251 HAND_IMG_RLE_PIXEL_DATA);
253 /* Draw progress bar border */
254 psplash_fb_draw_image (fb,
255 (fb->width - BAR_IMG_WIDTH)/2,
256 fb->height - (fb->height/6),
259 BAR_IMG_BYTES_PER_PIXEL,
260 BAR_IMG_RLE_PIXEL_DATA);
262 psplash_draw_progress (fb, 0);
264 psplash_draw_msg (fb, MSG);
266 psplash_main (fb, pipe_fd, 0);
268 if (!disable_console_switch)
269 psplash_console_reset ();
271 psplash_fb_destroy (fb);