update code - sleep mode, keyeventnode, eglib
authorPark Yong Chul <yc1216.park@samsung.com>
Tue, 11 Dec 2012 08:53:29 +0000 (17:53 +0900)
committerPark Yong Chul <yc1216.park@samsung.com>
Thu, 13 Dec 2012 06:05:07 +0000 (15:05 +0900)
Change-Id: If5c663349fd4cbd3c88bac0239b4e3dc95a4bd28
Signed-off-by: Park Yong Chul <yc1216.park@samsung.com>
debian/control
include/chg_misc.h
packaging/charging-animation.spec
run-chg-ani.in
src/chg_drmd.c
src/chg_fbd.c
src/chg_main.c
src/chg_misc.c
src/chg_png.c
src/chg_power.c

index 3471cf5..1db5c63 100644 (file)
@@ -1,7 +1,7 @@
 Source: charging-animation
 Section: devel
 Priority: extra
-Maintainer: YoungJin Lee <yj0701.lee@samsung.com>
+Maintainer: YongChul Park <yc1216.park@samsung.com>
 Uploaders: YoungJin Lee <yj0701.lee@samsung.com>, Dongil Park <dongil01.park@samsung.com>
 Build-Depends: debhelper (>= 5), libpng-dev, libdrm-dev
 Standards-Version: 0.1.0
index f4c5815..0323b7a 100755 (executable)
@@ -20,8 +20,10 @@ limitations under the License.
 
 #include <sys/types.h>
 
-extern int read_from_file(const char *path, char *buf, size_t size);
+extern int read_from_file(const char *path, char *buf, int size);
 extern int write_to_file(const char *path, const char *buf);
 extern int read_int_from_file(char *path);
+extern int system_cmd_wait(const char *command);
+extern int system_cmd_nowait(const char *command);
 
 #endif /* __CHG_MISC_H__ */
index 9588236..eb7ce9e 100755 (executable)
@@ -1,7 +1,7 @@
 Name:       charging-animation
 Summary:    charging-animation
 ExclusiveArch:  %{arm}
-Version:    0.0.2
+Version:    0.0.3
 Release:    1
 Group:      misc
 License:    Flora Software License
index 13e988b..7b2984b 100755 (executable)
@@ -20,13 +20,27 @@ do_charging_ani() {
        # export the platform specific variables
        source /etc/sysconfig/charging-animation
 
-       if [ "${CHG_ENV_SUPPORT_DRM}" = "1" ]; then
-               /sbin/udevd --daemon
-               /sbin/udevadm trigger --subsystem-match=drm
+       echo powersave > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
+
+       INPUT_SEARCH_BASE=/sys/class/input
+       CANDIDATE=`ls ${INPUT_SEARCH_BASE} | grep input`
+
+       FOUND=
+       for f in ${CANDIDATE}
+       do
+       DEV_NAME=`cat ${INPUT_SEARCH_BASE}/${f}/name`
+       if [ "${DEV_NAME}" = "gpio-keys" ]; then
+               FOUND=${f}
+                       break
+               fi
+       done
+       if [ "X${FOUND}" = "X" ]; then
+        echo "[error] cannot find key input event node"
        fi
+       FOUND_NUM=${FOUND##input}
+       KEY_EVENT=/dev/input/event${FOUND_NUM}
 
-       echo powersave > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
-       /usr/bin/charging-animation &
+       /usr/bin/charging-animation $KEY_EVENT &
 }
 
 
index 73339fb..7796059 100755 (executable)
@@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
+#define _GNU_SOURCE
+#define __USE_GNU
 #include <string.h>
 #include <unistd.h>
 #include "chg_common.h"
@@ -107,7 +109,7 @@ static int create_framebuffer(st_drmdi *drmdi)
 
        /* add drm framebuffer */
        if(drmModeAddFB(drmdi->fd, drmdi->bo_width, drmdi->bo_height,
-               32, 32, drmdi->bo_stride, drmdi->bo_handle, &drmdi->fb_id)) {
+               24, 32, drmdi->bo_stride, drmdi->bo_handle, &drmdi->fb_id)) {
                LOGD("[create_framebuffer] Cannot add drm fb\n");
                return -1;
        }
