defaul_backend: implement some animations - listening, processing, speaking, streaming 69/220669/1
authorjeon <jhyuni.kang@samsung.com>
Wed, 28 Aug 2019 05:32:33 +0000 (14:32 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Fri, 20 Dec 2019 07:20:26 +0000 (16:20 +0900)
Change-Id: Ia2ae64ae1a7a1da8b82b02e8bdcfd04119fbd0be

16 files changed:
backends/Makefile.am
backends/default_ani_emergency.c [new file with mode: 0644]
backends/default_ani_listening.c [new file with mode: 0644]
backends/default_ani_processing.c [new file with mode: 0644]
backends/default_ani_speaking.c [new file with mode: 0644]
backends/default_ani_streaming.c [new file with mode: 0644]
backends/default_backend.c
backends/default_backend.h [new file with mode: 0644]
backends/res/bixby_listening.json [deleted file]
backends/res/bixby_speaking.json [deleted file]
backends/res/emergency.json [moved from backends/res/noti_emergency.json with 100% similarity]
backends/res/listening.json [new file with mode: 0644]
backends/res/speaking.json [new file with mode: 0644]
backends/res/streaming.json [new file with mode: 0644]
backends/res/system_processing.json [new file with mode: 0644]
samples/PUI_sample.c

index 7ca90e7..2a68c52 100644 (file)
@@ -6,10 +6,16 @@ AM_CFLAGS = \
         -I$(top_srcdir)/src
 
 libpui_default_backend_includedir=$(includedir)
-libpui_default_backend_include_HEADERS =
+libpui_default_backend_include_HEADERS = \
+        default_backend.h
 
 libpui_default_backend_la_CFLAGS = $(AM_CFLAGS) $(DEFAULT_BACKEND_CFLAGS)
 libpui_default_backend_la_LIBADD = $(DEFAULT_BACKEND_LIBS)
 
 libpui_default_backend_la_SOURCES = \
-        default_backend.c
+        default_backend.c \
+        default_ani_listening.c \
+        default_ani_speaking.c \
+        default_ani_emergency.c \
+        default_ani_processing.c \
+        default_ani_streaming.c
diff --git a/backends/default_ani_emergency.c b/backends/default_ani_emergency.c
new file mode 100644 (file)
index 0000000..3693da7
--- /dev/null
@@ -0,0 +1,197 @@
+/*
+ * Copyright © 2019 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 "default_backend.h"
+
+static void
+_ani_backend_emergency_get_led_rgb(default_frame_info_t *frame, int led_idx, unsigned int *r, unsigned int *g, unsigned int *b)
+{
+       if (!frame) return;
+       if (!r || !g || !b) return;
+       if (led_idx > frame->num_led) return;
+
+       *r = (frame->leds[led_idx].color & LED_MASK_RED) >> 16;
+       *g = (frame->leds[led_idx].color & LED_MASK_GREEN) >> 8;
+       *b = (frame->leds[led_idx].color & LED_MASK_BLUE);
+}
+
+static void
+_ani_backend_emergency_free_frame(default_frame_info_t *frame)
+{
+       if (!frame) return;
+
+       if (frame->leds) free(frame->leds);
+       free(frame);
+}
+
+static default_frame_info_t *
+_ani_backend_emergency_get_frame(default_ani_info *ani_info)
+{
+       default_frame_info_t *frame, *key_frame;
+
+       frame = (default_frame_info_t *)calloc(sizeof(default_frame_info_t), 1);
+       if (!frame) return NULL;
+
+       key_frame = &ani_info->frames[0];
+       frame->num_led = key_frame->num_led;
+       frame->leds = (default_led_info_t *)calloc(sizeof(default_led_info_t), frame->num_led);
+       if (!frame->leds)
+       {
+               free(frame);
+               return NULL;
+       }
+       for (int i = 0; i < key_frame->num_led; i++)
+       {
+               int idx = (i - ani_info->frame_idx + key_frame->num_led) % key_frame->num_led;
+               frame->leds[idx] = key_frame->leds[i];
+       }
+       ani_info->frame_idx++;
+       if (ani_info->frame_idx >= key_frame->num_led)
+               ani_info->frame_idx = 0;
+
+       return frame;
+}
+
+static pui_bool
+_ani_backend_emergency_frame_cb(void *data, int serial)
+{
+       pui_int_error e = PUI_INT_ERROR_NONE;
+       pui_ani_t *ani = (pui_ani_t *)data;
+       pui_backend_ani_data *ani_data = NULL;
+       pui_ani_control_buffer *buffer = NULL;
+       default_frame_info_t *frame;
+       unsigned int r = 0x0, g = 0x0, b = 0x0;
+       double now;
+
+       ani_data = pui_backend_ani_get_ani_data(ani);
+       default_ani_info *ani_info = (default_ani_info *)ani_data->ani_info;
+
+       now = ecore_time_unix_get();
+       pui_info("[time:%.3f] serial=%d\n", now, serial);
+
+       /* TODO : make use of ani_info */
+       //(void) ani_info;
+
+       buffer = pui_backend_ani_get_buffer(ani);
+       if (!buffer) {
+               pui_err("Failed to get buffer for animation\n");
+               return (pui_bool)0;
+       }
+
+       frame = _ani_backend_emergency_get_frame(ani_info);
+       for(int i = 0; i<12; i++)
+       {
+               _ani_backend_emergency_get_led_rgb(frame, i, &r, &g, &b);
+               buffer->ptr[4*i] = 0;
+               buffer->ptr[4*i + 1] = b; /* BLUE */
+               buffer->ptr[4*i + 2] = g; /* GREEN */
+               buffer->ptr[4*i + 3] = r; /* RED */
+       }
+       _ani_backend_emergency_free_frame(frame);
+
+       e = pui_backend_ani_set_buffer(ani, buffer);
+
+       if (e != PUI_INT_ERROR_NONE)
+       {
+               pui_err("Failed on setting buffer on animation !(e=%d)\n", e);
+               return (pui_bool)0;
+       }
+
+       e = pui_backend_ani_update(ani);
+
+       if (e != PUI_INT_ERROR_NONE)
+       {
+               pui_err("Failed on updating animation !(e=%d)\n", e);
+               return (pui_bool)0;
+       }
+
+       pui_info("... update (serial=%d)\n", serial);
+
+       return (pui_bool)1;
+}
+
+pui_error
+_ani_emergency_start(pui_ani_t *ani, int repeat)
+{
+       pui_bool ret = 0;
+       pui_int_error e = PUI_INT_ERROR_NONE;
+       pui_backend_ani_data *ani_data = NULL;
+
+       ani_data = pui_backend_ani_get_ani_data(ani);
+       default_ani_info *info = (default_ani_info *)ani_data->ani_info;
+
+       //TODO
+       (void) info;
+
+       pui_info("... info->id: %s, repeat : %d, interval: %d\n", info->id, repeat, info->interval);
+       if (info->num_key_frames != 1)
+       {
+               pui_err("invalid key frames: %d\n", info->num_key_frames);
+               return PUI_INT_ERROR_INVALID_RESOURCES;
+       }
+
+       pui_backend_ani_status_update(ani, PUI_ANI_STATUS_STARTED);
+       ret = pui_backend_ani_add_frame_cb(ani, _ani_backend_emergency_frame_cb, info->interval / 1000.0);
+
+       if (!ret)
+       {
+               pui_err("Failed to add frame callback !\n");
+               e = PUI_INT_ERROR_INVALID_RESOURCES;
+       }
+
+       return e;
+}
+
+pui_error
+_ani_emergency_stop(pui_ani_t *ani)
+{
+       pui_int_error e = PUI_INT_ERROR_NONE;
+       pui_backend_ani_data *ani_data = NULL;
+
+       ani_data = pui_backend_ani_get_ani_data(ani);
+       default_ani_info *info = (default_ani_info *)ani_data->ani_info;
+
+       //TODO
+       (void) info;
+
+       pui_info("... info->id: %s\n", info->id);
+
+       pui_backend_ani_remove_frame_cb(ani);
+       pui_backend_ani_status_update(ani, PUI_ANI_STATUS_STOPPED);
+
+       return e;
+}
+
+
+void
+pui_default_backend_ani_emergency_func_set(pui_backend_ani_func *func)
+{
+       if (!func) return;
+
+       func->ani_start = _ani_emergency_start;
+       func->ani_stop = _ani_emergency_stop;
+}
+
+
diff --git a/backends/default_ani_listening.c b/backends/default_ani_listening.c
new file mode 100644 (file)
index 0000000..8a83894
--- /dev/null
@@ -0,0 +1,221 @@
+/*
+ * Copyright © 2019 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 "default_backend.h"
+
+static void
+_ani_backend_listening_get_led_rgb(default_frame_info_t *frame, int led_idx, unsigned int *r, unsigned int *g, unsigned int *b)
+{
+       if (!frame) return;
+       if (!r || !g || !b) return;
+       if (led_idx > frame->num_led) return;
+
+       *r = (frame->leds[led_idx].color & LED_MASK_RED) >> 16;
+       *g = (frame->leds[led_idx].color & LED_MASK_GREEN) >> 8;
+       *b = (frame->leds[led_idx].color & LED_MASK_BLUE);
+}
+
+static void
+_ani_backend_listening_free_frame(default_frame_info_t *frame)
+{
+       if (!frame) return;
+
+       if (frame->leds) free(frame->leds);
+       free(frame);
+}
+
+static default_frame_info_t *
+_ani_backend_listening_get_frame(default_ani_info *ani_info)
+{
+       default_frame_info_t *frame, *key_frame;
+       int division;
+
+       frame = (default_frame_info_t *)calloc(sizeof(default_frame_info_t), 1);
+       if (!frame) return NULL;
+
+       key_frame = &ani_info->frames[0];
+       frame->num_led = key_frame->num_led;
+       frame->leds = (default_led_info_t *)calloc(sizeof(default_led_info_t), frame->num_led);
+       if (!frame->leds)
+       {
+               free(frame);
+               return NULL;
+       }
+       division = (int)(frame->num_led / 2);
+       for (int i = 0; i < key_frame->num_led; i++)
+       {
+               int idx;
+               //int idx = (i - ani_info->frame_idx + key_frame->num_led) % key_frame->num_led;
+               if ((ani_info->frame_idx / division) <= 0)
+               {
+                       if (i < division)
+                       {
+                               idx = i - ani_info->frame_idx;
+                               if (idx < 0) continue;
+                       }
+                       else
+                       {
+                               idx = i + ani_info->frame_idx;
+                               if (idx >= key_frame->num_led) continue;
+                       }
+               }
+               else
+               {
+                       if (i < division)
+                       {
+                               idx = i - division + 1 + ani_info->frame_idx - division;
+                               if (idx < 0) continue;
+                       }
+                       else
+                       {
+                               idx = i + division - 1 - ani_info->frame_idx + division;
+                               if (idx >= key_frame->num_led) continue;
+                       }
+               }
+               frame->leds[idx] = key_frame->leds[i];
+       }
+       ani_info->frame_idx++;
+       if (ani_info->frame_idx >= key_frame->num_led)
+               ani_info->frame_idx = 0;
+
+       return frame;
+}
+
+static pui_bool
+_ani_backend_listening_frame_cb(void *data, int serial)
+{
+       pui_int_error e = PUI_INT_ERROR_NONE;
+       pui_ani_t *ani = (pui_ani_t *)data;
+       pui_backend_ani_data *ani_data = NULL;
+       pui_ani_control_buffer *buffer = NULL;
+       default_frame_info_t *frame;
+       unsigned int r = 0x0, g = 0x0, b = 0x0;
+       double now;
+
+       ani_data = pui_backend_ani_get_ani_data(ani);
+       default_ani_info *ani_info = (default_ani_info *)ani_data->ani_info;
+
+       now = ecore_time_unix_get();
+       pui_info("[time:%.3f] serial=%d\n", now, serial);
+
+       /* TODO : make use of ani_info */
+       //(void) ani_info;
+
+       buffer = pui_backend_ani_get_buffer(ani);
+       if (!buffer) {
+               pui_err("Failed to get buffer for animation\n");
+               return (pui_bool)0;
+       }
+
+       frame = _ani_backend_listening_get_frame(ani_info);
+       for(int i = 0; i<12; i++)
+       {
+               _ani_backend_listening_get_led_rgb(frame, i, &r, &g, &b);
+               buffer->ptr[4*i] = 0;
+               buffer->ptr[4*i + 1] = b; /* BLUE */
+               buffer->ptr[4*i + 2] = g; /* GREEN */
+               buffer->ptr[4*i + 3] = r; /* RED */
+       }
+       _ani_backend_listening_free_frame(frame);
+
+       e = pui_backend_ani_set_buffer(ani, buffer);
+
+       if (e != PUI_INT_ERROR_NONE)
+       {
+               pui_err("Failed on setting buffer on animation !(e=%d)\n", e);
+               return (pui_bool)0;
+       }
+
+       e = pui_backend_ani_update(ani);
+
+       if (e != PUI_INT_ERROR_NONE)
+       {
+               pui_err("Failed on updating animation !(e=%d)\n", e);
+               return (pui_bool)0;
+       }
+
+       pui_info("... update (serial=%d)\n", serial);
+
+       return (pui_bool)1;
+}
+
+pui_error
+_ani_listening_start(pui_ani_t *ani, int repeat)
+{
+       pui_bool ret = 0;
+       pui_int_error e = PUI_INT_ERROR_NONE;
+       pui_backend_ani_data *ani_data = NULL;
+
+       ani_data = pui_backend_ani_get_ani_data(ani);
+       default_ani_info *info = (default_ani_info *)ani_data->ani_info;
+
+       //TODO
+       (void) info;
+
+       pui_info("... info->id: %s, repeat : %d, interval: %d\n", info->id, repeat, info->interval);
+
+       pui_backend_ani_status_update(ani, PUI_ANI_STATUS_STARTED);
+       ret = pui_backend_ani_add_frame_cb(ani, _ani_backend_listening_frame_cb, info->interval / 1000.0);
+
+       if (!ret)
+       {
+               pui_err("Failed to add frame callback !\n");
+               e = PUI_INT_ERROR_INVALID_RESOURCES;
+       }
+
+       return e;
+}
+
+pui_error
+_ani_listening_stop(pui_ani_t *ani)
+{
+       pui_int_error e = PUI_INT_ERROR_NONE;
+       pui_backend_ani_data *ani_data = NULL;
+
+       ani_data = pui_backend_ani_get_ani_data(ani);
+       default_ani_info *info = (default_ani_info *)ani_data->ani_info;
+
+       //TODO
+       (void) info;
+
+       pui_info("... info->id: %s\n", info->id);
+
+       pui_backend_ani_remove_frame_cb(ani);
+       pui_backend_ani_status_update(ani, PUI_ANI_STATUS_STOPPED);
+
+       return e;
+}
+
+
+void
+pui_default_backend_ani_listening_func_set(pui_backend_ani_func *func)
+{
+       if (!func) return;
+
+       func->ani_start = _ani_listening_start;
+       func->ani_stop = _ani_listening_stop;
+}
+
+
diff --git a/backends/default_ani_processing.c b/backends/default_ani_processing.c
new file mode 100644 (file)
index 0000000..628f291
--- /dev/null
@@ -0,0 +1,197 @@
+/*
+ * Copyright © 2019 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 "default_backend.h"
+
+static void
+_ani_backend_processing_get_led_rgb(default_frame_info_t *frame, int led_idx, unsigned int *r, unsigned int *g, unsigned int *b)
+{
+       if (!frame) return;
+       if (!r || !g || !b) return;
+       if (led_idx > frame->num_led) return;
+
+       *r = (frame->leds[led_idx].color & LED_MASK_RED) >> 16;
+       *g = (frame->leds[led_idx].color & LED_MASK_GREEN) >> 8;
+       *b = (frame->leds[led_idx].color & LED_MASK_BLUE);
+}
+
+static void
+_ani_backend_processing_free_frame(default_frame_info_t *frame)
+{
+       if (!frame) return;
+
+       if (frame->leds) free(frame->leds);
+       free(frame);
+}
+
+static default_frame_info_t *
+_ani_backend_processing_get_frame(default_ani_info *ani_info)
+{
+       default_frame_info_t *frame, *key_frame;
+
+       frame = (default_frame_info_t *)calloc(sizeof(default_frame_info_t), 1);
+       if (!frame) return NULL;
+
+       key_frame = &ani_info->frames[0];
+       frame->num_led = key_frame->num_led;
+       frame->leds = (default_led_info_t *)calloc(sizeof(default_led_info_t), frame->num_led);
+       if (!frame->leds)
+       {
+               free(frame);
+               return NULL;
+       }
+       for (int i = 0; i < key_frame->num_led; i++)
+       {
+               int idx = (i - ani_info->frame_idx + key_frame->num_led) % key_frame->num_led;
+               frame->leds[idx] = key_frame->leds[i];
+       }
+       ani_info->frame_idx++;
+       if (ani_info->frame_idx >= key_frame->num_led)
+               ani_info->frame_idx = 0;
+
+       return frame;
+}
+
+static pui_bool
+_ani_backend_processing_frame_cb(void *data, int serial)
+{
+       pui_int_error e = PUI_INT_ERROR_NONE;
+       pui_ani_t *ani = (pui_ani_t *)data;
+       pui_backend_ani_data *ani_data = NULL;
+       pui_ani_control_buffer *buffer = NULL;
+       default_frame_info_t *frame;
+       unsigned int r = 0x0, g = 0x0, b = 0x0;
+       double now;
+
+       ani_data = pui_backend_ani_get_ani_data(ani);
+       default_ani_info *ani_info = (default_ani_info *)ani_data->ani_info;
+
+       now = ecore_time_unix_get();
+       pui_info("[time:%.3f] serial=%d\n", now, serial);
+
+       /* TODO : make use of ani_info */
+       //(void) ani_info;
+
+       buffer = pui_backend_ani_get_buffer(ani);
+       if (!buffer) {
+               pui_err("Failed to get buffer for animation\n");
+               return (pui_bool)0;
+       }
+
+       frame = _ani_backend_processing_get_frame(ani_info);
+       for(int i = 0; i<12; i++)
+       {
+               _ani_backend_processing_get_led_rgb(frame, i, &r, &g, &b);
+               buffer->ptr[4*i] = 0;
+               buffer->ptr[4*i + 1] = b; /* BLUE */
+               buffer->ptr[4*i + 2] = g; /* GREEN */
+               buffer->ptr[4*i + 3] = r; /* RED */
+       }
+       _ani_backend_processing_free_frame(frame);
+
+       e = pui_backend_ani_set_buffer(ani, buffer);
+
+       if (e != PUI_INT_ERROR_NONE)
+       {
+               pui_err("Failed on setting buffer on animation !(e=%d)\n", e);
+               return (pui_bool)0;
+       }
+
+       e = pui_backend_ani_update(ani);
+
+       if (e != PUI_INT_ERROR_NONE)
+       {
+               pui_err("Failed on updating animation !(e=%d)\n", e);
+               return (pui_bool)0;
+       }
+
+       pui_info("... update (serial=%d)\n", serial);
+
+       return (pui_bool)1;
+}
+
+pui_error
+_ani_processing_start(pui_ani_t *ani, int repeat)
+{
+       pui_bool ret = 0;
+       pui_int_error e = PUI_INT_ERROR_NONE;
+       pui_backend_ani_data *ani_data = NULL;
+
+       ani_data = pui_backend_ani_get_ani_data(ani);
+       default_ani_info *info = (default_ani_info *)ani_data->ani_info;
+
+       //TODO
+       (void) info;
+
+       pui_info("... info->id: %s, repeat : %d, interval: %d\n", info->id, repeat, info->interval);
+       if (info->num_key_frames != 1)
+       {
+               pui_err("invalid key frames: %d\n", info->num_key_frames);
+               return PUI_INT_ERROR_INVALID_RESOURCES;
+       }
+
+       pui_backend_ani_status_update(ani, PUI_ANI_STATUS_STARTED);
+       ret = pui_backend_ani_add_frame_cb(ani, _ani_backend_processing_frame_cb, info->interval / 1000.0);
+
+       if (!ret)
+       {
+               pui_err("Failed to add frame callback !\n");
+               e = PUI_INT_ERROR_INVALID_RESOURCES;
+       }
+
+       return e;
+}
+
+pui_error
+_ani_processing_stop(pui_ani_t *ani)
+{
+       pui_int_error e = PUI_INT_ERROR_NONE;
+       pui_backend_ani_data *ani_data = NULL;
+
+       ani_data = pui_backend_ani_get_ani_data(ani);
+       default_ani_info *info = (default_ani_info *)ani_data->ani_info;
+
+       //TODO
+       (void) info;
+
+       pui_info("... info->id: %s\n", info->id);
+
+       pui_backend_ani_remove_frame_cb(ani);
+       pui_backend_ani_status_update(ani, PUI_ANI_STATUS_STOPPED);
+
+       return e;
+}
+
+
+void
+pui_default_backend_ani_processing_func_set(pui_backend_ani_func *func)
+{
+       if (!func) return;
+
+       func->ani_start = _ani_processing_start;
+       func->ani_stop = _ani_processing_stop;
+}
+
+
diff --git a/backends/default_ani_speaking.c b/backends/default_ani_speaking.c
new file mode 100644 (file)
index 0000000..b627450
--- /dev/null
@@ -0,0 +1,208 @@
+/*
+ * Copyright © 2019 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 "default_backend.h"
+
+static void
+_ani_backend_speaking_get_led_rgb(default_frame_info_t *frame, int led_idx, unsigned int *r, unsigned int *g, unsigned int *b)
+{
+       if (!frame) return;
+       if (!r || !g || !b) return;
+       if (led_idx > frame->num_led) return;
+
+       *r = (frame->leds[led_idx].color & LED_MASK_RED) >> 16;
+       *g = (frame->leds[led_idx].color & LED_MASK_GREEN) >> 8;
+       *b = (frame->leds[led_idx].color & LED_MASK_BLUE);
+}
+
+static void
+_ani_backend_speaking_free_frame(default_frame_info_t *frame)
+{
+       if (!frame) return;
+
+       if (frame->leds) free(frame->leds);
+       free(frame);
+}
+
+static default_frame_info_t *
+_ani_backend_speaking_get_frame(default_ani_info *ani_info)
+{
+#define SMOOTH_FRAME 20
+       default_frame_info_t *frame, *key_frame, *key_frame2;
+       int idx, idx2;
+       unsigned int r, g, b, r2, g2, b2;
+       int r3, g3, b3;
+       double div;
+
+       frame = (default_frame_info_t *)calloc(sizeof(default_frame_info_t), 1);
+       if (!frame) return NULL;
+
+       idx = ((int)(ani_info->frame_idx / SMOOTH_FRAME)) % ani_info->num_key_frames;
+       idx2 = (idx + 1) % ani_info->num_key_frames;
+
+       key_frame = &ani_info->frames[idx];
+       key_frame2 = &ani_info->frames[idx2];
+       frame->num_led = key_frame->num_led;
+       frame->leds = (default_led_info_t *)calloc(sizeof(default_led_info_t), frame->num_led);
+       if (!frame->leds)
+       {
+               free(frame);
+               return NULL;
+       }
+       div = (double)(ani_info->frame_idx % SMOOTH_FRAME) / (double)SMOOTH_FRAME;
+       r = g = b = r2 = g2 = b2 = 0x0;
+       for (int i = 0; i < key_frame->num_led; i++)
+       {
+               _ani_backend_speaking_get_led_rgb(key_frame, i, &r, &g, &b);
+               _ani_backend_speaking_get_led_rgb(key_frame2, i, &r2, &g2, &b2);
+               r3 = (int)(r2 - r) * div + r;
+               g3 = (int)(g2 - g) * div + g;
+               b3 = (int)(b2 - b) * div + b;
+
+               frame->leds[i].color = (r3 << 16) + (g3 << 8) + (b3);
+       }
+       ani_info->frame_idx++;
+       if (ani_info->frame_idx >= (ani_info->num_key_frames * SMOOTH_FRAME))
+               ani_info->frame_idx = 0;
+
+       return frame;
+}
+
+static pui_bool
+_ani_backend_speaking_frame_cb(void *data, int serial)
+{
+       pui_int_error e = PUI_INT_ERROR_NONE;
+       pui_ani_t *ani = (pui_ani_t *)data;
+       pui_backend_ani_data *ani_data = NULL;
+       pui_ani_control_buffer *buffer = NULL;
+       default_frame_info_t *frame;
+       unsigned int r = 0x0, g = 0x0, b = 0x0;
+       double now;
+
+       ani_data = pui_backend_ani_get_ani_data(ani);
+       default_ani_info *ani_info = (default_ani_info *)ani_data->ani_info;
+
+       now = ecore_time_unix_get();
+       pui_info("[time:%.3f] serial=%d\n", now, serial);
+
+       /* TODO : make use of ani_info */
+       //(void) ani_info;
+
+       buffer = pui_backend_ani_get_buffer(ani);
+       if (!buffer) {
+               pui_err("Failed to get buffer for animation\n");
+               return (pui_bool)0;
+       }
+
+       frame = _ani_backend_speaking_get_frame(ani_info);
+       for(int i = 0; i<12; i++)
+       {
+               _ani_backend_speaking_get_led_rgb(frame, i, &r, &g, &b);
+               buffer->ptr[4*i] = 0;
+               buffer->ptr[4*i + 1] = b; /* BLUE */
+               buffer->ptr[4*i + 2] = g; /* GREEN */
+               buffer->ptr[4*i + 3] = r; /* RED */
+       }
+       _ani_backend_speaking_free_frame(frame);
+
+       e = pui_backend_ani_set_buffer(ani, buffer);
+
+       if (e != PUI_INT_ERROR_NONE)
+       {
+               pui_err("Failed on setting buffer on animation !(e=%d)\n", e);
+               return (pui_bool)0;
+       }
+
+       e = pui_backend_ani_update(ani);
+
+       if (e != PUI_INT_ERROR_NONE)
+       {
+               pui_err("Failed on updating animation !(e=%d)\n", e);
+               return (pui_bool)0;
+       }
+
+       pui_info("... update (serial=%d)\n", serial);
+
+       return (pui_bool)1;
+}
+
+pui_error
+_ani_speaking_start(pui_ani_t *ani, int repeat)
+{
+       pui_bool ret = 0;
+       pui_int_error e = PUI_INT_ERROR_NONE;
+       pui_backend_ani_data *ani_data = NULL;
+
+       ani_data = pui_backend_ani_get_ani_data(ani);
+       default_ani_info *info = (default_ani_info *)ani_data->ani_info;
+
+       //TODO
+       (void) info;
+
+       pui_info("... info->id: %s, repeat : %d, interval: %d\n", info->id, repeat, info->interval);
+
+       pui_backend_ani_status_update(ani, PUI_ANI_STATUS_STARTED);
+       ret = pui_backend_ani_add_frame_cb(ani, _ani_backend_speaking_frame_cb, info->interval / 1000.0);
+
+       if (!ret)
+       {
+               pui_err("Failed to add frame callback !\n");
+               e = PUI_INT_ERROR_INVALID_RESOURCES;
+       }
+
+       return e;
+}
+
+pui_error
+_ani_speaking_stop(pui_ani_t *ani)
+{
+       pui_int_error e = PUI_INT_ERROR_NONE;
+       pui_backend_ani_data *ani_data = NULL;
+
+       ani_data = pui_backend_ani_get_ani_data(ani);
+       default_ani_info *info = (default_ani_info *)ani_data->ani_info;
+
+       //TODO
+       (void) info;
+
+       pui_info("... info->id: %s\n", info->id);
+
+       pui_backend_ani_remove_frame_cb(ani);
+       pui_backend_ani_status_update(ani, PUI_ANI_STATUS_STOPPED);
+
+       return e;
+}
+
+
+void
+pui_default_backend_ani_speaking_func_set(pui_backend_ani_func *func)
+{
+       if (!func) return;
+
+       func->ani_start = _ani_speaking_start;
+       func->ani_stop = _ani_speaking_stop;
+}
+
+
diff --git a/backends/default_ani_streaming.c b/backends/default_ani_streaming.c
new file mode 100644 (file)
index 0000000..46bfaf7
--- /dev/null
@@ -0,0 +1,208 @@
+/*
+ * Copyright © 2019 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 "default_backend.h"
+
+static void
+_ani_backend_streaming_get_led_rgb(default_frame_info_t *frame, int led_idx, unsigned int *r, unsigned int *g, unsigned int *b)
+{
+       if (!frame) return;
+       if (!r || !g || !b) return;
+       if (led_idx > frame->num_led) return;
+
+       *r = (frame->leds[led_idx].color & LED_MASK_RED) >> 16;
+       *g = (frame->leds[led_idx].color & LED_MASK_GREEN) >> 8;
+       *b = (frame->leds[led_idx].color & LED_MASK_BLUE);
+}
+
+static void
+_ani_backend_streaming_free_frame(default_frame_info_t *frame)
+{
+       if (!frame) return;
+
+       if (frame->leds) free(frame->leds);
+       free(frame);
+}
+
+static default_frame_info_t *
+_ani_backend_streaming_get_frame(default_ani_info *ani_info)
+{
+#define SMOOTH_FRAME 15
+       default_frame_info_t *frame, *key_frame, *key_frame2;
+       int idx, idx2;
+       unsigned int r, g, b, r2, g2, b2;
+       int r3, g3, b3;
+       double div;
+
+       frame = (default_frame_info_t *)calloc(sizeof(default_frame_info_t), 1);
+       if (!frame) return NULL;
+
+       idx = ((int)(ani_info->frame_idx / SMOOTH_FRAME)) % ani_info->num_key_frames;
+       idx2 = (idx + 1) % ani_info->num_key_frames;
+
+       key_frame = &ani_info->frames[idx];
+       key_frame2 = &ani_info->frames[idx2];
+       frame->num_led = key_frame->num_led;
+       frame->leds = (default_led_info_t *)calloc(sizeof(default_led_info_t), frame->num_led);
+       if (!frame->leds)
+       {
+               free(frame);
+               return NULL;
+       }
+       div = (double)(ani_info->frame_idx % SMOOTH_FRAME) / (double)SMOOTH_FRAME;
+       r = g = b = r2 = g2 = b2 = 0x0;
+       for (int i = 0; i < key_frame->num_led; i++)
+       {
+               _ani_backend_streaming_get_led_rgb(key_frame, i, &r, &g, &b);
+               _ani_backend_streaming_get_led_rgb(key_frame2, i, &r2, &g2, &b2);
+               r3 = (int)(r2 - r) * div + r;
+               g3 = (int)(g2 - g) * div + g;
+               b3 = (int)(b2 - b) * div + b;
+
+               frame->leds[i].color = (r3 << 16) + (g3 << 8) + (b3);
+       }
+       ani_info->frame_idx++;
+       if (ani_info->frame_idx >= (ani_info->num_key_frames * SMOOTH_FRAME))
+               ani_info->frame_idx = 0;
+
+       return frame;
+}
+
+static pui_bool
+_ani_backend_streaming_frame_cb(void *data, int serial)
+{
+       pui_int_error e = PUI_INT_ERROR_NONE;
+       pui_ani_t *ani = (pui_ani_t *)data;
+       pui_backend_ani_data *ani_data = NULL;
+       pui_ani_control_buffer *buffer = NULL;
+       default_frame_info_t *frame;
+       unsigned int r = 0x0, g = 0x0, b = 0x0;
+       double now;
+
+       ani_data = pui_backend_ani_get_ani_data(ani);
+       default_ani_info *ani_info = (default_ani_info *)ani_data->ani_info;
+
+       now = ecore_time_unix_get();
+       pui_info("[time:%.3f] serial=%d\n", now, serial);
+
+       /* TODO : make use of ani_info */
+       //(void) ani_info;
+
+       buffer = pui_backend_ani_get_buffer(ani);
+       if (!buffer) {
+               pui_err("Failed to get buffer for animation\n");
+               return (pui_bool)0;
+       }
+
+       frame = _ani_backend_streaming_get_frame(ani_info);
+       for(int i = 0; i<12; i++)
+       {
+               _ani_backend_streaming_get_led_rgb(frame, i, &r, &g, &b);
+               buffer->ptr[4*i] = 0;
+               buffer->ptr[4*i + 1] = b; /* BLUE */
+               buffer->ptr[4*i + 2] = g; /* GREEN */
+               buffer->ptr[4*i + 3] = r; /* RED */
+       }
+       _ani_backend_streaming_free_frame(frame);
+
+       e = pui_backend_ani_set_buffer(ani, buffer);
+
+       if (e != PUI_INT_ERROR_NONE)
+       {
+               pui_err("Failed on setting buffer on animation !(e=%d)\n", e);
+               return (pui_bool)0;
+       }
+
+       e = pui_backend_ani_update(ani);
+
+       if (e != PUI_INT_ERROR_NONE)
+       {
+               pui_err("Failed on updating animation !(e=%d)\n", e);
+               return (pui_bool)0;
+       }
+
+       pui_info("... update (serial=%d)\n", serial);
+
+       return (pui_bool)1;
+}
+
+pui_error
+_ani_streaming_start(pui_ani_t *ani, int repeat)
+{
+       pui_bool ret = 0;
+       pui_int_error e = PUI_INT_ERROR_NONE;
+       pui_backend_ani_data *ani_data = NULL;
+
+       ani_data = pui_backend_ani_get_ani_data(ani);
+       default_ani_info *info = (default_ani_info *)ani_data->ani_info;
+
+       //TODO
+       (void) info;
+
+       pui_info("... info->id: %s, repeat : %d, interval: %d\n", info->id, repeat, info->interval);
+
+       pui_backend_ani_status_update(ani, PUI_ANI_STATUS_STARTED);
+       ret = pui_backend_ani_add_frame_cb(ani, _ani_backend_streaming_frame_cb, info->interval / 1000.0);
+
+       if (!ret)
+       {
+               pui_err("Failed to add frame callback !\n");
+               e = PUI_INT_ERROR_INVALID_RESOURCES;
+       }
+
+       return e;
+}
+
+pui_error
+_ani_streaming_stop(pui_ani_t *ani)
+{
+       pui_int_error e = PUI_INT_ERROR_NONE;
+       pui_backend_ani_data *ani_data = NULL;
+
+       ani_data = pui_backend_ani_get_ani_data(ani);
+       default_ani_info *info = (default_ani_info *)ani_data->ani_info;
+
+       //TODO
+       (void) info;
+
+       pui_info("... info->id: %s\n", info->id);
+
+       pui_backend_ani_remove_frame_cb(ani);
+       pui_backend_ani_status_update(ani, PUI_ANI_STATUS_STOPPED);
+
+       return e;
+}
+
+
+void
+pui_default_backend_ani_streaming_func_set(pui_backend_ani_func *func)
+{
+       if (!func) return;
+
+       func->ani_start = _ani_streaming_start;
+       func->ani_stop = _ani_streaming_stop;
+}
+
+
index 4f3eb32..c95082a 100644 (file)
  * SOFTWARE.
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <PUI_backend.h>
-
-#include <json-c/json.h>
-#include <dirent.h>
-#include <errno.h>
-#include <Eina.h>
-#include <Ecore.h>
-#include <config.h>
-
-#define ANI_COLLECTION_DIR "/usr/share/pui/"
-#define MAX_STR 1024
-
-#define ERROR_CHECK(exp, action, fmt, ...) \
-       do { \
-               if (!(exp)) \
-               { \
-                       printf(fmt, ##__VA_ARGS__);     \
-                       action; \
-               } \
-       } while (0)
+#include "default_backend.h"
 
 pui_backend_ani_func *ani_func = NULL;
 Eina_Hash *_animations_hash = NULL;
+pui_backend_ani_data *g_ani_data = NULL;
 
-typedef enum
-{
-       None,
-       Linear,
-       EaseInSine,
-       EaseOutSine,
-       EaseInQuart,
-       EaseOutQuart
-} pui_effect_func;
-
-typedef struct _default_ani_info default_ani_info;
-typedef struct _default_frame_info_t default_frame_info_t;
-typedef struct _default_led_info_t default_led_info_t;
-
-struct _default_ani_info
+#if 0
+static double
+_ani_backend_ease_function_get_intensity(pui_effect_func func, double interval)
 {
-       pui_id id;
-       pui_ani_status status;
-       pui_ani_control_buffer *buffer;
-       unsigned int repeat;
-
-       unsigned int key_frame_idx;
-       unsigned int num_key_frames;
-       default_frame_info_t *frames;
-       int interval;
-       pui_effect_func effect_func;
-};
+       double intensity = interval;
+       switch (func)
+       {
+               case None:
+                       break;
+               case Linear:
+                       break;
+               case EaseInSine:
+                       intensity = 1 - cos(PI / 2 * interval);
+                       break;
+               case EaseOutSine:
+                       intensity = sin(PI / 2 * interval);
+                       break;
+               case EaseInQuart:
+                       intensity = interval * interval;
+                       break;
+               case EaseOutQuart:
+                       intensity = interval * (2 - interval);
+                       break;
+               default:
+                       break;
+       }
 
-struct _default_frame_info_t
-{
-       default_led_info_t *leds;
-       int num_led;
-};
+       return intensity;
+}
 
