+++ /dev/null
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-SET(fw_name "capi-system-sensor")
-SET(fw_test "${fw_name}-test")
-
-INCLUDE(FindPkgConfig)
-pkg_check_modules(${fw_test} REQUIRED glib-2.0)
-FOREACH(flag ${${fw_test}_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall")
-INCLUDE_DIRECTORIES(../include)
-
-#ADD_EXECUTABLE("system-sensor" system-sensor.c)
-#TARGET_LINK_LIBRARIES("system-sensor" ${fw_name} ${${fw_test}_LDFLAGS})
-
-aux_source_directory(. sources)
-FOREACH(src ${sources})
- GET_FILENAME_COMPONENT(src_name ${src} NAME_WE)
- MESSAGE("${src_name}")
- ADD_EXECUTABLE(${src_name} ${src})
- TARGET_LINK_LIBRARIES(${src_name} ${fw_name} ${${fw_test}_LDFLAGS} ${fw_name} -lm)
-ENDFOREACH()
-
-IF(UNIX)
-
-ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution)
-ADD_CUSTOM_COMMAND(
- DEPENDS clean
- COMMENT "distribution clean"
- COMMAND find
- ARGS .
- -not -name config.cmake -and \(
- -name tester.c -or
- -name Testing -or
- -name CMakeFiles -or
- -name cmake.depends -or
- -name cmake.check_depends -or
- -name CMakeCache.txt -or
- -name cmake.check_cache -or
- -name *.cmake -or
- -name Makefile -or
- -name core -or
- -name core.* -or
- -name gmon.out -or
- -name install_manifest.txt -or
- -name *.pc -or
- -name *~ \)
- | grep -v TC | xargs rm -rf
- TARGET distclean
- VERBATIM
-)
-
-ENDIF(UNIX)
+++ /dev/null
-/*
- *
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- * PROPRIETARY/CONFIDENTIAL
- *
- * This software is the confidential and proprietary information of SAMSUNG
- * ELECTRONICS ("Confidential Information"). You agree and acknowledge that
- * this software is owned by Samsung and you shall not disclose such
- * Confidential Information and shall use it only in accordance with the terms
- * of the license agreement you entered into with SAMSUNG ELECTRONICS. SAMSUNG
- * make no representations or warranties about the suitability of the software,
- * either express or implied, including but not limited to the implied
- * warranties of merchantability, fitness for a particular purpose, or
- * non-infringement. SAMSUNG shall not be liable for any damages suffered by
- * licensee arising out of or related to this software.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <glib.h>
-#include <sensors.h>
-
-static GMainLoop *mainloop;
-
-const float Alpha = 0.8;
-
-struct three_axis_s{
- float x,y,z;
-};
-
-struct three_axis_s gravitys = {0,0,0};
-struct three_axis_s linear_accelation = {0,0,0};
-
-static void test_accelerometer_cb(sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data)
-{
- gravitys.x = Alpha * gravitys.x + ( 1 - Alpha ) * x;
- gravitys.y = Alpha * gravitys.y + ( 1 - Alpha ) * y;
- gravitys.z = Alpha * gravitys.z + ( 1 - Alpha ) * z;
-
- linear_accelation.x = x - gravitys.x;
- linear_accelation.y = y - gravitys.y;
- linear_accelation.z = z - gravitys.z;
-
- printf("[gravitys x=%f y=%f z=%f] [linear acc x=%f y=%f z=%f]\n",
- gravitys.x, gravitys.y, gravitys.z,
- linear_accelation.x, linear_accelation.y, linear_accelation.z);
-}
-
-static void sig_quit(int signo)
-{
- if(mainloop)
- {
- g_main_loop_quit(mainloop);
- }
-}
-
-int main(int argc, char *argv[])
-{
- int type = SENSOR_ACCELEROMETER;
- sensor_h handle;
- bool is_supported;
-
- float max = 0, min = 0, res = 0;
-
- if(sensor_is_supported(type, &is_supported) != SENSOR_ERROR_NONE){
- printf("unknown error\n");
- return 0;
- }
- if(!is_supported){
- printf("unsupported sensor\n");
- return 0;
- }
-
- signal(SIGINT, sig_quit);
- signal(SIGTERM, sig_quit);
- signal(SIGQUIT, sig_quit);
-
- mainloop = g_main_loop_new(NULL, FALSE);
-
- if(sensor_get_spec(type, &max, &min, &res) == SENSOR_ERROR_NONE){
- printf("max=%f, min=%f, res=%f\n", max, min, res);
- }else{
- printf("Error!!!!\n");
- }
-
- sensor_create(&handle);
-
- sensor_accelerometer_set_cb(handle, 0, test_accelerometer_cb, NULL);
-
- if(sensor_start(handle, type) == SENSOR_ERROR_NONE)
- printf("Success start \n");
-
- g_main_loop_run(mainloop);
- g_main_loop_unref(mainloop);
-
- sensor_accelerometer_unset_cb(handle);
-
- if(sensor_stop(handle, type) == SENSOR_ERROR_NONE)
- printf("Success stop \n");
-
- sensor_destroy(handle);
- return 0;
-}
+++ /dev/null
-/*
- *
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- * PROPRIETARY/CONFIDENTIAL
- *
- * This software is the confidential and proprietary information of SAMSUNG
- * ELECTRONICS ("Confidential Information"). You agree and acknowledge that
- * this software is owned by Samsung and you shall not disclose such
- * Confidential Information and shall use it only in accordance with the terms
- * of the license agreement you entered into with SAMSUNG ELECTRONICS. SAMSUNG
- * make no representations or warranties about the suitability of the software,
- * either express or implied, including but not limited to the implied
- * warranties of merchantability, fitness for a particular purpose, or
- * non-infringement. SAMSUNG shall not be liable for any damages suffered by
- * licensee arising out of or related to this software.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <glib.h>
-#include <sensors.h>
-#include <time.h>
-
-struct xyz_axis {
- float x,y,z;
-};
-
-static struct xyz_axis angles = {0,0,0};
-static time_t timestamp = 0;
-
-static GMainLoop *mainloop;
-
-static void test_gyroscope_cb(sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data)
-{
- time_t current_timestamp = time(0);
- if(timestamp != 0){
- const float dT = difftime(current_timestamp, timestamp);
- angles.x += x * dT;
- angles.y += y * dT;
- angles.z += z * dT;
- printf("angle x=%f y=%f z=%f\n", angles.x, angles.y, angles.z);
- }
- timestamp = current_timestamp;
-}
-
-static void sig_quit(int signo)
-{
- if(mainloop)
- {
- g_main_loop_quit(mainloop);
- }
-}
-
-int main(int argc, char *argv[])
-{
- int type = SENSOR_GYROSCOPE;
- sensor_h handle;
- bool is_supported;
-
- float max = 0, min = 0, res = 0;
-
- if(sensor_is_supported(type, &is_supported) != SENSOR_ERROR_NONE){
- printf("unknown error\n");
- return 0;
- }
- if(!is_supported){
- printf("unsupported sensor\n");
- return 0;
- }
-
- signal(SIGINT, sig_quit);
- signal(SIGTERM, sig_quit);
- signal(SIGQUIT, sig_quit);
-
- mainloop = g_main_loop_new(NULL, FALSE);
-
- if(sensor_get_spec(type, &max, &min, &res) == SENSOR_ERROR_NONE){
- printf("max=%f, min=%f, res=%f\n", max, min, res);
- }else{
- printf("Error!!!!\n");
- }
-
- sensor_create(&handle);
-
- sensor_gyroscope_set_cb(handle, 0, test_gyroscope_cb, NULL);
-
- if(sensor_start(handle, type) == SENSOR_ERROR_NONE)
- printf("Success start \n");
-
- g_main_loop_run(mainloop);
- g_main_loop_unref(mainloop);
-
- sensor_gyroscope_unset_cb(handle);
-
- if(sensor_stop(handle, type) == SENSOR_ERROR_NONE)
- printf("Success stop \n");
-
- sensor_destroy(handle);
- return 0;
-}
+++ /dev/null
-/*
- *
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- * PROPRIETARY/CONFIDENTIAL
- *
- * This software is the confidential and proprietary information of SAMSUNG
- * ELECTRONICS ("Confidential Information"). You agree and acknowledge that
- * this software is owned by Samsung and you shall not disclose such
- * Confidential Information and shall use it only in accordance with the terms
- * of the license agreement you entered into with SAMSUNG ELECTRONICS. SAMSUNG
- * make no representations or warranties about the suitability of the software,
- * either express or implied, including but not limited to the implied
- * warranties of merchantability, fitness for a particular purpose, or
- * non-infringement. SAMSUNG shall not be liable for any damages suffered by
- * licensee arising out of or related to this software.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <glib.h>
-#include <sensors.h>
-#include <math.h>
-
-#define RADIAN_VALUE (57.2957)
-#define PITCH_MIN 35
-#define PITCH_MAX 145
-
-
-static GMainLoop *mainloop;
-
-const float Alpha = 0.8;
-
-struct three_axis_s{
- float x,y,z;
-};
-
-struct three_axis_s gravitys = {0,0,0};
-struct three_axis_s linear_accelation = {0,0,0};
-
-enum {
- ROTATE_0,
- ROTATE_90,
- ROTATE_180,
- ROTATE_270,
- ROTATE_ERROR
-};
-
-static int current_rotate = -1;
-
-static void test_accelerometer_cb(sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data)
-{
- double atan_v, norm_z, raw_z;
- int acc_theta, acc_pitch;
- int rotate;
-
- atan_v = atan2(y, x);
- acc_theta = (int)(atan_v * (RADIAN_VALUE) + 270)%360;
- raw_z = (double)(z/(0.004 * 9.81));
-
- if(raw_z > 250){
- norm_z = 1.0;
- }else if(raw_z < -250){
- norm_z = -1.0;
- }else{
- norm_z = ((double)raw_z)/250;
- }
-
- acc_pitch = (int)( acos(norm_z) *(RADIAN_VALUE));
-
- if( (acc_pitch>35) && (acc_pitch<145) ) {
- if ((acc_theta >= 315 && acc_theta <=359) || (acc_theta >=0 && acc_theta < 45)){
- rotate = ROTATE_0;
- }
- else if(acc_theta >= 45 && acc_theta < 135){
- rotate = ROTATE_90;
- }
- else if(acc_theta >=135 && acc_theta < 225){
- rotate = ROTATE_180;
- }
- else if(acc_theta >=225 && acc_theta < 315){
- rotate = ROTATE_270;
- }
- else {
- rotate = ROTATE_ERROR;
- }
- }else{
- rotate = ROTATE_ERROR;
- }
-
- if(rotate != ROTATE_ERROR && current_rotate != rotate){
- current_rotate = rotate;
- printf("rotation is %d\n", rotate * 90);
- }
-}
-
-static void sig_quit(int signo)
-{
- if(mainloop)
- {
- g_main_loop_quit(mainloop);
- }
-}
-
-int main(int argc, char *argv[])
-{
- int type = SENSOR_ACCELEROMETER;
- sensor_h handle;
- bool is_supported;
-
- float max = 0, min = 0, res = 0;
-
- if(sensor_is_supported(type, &is_supported) != SENSOR_ERROR_NONE){
- printf("unknown error\n");
- return 0;
- }
- if(!is_supported){
- printf("unsupported sensor\n");
- return 0;
- }
-
- signal(SIGINT, sig_quit);
- signal(SIGTERM, sig_quit);
- signal(SIGQUIT, sig_quit);
-
- mainloop = g_main_loop_new(NULL, FALSE);
-
- if(sensor_get_spec(type, &max, &min, &res) == SENSOR_ERROR_NONE){
- printf("max=%f, min=%f, res=%f\n", max, min, res);
- }else{
- printf("Error!!!!\n");
- }
-
- sensor_create(&handle);
-
- sensor_accelerometer_set_cb(handle, 0, test_accelerometer_cb, NULL);
-
- if(sensor_start(handle, type) == SENSOR_ERROR_NONE)
- printf("Success start \n");
-
- g_main_loop_run(mainloop);
- g_main_loop_unref(mainloop);
-
- sensor_accelerometer_unset_cb(handle);
-
- if(sensor_stop(handle, type) == SENSOR_ERROR_NONE)
- printf("Success stop \n");
-
- sensor_destroy(handle);
- return 0;
-}
+++ /dev/null
-/*
- *
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- * PROPRIETARY/CONFIDENTIAL
- *
- * This software is the confidential and proprietary information of SAMSUNG
- * ELECTRONICS ("Confidential Information"). You agree and acknowledge that
- * this software is owned by Samsung and you shall not disclose such
- * Confidential Information and shall use it only in accordance with the terms
- * of the license agreement you entered into with SAMSUNG ELECTRONICS. SAMSUNG
- * make no representations or warranties about the suitability of the software,
- * either express or implied, including but not limited to the implied
- * warranties of merchantability, fitness for a particular purpose, or
- * non-infringement. SAMSUNG shall not be liable for any damages suffered by
- * licensee arising out of or related to this software.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <sensors.h>
-
-static char* TYPE_NAME[] = {
- "ACCELEROMETER",
- "MAGNETIC",
- "ORIENTATION",
- "GYROSCOPE",
- "LIGHT",
- "PROXIMITY",
- "MOTION_SNAP",
- "MOTION_SHAKE",
- "MOTION_DOUBLETAP",
- "MOTION_PANNING",
- "MOTION_FACEDOWN"
-};
-
-int main(int argc, char *argv[])
-{
- int err;
- sensor_type_e type;
- bool is_supported;
- char* supported_msg;
-
- for(type=0; type<=SENSOR_MOTION_FACEDOWN; type++){
- err = sensor_is_supported(type, &is_supported);
-
- supported_msg = err < 0 ? "error" : (is_supported ? "support" : "not support");
-
- printf("%d : %s [%s]\n", type, TYPE_NAME[type], supported_msg);
- }
- return 0;
-
-}
+++ /dev/null
-/*
- *
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- * PROPRIETARY/CONFIDENTIAL
- *
- * This software is the confidential and proprietary information of SAMSUNG
- * ELECTRONICS ("Confidential Information"). You agree and acknowledge that
- * this software is owned by Samsung and you shall not disclose such
- * Confidential Information and shall use it only in accordance with the terms
- * of the license agreement you entered into with SAMSUNG ELECTRONICS. SAMSUNG
- * make no representations or warranties about the suitability of the software,
- * either express or implied, including but not limited to the implied
- * warranties of merchantability, fitness for a particular purpose, or
- * non-infringement. SAMSUNG shall not be liable for any damages suffered by
- * licensee arising out of or related to this software.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <glib.h>
-#include <sensors.h>
-
-static GMainLoop *mainloop;
-
-static char* TYPE_NAME[] = {
- "ACCELEROMETER",
- "MAGNETIC",
- "ORIENTATION",
- "GYROSCOPE",
- "LIGHT",
- "PROXIMITY",
- "MOTION_SNAP",
- "MOTION_SHAKE",
- "MOTION_DOUBLETAP",
- "MOTION_PANNING",
- "MOTION_FACEDOWN"
-};
-
-static char* SNAP[] = {
- "NONE",
- "LEFT",
- "RIGHT"
-};
-
-static char* SHAKE[] = {
- "NONE",
- "DETECTION",
- "CONTINUING",
- "FINISH",
- "BREAK"
-};
-
-static void test_calibration_cb(void *user_data)
-{
- char* xx = (char*)user_data;
- printf("%s sensor is calibration needed!!!!!!!!!!!!!!!!!!\n", xx);
-}
-
-static void test_accelerometer_cb(sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data)
-{
- printf("ACCELEROMETER sensor acc=%d x=%f y=%f z=%f\n", accuracy, x, y, z);
-}
-
-static void test_magnetic_cb(sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data)
-{
- printf("MAGNETIC sensor acc=%d x=%f y=%f z=%f\n", accuracy, x, y, z);
-}
-
-static void test_orientation_cb(sensor_data_accuracy_e accuracy, float azimuth, float pitch, float roll, void *user_data)
-{
- printf("ORIENTATION sensor acc=%d azimuth=%f pitch=%f roll=%f\n", accuracy, azimuth, pitch, roll);
-}
-
-static void test_gyroscope_cb(sensor_data_accuracy_e accuracy, float x, float y, float z, void *user_data)
-{
- printf("GYROSCOPE sensor acc=%d x=%f y=%f z=%f\n", accuracy, x, y, z);
-}
-
-static void test_light_cb(sensor_data_accuracy_e accuracy, float lux, void *user_data)
-{
- printf("LIGHT sensor acc=%d lux=%f\n", accuracy, lux);
-}
-
-static void test_proximity_cb(sensor_data_accuracy_e accuracy, float distance, void *user_data)
-{
- printf("PROXIMITY sensor distance = %fcm\n", distance);
-}
-
-static void test_motion_snap_cb (sensor_motion_snap_e snap, void *user_data)
-{
- printf("MOTION_SNAP [%s]\n", SNAP[snap]);
-}
-
-static void test_motion_shake_cb (sensor_motion_shake_e shake, void *user_data)
-{
- printf("MOTION_SHAKE [%s]\n", SHAKE[shake]);
-}
-
-static void test_motion_doubletap_cb (void *user_data)
-{
- printf("MOTION_DOUBLETAP \n");
-}
-
-static void test_motion_panning_cb (int x, int y, void *user_data)
-{
- printf("MOTION_PANNING x=[%5d] y=[%5d]\n", x, y);
-}
-
-static void test_motion_facedown_cb (void *user_data)
-{
- printf("MOTION_FACEDOWN \n");
-}
-
-static void sig_quit(int signo)
-{
- if(mainloop)
- {
- g_main_loop_quit(mainloop);
- }
-}
-
-int main(int argc, char *argv[])
-{
- int i;
- int type;
- sensor_h handle;
- bool is_supported;
-
- float max = 0, min = 0, res = 0;
-
- if(argc < 2)
- {
- printf("input sensor type\n");
- for(i=0; i<=SENSOR_MOTION_FACEDOWN; i++){
- printf("%d : %s\n", i, TYPE_NAME[i]);
- }
- return 0;
- }
-
- type = atoi(argv[1]);
- /*
- if(sensor_is_supported(type, &is_supported) != SENSOR_ERROR_NONE){
- printf("unknown error\n");
- return 0;
- }
- if(!is_supported){
- printf("unsupported sensor\n");
- return 0;
- }
- */
-
- if(type < 0 || type > SENSOR_MOTION_FACEDOWN)
- printf("unknown sensor!\n");
- else
- printf("selected sensor is (%d)%s\n", type, TYPE_NAME[type]);
-
- signal(SIGINT, sig_quit);
- signal(SIGTERM, sig_quit);
- signal(SIGQUIT, sig_quit);
-
- mainloop = g_main_loop_new(NULL, FALSE);
-
-
- if(type < SENSOR_MOTION_SNAP){
- if(sensor_get_spec(type, &max, &min, &res) == SENSOR_ERROR_NONE){
- printf("max=%f, min=%f, res=%f\n", max, min, res);
- }else{
- printf("Error!!!!\n");
- }
- }
-
- sensor_create(&handle);
-
- switch(type){
- case SENSOR_ACCELEROMETER:
- sensor_accelerometer_set_cb(handle, 0, test_accelerometer_cb, TYPE_NAME[type]);
- break;
- case SENSOR_MAGNETIC:
- sensor_magnetic_set_cb(handle, 0, test_magnetic_cb, TYPE_NAME[type]);
- sensor_magnetic_set_calibration_cb(handle, test_calibration_cb, TYPE_NAME[type]);
- break;
- case SENSOR_ORIENTATION:
- sensor_orientation_set_cb(handle, 0, test_orientation_cb, TYPE_NAME[type]);
- sensor_orientation_set_calibration_cb(handle, test_calibration_cb, TYPE_NAME[type]);
- break;
- case SENSOR_GYROSCOPE:
- sensor_gyroscope_set_cb(handle, 0, test_gyroscope_cb, TYPE_NAME[type]);
- break;
- case SENSOR_LIGHT:
- sensor_light_set_cb(handle, 0, test_light_cb, TYPE_NAME[type]);
- break;
- case SENSOR_PROXIMITY:
- sensor_proximity_set_cb(handle, 0, test_proximity_cb, TYPE_NAME[type]);
- break;
- case SENSOR_MOTION_SNAP:
- sensor_motion_snap_set_cb(handle, test_motion_snap_cb, TYPE_NAME[type]);
- break;
- case SENSOR_MOTION_SHAKE:
- sensor_motion_shake_set_cb(handle, test_motion_shake_cb, TYPE_NAME[type]);
- break;
- case SENSOR_MOTION_DOUBLETAP:
- sensor_motion_doubletap_set_cb(handle, test_motion_doubletap_cb, TYPE_NAME[type]);
- break;
- case SENSOR_MOTION_PANNING:
- sensor_motion_panning_set_cb(handle, test_motion_panning_cb, TYPE_NAME[type]);
- break;
- case SENSOR_MOTION_FACEDOWN:
- sensor_motion_facedown_set_cb(handle, test_motion_facedown_cb, TYPE_NAME[type]);
- break;
- default:
- goto _ending;
- }
-
- printf("Success register callback \n");
-
- if(sensor_start(handle, type) == SENSOR_ERROR_NONE)
- printf("Success start \n");
-
- g_main_loop_run(mainloop);
- g_main_loop_unref(mainloop);
-
- switch(type){
- case SENSOR_ACCELEROMETER:
- sensor_accelerometer_unset_cb(handle);
- break;
- case SENSOR_MAGNETIC:
- sensor_magnetic_unset_calibration_cb(handle);
- sensor_magnetic_unset_cb(handle);
- break;
- case SENSOR_ORIENTATION:
- sensor_orientation_unset_calibration_cb(handle);
- sensor_orientation_unset_cb(handle);
- break;
- case SENSOR_GYROSCOPE:
- sensor_gyroscope_unset_cb(handle);
- break;
- case SENSOR_LIGHT:
- sensor_light_unset_cb(handle);
- break;
- case SENSOR_PROXIMITY:
- sensor_proximity_unset_cb(handle);
- break;
- case SENSOR_MOTION_SNAP:
- sensor_motion_snap_unset_cb(handle);
- break;
- case SENSOR_MOTION_SHAKE:
- sensor_motion_shake_unset_cb(handle);
- break;
- case SENSOR_MOTION_DOUBLETAP:
- sensor_motion_doubletap_unset_cb(handle);
- break;
- case SENSOR_MOTION_PANNING:
- sensor_motion_panning_unset_cb(handle);
- break;
- case SENSOR_MOTION_FACEDOWN:
- sensor_motion_facedown_unset_cb(handle);
- break;
-
- default:
- goto _ending;
- }
-
- if(sensor_stop(handle, type) == SENSOR_ERROR_NONE)
- printf("Success stop \n");
-
-_ending:
- sensor_destroy(handle);
- return 0;
-}