/* * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #define MAX_PATH_LENGTH 256 #define NOT_ASSIGNED -1 static int _PTN_VIBE[] = { SVI_VIB_TOUCH_TOUCH, SVI_VIB_TOUCH_MULTI_TAP, SVI_VIB_TOUCH_SIP, SVI_VIB_TOUCH_HOLD, SVI_VIB_TOUCH_HW_TAP, SVI_VIB_TOUCH_HW_HOLD }; static int _PTN_SND[] = { SVI_SND_TOUCH_TOUCH1, SVI_SND_TOUCH_MULTI_TAP, SVI_SND_TOUCH_SIP, SVI_SND_TOUCH_HOLD, SVI_SND_TOUCH_HW_TAP, SVI_SND_TOUCH_HW_HOLD }; static int _TYPE[] = { SVI_TYPE_SND, SVI_TYPE_VIB }; static int* _TYPE_PTN[] = { _PTN_SND, _PTN_VIBE }; static int svi_handle = NOT_ASSIGNED; int feedback_initialize() { int err; if(svi_handle == NOT_ASSIGNED){ err = svi_init(&svi_handle); if(err != SVI_SUCCESS){ svi_fini(svi_handle); LOGE("[%s] Operation failed(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_OPERATION_FAILED); return FEEDBACK_ERROR_OPERATION_FAILED; } } return FEEDBACK_ERROR_NONE; } int feedback_deinitialize() { int err; if(svi_handle != NOT_ASSIGNED){ err = svi_fini(svi_handle); if(err != SVI_SUCCESS){ LOGE("[%s] Operation failed(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_OPERATION_FAILED); return FEEDBACK_ERROR_OPERATION_FAILED; } svi_handle = NOT_ASSIGNED; } return FEEDBACK_ERROR_NONE; } int feedback_play(feedback_pattern_e pattern) { int err; if(svi_handle == NOT_ASSIGNED){ LOGE("[%s] Not Initialized(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_NOT_INITIALIZED); return FEEDBACK_ERROR_NOT_INITIALIZED; } if(pattern < FEEDBACK_PATTERN_TOUCH_TAP || pattern > FEEDBACK_PATTERN_HW_HOLD){ LOGE("[%s] Invalid parameter(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_INVALID_PARAMETER); return FEEDBACK_ERROR_INVALID_PARAMETER; } err = svi_play(svi_handle, _PTN_VIBE[pattern], _PTN_SND[pattern]); if(err != SVI_SUCCESS){ LOGE("[%s] Operation failed(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_OPERATION_FAILED); return FEEDBACK_ERROR_OPERATION_FAILED; } return FEEDBACK_ERROR_NONE; } int feedback_play_type(feedback_type_e type, feedback_pattern_e pattern) { int err; if(svi_handle == NOT_ASSIGNED){ LOGE("[%s] Not Initialized(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_NOT_INITIALIZED); return FEEDBACK_ERROR_NOT_INITIALIZED; } if(pattern < FEEDBACK_PATTERN_TOUCH_TAP || pattern > FEEDBACK_PATTERN_HW_HOLD){ LOGE("[%s] Invalid parameter(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_INVALID_PARAMETER); return FEEDBACK_ERROR_INVALID_PARAMETER; } switch(type) { case FEEDBACK_TYPE_SOUND : err = svi_play_sound(svi_handle, _PTN_SND[pattern]); break; case FEEDBACK_TYPE_VIBRATION : err = svi_play_vib(svi_handle, _PTN_VIBE[pattern]); break; default : LOGE("[%s] Invalid parameter(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_INVALID_PARAMETER); return FEEDBACK_ERROR_INVALID_PARAMETER; } if(err != SVI_SUCCESS){ LOGE("[%s] Operation failed(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_OPERATION_FAILED); return FEEDBACK_ERROR_OPERATION_FAILED; } return FEEDBACK_ERROR_NONE; } int feedback_get_resource_path(feedback_type_e type, feedback_pattern_e pattern, char** path) { int err; char buf[MAX_PATH_LENGTH]; if(path == NULL){ LOGE("[%s] Invalid parameter(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_INVALID_PARAMETER); return FEEDBACK_ERROR_INVALID_PARAMETER; } if(type < FEEDBACK_TYPE_SOUND || type > FEEDBACK_TYPE_VIBRATION){ LOGE("[%s] Invalid parameter(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_INVALID_PARAMETER); return FEEDBACK_ERROR_INVALID_PARAMETER; } if(pattern < FEEDBACK_PATTERN_TOUCH_TAP || pattern > FEEDBACK_PATTERN_HW_HOLD){ LOGE("[%s] Invalid parameter(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_INVALID_PARAMETER); return FEEDBACK_ERROR_INVALID_PARAMETER; } err = svi_get_path(_TYPE[type], _TYPE_PTN[type][pattern], buf, MAX_PATH_LENGTH); if(err != SVI_SUCCESS){ LOGE("[%s] Operation failed(0x%08x)", __FUNCTION__, FEEDBACK_ERROR_OPERATION_FAILED); return FEEDBACK_ERROR_OPERATION_FAILED; } *path = strdup(buf); return FEEDBACK_ERROR_NONE; }