diff options
Diffstat (limited to 'feature/src/ivug-vibration.c')
-rwxr-xr-x | feature/src/ivug-vibration.c | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/feature/src/ivug-vibration.c b/feature/src/ivug-vibration.c new file mode 100755 index 0000000..8ffcf4d --- /dev/null +++ b/feature/src/ivug-vibration.c @@ -0,0 +1,118 @@ +/*
+ * Copyright 2012 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+ *
+ * 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 "ivug-vibration.h" +#include "ivug-debug.h" + +#include <stdio.h> +#include <haptic.h> + +static const char *_conver_error(int err) +{ + switch(err) + { + case HAPTIC_ERROR_NONE: + return "Successful"; + case HAPTIC_ERROR_INVALID_PARAMETER: + return "Invalid parameter"; + case HAPTIC_ERROR_NO_SUCH_FILE: + return "No such file"; + case HAPTIC_ERROR_NOT_SUPPORTED_FORMAT: + return "Not supported file format"; + case HAPTIC_ERROR_NOT_INITIALIZED: + return
"Not initialized"; + case HAPTIC_ERROR_OPERATION_FAILED: + return "Operation failed"; + default: + { + static char error[128]; + sprintf(error, "Unknow Error : %d(0x%08x)", err, err); + return error; + } + } + + return NULL; + +} + + +int ivug_vibration_create() +{ + int ret = HAPTIC_ERROR_NONE; + + ret = haptic_initialize(); + + if (ret != HAPTIC_ERROR_NONE) + { + MSG_UTIL_ERROR("device_haptic_open failed. %s", _conver_error(ret)); + return -1; + } + + int vib_index = 0; // Means all vibratior. + + return vib_index; +} + +bool ivug_vibration_play(int handle, int duration) +{ + int ret = HAPTIC_ERROR_NONE; + + MSG_UTIL_HIGH("Vibration start. Handle=%d duration=%f", handle, duration); + + ret = haptic_vibrate_monotone(handle, duration, HAPTIC_LEVEL_3); + + if (ret != HAPTIC_ERROR_NONE) + { + MSG_UTIL_ERROR("haptic_vibrate_monotone error Handle=%d. %s", handle, _conver_error(ret)); + return false; + } + + return true; +} + +bool ivug_vibration_stop(int handle) +{ + MSG_UTIL_HIGH("Vibration stop. Handle=%d", handle); + + int ret = HAPTIC_ERROR_NONE; + + ret = haptic_stop_device(handle); + if (ret != 0) + { + MSG_UTIL_ERROR("haptic_stop_device failed. %s", _conver_error(ret)); + } + + return true; +} + + +bool ivug_vibration_delete(int handle) +{ + MSG_UTIL_HIGH("Vibration deinit. Handle=%d", handle); + + int ret = HAPTIC_ERROR_NONE; + + ret = haptic_deinitialize(); + + if (ret != HAPTIC_ERROR_NONE) + { + MSG_UTIL_ERROR("device_haptic_close failed. %s", _conver_error(ret)); + } + + return true; +} + + |