4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
26 #include <sys/types.h>
30 #include <device-node.h>
34 #include "core/data.h"
35 #include "core/common.h"
36 #include "core/devices.h"
37 #include "core/device-notifier.h"
38 #include "core/edbus-handler.h"
39 #include "hall-handler.h"
41 #define SIGNAL_HALL_STATE "ChangeState"
43 static int hall_ic_status = HALL_IC_OPENED;
45 static int hall_ic_get_status(void)
47 return hall_ic_status;
50 static void hall_ic_chgdet_cb(struct main_data *ad)
58 fd = open(HALL_IC_STATUS, O_RDONLY);
60 _E("%s open error: %s", HALL_IC_STATUS, strerror(errno));
66 _E("fail to get hall status %d", r);
72 hall_ic_status = atoi(buf);
73 _I("cover is opened(%d)", hall_ic_status);
75 device_notify(DEVICE_NOTIFIER_HALLIC_OPEN, (void *)hall_ic_status);
77 snprintf(str_status, sizeof(str_status), "%d", hall_ic_status);
80 broadcast_edbus_signal(DEVICED_PATH_HALL, DEVICED_INTERFACE_HALL,
81 SIGNAL_HALL_STATE, "i", arr);
83 /* Set touch screen flip mode when cover is closed */
84 ret = device_set_property(DEVICE_TYPE_TOUCH,
85 PROP_TOUCH_SCREEN_FLIP_MODE, (hall_ic_status ? 0 : 1));
87 _E("Failed to set touch screen flip mode!");
89 /* Set touch key flip mode when cover is closed */
90 ret = device_set_property(DEVICE_TYPE_TOUCH,
91 PROP_TOUCH_KEY_FLIP_MODE, (hall_ic_status ? 0 : 1));
93 _E("Failed to set touch key flip mode!");
97 static int hall_action(int argc, char **argv)
103 if (strncmp(argv[0], HALL_IC_NAME, strlen(HALL_IC_NAME)) == 0)
104 hall_ic_chgdet_cb(NULL);
108 static void hall_edbus_signal_handler(void *data, DBusMessage *msg)
110 _D("hall_edbus_signal_handler occurs!!!");
113 static DBusMessage *edbus_getstatus_cb(E_DBus_Object *obj, DBusMessage *msg)
115 DBusMessageIter iter;
119 ret = device_get_property(DEVICE_TYPE_HALL, PROP_HALL_STATUS, &val);
123 _D("get hall status %d, %d", val, ret);
125 reply = dbus_message_new_method_return(msg);
126 dbus_message_iter_init_append(reply, &iter);
127 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
131 static const struct edbus_method edbus_methods[] = {
132 { "getstatus", NULL, "i", edbus_getstatus_cb },
133 /* Add methods here */
136 static void hall_ic_init(void *data)
140 /* init dbus interface */
141 ret = register_edbus_method(DEVICED_PATH_HALL, edbus_methods, ARRAY_SIZE(edbus_methods));
143 _E("fail to init edbus method(%d)", ret);
145 register_action(PREDEF_HALL_IC, hall_action, NULL, NULL);
147 register_edbus_signal_handler(DEVICED_PATH_HALL, DEVICED_INTERFACE_HALL,
149 hall_edbus_signal_handler);
151 if (device_get_property(DEVICE_TYPE_HALL, PROP_HALL_STATUS, &val) >= 0)
152 hall_ic_status = val;
155 static const struct device_ops hall_device_ops = {
156 .priority = DEVICE_PRIORITY_NORMAL,
157 .name = HALL_IC_NAME,
158 .init = hall_ic_init,
159 .status = hall_ic_get_status,
162 DEVICE_OPS_REGISTER(&hall_device_ops)