-struct _default_led_info_t
+static unsigned int
+_ani_backend_get_value(unsigned int end_frame, unsigned int start_frame, double interval)
 {
-       unsigned int color;
-};
+       double res = 0.0;
 
-pui_backend_ani_data *g_ani_data = NULL;
+       // interval: frame ratio between key frame to key frame
+       // end_frame and start_frame is key frame
+
+       res = (end_frame - start_frame) * interval + start_frame;
+
+       return res;
+}
+#endif
 
 static pui_bool
 _ani_backend_frame_cb(void *data, int serial)
@@ -121,9 +104,9 @@ _ani_backend_frame_cb(void *data, int serial)
        for(int i = 0; i<12; i++)
        {
                buffer->ptr[4*i] = 0;
-               buffer->ptr[4*i + 1] = (ani_info->frames[ani_info->key_frame_idx].leds[i].color & 0xFF0000) >> 16;//R
-               buffer->ptr[4*i + 2] = (ani_info->frames[ani_info->key_frame_idx].leds[i].color & 0x00FF00) >> 8;//G
-               buffer->ptr[4*i + 3] = ani_info->frames[ani_info->key_frame_idx].leds[i].color & 0x0000FF;//B
+               buffer->ptr[4*i + 1] = (ani_info->frames[ani_info->frame_idx].leds[i].color & LED_MASK_RED) >> 16;//R
+               buffer->ptr[4*i + 2] = (ani_info->frames[ani_info->frame_idx].leds[i].color & LED_MASK_GREEN) >> 8;//G
+               buffer->ptr[4*i + 3] = ani_info->frames[ani_info->frame_idx].leds[i].color & LED_MASK_BLUE;//B
        }
 
        e = pui_backend_ani_set_buffer(ani, buffer);
