headless-server : add boot-animation 77/207177/1
authorlsj119 <lsj119@samsung.com>
Fri, 3 May 2019 05:24:09 +0000 (14:24 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Thu, 30 May 2019 08:34:00 +0000 (17:34 +0900)
Change-Id: I5b2614e033475e26925b7a734d8a01b8aee12277

src/bin/headless/Makefile.am
src/bin/headless/output/HL_UI_LED_APA102.c
src/bin/headless/output/boot_anim.c [new file with mode: 0644]
src/bin/headless/output/output_internal.h [new file with mode: 0644]
src/bin/headless/output/output_led.c

index cf7f936..65e6713 100644 (file)
@@ -9,4 +9,5 @@ headless_server_SOURCES = headless_server.c \
                          input.c \
                          output/output_led.c \
                          output/HL_UI_LED_APA102.c \
+                         output/boot_anim.c \
                          shell/shell.c
index c6f4ad9..367aae5 100644 (file)
@@ -102,9 +102,9 @@ HL_UI_LED_Get_Pixel_RGB(HL_UI_LED *handle, uint32_t index, uint8_t *red, uint8_t
 {
        if (index < handle->number) {
                uint8_t *ptr = &(handle->pixels[index * 4]);
-               red = ptr + R_OFF_SET;
-               green = ptr + G_OFF_SET;
-               blue = ptr + B_OFF_SET;
+               *red = ptr[R_OFF_SET];
+               *green = ptr[G_OFF_SET];
+               *blue = ptr[B_OFF_SET];
        }
 }
 
@@ -112,9 +112,10 @@ void
 HL_UI_LED_Set_Pixel_4byte(HL_UI_LED *handle, uint32_t index, uint32_t colour)
 {
        uint8_t  r, g, b;
-       r = colour >> 16;
-       g = colour >> 8;
-       b = colour;
+       uint8_t *ptr = (uint8_t *)&colour;
+       r = ptr[R_OFF_SET];
+       g = ptr[G_OFF_SET];
+       b = ptr[B_OFF_SET];
        HL_UI_LED_Set_Pixel_RGB(handle, index, r, g, b);
 }
 
@@ -123,10 +124,11 @@ HL_UI_LED_Get_Pixel_4byte(HL_UI_LED *handle, uint32_t index)
 {
        uint8_t r=0, g=0, b=0;
        uint32_t colour = 0;
+       uint8_t *ptr = (uint8_t *)&colour;
        HL_UI_LED_Get_Pixel_RGB(handle, index, &r, &g, &b);
-       r <<= 16;
-       g <<= 8;
-       colour = r | g | b;
+       ptr[R_OFF_SET] = r;
+       ptr[G_OFF_SET] = g;
+       ptr[B_OFF_SET] = b;
        return colour;
 }
 
diff --git a/src/bin/headless/output/boot_anim.c b/src/bin/headless/output/boot_anim.c
new file mode 100644 (file)
index 0000000..c0fb8cc
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+* Copyright © 2018 Samsung Electronics co., Ltd. All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice (including the next
+* paragraph) shall be included in all copies or substantial portions of the
+* Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+* DEALINGS IN THE SOFTWARE.
+*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <tbm_bufmgr.h>
+#include <wayland-tbm-server.h>
+#include <pepper-output-backend.h>
+#include "HL_UI_LED.h"
+#include "output_internal.h"
+
+typedef struct {
+       HL_UI_LED *led;
+
+       struct wl_event_source *source;
+       uint32_t serial;
+       int index;
+} boot_ani_t;
+
+#define ANI_INTERVAL   40      //20ms
+
+static int
+boot_ani_timer_cb(void *data)
+{
+       boot_ani_t *ani = (boot_ani_t *)data;
+       uint8_t r,g,b;
+       uint32_t color;
+
+       if (ani->index == 0) {
+               r = (uint8_t)(rand()%0xFF);
+               g = (uint8_t)(rand()%0xFF);
+               b = (uint8_t)(rand()%0xFF);
+               HL_UI_LED_Set_Pixel_RGB(ani->led, ani->index, r, g, b);
+       } else {
+               color = HL_UI_LED_Get_Pixel_4byte(ani->led, ani->index - 1);
+               HL_UI_LED_Set_Pixel_4byte(ani->led, ani->index, color);
+       }
+
+       HL_UI_LED_Refresh(ani->led);
+
+       ani->serial++;
+       ani->index = (ani->serial)%12;
+
+       wl_event_source_timer_update(ani->source, ANI_INTERVAL);
+
+       return 1;
+}
+
+void boot_ani_start(led_output_t *output)
+{
+       struct wl_event_loop *loop;
+       boot_ani_t *ani;
+       int ret;
+
+       PEPPER_TRACE("[OUTPUT] start boot-animation\n");
+
+       loop = wl_display_get_event_loop(pepper_compositor_get_display(output->compositor));
+       PEPPER_CHECK(loop, return, "failed to wl_display_get_event_loop()\n");
+
+       ani = (boot_ani_t *)calloc(sizeof(boot_ani_t), 1);
+       PEPPER_CHECK(ani, return, "failed to alloc\n");
+       
+       ani->source = wl_event_loop_add_timer(loop, boot_ani_timer_cb, ani);
+       PEPPER_CHECK(ani, goto err, "failed to wl_event_loop_add_timer()\n");
+
+       ret = wl_event_source_timer_update(ani->source, ANI_INTERVAL);
+       PEPPER_CHECK(!ret, goto err, "failed to wl_event_source_timer_update\n");
+
+       ani->led = output->ui_led;
+       output->boot_ani = ani;
+       return;
+err:
+       if (ani) {
+               if (ani->source)
+                       wl_event_source_remove(ani->source);
+
+               free(ani);
+       }
+       return;
+}
+
+void boot_ani_stop(led_output_t *output)
+{
+       boot_ani_t *ani;
+
+       if (!output->boot_ani) return;
+
+       ani = (boot_ani_t *)output->boot_ani;
+
+       HL_UI_LED_Clear_All(ani->led);
+       wl_event_source_remove(ani->source);
+       free(ani);
+
+       output->boot_ani = NULL;
+       return;
+}
diff --git a/src/bin/headless/output/output_internal.h b/src/bin/headless/output/output_internal.h
new file mode 100644 (file)
index 0000000..59d1d95
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+* Copyright © 2018 Samsung Electronics co., Ltd. All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice (including the next
+* paragraph) shall be included in all copies or substantial portions of the
+* Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+* DEALINGS IN THE SOFTWARE.
+*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <pepper-output-backend.h>
+
+#define NUM_LED 12
+
+typedef struct {
+       pepper_compositor_t *compositor;
+       pepper_output_t   *output;
+       pepper_plane_t    *plane;
+
+       int num_led;
+       HL_UI_LED *ui_led;
+
+       struct wayland_tbm_server *tbm_server;
+       struct wl_event_source *frame_done;
+
+       pepper_view_t *top_view;
+
+       //For booting animation
+       void *boot_ani;
+}led_output_t;
+
+PEPPER_API void boot_ani_start(led_output_t *output);
+PEPPER_API void boot_ani_stop(led_output_t *output);
\ No newline at end of file
index d346a13..1a2198d 100644 (file)
 #include <wayland-tbm-server.h>
 #include <pepper-output-backend.h>
 #include "HL_UI_LED.h"
-
-#define NUM_LED 12
-
-typedef struct {
-       pepper_compositor_t *compositor;
-       pepper_output_t   *output;
-       pepper_plane_t    *plane;
-
-       int num_led;
-       HL_UI_LED *ui_led;
-
-       struct wayland_tbm_server *tbm_server;
-       struct wl_event_source *frame_done;
-
-       pepper_view_t *top_view;
-}led_output_t;
+#include "output_internal.h"
 
 static const int KEY_OUTPUT;
 static void led_output_add_frame_done(led_output_t *output);
@@ -311,6 +296,8 @@ headless_output_init(pepper_compositor_t *compositor)
        output->ui_led = HL_UI_LED_Init(output->num_led);
        if (!output->ui_led)
                PEPPER_ERROR("HL_UI_LED_Init() failed.\n");
+       else
+               boot_ani_start(output);
 
        output->output = pepper_compositor_add_output(compositor,
                        &led_output_backend, "led_output",