#include "../default_backend.h"
+static default_frame_info_t *ani_frame = NULL;
+
static void
_ani_backend_networkerror_get_led_rgb(default_frame_info_t *frame, int led_idx, unsigned int *r, unsigned int *g, unsigned int *b)
{
*b = (frame->leds[led_idx].color & LED_MASK_BLUE);
}
-static void
-_ani_backend_networkerror_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_networkerror_get_frame(default_ani_info *ani_info)
{
-#define BLINK_FRAME 40
- default_frame_info_t *frame, *key_frame;
+ default_frame_info_t *key_frame;
+ int idx;
- 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)
+ if (ani_info->frame_idx == 0)
{
- free(frame);
- return NULL;
+ ani_info->frame_max = (unsigned int)(ani_info->frames[ani_info->key_frame_cur].frame_duration / ani_info->interval);
}
- if (ani_info->frame_idx % BLINK_FRAME == 0)
- {
- for (int i = 0; i < key_frame->num_led; i++)
- {
- frame->leds[i].color = key_frame->leds[i].color;
- }
- }
- else
+ idx = ani_info->key_frame_cur;
+ key_frame = &ani_info->frames[idx];
+
+ for (int i = 0; i < key_frame->num_led; i++)
{
- for (int i = 0; i < key_frame->num_led; i++)
- {
- frame->leds[i].color = 0x000000;
- }
+ ani_frame->leds[i].color = key_frame->leds[i].color;
}
ani_info->frame_idx++;
- if (ani_info->frame_idx >= BLINK_FRAME)
+ if (ani_info->frame_idx >= ani_info->frame_max)
+ {
ani_info->frame_idx = 0;
+ ani_info->key_frame_cur = (ani_info->key_frame_cur + 1) % ani_info->num_key_frames;
+ if (ani_info->repeat >= 0 && ani_info->key_frame_cur == 0)
+ ani_info->repeat_cur++;
+ }
- return frame;
+ return ani_frame;
}
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->ptr[4*i + 2] = g; /* GREEN */
buffer->ptr[4*i + 3] = r; /* RED */
}
- _ani_backend_networkerror_free_frame(frame);
+ backend_util_cleanup_frame(frame);
e = pui_backend_ani_set_buffer(ani, buffer);
return (pui_bool)0;
}
- pui_info("... update (serial=%d)\n", serial);
+ pui_info("... update (serial=%d), (repeat| cur: %d, want: %d)\n",
+ serial, ani_info->repeat_cur, ani_info->repeat);
+
+ if (ani_info->repeat >= 0 &&
+ ani_info->repeat_cur >= ani_info->repeat)
+ {
+ ani_data->ani_func->ani_stop(ani, EINA_FALSE);
+ }
return (pui_bool)1;
}
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_networkerror_frame_cb, info->interval / 1000.0);
+ if (repeat == 0) info->repeat = 1;
+ else info->repeat = repeat;
+
+ info->key_frame_cur = 0;
+ info->frame_idx = 0;
+ info->repeat_cur = 0;
+
+ if (!ani_frame)
+ ani_frame = backend_util_alloc_frame(info);
+ ERROR_CHECK(ani_frame, return PUI_INT_ERROR_INVALID_RESOURCES, "Failed to alloc memory for frame\n");
+ ret = pui_backend_ani_add_frame_cb(ani, _ani_backend_networkerror_frame_cb, info->interval / 1000.0);
if (!ret)
{
pui_err("Failed to add frame callback !\n");
else
pui_backend_ani_status_update(ani, PUI_ANI_STATUS_STOPPED);
+ if (ani_frame)
+ {
+ backend_util_free_frame(ani_frame);
+ ani_frame = NULL;
+ }
return e;
}