@@ -437,10 +420,6 @@ _ani_create(pui_id id)
                return NULL;
        }
 
-       /* Assign each function pointer that corresponds to the given id if needed. */
-       ani_func->ani_start = _ani_start;
-       ani_func->ani_stop = _ani_stop;
-
        /* get animation info associate with the given id from animation collection */
        ani_info = get_ani_info_from_ani_collection(id);
        
@@ -458,6 +437,35 @@ _ani_create(pui_id id)
                pui_err("Failed to allocate memory for pui backend ani data !\n");
                goto err;
        }
+
+       /* Assign each function pointer that corresponds to the given id if needed. */
+       if (!strncmp(ani_info->id, "processing", sizeof("processing")))
+       {
+               pui_default_backend_ani_processing_func_set(ani_func);
+       }
+       else if (!strncmp(ani_info->id, "emergency", sizeof("emergency")))
+       {
+               pui_default_backend_ani_emergency_func_set(ani_func);
+       }
+       else if (!strncmp(ani_info->id, "listening", sizeof("listening")))
+       {
+               pui_default_backend_ani_listening_func_set(ani_func);
+       }
+       else if (!strncmp(ani_info->id, "speaking", sizeof("speaking")))
+       {
+               pui_default_backend_ani_speaking_func_set(ani_func);
+       }
+       else if (!strncmp(ani_info->id, "streaming", sizeof("streaming")))
+       {
+               pui_default_backend_ani_streaming_func_set(ani_func);
+       }
+       else
+       {
+               pui_info("%s animation has no animation handler, using default handler\n", ani_info->id);
+               /* Assign each function pointer that corresponds to the given id if needed. */
+               ani_func->ani_start = _ani_start;
+               ani_func->ani_stop = _ani_stop;
+       }
        
        ani_data->ani_func = ani_func;
        ani_data->ani_info = (pui_backend_ani_info *)ani_info;
