/* * 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 #include #define TEST_IVT "/usr/share/immersion/01_Touch/touch_20ms_sharp.ivt" static GMainLoop *mainloop; static void sig_quit(int signo) { if(mainloop) { g_main_loop_quit(mainloop); } } static char* error_msg(int err){ switch(err){ case HAPTIC_ERROR_NONE : return "HAPTIC_ERROR_NONE"; case HAPTIC_ERROR_INVALID_PARAMETER : return "HAPTIC_ERROR_INVALID_PARAMETER"; case HAPTIC_ERROR_NO_SUCH_FILE : return "HAPTIC_ERROR_NO_SUCH_FILE"; case HAPTIC_ERROR_NOT_SUPPORTED_FORMAT : return "HAPTIC_ERROR_NOT_SUPPORTED_FORMAT"; case HAPTIC_ERROR_NOT_INITIALIZED : return "HAPTIC_ERROR_NOT_INITIALIZED"; case HAPTIC_ERROR_OPERATION_FAILED : return "HAPTIC_ERROR_OPERATION_FAILED"; } return "------??"; } int main(int argc, char *argv[]) { int count, i, err; if(haptic_initialize() == HAPTIC_ERROR_NONE){ printf("haptic device opened\n"); }else{ printf("haptic_open fail\n"); } signal(SIGINT, sig_quit); signal(SIGTERM, sig_quit); signal(SIGQUIT, sig_quit); mainloop = g_main_loop_new(NULL, FALSE); haptic_get_count(&count); printf("count = %d\n", count); for(i=0; i<=count;i++){ printf("play with device(%d)\n", i); if((err = haptic_vibrate_monotone(count, 1000)) < 0){ printf("haptic play fail [%s]\n", error_msg(err)); }else{ printf("haptic play success\n"); } if(haptic_stop_device(count) < 0){ printf("haptic play fail\n"); }else{ printf("haptic play success\n"); } if(haptic_vibrate_file(count, TEST_IVT, 1, HAPTIC_LEVEL_AUTO) < 0){ printf("haptic play fail\n"); }else{ printf("haptic play success\n"); } } g_main_loop_run(mainloop); g_main_loop_unref(mainloop); if(haptic_deinitialize() == HAPTIC_ERROR_NONE){ printf("haptic device closed\n"); }else{ printf("haptic_close fail\n"); } return 0; }