Apply conf for rotation baseline in auto-rotation sensor 75/280175/8 accepted/tizen/unified/20220919.021610
authorTaeminYeom <taemin.yeom@samsung.com>
Thu, 25 Aug 2022 02:00:36 +0000 (11:00 +0900)
committerTaeminYeom <taemin.yeom@samsung.com>
Thu, 25 Aug 2022 07:28:24 +0000 (16:28 +0900)
Change-Id: Icfc14b1f0641d5ba840c0085c4290703c388e756
Signed-off-by: TaeminYeom <taemin.yeom@samsung.com>
conf/auto_rotation.conf [new file with mode: 0644]
packaging/sensord.spec
src/fusion-sensor/CMakeLists.txt
src/fusion-sensor/auto_rotation/auto_rotation_alg_emul.cpp
src/fusion-sensor/auto_rotation/auto_rotation_alg_emul.h

diff --git a/conf/auto_rotation.conf b/conf/auto_rotation.conf
new file mode 100644 (file)
index 0000000..c1a04ef
--- /dev/null
@@ -0,0 +1,3 @@
+[AutoRotation]
+Fix=no
+DefaultValue=0
index 8ab90198ac6ed54764a52c8f5d2946d64d341ec9..a8140891650554ce7137c4a292214c58a401dad1 100644 (file)
@@ -14,6 +14,7 @@ BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(glib-2.0)
 BuildRequires:  pkgconfig(vconf)
 BuildRequires:  pkgconfig(libsystemd)
+BuildRequires:  pkgconfig(libsyscommon)
 BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  pkgconfig(cynara-creds-socket)
 BuildRequires:  pkgconfig(cynara-client)
@@ -78,6 +79,9 @@ mkdir -p %{buildroot}%{_unitdir}
 install -m 0644 %SOURCE1 %{buildroot}%{_unitdir}
 install -m 0644 %SOURCE2 %{buildroot}%{_unitdir}
 
+mkdir -p %{buildroot}%{_sysconfdir}/sensord
+install -m 644 conf/auto_rotation.conf   %{buildroot}/etc/sensord/auto_rotation.conf
+
 %install_service multi-user.target.wants sensord.service
 %install_service sockets.target.wants sensord.socket
 
@@ -105,6 +109,7 @@ echo "You need to reinstall %{name}-dummy to keep using the APIs after uninstall
 %{_unitdir}/sensord.socket
 %{_unitdir}/multi-user.target.wants/sensord.service
 %{_unitdir}/sockets.target.wants/sensord.socket
+%config %{_sysconfdir}/sensord/auto_rotation.conf
 %license LICENSE.APLv2
 
 