diff --git a/backends/default_backend.h b/backends/default_backend.h
new file mode 100644 (file)
index 0000000..e7b0b8d
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * Copyright © 2019 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 <PUI_backend.h>
+
+#include <json-c/json.h>
+#include <dirent.h>
+#include <errno.h>
+#include <Eina.h>
+#include <config.h>
+#include <Ecore.h>
+//#include <cmath.h>
+
+#define ANI_COLLECTION_DIR "/usr/share/pui/"
+#define MAX_STR 1024
+
+#ifndef PI
+#define PI 3.1415926545
+#endif
+
+#define LED_MASK_RED   0xFF0000
+#define LED_MASK_GREEN 0x00FF00
+#define LED_MASK_BLUE  0x0000FF
+
+#define ERROR_CHECK(exp, action, fmt, ...) \
+       do { \
+               if (!(exp)) \
+               { \
+                       printf(fmt, ##__VA_ARGS__);     \
+                       action; \
+               } \
+       } while (0)
+
+typedef enum
+{
+       None,
+       Linear,
+       EaseInSine,
+       EaseOutSine,
+       EaseInQuart,
+       EaseOutQuart
+} pui_effect_func;
+
+typedef struct _default_ani_info default_ani_info;
+typedef struct _default_frame_info_t default_frame_info_t;
+typedef struct _default_led_info_t default_led_info_t;
+
+struct _default_ani_info
+{
+       pui_id id;
+       pui_ani_status status;
+       pui_ani_control_buffer *buffer;
+       unsigned int repeat;
+
+       unsigned int num_key_frames;
+       default_frame_info_t *frames;
+       int interval;
+       pui_effect_func effect_func;
+
+       unsigned int frame_idx;
+};
+
+struct _default_frame_info_t
+{
+       default_led_info_t *leds;
+       int num_led;
+};
+
+struct _default_led_info_t
+{
+       unsigned int color;
+};
+
+void pui_default_backend_ani_listening_func_set(pui_backend_ani_func *func);
+void pui_default_backend_ani_speaking_func_set(pui_backend_ani_func *func);
+void pui_default_backend_ani_emergency_func_set(pui_backend_ani_func *func);
+void pui_default_backend_ani_processing_func_set(pui_backend_ani_func *func);
+void pui_default_backend_ani_streaming_func_set(pui_backend_ani_func *func);
+
diff --git a/backends/res/bixby_listening.json b/backends/res/bixby_listening.json
deleted file mode 100644 (file)
index b744024..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-{
-       "type": "bixby listening",
-       "interval": 30,
-       "frame": [
-               {
-                       "frame_id": 1,
-                       "led": [
-                               {"id": 1,  "color": "101010"},
-                               {"id": 2,  "color": "101010"},
-                               {"id": 3,  "color": "101010"},
-                               {"id": 4,  "color": "101010"},
-                               {"id": 5,  "color": "101010"},
-                               {"id": 6,  "color": "101010"},
-                               {"id": 7,  "color": "101010"},
-                               {"id": 8,  "color": "101010"},
-                               {"id": 9,  "color": "101010"},
-                               {"id": 10, "color": "101010"},
-                               {"id": 11, "color": "101010"},
-                               {"id": 12, "color": "101010"},
-                               {"id": 13, "color": "101010"},
-                               {"id": 14, "color": "101010"},
-                               {"id": 15, "color": "101010"},
-                               {"id": 16, "color": "101010"}
-                       ]
-               },
-               {
-                       "frame_id": 2,
-                       "led": [
-                               {"id": 1,  "color": "bbbbbb"},
-                               {"id": 2,  "color": "bbbbbb"},
-                               {"id": 3,  "color": "bbbbbb"},
-                               {"id": 4,  "color": "bbbbbb"},
-                               {"id": 5,  "color": "bbbbbb"},
-                               {"id": 6,  "color": "bbbbbb"},
-                               {"id": 7,  "color": "bbbbbb"},
-                               {"id": 8,  "color": "bbbbbb"},
-                               {"id": 9,  "color": "bbbbbb"},
-                               {"id": 10, "color": "bbbbbb"},
-                               {"id": 11, "color": "bbbbbb"},
-                               {"id": 12, "color": "bbbbbb"},
-                               {"id": 13, "color": "bbbbbb"},
-                               {"id": 14, "color": "bbbbbb"},
-                               {"id": 15, "color": "bbbbbb"},
-                               {"id": 16, "color": "bbbbbb"}
-                       ]
-               },
-               {
-                       "frame_id": 3,
-                       "led": [
-                               {"id": 1,  "color": "bbbbbb"},
-                               {"id": 2,  "color": "bbbbbb"},
-                               {"id": 3,  "color": "bbbbbb"},
-                               {"id": 4,  "color": "bbbbbb"},
-                               {"id": 5,  "color": "bbbbbb"},
-                               {"id": 6,  "color": "bbbbbb"},
-                               {"id": 7,  "color": "bbbbbb"},
-                               {"id": 8,  "color": "bbbbbb"},
-                               {"id": 9,  "color": "bbbbbb"},
-                               {"id": 10, "color": "bbbbbb"},
-                               {"id": 11, "color": "bbbbbb"},
-                               {"id": 12, "color": "bbbbbb"},
-                               {"id": 13, "color": "bbbbbb"},
-                               {"id": 14, "color": "bbbbbb"},
-                               {"id": 15, "color": "bbbbbb"},
-                               {"id": 16, "color": "bbbbbb"}
-                       ]
-               },
-               {
-                       "frame_id": 4,
-                       "led": [
-                               {"id": 1,  "color": "101010"},
-                               {"id": 2,  "color": "101010"},
-                               {"id": 3,  "color": "101010"},
-                               {"id": 4,  "color": "101010"},
-                               {"id": 5,  "color": "101010"},
-                               {"id": 6,  "color": "101010"},
-                               {"id": 7,  "color": "101010"},
-                               {"id": 8,  "color": "101010"},
-                               {"id": 9,  "color": "101010"},
-                               {"id": 10, "color": "101010"},
-                               {"id": 11, "color": "101010"},
-                               {"id": 12, "color": "101010"},
-                               {"id": 13, "color": "101010"},
-                               {"id": 14, "color": "101010"},
-                               {"id": 15, "color": "101010"},
-                               {"id": 16, "color": "101010"}
-                       ]
-               },
-       ]
-}
diff --git a/backends/res/bixby_speaking.json b/backends/res/bixby_speaking.json
deleted file mode 100644 (file)
index 06f6af6..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-{
-       "type": "bixby speaking",
-       "interval": 30,
-       "frame": [
-               {
-                       "frame_id": 1,
-                       "led": [
-                               {"id": 1,  "color": "101010"},
-                               {"id": 2,  "color": "101010"},
-                               {"id": 3,  "color": "101010"},
-                               {"id": 4,  "color": "101010"},
-                               {"id": 5,  "color": "101010"},
-                               {"id": 6,  "color": "101010"},
-                               {"id": 7,  "color": "101010"},
-                               {"id": 8,  "color": "101010"},
-                               {"id": 9,  "color": "101010"},
-                               {"id": 10, "color": "101010"},
-                               {"id": 11, "color": "101010"},
-                               {"id": 12, "color": "101010"},
-                               {"id": 13, "color": "101010"},
-                               {"id": 14, "color": "101010"},
-                               {"id": 15, "color": "101010"},
-                               {"id": 16, "color": "101010"}
-                       ]
-               },
-               {
-                       "frame_id": 2,
-                       "led": [
-                               {"id": 1,  "color": "bbbbbb"},
-                               {"id": 2,  "color": "bbbbbb"},
-                               {"id": 3,  "color": "bbbbbb"},
-                               {"id": 4,  "color": "bbbbbb"},
-                               {"id": 5,  "color": "bbbbbb"},
-                               {"id": 6,  "color": "bbbbbb"},
-                               {"id": 7,  "color": "bbbbbb"},
-                               {"id": 8,  "color": "bbbbbb"},
-                               {"id": 9,  "color": "bbbbbb"},
-                               {"id": 10, "color": "bbbbbb"},
-                               {"id": 11, "color": "bbbbbb"},
-                               {"id": 12, "color": "bbbbbb"},
-                               {"id": 13, "color": "bbbbbb"},
-                               {"id": 14, "color": "bbbbbb"},
-                               {"id": 15, "color": "bbbbbb"},
-                               {"id": 16, "color": "bbbbbb"}
-                       ]
-               },
-               {
-                       "frame_id": 3,
-                       "led": [
-                               {"id": 1,  "color": "bbbbbb"},
-                               {"id": 2,  "color": "bbbbbb"},
-                               {"id": 3,  "color": "bbbbbb"},
-                               {"id": 4,  "color": "bbbbbb"},
-                               {"id": 5,  "color": "bbbbbb"},
-                               {"id": 6,  "color": "bbbbbb"},
-                               {"id": 7,  "color": "bbbbbb"},
-                               {"id": 8,  "color": "bbbbbb"},
-                               {"id": 9,  "color": "bbbbbb"},
-                               {"id": 10, "color": "bbbbbb"},
-                               {"id": 11, "color": "bbbbbb"},
-                               {"id": 12, "color": "bbbbbb"},
-                               {"id": 13, "color": "bbbbbb"},
-                               {"id": 14, "color": "bbbbbb"},
-                               {"id": 15, "color": "bbbbbb"},
-                               {"id": 16, "color": "bbbbbb"}
-                       ]
-               },
-               {
-                       "frame_id": 4,
-                       "led": [
-                               {"id": 1,  "color": "101010"},
-                               {"id": 2,  "color": "101010"},
-                               {"id": 3,  "color": "101010"},
-                               {"id": 4,  "color": "101010"},
-                               {"id": 5,  "color": "101010"},
-                               {"id": 6,  "color": "101010"},
-                               {"id": 7,  "color": "101010"},
-                               {"id": 8,  "color": "101010"},
-                               {"id": 9,  "color": "101010"},
-                               {"id": 10, "color": "101010"},
-                               {"id": 11, "color": "101010"},
-                               {"id": 12, "color": "101010"},
-                               {"id": 13, "color": "101010"},
-                               {"id": 14, "color": "101010"},
-                               {"id": 15, "color": "101010"},
-                               {"id": 16, "color": "101010"}
-                       ]
-               },
-       ]
-}
diff --git a/backends/res/listening.json b/backends/res/listening.json
new file mode 100644 (file)
index 0000000..e2343ea
--- /dev/null
@@ -0,0 +1,40 @@
+{
+       "type": "listening",
+       "interval": 70,
+       "frame": [
+               {
+                       "frame_id": 1,
+                       "led": [
+                               {"id": 1,  "color": "000000"},
+                               {"id": 2,  "color": "000000"},
+                               {"id": 3,  "color": "000000"},
+                               {"id": 4,  "color": "000000"},
+                               {"id": 5,  "color": "000000"},
+                               {"id": 6,  "color": "ffffff"},
+                               {"id": 7,  "color": "ffffff"},
+                               {"id": 8,  "color": "000000"},
+                               {"id": 9,  "color": "000000"},
+                               {"id": 10, "color": "000000"},
+                               {"id": 11, "color": "000000"},
+                               {"id": 12, "color": "000000"}
+                       ]
+               },
+               {
+                       "frame_id": 2,
+                       "led": [
+                               {"id": 1,  "color": "ffffff"},
+                               {"id": 2,  "color": "000000"},
+                               {"id": 3,  "color": "000000"},
+                               {"id": 4,  "color": "000000"},
+                               {"id": 5,  "color": "000000"},
+                               {"id": 6,  "color": "000000"},
+                               {"id": 7,  "color": "000000"},
+                               {"id": 8,  "color": "000000"},
+                               {"id": 9,  "color": "000000"},
+                               {"id": 10, "color": "000000"},
+                               {"id": 11, "color": "000000"},
+                               {"id": 12, "color": "ffffff"}
+                       ]
+               },
+       ]
+}
diff --git a/backends/res/speaking.json b/backends/res/speaking.json
new file mode 100644 (file)
index 0000000..0071822
--- /dev/null
@@ -0,0 +1,40 @@
+{
+       "type": "speaking",
+       "interval": 30,
+       "frame": [
+               {
+                       "frame_id": 1,
+                       "led": [
+                               {"id": 1,  "color": "222222"},
+                               {"id": 2,  "color": "222222"},
+                               {"id": 3,  "color": "222222"},
+                               {"id": 4,  "color": "222222"},
+                               {"id": 5,  "color": "222222"},
+                               {"id": 6,  "color": "222222"},
+                               {"id": 7,  "color": "222222"},
+                               {"id": 8,  "color": "222222"},
+                               {"id": 9,  "color": "222222"},
+                               {"id": 10, "color": "222222"},
+                               {"id": 11, "color": "222222"},
+                               {"id": 12, "color": "222222"}
+                       ]
+               },
+               {
+                       "frame_id": 2,
+                       "led": [
+                               {"id": 1,  "color": "eeeeee"},
+                               {"id": 2,  "color": "eeeeee"},
+                               {"id": 3,  "color": "eeeeee"},
+                               {"id": 4,  "color": "eeeeee"},
+                               {"id": 5,  "color": "eeeeee"},
+                               {"id": 6,  "color": "eeeeee"},
+                               {"id": 7,  "color": "eeeeee"},
+                               {"id": 8,  "color": "eeeeee"},
+                               {"id": 9,  "color": "eeeeee"},
+                               {"id": 10, "color": "eeeeee"},
+                               {"id": 11, "color": "eeeeee"},
+                               {"id": 12, "color": "eeeeee"}
+                       ]
+               },
+       ]
+}
diff --git a/backends/res/streaming.json b/backends/res/streaming.json
new file mode 100644 (file)
index 0000000..c1e87f0
--- /dev/null
@@ -0,0 +1,40 @@
+{
+       "type": "streaming",
+       "interval": 30,
+       "frame": [
+               {
+                       "frame_id": 1,
+                       "led": [
+                               {"id": 1,  "color": "ffffff"},
+                               {"id": 2,  "color": "000000"},
+                               {"id": 3,  "color": "000000"},
+                               {"id": 4,  "color": "000000"},
+                               {"id": 5,  "color": "000000"},
+                               {"id": 6,  "color": "000000"},
+                               {"id": 7,  "color": "000000"},
+                               {"id": 8,  "color": "000000"},
+                               {"id": 9,  "color": "000000"},
+                               {"id": 10, "color": "000000"},
+                               {"id": 11, "color": "000000"},
+                               {"id": 12, "color": "ffffff"}
+                       ]
+               },
+               {
+                       "frame_id": 2,
+                       "led": [
+                               {"id": 1,  "color": "222222"},
+                               {"id": 2,  "color": "000000"},
+                               {"id": 3,  "color": "000000"},
+                               {"id": 4,  "color": "000000"},
+                               {"id": 5,  "color": "000000"},
+                               {"id": 6,  "color": "000000"},
+                               {"id": 7,  "color": "000000"},
+                               {"id": 8,  "color": "000000"},
+                               {"id": 9,  "color": "000000"},
+                               {"id": 10, "color": "000000"},
+                               {"id": 11, "color": "000000"},
+                               {"id": 12, "color": "222222"}
+                       ]
+               },
+       ]
+}
diff --git a/backends/res/system_processing.json b/backends/res/system_processing.json
new file mode 100644 (file)
index 0000000..a402de9
--- /dev/null
@@ -0,0 +1,23 @@
+{
+       "type": "processing",
+       "interval": 100,
+       "frame": [
+               {
+                       "frame_id": 1,
+                       "led": [
+                               {"id": 1,  "color": "bbbbbb"},
+                               {"id": 2,  "color": "a0a0a0"},
+                               {"id": 3,  "color": "909090"},
+                               {"id": 4,  "color": "666666"},
+                               {"id": 5,  "color": "454545"},
+                               {"id": 6,  "color": "202020"},
+                               {"id": 7,  "color": "000000"},
+                               {"id": 8,  "color": "000000"},
+                               {"id": 9,  "color": "000000"},
+                               {"id": 10, "color": "000000"},
+                               {"id": 11, "color": "000000"},
+                               {"id": 12, "color": "000000"},
+                       ]
+               },
+       ]
+}
index 53e8bd4..433e6e3 100644 (file)
@@ -61,12 +61,18 @@ struct app_data
 
 static Eina_Array *_ecore_event_hdls = NULL;
 static animation_t ani_collection[] = {
+       { "processing", PUI_ANI_CMD_START, -1 },
+       { "listening", PUI_ANI_CMD_START, -1 },
+       { "speaking", PUI_ANI_CMD_START, -1 },
+       { "streaming", PUI_ANI_CMD_START, -1 },
+#if 0  
        { "alarm calm", PUI_ANI_CMD_START, 1 },
        { "bixby listening", PUI_ANI_CMD_START, -1 },
        { "bixby speaking", PUI_ANI_CMD_START, -1 },
        { "bixby_error", PUI_ANI_CMD_START, 1 },
        { "blinking", PUI_ANI_CMD_START, -1 },
        { "notification", PUI_ANI_CMD_START, -1 },
+#endif
 };
 
 static void