#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include <errno.h>
#include <pthread.h>
#include <device-node.h>
#define MAX_LEVEL 255.0f
#define DEFAULT_EFFECT_HANDLE 0x02
+#define PREDEF_HAPTIC "haptic"
+
enum {
- PLAY_HAPTIC = 0,
- STOP_HAPTIC,
- LEVEL_HAPTIC,
+ OPEN = 0,
+ CLOSE,
+ PLAY,
+ ONESHOT,
+ STOP,
+ LEVEL,
};
typedef struct {
+ int handle;
unsigned char **ppbuffer;
int channels;
int length;
static int _cancel_thread(void)
{
- int *ptr = NULL;
- int ret = -1;
+ int *ptr;
+ int ret;
if (!tid) {
MODULE_LOG("pthread not initialized");
return 0;
}
+static int __haptic_predefine_action(int handle, int prop, int val)
+{
+ char buf_pid[32];
+ char buf_prop[32];
+ char buf_handle[32];
+ char buf_val[32];
+
+ snprintf(buf_pid, sizeof(buf_pid), "%d", getpid());
+ snprintf(buf_prop, sizeof(buf_prop), "%d", prop);
+ snprintf(buf_handle, sizeof(buf_handle), "%d", handle);
+ snprintf(buf_val, sizeof(buf_val), "%d", val);
+
+ MODULE_LOG("pid : %s, prop : %s, handle : %s", buf_pid, buf_prop, buf_handle);
+ return __haptic_call_predef_action(PREDEF_HAPTIC, 4, buf_pid, buf_prop, buf_handle, buf_val);
+}
+
static void __clean_up(void *arg)
{
BUFFER *pbuffer = (BUFFER*)arg;
- int i = 0;
+ int i;
MODULE_LOG("clean up handler!!! : %d", tid);
- __haptic_predefine_action(STOP_HAPTIC, NULL);
+ __haptic_predefine_action(pbuffer->handle, STOP, NULL);
for (i = 0; i < pbuffer->channels; ++i) {
free(pbuffer->ppbuffer[i]);
static void* __play_cb(void *arg)
{
BUFFER *pbuffer = (BUFFER*)arg;
- int i = -1, j = -1, k = -1, value = -1;
+ int i, j, k;
unsigned char ch;
unsigned char prev = -1;
pthread_cleanup_push(__clean_up, arg);
- __haptic_predefine_action(PLAY_HAPTIC, NULL);
+ __haptic_predefine_action(pbuffer->handle, PLAY, NULL);
/* Copy buffer from source buffer */
for (i = 0; i < pbuffer->iteration; i++) {
for (k = 0; k < pbuffer->channels; ++k) {
ch = pbuffer->ppbuffer[k][j];
if (ch != prev) {
- __haptic_predefine_action(LEVEL_HAPTIC, ch);
+ __haptic_predefine_action(pbuffer->handle, LEVEL, ch);
prev = ch;
}
usleep(BITPERMS * 1000);
int GetHapticLevelMax(int *max)
{
- int status = -1;
+ int status;
status = device_get_property(DEVICE_TYPE_VIBRATOR, PROP_VIBRATOR_LEVEL_MAX, max);
if (status < 0) {
MODULE_ERROR("device_get_property fail : %d", status);
return 0;
}
-int SetHapticEnable(int value)
+int InitializeBuffer(unsigned char *vibe_buffer, int max_bufsize)
{
- int status = -1;
- status = device_set_property(DEVICE_TYPE_VIBRATOR, PROP_VIBRATOR_ENABLE, value);
- if (status < 0) {
- MODULE_ERROR("device_set_property fail : %d", status);
- return -1;
- }
- return 0;
-}
-
-int SetHapticLevel(int value)
-{
- int status = -1;
- status = device_set_property(DEVICE_TYPE_VIBRATOR, PROP_VIBRATOR_LEVEL, value);
- if (status < 0) {
- MODULE_ERROR("device_set_property fail : %d", status);
- return -1;
- }
- return 0;
-}
-
-int SetHapticOneshot(int value)
-{
- int status = -1;
- status = device_set_property(DEVICE_TYPE_VIBRATOR, PROP_VIBRATOR_ONESHOT, value);
- if (status < 0) {
- MODULE_ERROR("device_set_property fail : %d", status);
- return -1;
- }
- return 0;
-}
-
-int InitializeHapticBuffer(unsigned char *vibe_buffer, int max_bufsize)
-{
- HapticFile *pfile = NULL;
+ HapticFile *pfile;
if (max_bufsize < sizeof(HapticFile)) {
- MODULE_ERROR("buffer lacks a memory : size(%d) minimum size(%d)", max_bufsize, sizeof(HapticFile));
+ MODULE_ERROR("buffer lacks a memory : size(%d) minimum size(%d)",
+ max_bufsize, sizeof(HapticFile));
return -1;
}
- MODULE_LOG("FormatChunk : %d, DataChunk : %d, HapticFile : %d", sizeof(FormatChunk), sizeof(DataChunk), sizeof(HapticFile));
- MODULE_LOG("Bufsize : %d", max_bufsize);
-
memset(vibe_buffer, 0, sizeof(char)*max_bufsize);
pfile = (HapticFile*)vibe_buffer;
return 0;
}
-int InsertHapticElement(unsigned char *vibe_buffer, int max_bufsize, HapticElement *element)
+int InsertElement(unsigned char *vibe_buffer, int max_bufsize, HapticElement *element)
{
- HapticFile *pfile = NULL;
- int databuf = -1;
- int needbuf = -1;
+ HapticFile *pfile;
+ int databuf;
+ int needbuf;
int duration;
unsigned char level;
- int i = -1;
+ int i;
pfile = (HapticFile*)vibe_buffer;
if (_check_valid_haptic_format(pfile) < 0) {
return 0;
}
-int GetHapticBufferSize(const unsigned char *vibe_buffer, int *size)
+int GetBufferSize(const unsigned char *vibe_buffer, int *size)
{
- HapticFile *pfile = NULL;
+ HapticFile *pfile;
pfile = (HapticFile*)vibe_buffer;
if (_check_valid_haptic_format(pfile) < 0) {
return 0;
}
-int GetHapticBufferDuration(const unsigned char *vibe_buffer, int *duration)
+int GetBufferDuration(const unsigned char *vibe_buffer, int *duration)
{
- HapticFile *pfile = NULL;
+ HapticFile *pfile;
pfile = (HapticFile*)vibe_buffer;
if (_check_valid_haptic_format(pfile) < 0) {
return 0;
}
-int PlayHapticBuffer(const unsigned char *vibe_buffer, int iteration, int level, int *effect_handle)
+int PlayOneshot(int handle, int duration, int level)
{
- HapticFile *pfile = NULL;
- unsigned char **ppbuffer = NULL;
+ char buf_pid[32];
+ char buf_prop[32];
+ char buf_handle[32];
+ char buf_duration[32];
+ char buf_level[32];
+
+ if (_cancel_thread() < 0) {
+ MODULE_ERROR("_cancel_thread fail");
+ return -1;
+ }
+
+ snprintf(buf_pid, sizeof(buf_pid), "%d", getpid());
+ snprintf(buf_prop, sizeof(buf_prop), "%d", ONESHOT);
+ snprintf(buf_handle, sizeof(buf_handle), "%d", handle);
+ snprintf(buf_duration, sizeof(buf_duration), "%d", duration);
+ snprintf(buf_level, sizeof(buf_level), "%d", level);
+
+ MODULE_LOG("pid : %s, prop : %s, handle : %s", buf_pid, buf_prop, buf_handle);
+ return __haptic_call_predef_action(PREDEF_HAPTIC, 5, buf_pid, buf_prop,
+ buf_handle, buf_duration, buf_level);
+}
+
+int PlayBuffer(int handle, const unsigned char *vibe_buffer, int iteration, int level)
+{
+ HapticFile *pfile;
+ unsigned char **ppbuffer;
unsigned int channels, length, align;
unsigned char data;
- int i = -1, j = -1;
+ int i, j;
pfile = (HapticFile*)vibe_buffer;
if (_check_valid_haptic_format(pfile) < 0) {
}
}
+ gbuffer.handle = handle;
gbuffer.ppbuffer = ppbuffer;
gbuffer.channels = channels;
gbuffer.length = length;
return -1;
}
- *effect_handle = DEFAULT_EFFECT_HANDLE;
return 0;
}
-int StopHaptic(void)
+int Stop(int handle)
{
- __haptic_predefine_action(STOP_HAPTIC, NULL);
+ char buf_pid[32];
+ char buf_prop[32];
+ char buf_handle[32];
- return 0;
+ if (_cancel_thread() < 0) {
+ MODULE_ERROR("_cancel_thread fail");
+ return -1;
+ }
+
+ snprintf(buf_pid, sizeof(buf_pid), "%d", getpid());
+ snprintf(buf_prop, sizeof(buf_prop), "%d", STOP);
+ snprintf(buf_handle, sizeof(buf_handle), "%d", handle);
+
+ MODULE_LOG("pid : %s, prop : %s, handle : %s", buf_pid, buf_prop, buf_handle);
+ return __haptic_call_predef_action(PREDEF_HAPTIC, 3, buf_pid, buf_prop, buf_handle);
}
-int CloseHapticDevice(void)
+int OpenDevice(int handle)
{
+ char buf_pid[32];
+ char buf_prop[32];
+ char buf_handle[32];
+
+ snprintf(buf_pid, sizeof(buf_pid), "%d", getpid());
+ snprintf(buf_prop, sizeof(buf_prop), "%d", OPEN);
+ snprintf(buf_handle, sizeof(buf_handle), "%d", handle);
+
+ MODULE_LOG("pid : %s, prop : %s, handle : %s", buf_pid, buf_prop, buf_handle);
+ return __haptic_call_predef_action(PREDEF_HAPTIC, 3, buf_pid, buf_prop, buf_handle);
+}
+
+int CloseDevice(int handle)
+{
+ char buf_pid[32];
+ char buf_prop[32];
+ char buf_handle[32];
+
if (_cancel_thread() < 0) {
MODULE_ERROR("_cancel_thread fail");
return -1;
}
- return 0;
+
+ snprintf(buf_pid, sizeof(buf_pid), "%d", getpid());
+ snprintf(buf_prop, sizeof(buf_prop), "%d", CLOSE);
+ snprintf(buf_handle, sizeof(buf_handle), "%d", handle);
+
+ MODULE_LOG("pid : %s, prop : %s, handle : %s", buf_pid, buf_prop, buf_handle);
+ return __haptic_call_predef_action(PREDEF_HAPTIC, 3, buf_pid, buf_prop, buf_handle);
}
#include <sys/stat.h>
#include <fcntl.h>
#include <assert.h>
+#include <time.h>
#include <vconf.h>
#include <haptic_plugin_intf.h>
#define EXTAPI __attribute__ ((visibility("default")))
#endif
-#define DEFAULT_MOTOR_COUNT 1
+#define DEFAULT_MOTOR_COUNT 1
#define DEFAULT_DEVICE_HANDLE 0x01
#define DEFAULT_EFFECT_HANDLE 0x02
#define HAPTIC_FEEDBACK_AUTO 101
return 0;
}
-static int __vibrate(const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle)
+static int __vibrate(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority)
{
int status;
int level;
- int handle;
assert(vibe_buffer);
if (status != HAPTIC_MODULE_ERROR_NONE)
return status;
- status = PlayHapticBuffer(vibe_buffer, iteration, level, &handle);
+ status = PlayBuffer(device_handle, vibe_buffer, iteration, level);
if (status < 0) {
- MODULE_ERROR("PlayHapticBuffer fail: %d", status);
+ MODULE_ERROR("PlayHapticBuffer fail : %d", status);
return HAPTIC_MODULE_OPERATION_FAILED;
}
- if (effect_handle)
- *effect_handle = handle;
-
return 0;
}
+
+static void *_create_handle(void)
+{
+ return ((getpid()<<16)|time(NULL));
+}
/* END of Static Function Section */
return HAPTIC_MODULE_INVALID_ARGUMENT;
*count = DEFAULT_MOTOR_COUNT;
-
return HAPTIC_MODULE_ERROR_NONE;
}
static int _open_device(int device_index, int *device_handle)
{
+ int handle;
+ int status;
+
if (device_index < HAPTIC_MODULE_DEVICE_0 || device_index > HAPTIC_MODULE_DEVICE_ALL)
return HAPTIC_MODULE_INVALID_ARGUMENT;
if (device_handle == NULL)
return HAPTIC_MODULE_INVALID_ARGUMENT;
- *device_handle = DEFAULT_DEVICE_HANDLE;
+ handle = _create_handle();
+ status = OpenDevice(handle);
+ if (status < 0) {
+ MODULE_ERROR("OpenHapticDevice fail :%d", status);
+ return HAPTIC_MODULE_OPERATION_FAILED;
+ }
+
+ *device_handle = handle;
return HAPTIC_MODULE_ERROR_NONE;
}
if (device_handle < 0)
return HAPTIC_MODULE_INVALID_ARGUMENT;
- status = CloseHapticDevice();
+ status = CloseDevice(device_handle);
if (status < 0) {
MODULE_ERROR("CloseHapticDevice fail : %d", status);
return HAPTIC_MODULE_OPERATION_FAILED;
static int _vibrate_monotone(int device_handle, int duration, int feedback, int priority, int *effect_handle)
{
int status;
- int input_feedback;
+ int level;
if (device_handle < 0)
return HAPTIC_MODULE_INVALID_ARGUMENT;
if (feedback == HAPTIC_MODULE_FEEDBACK_MIN)
return HAPTIC_MODULE_ERROR_NONE;
- status = __to_level(feedback, &input_feedback);
+ status = __to_level(feedback, &level);
if (status != HAPTIC_MODULE_ERROR_NONE)
return status;
- status = SetHapticLevel(input_feedback);
+ status = PlayOneshot(device_handle, duration, level);
if (status < 0) {
- MODULE_ERROR("SetHapticLevel fail : %d", status);
- return HAPTIC_MODULE_OPERATION_FAILED;
- }
-
- status = SetHapticOneshot(duration);
- if (status < 0) {
- MODULE_ERROR("SetHapticOneshot fail : %d", status);
+ MODULE_ERROR("PlayOneshot fail : %d", status);
return HAPTIC_MODULE_OPERATION_FAILED;
}
*effect_handle = DEFAULT_EFFECT_HANDLE;
-
return HAPTIC_MODULE_ERROR_NONE;
}
return HAPTIC_MODULE_OPERATION_FAILED;
}
- status = __vibrate(vibe_buffer, iteration, feedback , priority, effect_handle);
+ status = __vibrate(device_handle, vibe_buffer, iteration, feedback, priority);
free(vibe_buffer);
return status;
if (feedback == HAPTIC_MODULE_FEEDBACK_MIN)
return HAPTIC_MODULE_ERROR_NONE;
- return __vibrate(vibe_buffer, iteration, feedback, priority, effect_handle);
+ return __vibrate(device_handle, vibe_buffer, iteration, feedback, priority);
}
static int _stop_effect(int device_handle, int effect_handle)
if (effect_handle < 0)
return HAPTIC_MODULE_INVALID_ARGUMENT;
- status = StopHaptic();
+ status = Stop(device_handle);
if (status < 0) {
MODULE_ERROR("StopHaptic fail : %d", status);
return HAPTIC_MODULE_OPERATION_FAILED;
if (device_handle < 0)
return HAPTIC_MODULE_INVALID_ARGUMENT;
- status = StopHaptic();
+ status = Stop(device_handle);
if (status < 0) {
MODULE_ERROR("StopHaptic fail : %d", status);
return HAPTIC_MODULE_OPERATION_FAILED;
if (max_elemcnt < 0)
return HAPTIC_MODULE_INVALID_ARGUMENT;
- status = InitializeHapticBuffer(vibe_buffer, max_bufsize);
+ status = InitializeBuffer(vibe_buffer, max_bufsize);
if (status < 0) {
MODULE_ERROR("InitializeHapticBuffer fail: %d", status);
return HAPTIC_MODULE_OPERATION_FAILED;
elem.level = elem_arr[i].haptic_level;
MODULE_LOG("%d) duration : %d, level : %d", i, elem_arr[i].haptic_duration, elem_arr[i].haptic_level);
- status = InsertHapticElement(vibe_buffer, max_bufsize, &elem);
+ status = InsertElement(vibe_buffer, max_bufsize, &elem);
if (status < 0) {
MODULE_ERROR("InsertHapticElement fail: %d", status);
return HAPTIC_MODULE_OPERATION_FAILED;
if (file_path == NULL)
return HAPTIC_MODULE_INVALID_ARGUMENT;
- status = GetHapticBufferSize(vibe_buffer, &size);
+ status = GetBufferSize(vibe_buffer, &size);
if (status < 0) {
MODULE_ERROR("GetHapticBufferSize fail: %d", status);
return HAPTIC_MODULE_OPERATION_FAILED;
{
int status;
unsigned char *vibe_buffer;
- int duration = -1;
+ int duration;
if (device_handle < 0)
return HAPTIC_MODULE_INVALID_ARGUMENT;
return HAPTIC_MODULE_OPERATION_FAILED;
}
- status = GetHapticBufferDuration(vibe_buffer, &duration);
+ status = GetBufferDuration(vibe_buffer, &duration);
free(vibe_buffer);
if (status < 0) {
MODULE_ERROR("GetHapticBufferDuration fail: %d", status);
- free(vibe_buffer);
return HAPTIC_MODULE_OPERATION_FAILED;
}
if (buffer_duration == NULL)
return HAPTIC_MODULE_INVALID_ARGUMENT;
- status = GetHapticBufferDuration(vibe_buffer, &duration);
+ status = GetBufferDuration(vibe_buffer, &duration);
if (status < 0) {
MODULE_ERROR("GetHapticBufferDuration fail: %d", status);
return HAPTIC_MODULE_OPERATION_FAILED;
}
*buffer_duration = duration;
-
return HAPTIC_MODULE_ERROR_NONE;
}