index d3c1650..53ba93f 100755 (executable)
@@ -58,7 +58,7 @@ int fbd_open(st_fbdi *fbdi)
            (unsigned char *)mmap(0, fbdi->fb_buf_size,
                                  PROT_READ | PROT_WRITE, MAP_SHARED,
                                  fbdi->fb_fd, 0);
-       if ((int)fbdi->fb_buf == -1) {
+       if ((void*)fbdi->fb_buf == (void*)-1) {
                close(fbdi->fb_fd);
                LOGD("Error: failed to map framebuffer device to memory.\n");
                return -1;
index 05a133b..36dd24e 100755 (executable)
@@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
+#define _GNU_SOURCE
+#define __USE_GNU
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -31,15 +33,19 @@ limitations under the License.
 #include "chg_battery.h"
 #include "chg_env.h"
 
-
-#define LCD_DIMM_COUNT         5
-#define LCD_OFF_COUNT          15
-
-
 #define KEY_VAL_PRESS          1
 #define KEY_VAL_RELEASE        0
 #define KEY_CODE_POWER         116
 
+#define EVT_LOOP_DURATION      1000
+
+#define LCD_DIMM_TIME          10000
+#define LCD_OFF_TIME           30000
+#define LCD_DIMM_COUNT         (LCD_DIMM_TIME/EVT_LOOP_DURATION)
+#define LCD_OFF_COUNT          (LCD_OFF_TIME/EVT_LOOP_DURATION)
+
+#define KEY_INPUT_PATH         "/dev/input/event7"
+
 FbInfo fbi;
 
 /*-----------------------------------------------------------------------------
@@ -58,12 +64,10 @@ int event_monitor_process(void *arg)
        static int key_release_time = 0;
        char* key_dev_node;
 
-       LOGD("[main] event_monitor_process() started. \n");
-
-       key_dev_node = chg_env_str[EN_ENV_KEY_EVENT];
+       LOGD("[main] event_monitor_process() started. %s\n", arg);
 
-       if ((fd = open(key_dev_node, O_RDWR)) < 0) {
-               LOGD("%s: open error, fd = %d\n", key_dev_node, fd);
+       if ((fd = open(arg, O_RDWR)) < 0) {
+               LOGD("%s: open error, fd = %d\n", arg, fd);
                return -1;
        }
 
@@ -73,7 +77,7 @@ int event_monitor_process(void *arg)
 
        while (1) {
 
-               ret = poll(&pollevents, 1, 2000);
+               ret = poll(&pollevents, 1, EVT_LOOP_DURATION);
 
                if (ret < 0)
                        LOGD("poll error\n");
@@ -112,7 +116,7 @@ int event_monitor_process(void *arg)
                }
 
                if (sys_power_cnt > 0xFFFE)
-                       sys_power_cnt = 16;
+                       sys_power_cnt = LCD_OFF_COUNT;
 
                sys_power_cnt++;
 
@@ -122,7 +126,7 @@ int event_monitor_process(void *arg)
                        gettimeofday(&tv, NULL);
                        key_release_time = tv.tv_sec * 1000 + tv.tv_usec / 1000;
 
-                       if ((key_release_time - key_push_time) > 3000) {
+                       if ((key_release_time - key_push_time) > 2000) {
                                sys_power_reboot();
                                break;
                        }
@@ -230,6 +234,12 @@ int charging_animation_process(void)
 int main(int argc, char *argv[])
 {
        int child_stack[4096];
+       char key_path[256];
+
+       if (argc > 1)
+               strncpy(key_path, argv[1], 255);
+       else
+               strncpy(key_path, KEY_INPUT_PATH, 255);
 
        chg_env_str_load();
 
@@ -238,12 +248,14 @@ int main(int argc, char *argv[])
                return -1;
        }
 
+       LOGD("charging-animation main function called.");
+
        sys_power_wakeup(&fbi);
        lcd_bl_on(&fbi);
        lcd_br_normal();
 
        if (clone(event_monitor_process, (void *)(child_stack + 4095),
-                 CLONE_VM | CLONE_THREAD | CLONE_SIGHAND, NULL) < 0) {
+                 CLONE_VM | CLONE_THREAD | CLONE_SIGHAND, key_path) < 0) {
                LOGD("[main] cannot creat thread ... \n");
                goto main_exit;
        }
index 80dfe99..c0b0540 100755 (executable)
@@ -15,8 +15,11 @@ limitations under the License.
 */
 
 #include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <errno.h>
 #include <string.h>
 #include <stdlib.h>
 #include "chg_common.h"
@@ -25,10 +28,10 @@ limitations under the License.
 /*-----------------------------------------------------------------------------
   read_from_file()
  ----------------------------------------------------------------------------*/
-int read_from_file(const char *path, char *buf, size_t size)
+int read_from_file(const char *path, char *buf, int size)
 {
        int fd;
-       size_t count;
+       int count;
 
        if (!path)
                return -1;
@@ -39,7 +42,7 @@ int read_from_file(const char *path, char *buf, size_t size)
                return -1;
        }
 
-       count = read(fd, buf, size);
+       count = (int)read(fd, buf, size);
        if (count > 0) {
                count = (count < size) ? count : size - 1;
                while (count > 0 && buf[count - 1] == '\n')
@@ -61,7 +64,7 @@ int read_from_file(const char *path, char *buf, size_t size)
 int write_to_file(const char *path, const char *buf)
 {
        int fd;
-       size_t count;
+       ssize_t count;
 
        if (!path)
                return -1;
@@ -76,7 +79,7 @@ int write_to_file(const char *path, const char *buf)
        close(fd);
        if (count < 0) {
                LOGD("[write_to_file] %s write error", path);
-               return count;
+               return (int)count;
        }
 
        return 0;
@@ -96,3 +99,75 @@ int read_int_from_file(char *path)
        return value;
 }
 
+/*-----------------------------------------------------------------------------
+  system_cmd_wait()
+ ----------------------------------------------------------------------------*/
+int system_cmd_wait(const char *command)
+{
+
+       int pid = 0;
+       int status = 0;
+       char* const environ[2] = {"DISPLAY=:0", NULL };
+
+       if (command == NULL)
+               return -1;
+
+       pid = fork();
+
+       if (pid == -1)
+               return -1;
+
+       if (pid == 0) {
+               char *argv[4];
+               argv[0] = "sh";
+               argv[1] = "-c";
+               argv[2] = (char*)command;
+               argv[3] = 0;
+               execve("/bin/sh", argv, environ);
+               exit(127);
+       }
+
+       do {
+               if (waitpid(pid, &status, 0) == -1) {
+                       if (errno != EINTR)
+                               return -1;
+               } else {
+                       return status;
+               }
+       } while(1);
+}
+
+/*-----------------------------------------------------------------------------
+  system_cmd_nowait()
+ ----------------------------------------------------------------------------*/
+int system_cmd_nowait(const char *command)
+{
+
+       int pid = 0;
+       char* const environ[2] = {"DISPLAY=:0", NULL };
+
+       if (command == NULL)
+               return -1;
+
+       pid = fork();
+
+       if (pid == -1)
+               return -1;
+
+       if (pid == 0) {
+               char *argv[4];
+               argv[0] = "sh";
+               argv[1] = "-c";
+               argv[2] = (char*)command;
+               argv[3] = 0;
+               execve("/bin/sh", argv, environ);
+               exit(127);
+       } else if (pid < 0) {
+               LOGD("execve fail : '%s'", command);
+               return -1;
+       }
+
+       return 0;
+}
+
+
index 73ac1d4..3a60f66 100755 (executable)
@@ -45,7 +45,7 @@ int read_png_file(char *file_name)
                return -1;
        }
 
-       fread(header, 1, 8, fp);
+       (void)fread(header, 1, 8, fp);
        if (png_sig_cmp((png_bytep)header, 0, 8)) {
                fclose(fp);
                LOGD("[read_png_file] File %s is not recognized"
index 4f362b6..fe4868b 100755 (executable)
@@ -201,6 +201,7 @@ int sys_power_state(void)
  ----------------------------------------------------------------------------*/
 void sys_power_reboot(void)
 {
+       LOGD("sys_power_reboot() is called.\n");
        reboot(RB_AUTOBOOT);
 }
 
@@ -209,6 +210,7 @@ void sys_power_reboot(void)
  ----------------------------------------------------------------------------*/
 void sys_power_off(void)
 {
+       LOGD("sys_power_off() is called.\n");
        reboot(RB_POWER_OFF);
 }