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, barwidth;
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;
75 barwidth = (CLAMP(value,0,100) * width) / 100;
76 psplash_fb_draw_rect (fb, x + barwidth, y,
77 width - barwidth, height,
79 psplash_fb_draw_rect (fb, x, y, barwidth,
80 height, 0x6d, 0x6d, 0x70);
84 barwidth = (CLAMP(-value,0,100) * width) / 100;
85 psplash_fb_draw_rect (fb, x, y,
86 width - barwidth, height,
88 psplash_fb_draw_rect (fb, x + width - barwidth,
93 DBG("value: %i, width: %i, barwidth :%i\n", value,
98 parse_command (PSplashFB *fb, char *string, int length)
103 parsed = strlen(string)+1;
105 DBG("got cmd %s", string);
107 if (strcmp(string,"QUIT") == 0)
110 command = strtok(string," ");
112 if (!strcmp(command,"PROGRESS"))
114 psplash_draw_progress (fb, atoi(strtok(NULL,"\0")));
116 else if (!strcmp(command,"MSG"))
118 psplash_draw_msg (fb, strtok(NULL,"\0"));
120 else if (!strcmp(command,"QUIT"))
129 psplash_main (PSplashFB *fb, int pipe_fd, int timeout)
141 FD_ZERO(&descriptors);
142 FD_SET(pipe_fd, &descriptors);
149 err = select(pipe_fd+1, &descriptors, NULL, NULL, &tv);
151 err = select(pipe_fd+1, &descriptors, NULL, NULL, NULL);
162 length += read (pipe_fd, end, sizeof(command) - (end - command));
166 /* Reopen to see if there's anything more for us */
168 pipe_fd = open(PSPLASH_FIFO,O_RDONLY|O_NONBLOCK);
172 if (command[length-1] == '\0')
174 if (parse_command(fb, command, strlen(command)))
178 else if (command[length-1] == '\n')
180 command[length-1] = '\0';
181 if (parse_command(fb, command, strlen(command)))
188 end = &command[length];
193 FD_ZERO(&descriptors);
194 FD_SET(pipe_fd,&descriptors);
201 main (int argc, char** argv)
204 int pipe_fd, i = 0, angle = 0;
206 bool disable_console_switch = FALSE;
208 signal(SIGHUP, psplash_exit);
209 signal(SIGINT, psplash_exit);
210 signal(SIGQUIT, psplash_exit);
214 if (!strcmp(argv[i],"-n") || !strcmp(argv[i],"--no-console-switch"))
216 disable_console_switch = TRUE;
220 if (!strcmp(argv[i],"-a") || !strcmp(argv[i],"--angle"))
222 if (++i > argc) goto fail;
223 angle = atoi(argv[i]);
229 "Usage: %s [-n|--no-console-switch][-a|--angle <0|90|180|270>]\n",
234 tmpdir = getenv("TMPDIR");
241 if (mkfifo(PSPLASH_FIFO, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP))
250 pipe_fd = open (PSPLASH_FIFO,O_RDONLY|O_NONBLOCK);
258 if (!disable_console_switch)
259 psplash_console_switch ();
261 if ((fb = psplash_fb_new(angle)) == NULL)
264 /* Clear the background with #ecece1 */
265 psplash_fb_draw_rect (fb, 0, 0, fb->width, fb->height, 0xec, 0xec, 0xe1);
267 /* Draw the OH logo */
268 psplash_fb_draw_image (fb,
269 (fb->width - HAND_IMG_WIDTH)/2,
270 (fb->height - HAND_IMG_HEIGHT)/2,
273 HAND_IMG_BYTES_PER_PIXEL,
274 HAND_IMG_RLE_PIXEL_DATA);
276 /* Draw progress bar border */
277 psplash_fb_draw_image (fb,
278 (fb->width - BAR_IMG_WIDTH)/2,
279 fb->height - (fb->height/6),
282 BAR_IMG_BYTES_PER_PIXEL,
283 BAR_IMG_RLE_PIXEL_DATA);
285 psplash_draw_progress (fb, 0);
287 psplash_draw_msg (fb, MSG);
289 psplash_main (fb, pipe_fd, 0);
291 unlink(PSPLASH_FIFO);
293 if (!disable_console_switch)
294 psplash_console_reset ();
296 psplash_fb_destroy (fb);