trans_table is used for getting next display state according to event type.
It has following display state for a specific event in the current display state.
To get and set display state, these functions are added to below display-state-transition.
int display_state_transition_get_next_transition_display_state(enum state_t from_state, enum state_t *to_state, int evt_type);
int display_state_transition_set_transition_table_display_state(enum state_t display_state, enum state_t set_state, int evt_type);
Change-Id: I013a63b6059748b58db04e7b52e8366615c6b1ac
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
#include "display-misc.h"
#include "display-panel.h"
#include "display-config.h"
+#include "display-state-transition.h"
#include "shared/plugin.h"
/**
{ S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL },
};
-static int trans_table[S_END][EVENT_END] = {
- /* Timeout, Input */
- { S_START, S_START }, /* S_START */
- { S_LCDDIM, S_NORMAL }, /* S_NORMAL */
- { S_LCDOFF, S_NORMAL }, /* S_LCDDIM */
- { S_SLEEP, S_NORMAL }, /* S_LCDOFF */
- { S_SLEEP, S_STANDBY }, /* S_STANDBY */
- { S_LCDOFF, S_NORMAL }, /* S_SLEEP */
- { S_POWEROFF, S_POWEROFF }, /* S_POWEROFF */
-};
-
#define SHIFT_UNLOCK 4
#define SHIFT_CHANGE_STATE 7
#define CHANGE_STATE_BIT 0xF00 /* 1111 0000 0000 */
void reset_timeout(int timeout)
{
+ enum state_t next_state;
+
if (!display_conf.timeout_enable)
return;
timeout_src_id = 0;
}
- if (trans_table[get_pm_cur_state()][EVENT_TIMEOUT] == get_pm_cur_state())
+ display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, EVENT_TIMEOUT);
+ if (next_state == get_pm_cur_state())
return;
if (timeout > 0)
static int default_trans(int evt)
{
struct state *st = &states[get_pm_cur_state()];
- int next_state;
+ enum state_t next_state;
- next_state = (enum state_t)trans_table[get_pm_cur_state()][evt];
+ display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, evt);
/* check conditions */
if (st->check && !st->check(get_pm_cur_state(), next_state)) {
if (display_conf.lcd_always_on) {
_I("LCD always on.");
- trans_table[S_NORMAL][EVENT_TIMEOUT] = S_NORMAL;
+ display_state_transition_set_transition_table_display_state(S_NORMAL, S_NORMAL, EVENT_TIMEOUT);
}
if (flags & WITHOUT_STARTNOTI) { /* start without noti */
#include "display-misc.h"
#include "display-panel.h"
#include "display-config.h"
+#include "display-state-transition.h"
#include "shared/plugin.h"
/**
{ S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL },
};
-static int trans_table[S_END][EVENT_END] = {
- /* Timeout, Input */
- { S_START, S_START }, /* S_START */
- { S_LCDDIM, S_NORMAL }, /* S_NORMAL */
- { S_LCDOFF, S_NORMAL }, /* S_LCDDIM */
- { S_SLEEP, S_NORMAL }, /* S_LCDOFF */
- { S_SLEEP, S_STANDBY }, /* S_STANDBY */
- { S_LCDOFF, S_NORMAL }, /* S_SLEEP */
- { S_POWEROFF, S_POWEROFF }, /* S_POWEROFF */
-};
-
#define SHIFT_UNLOCK 4
#define SHIFT_CHANGE_STATE 7
#define CHANGE_STATE_BIT 0xF00 /* 1111 0000 0000 */
void reset_timeout(int timeout)
{
+ enum state_t next_state;
+
if (!display_conf.timeout_enable)
return;
timeout_src_id = 0;
}
- if (trans_table[get_pm_cur_state()][EVENT_TIMEOUT] == get_pm_cur_state())
+ display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, EVENT_TIMEOUT);
+ if (next_state == get_pm_cur_state())
return;
if (timeout > 0)
static int default_trans(int evt)
{
struct state *st = &states[get_pm_cur_state()];
- int next_state;
+ enum state_t next_state;
- next_state = (enum state_t)trans_table[get_pm_cur_state()][evt];
+ display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, evt);
/* check conditions */
if (st->check && !st->check(get_pm_cur_state(), next_state)) {
if (display_conf.lcd_always_on) {
_I("LCD always on.");
- trans_table[S_NORMAL][EVENT_TIMEOUT] = S_NORMAL;
+ display_state_transition_set_transition_table_display_state(S_NORMAL, S_NORMAL, EVENT_TIMEOUT);
}
if (flags & WITHOUT_STARTNOTI) { /* start without noti */
#include "display-misc.h"
#include "display-panel.h"
#include "display-config.h"
+#include "display-state-transition.h"
#include "shared/plugin.h"
/**
{ S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL },
};
-static int trans_table[S_END][EVENT_END] = {
- /* Timeout, Input */
- { S_START, S_START }, /* S_START */
- { S_LCDDIM, S_NORMAL }, /* S_NORMAL */
- { S_LCDOFF, S_NORMAL }, /* S_LCDDIM */
- { S_SLEEP, S_NORMAL }, /* S_LCDOFF */
- { S_SLEEP, S_STANDBY }, /* S_STANDBY */
- { S_LCDOFF, S_NORMAL }, /* S_SLEEP */
- { S_POWEROFF, S_POWEROFF }, /* S_POWEROFF */
-};
-
#define SHIFT_UNLOCK 4
#define SHIFT_CHANGE_STATE 7
#define CHANGE_STATE_BIT 0xF00 /* 1111 0000 0000 */
void reset_timeout(int timeout)
{
+ enum state_t next_state;
+
if (!display_conf.timeout_enable)
return;
timeout_src_id = 0;
}
- if (trans_table[get_pm_cur_state()][EVENT_TIMEOUT] == get_pm_cur_state())
+ display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, EVENT_TIMEOUT);
+ if (next_state == get_pm_cur_state())
return;
if (timeout > 0)
static int default_trans(int evt)
{
struct state *st = &states[get_pm_cur_state()];
- int next_state;
+ enum state_t next_state;
- next_state = (enum state_t)trans_table[get_pm_cur_state()][evt];
+ display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, evt);
/* check conditions */
if (st->check && !st->check(get_pm_cur_state(), next_state)) {
if (display_conf.lcd_always_on) {
_I("LCD always on.");
- trans_table[S_NORMAL][EVENT_TIMEOUT] = S_NORMAL;
+ display_state_transition_set_transition_table_display_state(S_NORMAL, S_NORMAL, EVENT_TIMEOUT);
}
if (flags & WITHOUT_STARTNOTI) { /* start without noti */
#include "display-misc.h"
#include "display-panel.h"
#include "display-config.h"
+#include "display-state-transition.h"
#include "shared/plugin.h"
#define POWERLOCK_CONF_FILE "/etc/deviced/powerlock.conf"
{ S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL },
};
-static int trans_table[S_END][EVENT_END] = {
- /* Timeout, Input */
- { S_START, S_START }, /* S_START */
- { S_LCDDIM, S_NORMAL }, /* S_NORMAL */
- { S_LCDOFF, S_NORMAL }, /* S_LCDDIM */
- { S_SLEEP, S_NORMAL }, /* S_LCDOFF */
- { S_SLEEP, S_STANDBY }, /* S_STANDBY */
- { S_LCDOFF, S_NORMAL }, /* S_SLEEP */
- { S_POWEROFF, S_POWEROFF }, /* S_POWEROFF */
-};
-
#define SHIFT_UNLOCK 4
#define SHIFT_CHANGE_STATE 7
#define CHANGE_STATE_BIT 0xF00 /* 1111 0000 0000 */
void reset_timeout(int timeout)
{
+ enum state_t next_state;
+
if (!display_conf.timeout_enable)
return;
timeout_src_id = 0;
}
- if (trans_table[get_pm_cur_state()][EVENT_TIMEOUT] == get_pm_cur_state())
+ display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, EVENT_TIMEOUT);
+ if (next_state == get_pm_cur_state())
return;
if (timeout > 0)
static int default_trans(int evt)
{
struct state *st = &states[get_pm_cur_state()];
- int next_state, ret;
+ int ret;
+ enum state_t next_state;
- next_state = (enum state_t)trans_table[get_pm_cur_state()][evt];
+ display_state_transition_get_next_transition_display_state(get_pm_cur_state(), &next_state, evt);
/* check conditions */
if (st->check && !st->check(get_pm_cur_state(), next_state)) {
if (display_conf.lcd_always_on) {
_I("LCD always on.");
- trans_table[S_NORMAL][EVENT_TIMEOUT] = S_NORMAL;
+ display_state_transition_set_transition_table_display_state(S_NORMAL, S_NORMAL, EVENT_TIMEOUT);
}
if (flags & WITHOUT_STARTNOTI) { /* start without noti */
--- /dev/null
+/*
+ * deviced
+ *
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+/**
+ * @file display-state-transition.c
+ * @brief This file has functions related to display state transition
+ */
+
+#include "device-interface.h"
+#include "display-state-transition.h"
+#include "display-plugin.h"
+
+static int trans_table[S_END][EVENT_END] = {
+ /* Timeout, Input */
+ { S_START, S_START }, /* S_START */
+ { S_LCDDIM, S_NORMAL }, /* S_NORMAL */
+ { S_LCDOFF, S_NORMAL }, /* S_LCDDIM */
+ { S_SLEEP, S_NORMAL }, /* S_LCDOFF */
+ { S_SLEEP, S_STANDBY }, /* S_STANDBY */
+ { S_LCDOFF, S_NORMAL }, /* S_SLEEP */
+ { S_POWEROFF, S_POWEROFF }, /* S_POWEROFF */
+};
+
+static bool is_display_state_valid(enum state_t display_state)
+{
+ return (display_state >= S_START && display_state < S_END);
+}
+
+static bool is_device_event_type_valid(int event_type)
+{
+ return (event_type >= EVENT_TIMEOUT && event_type < EVENT_END);
+}
+
+int display_state_transition_get_next_transition_display_state(enum state_t from_state, enum state_t *to_state, int evt_type)
+{
+ if (!to_state || !is_display_state_valid(from_state) || !is_device_event_type_valid(evt_type))
+ return -EINVAL;
+
+ *to_state = trans_table[from_state][evt_type];
+ return 0;
+}
+
+int display_state_transition_set_transition_table_display_state(enum state_t display_state, enum state_t set_state, int evt_type)
+{
+ if (!is_display_state_valid(display_state) || !is_device_event_type_valid(evt_type) || !is_display_state_valid(set_state))
+ return -EINVAL;
+
+ trans_table[display_state][evt_type] = set_state;
+ return 0;
+}
\ No newline at end of file
--- /dev/null
+/*
+ * deviced
+ *
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+/**
+ * @file display-state-transition.h
+ * @brief This is temporary header to devide plugin and core display module.
+ * After refactoring, this file will be removed.
+ */
+#ifndef __DISPLAY_STATE_TRANSITION_H__
+#define __DISPLAY_STATE_TRANSITION_H__
+
+#include "core.h"
+
+int display_state_transition_get_next_transition_display_state(enum state_t from_state, enum state_t *to_state, int evt_type);
+int display_state_transition_set_transition_table_display_state(enum state_t display_state, enum state_t set_state, int evt_type);
+
+#endif /* __DISPLAY_STATE_TRANSITION_H__ */
\ No newline at end of file