index f1180b6d7ad3f020c2f75c231525a4fbdcaf1754..5a3a3008a69aaed4cd06d15a8d01cdf65d0f8459 100644 (file)
@@ -25,7 +25,7 @@ MESSAGE("FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
 #ADD_DEFINITIONS(-Wall -g -D_DEBUG)
 
 INCLUDE(FindPkgConfig)
-PKG_CHECK_MODULES(PLUGINS_PKGS REQUIRED dlog)
+PKG_CHECK_MODULES(PLUGINS_PKGS REQUIRED "dlog libsyscommon")
 
 FOREACH(flag ${PLUGINS_PKGS_CFLAGS})
        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
index 601f817c1a2770000e9001952f863e22c20c936f..66f0f76c10d3bfd3c336d1da87fd6fca1fc7e29e 100644 (file)
 
 #include <math.h>
 #include <stdlib.h>
+#include <sensor_log.h>
 #include <sensor_types.h>
+#include <libsyscommon/ini-parser.h>
 
-#define ROTATION_RULE_CNT 4
+#define ROTATION_RULE_CNT       4
+#define AUTO_ROTATION_CONF_PATH "/etc/sensord/auto_rotation.conf"
+
+static struct auto_rotation_config auto_rotation_conf = {
+       .fix = false,
+       .value = 0,
+};
 
 struct rotation_rule {
        int tilt;
@@ -37,8 +45,26 @@ struct rotation_rule rot_rule[ROTATION_RULE_CNT] = {
        {90, 60},
 };
 
+int auto_rotation_load_config(struct parse_result *result, void *user_data)
+{
+       struct auto_rotation_config *c = (struct auto_rotation_config*) user_data;
+
+       if (!MATCH(result->section, "AutoRotation"))
+               return 0;
+
+       if (MATCH(result->name, "Fix"))
+               c->fix = (MATCH(result->value, "yes") ? 1 : 0);
+       else if (MATCH(result->name, "DefaultValue"))
+               SET_CONF(c->value, atoi(result->value));
+
+       return 0;
+}
+
 auto_rotation_alg_emul::auto_rotation_alg_emul()
 {
+       int ret = config_parse(AUTO_ROTATION_CONF_PATH, auto_rotation_load_config, &auto_rotation_conf);
+       if (ret < 0)
+               _D("Failed to load '%s', so use default config", AUTO_ROTATION_CONF_PATH);
 }
 
 auto_rotation_alg_emul::~auto_rotation_alg_emul()
@@ -88,6 +114,26 @@ int auto_rotation_alg_emul::convert_rotation(int prev_rotation,
 bool auto_rotation_alg_emul::get_rotation(float acc[3],
                unsigned long long timestamp, int prev_rotation, int &cur_rotation)
 {
+       if (auto_rotation_conf.fix) {
+               if (auto_rotation_conf.value == 0) {
+                       cur_rotation = AUTO_ROTATION_DEGREE_0;
+               }
+               else if (auto_rotation_conf.value == 90) {
+                       cur_rotation = AUTO_ROTATION_DEGREE_90;
+               }
+               else if (auto_rotation_conf.value == 180) {
+                       cur_rotation = AUTO_ROTATION_DEGREE_180;
+               }
+               else if (auto_rotation_conf.value == 270) {
+                       cur_rotation = AUTO_ROTATION_DEGREE_270;
+               }
+
+               if (prev_rotation == 0)
+                       return true;
+               else
+                       return false;
+       }
+
        const int ROTATION_90 = 90;
        const int RADIAN = 57.29747;
 
@@ -110,9 +156,24 @@ bool auto_rotation_alg_emul::get_rotation(float acc[3],
 
        if (new_rotation == AUTO_ROTATION_DEGREE_UNKNOWN) {
                if (prev_rotation == AUTO_ROTATION_DEGREE_UNKNOWN) {
-                       cur_rotation = AUTO_ROTATION_DEGREE_0; /* default degree is 0 */
+                       if (auto_rotation_conf.value == 0) {
+                               cur_rotation = AUTO_ROTATION_DEGREE_0;
+                       }
+                       else if (auto_rotation_conf.value == 90) {
+                               cur_rotation = AUTO_ROTATION_DEGREE_90;
+                       }
+                       else if (auto_rotation_conf.value == 180) {
+                               cur_rotation = AUTO_ROTATION_DEGREE_180;
+                       }
+                       else if (auto_rotation_conf.value == 270) {
+                               cur_rotation = AUTO_ROTATION_DEGREE_270;
+                       }
+                       else {
+                               cur_rotation = AUTO_ROTATION_DEGREE_0; /* if there is no conf, default degree is 0 */
+                       }
                        return true;
                }
+
                return false;
        }
 
index bf148a028c8f0858250a6f4823d0dce13f05f0f7..d9f6ee800c0a2c883b91893c66978b6b71f4f2e6 100644 (file)
 
 #include "auto_rotation_alg.h"
 
+struct auto_rotation_config {
+       bool fix;
+       int value;
+};
+
 class auto_rotation_alg_emul : public auto_rotation_alg {
 public:
        auto_rotation_alg_emul();