apply FSL(Flora Software License)
authorKim Kibum <kb0929.kim@samsung.com>
Fri, 8 Jun 2012 05:53:55 +0000 (14:53 +0900)
committerKim Kibum <kb0929.kim@samsung.com>
Fri, 8 Jun 2012 05:53:55 +0000 (14:53 +0900)
50 files changed:
AUTHORS [new file with mode: 0644]
CMakeLists.txt [new file with mode: 0755]
LICENSE [new file with mode: 0755]
config/common.cfg [new file with mode: 0755]
config/tizen.cfg [new file with mode: 0755]
debian/changelog [new file with mode: 0644]
debian/charging-animation.install.in [new file with mode: 0644]
debian/charging-animation.postinst [new file with mode: 0644]
debian/compat [new file with mode: 0644]
debian/control [new file with mode: 0644]
debian/dirs [new file with mode: 0644]
debian/docs [new file with mode: 0644]
debian/rules [new file with mode: 0755]
include/chg_battery.h [new file with mode: 0755]
include/chg_common.h [new file with mode: 0755]
include/chg_drmd.h [new file with mode: 0755]
include/chg_env.h [new file with mode: 0755]
include/chg_fb.h [new file with mode: 0755]
include/chg_fbd.h [new file with mode: 0755]
include/chg_misc.h [new file with mode: 0755]
include/chg_png.h [new file with mode: 0755]
include/chg_power.h [new file with mode: 0755]
packaging/charging-animation.spec [new file with mode: 0755]
res/images/chg_img/720x1280/batt_chg_level_10.png [new file with mode: 0755]
res/images/chg_img/720x1280/batt_chg_level_100.png [new file with mode: 0755]
res/images/chg_img/720x1280/batt_chg_level_20.png [new file with mode: 0755]
res/images/chg_img/720x1280/batt_chg_level_30.png [new file with mode: 0755]
res/images/chg_img/720x1280/batt_chg_level_40.png [new file with mode: 0755]
res/images/chg_img/720x1280/batt_chg_level_50.png [new file with mode: 0755]
res/images/chg_img/720x1280/batt_chg_level_60.png [new file with mode: 0755]
res/images/chg_img/720x1280/batt_chg_level_70.png [new file with mode: 0755]
res/images/chg_img/720x1280/batt_chg_level_80.png [new file with mode: 0755]
res/images/chg_img/720x1280/batt_chg_level_90.png [new file with mode: 0755]
res/images/chg_img/720x1280/batt_disconnect.png [new file with mode: 0755]
res/images/chg_img/720x1280/batt_temp_error.png [new file with mode: 0755]
res/images/chg_img/720x1280/progress_01.png [new file with mode: 0755]
res/images/chg_img/720x1280/progress_02.png [new file with mode: 0755]
res/images/chg_img/720x1280/progress_03.png [new file with mode: 0755]
res/images/chg_img/720x1280/progress_04.png [new file with mode: 0755]
res/images/chg_img/720x1280/progress_05.png [new file with mode: 0755]
run-chg-ani.in [new file with mode: 0755]
src/chg_battery.c [new file with mode: 0755]
src/chg_drmd.c [new file with mode: 0755]
src/chg_env.c [new file with mode: 0755]
src/chg_fb.c [new file with mode: 0755]
src/chg_fbd.c [new file with mode: 0755]
src/chg_main.c [new file with mode: 0755]
src/chg_misc.c [new file with mode: 0755]
src/chg_png.c [new file with mode: 0755]
src/chg_power.c [new file with mode: 0755]

diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..2b68e9c
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
+YoungJin Lee <yj0701.lee@samsung.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..73409eb
--- /dev/null
@@ -0,0 +1,71 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(charging-animation C)
+
+SET(SRCS
+       src/chg_main.c
+       src/chg_fb.c
+       src/chg_fbd.c
+       src/chg_drmd.c
+       src/chg_env.c
+       src/chg_png.c
+       src/chg_power.c
+       src/chg_battery.c
+       src/chg_misc.c
+)
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
+SET(PACKAGE ${PROJECT_NAME})
+SET(PKGNAME "${PACKAGE}")
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(BINDIR "${PREFIX}/bin")
+SET(PKGDIR "${PREFIX}/share/charging-animation")
+SET(RESDIR "${PKGDIR}/res")
+SET(CFGDIR "${PKGDIR}/config")
+
+
+IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+       SET(CMAKE_BUILD_TYPE "Release")
+ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
+
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED
+       libpng
+       libdrm
+       libkms
+)
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+SET(CMAKE_C_FLAGS_RELEASE "-O2")
+
+FIND_PROGRAM(UNAME NAMES uname)
+EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
+IF("${ARCH}" STREQUAL "arm")
+       ADD_DEFINITIONS("-DTARGET")
+       MESSAGE("add -DTARGET")
+ENDIF("${ARCH}" STREQUAL "arm")
+
+ADD_DEFINITIONS("-DPACKAGE=\"${PACKAGE}\"")
+ADD_DEFINITIONS("-DPACKAGE_NAME=\"${PKGNAME}\"")
+ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
+ADD_DEFINITIONS("-DRESDIR=\"${RESDIR}\"")
+
+#SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
+SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed")
+
+ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS})
+
+CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/run-chg-ani.in ${CMAKE_SOURCE_DIR}/run-chg-ani @ONLY)
+
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${BINDIR})
+INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/res/images DESTINATION ${RESDIR})
+INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/config DESTINATION ${PKGDIR})
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/run-chg-ani DESTINATION /etc/rc.d/init.d)
diff --git a/LICENSE b/LICENSE
new file mode 100755 (executable)
index 0000000..7ccb5b5
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,75 @@
+Flora License
+
+Version 1.0, May, 2012
+
+http://www.tizenopensource.org/license
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
+
+"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
+
+"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
+
+"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
+
+"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
+
+"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
+
+"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
+
+"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
+
+"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
+
+"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
+
+"Tizen Certified Platform" shall mean a software platform that complies with the standards set forth in the Compatibility Definition Document and passes the Compatibility Test Suite as defined from time to time by the Tizen Technical Steering Group and certified by the Tizen Association or its designated agent.
+
+2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work solely as incorporated into a Tizen Certified Platform, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work solely as incorporated into a Tizen Certified Platform to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof pursuant to the copyright license above, in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
+
+  1. You must give any other recipients of the Work or Derivative Works a copy of this License; and
+
+  2. You must cause any modified files to carry prominent notices stating that You changed the files; and
+
+  3. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
+
+  4. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Flora License to your work
+
+To apply the Flora License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+
+   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.
diff --git a/config/common.cfg b/config/common.cfg
new file mode 100755 (executable)
index 0000000..7c42ae3
--- /dev/null
@@ -0,0 +1,23 @@
+
+export CHG_ENV_BATT_CAP=/sys/class/power_supply/battery/capacity
+export CHG_ENV_BATT_VOL_NOW=/sys/class/power_supply/battery/voltage_now
+export CHG_ENV_BATT_CHG_NOW=/sys/class/power_supply/battery/charge_now
+export CHG_ENV_BATT_TEMP=/sys/class/power_supply/battery/temp
+export CHG_ENV_BATT_CHG_FULL=/sys/class/power_supply/battery/charge_full
+export CHG_ENV_BATT_ONLINE=/sys/class/power_supply/battery/online
+export CHG_ENV_BATT_HEALTH=/sys/class/power_supply/battery/health
+export CHG_ENV_BATT_PRESENT=/sys/class/power_supply/battery/present
+
+export CHG_ENV_POWER_STATE=/sys/power/state
+
+PATH_BRIGHT=
+for file in /sys/class/backlight/*; do
+       if [ -e $file ]; then
+               PATH_BRIGHT=$file
+               break
+       fi
+done
+
+export CHG_ENV_LCD_BRIGHT=${PATH_BRIGHT}/brightness
+
+
diff --git a/config/tizen.cfg b/config/tizen.cfg
new file mode 100755 (executable)
index 0000000..4f9bbb7
--- /dev/null
@@ -0,0 +1,20 @@
+
+export CHG_ENV_SUPPORT_FB=1
+export CHG_ENV_SUPPORT_DRM=0
+
+export CHG_ENV_DEV_FB=/dev/fb3
+export CHG_ENV_DEV_DRM_NAME=
+
+export CHG_ENV_LCD_BR_DIMM_VAL=0
+export CHG_ENV_LCD_BR_NORM_VAL=10
+
+export CHG_ENV_LCD_BL_ONOFF=/sys/class/graphics/fb3/blank
+export CHG_ENV_LCD_BL_ON_VAL=0
+export CHG_ENV_LCD_BL_OFF_VAL=4
+export CHG_ENV_LCD_BL_NORM_VAL=
+
+export CHG_ENV_LCD_XRES=720
+export CHG_ENV_LCD_YRES=1280
+
+export CHG_ENV_KEY_EVENT=/dev/event1
+
diff --git a/debian/changelog b/debian/changelog
new file mode 100644 (file)
index 0000000..b0dfc1a
--- /dev/null
@@ -0,0 +1,7 @@
+charging-animation (0.0.2) unstable; urgency=low
+
+  * Fix LCD on issue and change image postition
+  * Git: shared/pkgs/c/charging-animation
+  * Tag : charging-animation_0.0.2
+
+ -- YoungJin Lee <yj0701.lee@samsung.com>  Tue, 10 Apr 2012 15:31:35 +0900
diff --git a/debian/charging-animation.install.in b/debian/charging-animation.install.in
new file mode 100644 (file)
index 0000000..f389df7
--- /dev/null
@@ -0,0 +1,3 @@
+@PREFIX@/bin/*
+@PREFIX@/share/*
+/etc/*
diff --git a/debian/charging-animation.postinst b/debian/charging-animation.postinst
new file mode 100644 (file)
index 0000000..dbce13e
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+if [ ${USER} = "root" ]
+then
+       /bin/chmod 744 /etc/rc.d/init.d/run-chg-ani
+fi
+
diff --git a/debian/compat b/debian/compat
new file mode 100644 (file)
index 0000000..7ed6ff8
--- /dev/null
@@ -0,0 +1 @@
+5
diff --git a/debian/control b/debian/control
new file mode 100644 (file)
index 0000000..3471cf5
--- /dev/null
@@ -0,0 +1,18 @@
+Source: charging-animation
+Section: devel
+Priority: extra
+Maintainer: YoungJin Lee <yj0701.lee@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
+
+Package: charging-animation
+Architecture: armel
+Depends: ${shlibs:Depends}, ${misc:Depends}, libpng12-0, libdrm2, libkms1
+Description: charging-animation application
+
+Package: charging-animation-dbg
+Section: debug
+Architecture: armel
+Depends: charging-animation (= ${Source-Version}), ${misc:Depends}
+Description: charging-animation debug package(unstripped)
diff --git a/debian/dirs b/debian/dirs
new file mode 100644 (file)
index 0000000..ca882bb
--- /dev/null
@@ -0,0 +1,2 @@
+usr/bin
+usr/sbin
diff --git a/debian/docs b/debian/docs
new file mode 100644 (file)
index 0000000..a0f0008
--- /dev/null
@@ -0,0 +1 @@
+CMakeLists.txt
diff --git a/debian/rules b/debian/rules
new file mode 100755 (executable)
index 0000000..d960715
--- /dev/null
@@ -0,0 +1,126 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+# Sample debian/rules that uses debhelper.
+# This file was originally written by Joey Hess and Craig Small.
+# As a special exception, when this file is copied by dh-make into a
+# dh-make output file, you may use that output file without restriction.
+# This special exception was added by Craig Small in version 0.37 of dh-make.
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+CFLAGS ?= -Wall -g
+LDFLAGS ?=
+PREFIX ?= /usr
+DATADIR ?= /usr/share
+
+#ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+#      CFLAGS += -O0
+#else
+#      CFLAGS += -O2
+#endif
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+        BUILD_TYPE=Debug
+else
+        BUILD_TYPE=Release
+endif
+
+LDFLAGS += -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed
+
+CMAKE_BUILD_DIR ?= $(CURDIR)/cmake_build_tmp
+
+configure: configure-stamp
+configure-stamp:
+       dh_testdir
+       # Add here commands to configure the package.
+       mkdir -p $(CMAKE_BUILD_DIR) && cd $(CMAKE_BUILD_DIR) && \
+       CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" cmake .. -DCMAKE_INSTALL_PREFIX="$(PREFIX)" -DCMAKE_BUILD_TYPE="$(BUILD_TYPE)"
+
+       touch configure-stamp
+
+build: build-stamp
+
+build-stamp: configure-stamp 
+       dh_testdir
+
+       # Add here commands to compile the package.
+       cd $(CMAKE_BUILD_DIR) && $(MAKE)
+
+       for f in `find $(CURDIR)/debian/ -name "*.in"`; do \
+               cat $$f > $${f%.in}; \
+               sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \
+               sed -i -e "s#@DATADIR@#$(DATADIR)#g" $${f%.in}; \
+       done
+
+       touch $@
+
+clean:
+       dh_testdir
+       dh_testroot
+       rm -f build-stamp configure-stamp
+
+       # Add here commands to clean up after the build process.
+       -$(MAKE) clean
+       rm -fr CMakeCache.txt
+       rm -fr CMakeFiles
+       rm -fr cmake_install.cmake
+       rm -fr Makefile
+       rm -fr install_manifest.txt
+       rm -fr run-chg-ani
+       rm -rf $(CMAKE_BUILD_DIR)
+
+       for f in `find $(CURDIR)/debian/ -name "*.in"`; do \
+               rm -f $${f%.in}; \
+       done
+
+       dh_clean 
+
+install: build
+       dh_testdir
+       dh_testroot
+       dh_clean -k 
+#      dh_installdirs
+
+       # Add here commands to install the package into debian/wavplayer.
+       cd $(CMAKE_BUILD_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
+
+       mkdir -p $(CURDIR)/debian/tmp/etc/rc.d/rc2.d/
+       ln -s ../init.d/run-chg-ani $(CURDIR)/debian/tmp/etc/rc.d/rc2.d/S01charging-animation
+
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+       dh_testdir
+       dh_testroot
+#      dh_installchangelogs 
+#      dh_installdocs
+#      dh_installexamples
+       dh_install --sourcedir=debian/tmp
+#      dh_installmenu
+#      dh_installdebconf       
+#      dh_installlogrotate
+#      dh_installemacsen
+#      dh_installpam
+#      dh_installmime
+#      dh_python
+#      dh_installinit
+#      dh_installcron
+#      dh_installinfo
+       dh_installman
+       dh_link
+       dh_strip --dbg-package=charging-animation-dbg
+       dh_compress
+       dh_fixperms
+#      dh_perl
+       dh_makeshlibs
+       dh_installdeb
+       dh_shlibdeps
+       dh_gencontrol
+       dh_md5sums
+       dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install configure
diff --git a/include/chg_battery.h b/include/chg_battery.h
new file mode 100755 (executable)
index 0000000..a4da12e
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+Copyright 2012  Samsung Electronics Co., Ltd
+
+Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+
+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.
+*/
+
+#ifndef __CHG_BATTERY_H__
+#define __CHG_BATTERY_H__
+
+
+enum {
+       BATT_HEALTH_BAD = 0,
+       BATT_HEALTH_GOOD = 1
+};
+
+enum {
+       BATT_STATE_CHARGING,
+       BATT_STATE_FULL,
+       BATT_STATE_ERROR,
+       BATT_STATE_DISCONNECT
+};
+
+extern int batt_chg_state();
+extern int batt_chg_level();
+extern void show_batt_info(void);
+extern int is_batt_chg_full(void);
+
+#endif /* __CHG_BATTERY_H__ */
diff --git a/include/chg_common.h b/include/chg_common.h
new file mode 100755 (executable)
index 0000000..3855066
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+Copyright 2012  Samsung Electronics Co., Ltd
+
+Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+
+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.
+*/
+
+#ifndef __CHG_COMMON_H__
+#define __CHG_COMMON_H__
+
+
+#include <stdio.h>
+
+#define LOGD                   printf
+#define FILE_IO_BUF_SIZE       128
+
+
+#endif /* __CHG_COMMON_H__ */
diff --git a/include/chg_drmd.h b/include/chg_drmd.h
new file mode 100755 (executable)
index 0000000..0651e90
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+Copyright 2012  Samsung Electronics Co., Ltd
+
+Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+
+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.
+*/
+
+#ifndef __CHG_DRMD_H__
+#define __CHG_DRMD_H__
+
+
+#include "xf86drm.h"
+#include "xf86drmMode.h"
+#include "libkms.h"
+
+#define DPMSModeOn             0
+#define DPMSModeStandby        1
+#define DPMSModeSuspend        2
+#define DPMSModeOff            3
+
+typedef struct _st_drmdi {
+       char *driver_name;
+       char *device_name;
+       int fd;
+       int dpms_mode;
+
+       struct kms_driver* kms;
+       drmModeResPtr res_mode;
+       drmModeConnectorPtr connector;
+       drmModeEncoderPtr encoder;
+       drmModeCrtcPtr crtc;
+
+       /*framebuffer*/
+       unsigned int fb_id;
+       struct kms_bo *bo;
+       unsigned char *fb_buf;
+       unsigned int bo_stride;
+       unsigned int bo_handle;
+       unsigned int bo_width, bo_height;
+} st_drmdi;
+
+
+extern int drmd_open(st_drmdi *drmdi);
+extern void drmd_close(st_drmdi *drmdi);
+extern int drmd_lcd_on(st_drmdi *drmdi);
+extern int drmd_lcd_off(st_drmdi *drmdi);
+
+#endif /* __CHG_DRMD_H__ */
diff --git a/include/chg_env.h b/include/chg_env.h
new file mode 100755 (executable)
index 0000000..0dc4160
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+Copyright 2012  Samsung Electronics Co., Ltd
+
+Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+
+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.
+*/
+
+#ifndef __CHG_ENV_H__
+#define __CHG_ENV_H__
+
+
+#define ENV_MAX_LEN                    1024
+
+enum {
+       EN_ENV_BATT_CAP = 0,
+       EN_ENV_BATT_VOL_NOW,
+       EN_ENV_BATT_CHG_NOW,
+       EN_ENV_BATT_TEMP,
+       EN_ENV_BATT_CHG_FULL,
+       EN_ENV_BATT_ONLINE,
+       EN_ENV_BATT_HEALTH,
+       EN_ENV_BATT_PRESENT,
+       EN_ENV_POWER_STATE,
+       EN_ENV_LCD_BRIGHT,
+       EN_ENV_LCD_BR_DIMM_VAL,
+       EN_ENV_LCD_BR_NORM_VAL,
+
+       EN_ENV_SUPPORT_FB,
+       EN_ENV_SUPPORT_DRM,
+       EN_ENV_DEV_FB,
+       EN_ENV_DEV_DRM_NAME,
+       EN_ENV_LCD_BL_ONOFF,
+       EN_ENV_LCD_BL_ON_VAL,
+       EN_ENV_LCD_BL_OFF_VAL,
+       EN_ENV_LCD_BL_NORM_VAL,
+       EN_ENV_LCD_XRES,
+       EN_ENV_LCD_YRES,
+       EN_ENV_KEY_EVENT,
+       EN_ENV_MAX
+};
+
+
+#define CHG_ENV_BATT_CAP               "CHG_ENV_BATT_CAP"
+#define CHG_ENV_BATT_VOL_NOW           "CHG_ENV_BATT_VOL_NOW"
+#define CHG_ENV_BATT_CHG_NOW           "CHG_ENV_BATT_CHG_NOW"
+#define CHG_ENV_BATT_TEMP              "CHG_ENV_BATT_TEMP"
+#define CHG_ENV_BATT_CHG_FULL  "CHG_ENV_BATT_CHG_FULL"
+#define CHG_ENV_BATT_ONLINE            "CHG_ENV_BATT_ONLINE"
+#define CHG_ENV_BATT_HEALTH            "CHG_ENV_BATT_HEALTH"
+#define CHG_ENV_BATT_PRESENT           "CHG_ENV_BATT_PRESENT"
+#define CHG_ENV_POWER_STATE            "CHG_ENV_POWER_STATE"
+#define CHG_ENV_LCD_BRIGHT             "CHG_ENV_LCD_BRIGHT"
+#define CHG_ENV_LCD_BR_DIMM_VAL        "CHG_ENV_LCD_BR_DIMM_VAL"
+#define CHG_ENV_LCD_BR_NORM_VAL        "CHG_ENV_LCD_BR_NORM_VAL"
+
+#define CHG_ENV_SUPPORT_FB             "CHG_ENV_SUPPORT_FB"
+#define CHG_ENV_SUPPORT_DRM            "CHG_ENV_SUPPORT_DRM"
+#define CHG_ENV_DEV_FB                 "CHG_ENV_DEV_FB"
+#define CHG_ENV_DEV_DRM_NAME           "CHG_ENV_DEV_DRM_NAME"
+#define CHG_ENV_LCD_BL_ONOFF           "CHG_ENV_LCD_BL_ONOFF"
+#define CHG_ENV_LCD_BL_ON_VAL  "CHG_ENV_LCD_BL_ON_VAL"
+#define CHG_ENV_LCD_BL_OFF_VAL         "CHG_ENV_LCD_BL_OFF_VAL"
+#define CHG_ENV_LCD_BL_NORM_VAL        "CHG_ENV_LCD_BL_NORM_VAL"
+#define CHG_ENV_LCD_XRES               "CHG_ENV_LCD_XRES"
+#define CHG_ENV_LCD_YRES               "CHG_ENV_LCD_YRES"
+#define CHG_ENV_KEY_EVENT              "CHG_ENV_KEY_EVENT"
+
+
+extern char chg_env_str[EN_ENV_MAX][ENV_MAX_LEN];
+
+
+extern void get_env(char *name, char *buf, int size);
+extern void chg_env_str_load(void);
+
+
+
+#endif /* __CHG_ENV_H__ */
+
diff --git a/include/chg_fb.h b/include/chg_fb.h
new file mode 100755 (executable)
index 0000000..b72514b
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+Copyright 2012  Samsung Electronics Co., Ltd
+
+Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+
+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.
+*/
+
+#ifndef __CHG_FB_H__
+#define __CHG_FB_H__
+
+
+enum fb_dev_t {
+       FB_DEV_FB,
+       FB_DEV_DRM
+};
+
+typedef struct _FbInfo {
+       unsigned char *buf;
+       int w;
+       int h;
+       int sz;
+       int type;
+       void* dev;
+} FbInfo;
+
+
+extern void set_chg_img_params(void);
+extern int fb_open(FbInfo *fbi);
+extern void fb_close(FbInfo *fbi);
+
+extern void fb_clear_screen(FbInfo *fbi, unsigned int color);
+extern void fb_fill_rect(FbInfo *fbi, int x1, int y1, int x2, int y2,
+                        unsigned int color);
+extern void fb_draw_img_normal_charging(FbInfo *fbi);
+extern void fb_draw_img_full_charging(FbInfo *fbi);
+extern void fb_draw_img_batt_err_plug(FbInfo *fbi);
+extern void fb_draw_img_batt_err_temp(FbInfo *fbi);
+
+
+#endif /* __CHG_FB_H__ */
diff --git a/include/chg_fbd.h b/include/chg_fbd.h
new file mode 100755 (executable)
index 0000000..93a347c
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+Copyright 2012  Samsung Electronics Co., Ltd
+
+Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+
+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.
+*/
+
+#ifndef __CHG_FBD_H__
+#define __CHG_FBD_H__
+
+
+#include <linux/fb.h>
+
+typedef struct _st_fbdi {
+       unsigned char *fb_buf;
+       unsigned fb_buf_size;
+       int fb_fd;
+       struct fb_fix_screeninfo fi;
+       struct fb_var_screeninfo vi;
+} st_fbdi;
+
+extern int fbd_open(st_fbdi *fbdi);
+extern void fbd_close(st_fbdi *fbdi);
+
+
+#endif /* __CHG_FBD_H__ */
diff --git a/include/chg_misc.h b/include/chg_misc.h
new file mode 100755 (executable)
index 0000000..f4c5815
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+Copyright 2012  Samsung Electronics Co., Ltd
+
+Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+
+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.
+*/
+
+#ifndef __CHG_MISC_H__
+#define __CHG_MISC_H__
+
+
+#include <sys/types.h>
+
+extern int read_from_file(const char *path, char *buf, size_t size);
+extern int write_to_file(const char *path, const char *buf);
+extern int read_int_from_file(char *path);
+
+#endif /* __CHG_MISC_H__ */
diff --git a/include/chg_png.h b/include/chg_png.h
new file mode 100755 (executable)
index 0000000..9eb3b1f
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+Copyright 2012  Samsung Electronics Co., Ltd
+
+Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+
+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.
+*/
+
+#ifndef __CHG_PNG_H__
+#define __CHG_PNG_H__
+
+
+#include "chg_fb.h"
+
+extern int read_png_file(char *file_name);
+extern void draw_png_img_xy(FbInfo *fbi, int x1, int y1);
+extern void release_png_res(void);
+
+
+#endif /* __CHG_PNG_H__ */
diff --git a/include/chg_power.h b/include/chg_power.h
new file mode 100755 (executable)
index 0000000..4d284a3
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+Copyright 2012  Samsung Electronics Co., Ltd
+
+Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+
+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.
+*/
+
+#ifndef __CHG_POWER_H__
+#define __CHG_POWER_H__
+
+#include "chg_fb.h"
+
+enum {
+       LCD_BL_ON,
+       LCD_BL_OFF
+};
+
+enum {
+       LCD_BR_DIMM,
+       LCD_BR_NORMAL
+};
+
+enum {
+       SYS_POWER_ON,
+       SYS_POWER_OFF
+};
+
+
+extern int lcd_bl_on(FbInfo *fbi);
+extern int lcd_bl_off(FbInfo *fbi);
+extern int lcd_bl_state(void);
+extern int lcd_br_normal(void);
+extern int lcd_br_dimm(void);
+extern int lcd_br_state(void);
+extern int sys_power_wakeup(FbInfo *fbi);
+extern int sys_power_sleep(FbInfo *fbi);
+extern int sys_power_state(void);
+extern void sys_power_reboot(void);
+extern void sys_power_off(void);
+
+#endif /* __CHG_POWER_H__ */
diff --git a/packaging/charging-animation.spec b/packaging/charging-animation.spec
new file mode 100755 (executable)
index 0000000..0b7ee16
--- /dev/null
@@ -0,0 +1,46 @@
+Name:       charging-animation
+Summary:    charging-animation
+ExclusiveArch:  %{arm}
+Version:    0.0.2
+Release:    1
+Group:      misc
+License:    Flora Software License
+Source0:    %{name}-%{version}.tar.gz
+
+BuildRequires: cmake
+
+BuildRequires: pkgconfig(libpng)
+BuildRequires: pkgconfig(libdrm)
+BuildRequires: pkgconfig(libkms)
+
+%description
+charging-animation
+
+%prep
+%setup -q
+
+
+%build
+export LDFLAGS+="-Wl,--rpath=%{_prefix}/lib -Wl,--as-needed"
+mkdir cmake_tmp
+cd cmake_tmp
+LDFLAGS="$LDFLAGS" cmake .. -DCMAKE_INSTALL_PREFIX=%{_prefix}
+
+make %{?jobs:-j%jobs}
+
+%install
+cd cmake_tmp
+%make_install
+
+%post
+chmod 755 /etc/rc.d/init.d/run-chg-ani
+mkdir -p /etc/rc.d/rc2.d
+ln -s /etc/rc.d/init.d/run-chg-ani /etc/rc.d/rc2.d/S01charging-animation
+
+%files
+%defattr(-,root,root,-)
+%{_prefix}/bin/*
+%{_prefix}/share/*
+/etc/*
+
+
diff --git a/res/images/chg_img/720x1280/batt_chg_level_10.png b/res/images/chg_img/720x1280/batt_chg_level_10.png
new file mode 100755 (executable)
index 0000000..c7ae828
Binary files /dev/null and b/res/images/chg_img/720x1280/batt_chg_level_10.png differ
diff --git a/res/images/chg_img/720x1280/batt_chg_level_100.png b/res/images/chg_img/720x1280/batt_chg_level_100.png
new file mode 100755 (executable)
index 0000000..7baa0f3
Binary files /dev/null and b/res/images/chg_img/720x1280/batt_chg_level_100.png differ
diff --git a/res/images/chg_img/720x1280/batt_chg_level_20.png b/res/images/chg_img/720x1280/batt_chg_level_20.png
new file mode 100755 (executable)
index 0000000..4877df4
Binary files /dev/null and b/res/images/chg_img/720x1280/batt_chg_level_20.png differ
diff --git a/res/images/chg_img/720x1280/batt_chg_level_30.png b/res/images/chg_img/720x1280/batt_chg_level_30.png
new file mode 100755 (executable)
index 0000000..f4fbcfa
Binary files /dev/null and b/res/images/chg_img/720x1280/batt_chg_level_30.png differ
diff --git a/res/images/chg_img/720x1280/batt_chg_level_40.png b/res/images/chg_img/720x1280/batt_chg_level_40.png
new file mode 100755 (executable)
index 0000000..3060401
Binary files /dev/null and b/res/images/chg_img/720x1280/batt_chg_level_40.png differ
diff --git a/res/images/chg_img/720x1280/batt_chg_level_50.png b/res/images/chg_img/720x1280/batt_chg_level_50.png
new file mode 100755 (executable)
index 0000000..d58b96f
Binary files /dev/null and b/res/images/chg_img/720x1280/batt_chg_level_50.png differ
diff --git a/res/images/chg_img/720x1280/batt_chg_level_60.png b/res/images/chg_img/720x1280/batt_chg_level_60.png
new file mode 100755 (executable)
index 0000000..a4ff7c7
Binary files /dev/null and b/res/images/chg_img/720x1280/batt_chg_level_60.png differ
diff --git a/res/images/chg_img/720x1280/batt_chg_level_70.png b/res/images/chg_img/720x1280/batt_chg_level_70.png
new file mode 100755 (executable)
index 0000000..7c3ab11
Binary files /dev/null and b/res/images/chg_img/720x1280/batt_chg_level_70.png differ
diff --git a/res/images/chg_img/720x1280/batt_chg_level_80.png b/res/images/chg_img/720x1280/batt_chg_level_80.png
new file mode 100755 (executable)
index 0000000..eda4ec9
Binary files /dev/null and b/res/images/chg_img/720x1280/batt_chg_level_80.png differ
diff --git a/res/images/chg_img/720x1280/batt_chg_level_90.png b/res/images/chg_img/720x1280/batt_chg_level_90.png
new file mode 100755 (executable)
index 0000000..dd3f42c
Binary files /dev/null and b/res/images/chg_img/720x1280/batt_chg_level_90.png differ
diff --git a/res/images/chg_img/720x1280/batt_disconnect.png b/res/images/chg_img/720x1280/batt_disconnect.png
new file mode 100755 (executable)
index 0000000..9457fa9
Binary files /dev/null and b/res/images/chg_img/720x1280/batt_disconnect.png differ
diff --git a/res/images/chg_img/720x1280/batt_temp_error.png b/res/images/chg_img/720x1280/batt_temp_error.png
new file mode 100755 (executable)
index 0000000..bbf3a36
Binary files /dev/null and b/res/images/chg_img/720x1280/batt_temp_error.png differ
diff --git a/res/images/chg_img/720x1280/progress_01.png b/res/images/chg_img/720x1280/progress_01.png
new file mode 100755 (executable)
index 0000000..f42f5a8
Binary files /dev/null and b/res/images/chg_img/720x1280/progress_01.png differ
diff --git a/res/images/chg_img/720x1280/progress_02.png b/res/images/chg_img/720x1280/progress_02.png
new file mode 100755 (executable)
index 0000000..6329a05
Binary files /dev/null and b/res/images/chg_img/720x1280/progress_02.png differ
diff --git a/res/images/chg_img/720x1280/progress_03.png b/res/images/chg_img/720x1280/progress_03.png
new file mode 100755 (executable)
index 0000000..2fb24ee
Binary files /dev/null and b/res/images/chg_img/720x1280/progress_03.png differ
diff --git a/res/images/chg_img/720x1280/progress_04.png b/res/images/chg_img/720x1280/progress_04.png
new file mode 100755 (executable)
index 0000000..195bf69
Binary files /dev/null and b/res/images/chg_img/720x1280/progress_04.png differ
diff --git a/res/images/chg_img/720x1280/progress_05.png b/res/images/chg_img/720x1280/progress_05.png
new file mode 100755 (executable)
index 0000000..cad2d3e
Binary files /dev/null and b/res/images/chg_img/720x1280/progress_05.png differ
diff --git a/run-chg-ani.in b/run-chg-ani.in
new file mode 100755 (executable)
index 0000000..844ba32
--- /dev/null
@@ -0,0 +1,35 @@
+#! /bin/sh
+#
+# For Charging Boot
+
+do_charging_ani() {
+       echo "charging animation ..."
+
+#export HW-dependent ENV variables which are read by charging-animation
+       HW_REVISION=`cat /proc/cpuinfo | grep Revision | awk -F ':' '{print $2}' | tr -d ' '`
+       if [ "${HW_REVISION}" = "0001" ]; then
+               source @CFGDIR@/tizen.cfg
+       else
+               source @CFGDIR@/tizen.cfg
+       fi
+
+       source @CFGDIR@/common.cfg
+
+       if [ "${CHG_ENV_SUPPORT_DRM}" = "1" ]; then
+               /sbin/udevd --daemon
+               /sbin/udevadm trigger --subsystem-match=drm
+       fi
+
+       echo powersave > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
+       /usr/bin/charging-animation &
+}
+
+
+charging_boot=`grep charger_detect_boot /proc/cmdline`
+if [ "z$charging_boot" != "z" ]; then
+       do_charging_ani
+# for logs
+       mount -a
+       syslogd -O /opt/var/log/messages-chrg
+       klogd
+fi
diff --git a/src/chg_battery.c b/src/chg_battery.c
new file mode 100755 (executable)
index 0000000..c485706
--- /dev/null
@@ -0,0 +1,157 @@
+/*
+Copyright 2012  Samsung Electronics Co., Ltd
+
+Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+
+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.
+*/
+
+#include <stdlib.h>
+#include <string.h>
+#include "chg_common.h"
+#include "chg_battery.h"
+#include "chg_env.h"
+#include "chg_misc.h"
+
+
+/*-----------------------------------------------------------------------------
+  get_batt_health()
+
+  return value
+       0 : not good
+       1 : good
+ ----------------------------------------------------------------------------*/
+static int get_batt_health(void)
+{
+       char buf[FILE_IO_BUF_SIZE];
+       int value = BATT_HEALTH_BAD;
+
+       if (read_from_file((const char*)chg_env_str[EN_ENV_BATT_HEALTH],
+               buf, FILE_IO_BUF_SIZE) > 0) {
+               if (strncmp(buf, "Good", 4) == 0)
+                       value = BATT_HEALTH_GOOD;
+       }
+       return value;
+}
+
+/*-----------------------------------------------------------------------------
+  is_ta_online()
+ ----------------------------------------------------------------------------*/
+static int is_ta_online(void)
+{
+       int ret;
+
+       ret = read_int_from_file(chg_env_str[EN_ENV_BATT_ONLINE]);
+
+       return !!ret;
+}
+
+/*-----------------------------------------------------------------------------
+  is_batt_present()
+ ----------------------------------------------------------------------------*/
+static int is_batt_present(void)
+{
+       int ret;
+
+       ret = read_int_from_file(chg_env_str[EN_ENV_BATT_PRESENT]);
+
+       return !!ret;
+}
+
+/*-----------------------------------------------------------------------------
+  is_batt_healthy()
+ ----------------------------------------------------------------------------*/
+static int is_batt_healthy(void)
+{
+       int ret;
+
+       ret = (get_batt_health() == BATT_HEALTH_GOOD);
+
+       return ret;
+}
+
+/*-----------------------------------------------------------------------------
+  is_batt_chg_full()
+ ----------------------------------------------------------------------------*/
+int is_batt_chg_full(void)
+{
+       int ret;
+
+       ret = read_int_from_file(chg_env_str[EN_ENV_BATT_CHG_FULL]);
+
+       return !!ret;
+}
+
+/*-----------------------------------------------------------------------------
+  batt_chg_state()
+
+  return value
+       0 : charging
+       1 : full
+       2 : no good
+       3 : disconnected
+ ----------------------------------------------------------------------------*/
+int batt_chg_state()
+{
+       int val = 0;
+
+       if (!is_ta_online() || !is_batt_present()) {
+               val = BATT_STATE_DISCONNECT;
+       } else if (!is_batt_healthy()) {
+               val = BATT_STATE_ERROR;
+       } else if (is_batt_chg_full()) {
+               val = BATT_STATE_FULL;
+       } else {
+               val = BATT_STATE_CHARGING;
+       }
+
+       return val;
+}
+
+/*-----------------------------------------------------------------------------
+  batt_chg_level()
+ ----------------------------------------------------------------------------*/
+int batt_chg_level()
+{
+       int bat_soc;
+       int bat_bar = 0;
+
+       bat_soc = read_int_from_file(chg_env_str[EN_ENV_BATT_CAP]);
+
+       bat_bar = bat_soc / 10;
+       bat_bar = bat_bar * 10;
+       if (bat_bar == 0) {
+               bat_bar = 10;
+       } else if (bat_bar >= 100) {
+               bat_bar = 90;
+       }
+       return bat_bar;
+};
+
+/*-----------------------------------------------------------------------------
+  show_batt_info()
+ ----------------------------------------------------------------------------*/
+void show_batt_info(void)
+{
+       int bat_soc;
+       int bat_vol;
+       int bat_chg_now;
+
+       bat_soc = read_int_from_file(chg_env_str[EN_ENV_BATT_CAP]);
+       bat_vol = read_int_from_file(chg_env_str[EN_ENV_BATT_VOL_NOW]);
+       bat_chg_now = read_int_from_file(chg_env_str[EN_ENV_BATT_CHG_NOW]);
+
+       LOGD("[capacity] %d\n", bat_soc);
+       LOGD("[voltage_now] %d\n", bat_vol);
+       LOGD("[charge_now] %d\n", bat_chg_now);
+}
+
+
diff --git a/src/chg_drmd.c b/src/chg_drmd.c
new file mode 100755 (executable)
index 0000000..80ee8a7
--- /dev/null
@@ -0,0 +1,372 @@
+/*
+Copyright 2012  Samsung Electronics Co., Ltd
+
+Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+
+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.
+*/
+
+#include <string.h>
+#include <unistd.h>
+#include "chg_common.h"
+#include "chg_drmd.h"
+#include "chg_env.h"
+
+/*-----------------------------------------------------------------------------
+  find_connector()
+ ----------------------------------------------------------------------------*/
+static int find_connector(st_drmdi *drmdi, int type)
+{
+       int i;
+       int fd;
+       drmModeConnectorPtr connector=NULL;
+       drmModeEncoderPtr encoder=NULL;
+       drmModeCrtcPtr crtc;
+       drmModeResPtr res_mode;
+
+       if (drmdi == NULL)
+               return -1;
+
+       fd = drmdi->fd;
+       res_mode = drmdi->res_mode;
+
+       for(i=0; i<res_mode->count_connectors; i++) {
+               connector =drmModeGetConnector(fd, res_mode->connectors[i]);
+               if(connector->connector_type == type)
+                       break;
+
+               drmModeFreeConnector(connector);
+               connector = NULL;
+       }
+
+       if(!connector) {
+               LOGD("[find_connector] Cannot find connector:%d\n", type);
+               return -1;
+       }
+
+       if(connector->connection != DRM_MODE_CONNECTED) {
+               LOGD("[find_connector] connector is not connected (%d)\n",
+                       (int)connector->connection);
+               return -1;
+       }
+
+       /* find default encoder */
+       encoder = drmModeGetEncoder(fd, connector->encoder_id);
+       if(!encoder) {
+               LOGD("[find_connector] Cannot get encoder:%d\n", type);
+               return -1;
+       }
+
+       /* find default crtc */
+       crtc = drmModeGetCrtc(fd, encoder->crtc_id);
+       if(!crtc) {
+               LOGD("[find_connector] Cannot get CRTC\n");
+               return -1;
+       }
+
+       drmdi->connector = connector;
+       drmdi->encoder = encoder;
+       drmdi->crtc = crtc;
+
+       return 0;
+}
+
+/*-----------------------------------------------------------------------------
+  create_framebuffer()
+ ----------------------------------------------------------------------------*/
+static int create_framebuffer(st_drmdi *drmdi)
+{
+       unsigned int attrs[]={
+               KMS_WIDTH,   0,
+               KMS_HEIGHT,  0,
+               KMS_BO_TYPE, KMS_BO_TYPE_SCANOUT_X8R8G8B8,
+               KMS_TERMINATE_PROP_LIST
+       };
+
+       /* Create kms bo */
+       attrs[1] = drmdi->connector->modes[0].hdisplay;
+       attrs[3] = drmdi->connector->modes[0].vdisplay;
+
+       if(kms_bo_create(drmdi->kms, attrs, &drmdi->bo)) {
+               LOGD("[create_framebuffer] Cannot create kms bo\n");
+               return -1;
+       }
+
+       drmdi->bo_width = drmdi->connector->modes[0].hdisplay;
+       drmdi->bo_height = drmdi->connector->modes[0].vdisplay;
+       kms_bo_get_prop(drmdi->bo, KMS_PITCH, &drmdi->bo_stride);
+       kms_bo_get_prop(drmdi->bo, KMS_HANDLE, &drmdi->bo_handle);
+
+       /* add drm framebuffer */
+       if(drmModeAddFB(drmdi->fd, drmdi->bo_width, drmdi->bo_height,
+               32, 32, drmdi->bo_stride, drmdi->bo_handle, &drmdi->fb_id)) {
+               LOGD("[create_framebuffer] Cannot add drm fb\n");
+               return -1;
+       }
+
+       return 0;
+}
+
+/*-----------------------------------------------------------------------------
+  set_mode()
+ ----------------------------------------------------------------------------*/
+static int set_drm_mode(st_drmdi *drmdi)
+{
+       if(drmModeSetCrtc(drmdi->fd
+                       , drmdi->crtc->crtc_id
+                       , drmdi->fb_id
+                       , 0, 0
+                       , &drmdi->connector->connector_id, 1
+                       , drmdi->connector->modes)) {
+               LOGD("[set_drm_mode] Cannot set drm mode\n");
+               return -1;
+       }
+
+       return 0;
+}
+
+/*-----------------------------------------------------------------------------
+  init_drm()
+ ----------------------------------------------------------------------------*/
+static void free_drm_res(st_drmdi *drmdi)
+{
+       if(drmdi->connector)
+               drmModeFreeConnector(drmdi->connector);
+
+       if(drmdi->encoder)
+               drmModeFreeEncoder(drmdi->encoder);
+
+       if(drmdi->crtc)
+               drmModeFreeCrtc(drmdi->crtc);
+
+       if(drmdi->res_mode)
+               drmModeFreeResources(drmdi->res_mode);
+
+       if(drmdi->fb_id)
+               drmModeRmFB(drmdi->fd, drmdi->fb_id);
+
+       if(drmdi->bo)
+               kms_bo_destroy(&drmdi->bo);
+
+       if(drmdi->kms)
+               kms_destroy(&drmdi->kms);
+
+       drmClose(drmdi->fd);
+}
+
+/*-----------------------------------------------------------------------------
+  drmd_open()
+ ----------------------------------------------------------------------------*/
+int drmd_open(st_drmdi *drmdi)
+{
+       drm_magic_t magic;
+       drmVBlank vbl;
+       void *ptr;
+       int ret;
+
+       if (drmdi == NULL) {
+               LOGD("[drmd_open] drmdi is NULL\n");
+               return -1;
+       }
+
+       memset(drmdi, 0x00, sizeof(st_drmdi));
+
+       drmdi->fd = drmOpen(chg_env_str[EN_ENV_DEV_DRM_NAME], NULL);
+       if(drmdi->fd<0) {
+               LOGD("[drmd_open] Cannot open drm:%s\n",
+                       chg_env_str[EN_ENV_DEV_DRM_NAME]);
+               return -1;
+       }
+
+       drmdi->driver_name = drmGetDeviceNameFromFd(drmdi->fd);
+       LOGD("[drmd_open] Init DRM(name:%s, fd:%d)...OK\n",
+               drmdi->driver_name, drmdi->fd);
+
+       /* Auth DRM */
+       if(drmGetMagic(drmdi->fd, &magic)) {
+               LOGD("[drmd_open] Cannot get magic\n");
+               goto drm_err_exit;
+       }
+
+       if(drmAuthMagic(drmdi->fd, magic)) {
+               LOGD("[drmd_open] Cannot auth magic\n");
+               goto drm_err_exit;
+       }
+
+       /* Create KMS */
+       if(kms_create(drmdi->fd, &drmdi->kms)) {
+               LOGD("[drmd_open] Cannot create kms\n");
+               goto drm_err_exit;
+       }
+
+       /* Get drmmode resource */
+       drmdi->res_mode = drmModeGetResources(drmdi->fd);
+       if(!drmdi->res_mode) {
+               LOGD("[drmd_open] Cannot get drmmode resources\n");
+               goto drm_err_exit;
+       }
+
+       ret = find_connector(drmdi, DRM_MODE_CONNECTOR_LVDS);
+       if(ret < 0) {
+               LOGD("[drmd_open] Cannot get default(LVDS) connector\n");
+               goto drm_err_exit;
+       }
+
+       /* Create framebuffer */
+       ret = create_framebuffer(drmdi);
+       if(ret < 0) {
+               LOGD("[drmd_open] Cannot create frame buffer\n");
+               goto drm_err_exit;
+       }
+
+       if (kms_bo_map(drmdi->bo, &ptr)) {
+               LOGD("[drmd_open] kms_bo_map() failed. \n");
+               goto drm_err_exit;
+       }
+       drmdi->fb_buf = ptr;
+       drmdi->dpms_mode = DPMSModeOn;
+       memset(ptr, 0x00, drmdi->bo_stride * drmdi->bo_height);
+
+
+       /* enable vblank */
+       vbl.request.type = DRM_VBLANK_RELATIVE;
+       vbl.request.sequence = 0;
+       ret = drmWaitVBlank (drmdi->fd, &vbl);
+
+       /* delay for wait vblank */
+       usleep(30000);
+
+       /* Set mode */
+       ret = set_drm_mode(drmdi);
+       if(ret < 0) {
+               LOGD("[drmd_open] Cannot set drm mode\n");
+               goto drm_err_exit;
+       }
+
+       return 0;
+
+drm_err_exit:
+       free_drm_res(drmdi);
+       return -1;
+}
+
+/*-----------------------------------------------------------------------------
+  drmd_close()
+ ----------------------------------------------------------------------------*/
+void drmd_close(st_drmdi *drmdi)
+{
+       kms_bo_unmap(drmdi->bo);
+       free_drm_res(drmdi);
+}
+
+/*-----------------------------------------------------------------------------
+  drmd_set_dpms_mode()
+ ----------------------------------------------------------------------------*/
+static int drmd_set_dpms_mode(st_drmdi *drmdi, int dpms_mode)
+{
+       int i;
+       drmModeConnectorPtr connector;
+
+       if (drmdi == NULL) {
+               LOGD("[drmd_set_dpms_mode] drmdi is NULL\n");
+               return -1;
+       }
+
+       connector = drmdi->connector;
+
+       if (dpms_mode == DPMSModeStandby || dpms_mode == DPMSModeSuspend) {
+               LOGD("[drmd_set_dpms_mode] dmps_mode %s is not supported.\n",
+                       (dpms_mode == DPMSModeStandby)?
+                       "DPMSModeStandby":"DPMSModeSuspend");
+               return -1;
+       }
+
+       for (i = 0; i < connector->count_props; i++) {
+               drmModePropertyPtr props;
+               props = drmModeGetProperty (drmdi->fd, connector->props[i]);
+               if (!props)
+                       continue;
+
+               if (!strcmp(props->name, "DPMS")) {
+                       int _tmp_dpms = dpms_mode;
+                       switch (dpms_mode) {
+                       case DPMSModeOn:
+                               if (drmdi->dpms_mode == DPMSModeOn) {
+                                       drmModeFreeProperty (props);
+                                       return 0;
+                               }
+
+                               /* lcd on */
+                               _tmp_dpms = DPMSModeOn;
+                               drmdi->dpms_mode = DPMSModeOn;
+                               break;
+
+                       case DPMSModeOff:
+                               if (drmdi->dpms_mode == DPMSModeOff) {
+                                       drmModeFreeProperty(props);
+                                       return 0;
+                               }
+
+                               /* lcd off */
+                               _tmp_dpms = DPMSModeOff;
+                               drmdi->dpms_mode = DPMSModeOff;
+                               break;
+                       default:
+                               return -1;
+                       }
+
+                       drmModeConnectorSetProperty(drmdi->fd,
+                               connector->connector_id,
+                               props->prop_id,
+                               _tmp_dpms);
+
+                       drmModeFreeProperty(props);
+                       return 0;
+               }
+
+               drmModeFreeProperty(props);
+       }
+
+       return -1;
+}
+
+/*-----------------------------------------------------------------------------
+  drmd_lcd_on()
+ ----------------------------------------------------------------------------*/
+int drmd_lcd_on(st_drmdi *drmdi)
+{
+       int ret;
+
+       ret = drmd_set_dpms_mode(drmdi, DPMSModeOn);
+       if (ret < 0) {
+               LOGD("[drmd_lcd_on] drmd_set_dpms_mode() fail.\n");
+               return -1;
+       }
+
+       return 0;
+}
+
+/*-----------------------------------------------------------------------------
+  drmd_lcd_off()
+ ----------------------------------------------------------------------------*/
+int drmd_lcd_off(st_drmdi *drmdi)
+{
+       int ret;
+
+       ret = drmd_set_dpms_mode(drmdi, DPMSModeOff);
+       if (ret < 0) {
+               LOGD("[drmd_lcd_off] drmd_set_dpms_mode() fail.\n");
+               return -1;
+       }
+
+       return 0;
+}
+
diff --git a/src/chg_env.c b/src/chg_env.c
new file mode 100755 (executable)
index 0000000..21ca702
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+Copyright 2012  Samsung Electronics Co., Ltd
+
+Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+
+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.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "chg_common.h"
+#include "chg_env.h"
+
+
+char chg_env_str[EN_ENV_MAX][ENV_MAX_LEN];
+
+void get_env(char *name, char *buf, int size)
+{
+       char *ret;
+
+       ret = getenv(name);
+       if ((ret == NULL) || (strlen(ret) > ENV_MAX_LEN)) {
+               memset(buf, 0x00, size);
+       } else {
+               snprintf(buf, size, "%s", ret);
+       }
+
+       LOGD("[gen_env] %s ---> %s\n", name, buf);
+}
+
+void chg_env_str_load(void)
+{
+       get_env(CHG_ENV_BATT_CAP,
+               chg_env_str[EN_ENV_BATT_CAP], ENV_MAX_LEN);
+       get_env(CHG_ENV_BATT_VOL_NOW,
+               chg_env_str[EN_ENV_BATT_VOL_NOW], ENV_MAX_LEN);
+       get_env(CHG_ENV_BATT_CHG_NOW,
+               chg_env_str[EN_ENV_BATT_CHG_NOW], ENV_MAX_LEN);
+       get_env(CHG_ENV_BATT_TEMP,
+               chg_env_str[EN_ENV_BATT_TEMP], ENV_MAX_LEN);
+       get_env(CHG_ENV_BATT_CHG_FULL,
+               chg_env_str[EN_ENV_BATT_CHG_FULL], ENV_MAX_LEN);
+       get_env(CHG_ENV_BATT_ONLINE,
+               chg_env_str[EN_ENV_BATT_ONLINE], ENV_MAX_LEN);
+       get_env(CHG_ENV_BATT_HEALTH,
+               chg_env_str[EN_ENV_BATT_HEALTH], ENV_MAX_LEN);
+       get_env(CHG_ENV_BATT_PRESENT,
+               chg_env_str[EN_ENV_BATT_PRESENT], ENV_MAX_LEN);
+       get_env(CHG_ENV_POWER_STATE,
+               chg_env_str[EN_ENV_POWER_STATE], ENV_MAX_LEN);
+       get_env(CHG_ENV_LCD_BRIGHT,
+               chg_env_str[EN_ENV_LCD_BRIGHT], ENV_MAX_LEN);
+       get_env(CHG_ENV_LCD_BR_DIMM_VAL,
+               chg_env_str[EN_ENV_LCD_BR_DIMM_VAL], ENV_MAX_LEN);
+       get_env(CHG_ENV_LCD_BR_NORM_VAL,
+               chg_env_str[EN_ENV_LCD_BR_NORM_VAL], ENV_MAX_LEN);
+
+       get_env(CHG_ENV_SUPPORT_FB,
+               chg_env_str[EN_ENV_SUPPORT_FB], ENV_MAX_LEN);
+       get_env(CHG_ENV_SUPPORT_DRM,
+               chg_env_str[EN_ENV_SUPPORT_DRM], ENV_MAX_LEN);
+       get_env(CHG_ENV_DEV_FB,
+               chg_env_str[EN_ENV_DEV_FB], ENV_MAX_LEN);
+       get_env(CHG_ENV_DEV_DRM_NAME,
+               chg_env_str[EN_ENV_DEV_DRM_NAME], ENV_MAX_LEN);
+       get_env(CHG_ENV_LCD_BL_ONOFF,
+               chg_env_str[EN_ENV_LCD_BL_ONOFF], ENV_MAX_LEN);
+       get_env(CHG_ENV_LCD_BL_ON_VAL,
+               chg_env_str[EN_ENV_LCD_BL_ON_VAL], ENV_MAX_LEN);
+       get_env(CHG_ENV_LCD_BL_OFF_VAL,
+               chg_env_str[EN_ENV_LCD_BL_OFF_VAL], ENV_MAX_LEN);
+       get_env(CHG_ENV_LCD_BL_NORM_VAL,
+               chg_env_str[EN_ENV_LCD_BL_NORM_VAL], ENV_MAX_LEN);
+       get_env(CHG_ENV_LCD_XRES,
+               chg_env_str[EN_ENV_LCD_XRES], ENV_MAX_LEN);
+       get_env(CHG_ENV_LCD_YRES,
+               chg_env_str[EN_ENV_LCD_YRES], ENV_MAX_LEN);
+       get_env(CHG_ENV_KEY_EVENT,
+               chg_env_str[EN_ENV_KEY_EVENT], ENV_MAX_LEN);
+}
+
diff --git a/src/chg_fb.c b/src/chg_fb.c
new file mode 100755 (executable)
index 0000000..09bd34e
--- /dev/null
@@ -0,0 +1,378 @@
+/*
+Copyright 2012  Samsung Electronics Co., Ltd
+
+Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+
+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.
+*/
+
+#include <string.h>
+#include <stdlib.h>
+#include "chg_common.h"
+#include "chg_fb.h"
+#include "chg_fbd.h"
+#include "chg_drmd.h"
+#include "chg_png.h"
+#include "chg_env.h"
+#include "chg_battery.h"
+
+
+#define MAX_IMG_FILE_PATH      1024
+#define MAX_PROGRESS_CNT       5
+
+
+#if !defined(RESDIR)
+#define RESDIR                         "/usr/share/charging-animation/res"
+#endif
+#define CHG_IMG_BASE                   RESDIR "/images/chg_img"
+#define CHG_IMG_DIR_480x800            "/480x800/"
+#define CHG_IMG_DIR_320x480            "/320x480/"
+#define CHG_IMG_DIR_1024x600           "/1024x600/"
+#define CHG_IMG_DIR_720x1280           "/720x1280/"
+
+enum {
+       E_LCD_RES_480x800,
+       E_LCD_RES_320x480,
+       E_LCD_RES_1024x600,
+       E_LCD_RES_720x1280,
+       E_LCD_RES_1280x800,
+       E_LCD_RES_MAX
+};
+
+
+#define CHG_IMG_NORMAL_PREFIX       "batt_chg_level"
+#define CHG_IMG_PROGRESS_PREFIX     "progress"
+#define CHG_IMG_TEMP_ERROR          "batt_temp_error"
+#define CHG_IMG_DISCONNECT          "batt_disconnect"
+
+
+static char str_chg_img_dir[1024];
+
+static int s_normal_img_x;
+static int s_normal_img_y;
+static int s_progress_img_x;
+static int s_progress_img_y;
+static int s_err_img_x;
+static int s_err_img_y;
+
+
+
+st_fbdi s_fbdi;
+st_drmdi s_drmdi;
+
+/*-----------------------------------------------------------------------------
+  get_lcd_resolution()
+ ----------------------------------------------------------------------------*/
+static int get_lcd_resolution(void)
+{
+       int ret_lcd_res = E_LCD_RES_480x800;
+       int xres = 0;
+       int yres = 0;
+
+       if (strlen(chg_env_str[EN_ENV_LCD_XRES]) > 0)
+               xres = atoi(chg_env_str[EN_ENV_LCD_XRES]);
+       if (strlen(chg_env_str[EN_ENV_LCD_YRES]) > 0)
+               yres = atoi(chg_env_str[EN_ENV_LCD_YRES]);
+
+       if ((xres == 320) && (yres == 480)) {
+               LOGD("[get_lcd_resolution] E_LCD_RES_320x480 \n");
+               ret_lcd_res = E_LCD_RES_320x480;
+       } else if ((xres == 1024) && (yres == 600)) {
+               LOGD("[get_lcd_resolution] E_LCD_RES_1024x600 \n");
+               ret_lcd_res = E_LCD_RES_1024x600;
+       } else if ((xres == 720) && (yres == 1280)) {
+               LOGD("[get_lcd_resolution] E_LCD_RES_720x1280 \n");
+               ret_lcd_res = E_LCD_RES_720x1280;
+       } else if ((xres == 1280) && (yres == 800)) {
+               LOGD("[get_lcd_resolution] E_LCD_RES_1280x800 \n");
+               ret_lcd_res = E_LCD_RES_1280x800;
+       } else {
+               LOGD("[get_lcd_resolution] E_LCD_RES_480x800 \n");
+       }
+
+
+       return ret_lcd_res;
+}
+
+/*-----------------------------------------------------------------------------
+  set_chg_img_params()
+ ----------------------------------------------------------------------------*/
+void set_chg_img_params(void)
+{
+       int lcd_res;
+
+       lcd_res = get_lcd_resolution();
+
+       /* charging images are different with models */
+       switch (lcd_res) {
+       case E_LCD_RES_1024x600:
+               snprintf(str_chg_img_dir, sizeof(str_chg_img_dir)-1, "%s%s", CHG_IMG_BASE, CHG_IMG_DIR_1024x600);
+               s_normal_img_x = 376;
+               s_normal_img_y = 83;
+               s_progress_img_x = 354;
+               s_progress_img_y = 226;
+               s_err_img_x = 340;
+               s_err_img_y = 92;
+               break;
+       case E_LCD_RES_320x480:
+               snprintf(str_chg_img_dir, sizeof(str_chg_img_dir)-1, "%s%s", CHG_IMG_BASE, CHG_IMG_DIR_320x480);
+               s_normal_img_x = 45;
+               s_normal_img_y = 161;
+               s_progress_img_x = 120;
+               s_progress_img_y = 303;
+               s_err_img_x = 49;
+               s_err_img_y = 177;
+               break;
+       case E_LCD_RES_720x1280:
+               snprintf(str_chg_img_dir, sizeof(str_chg_img_dir)-1, "%s%s", CHG_IMG_BASE, CHG_IMG_DIR_720x1280);
+               s_normal_img_x = 266;
+               s_normal_img_y = 468;
+               s_progress_img_x = 270;
+               s_progress_img_y = 914;
+               s_err_img_x = 266;
+               s_err_img_y = 468;
+               break;
+       case E_LCD_RES_1280x800:
+               snprintf(str_chg_img_dir, sizeof(str_chg_img_dir)-1, "%s%s", CHG_IMG_BASE, CHG_IMG_DIR_480x800);
+               s_normal_img_x = 466;
+               s_normal_img_y = 270;
+               s_progress_img_x = 580;
+               s_progress_img_y = 507;
+               s_err_img_x = 472;
+               s_err_img_y = 298;
+               break;
+       default:
+               snprintf(str_chg_img_dir, sizeof(str_chg_img_dir)-1, "%s%s", CHG_IMG_BASE, CHG_IMG_DIR_480x800);
+               s_normal_img_x = 66;
+               s_normal_img_y = 270;
+               s_progress_img_x = 180;
+               s_progress_img_y = 507;
+               s_err_img_x = 72;
+               s_err_img_y = 298;
+               break;
+       }
+
+}
+
+/*-----------------------------------------------------------------------------
+  fb_open()
+ ----------------------------------------------------------------------------*/
+int fb_open(FbInfo *fbi)
+{
+       int support_fb;
+       int support_drm;
+
+       support_fb = atoi(chg_env_str[EN_ENV_SUPPORT_FB]);
+       support_drm = atoi(chg_env_str[EN_ENV_SUPPORT_DRM]);
+
+       if ((support_fb == 1) && (support_drm == 0)) {
+               LOGD("[fb_open] fb device is detected. \n");
+               fbi->type = FB_DEV_FB;
+       } else if ((support_fb == 0) && (support_drm == 1)) {
+               LOGD("[fb_open] drm device is detected. \n");
+               fbi->type = FB_DEV_DRM;
+       } else {
+               LOGD("[fb_open] No graphic device is specified. \n");
+               return -1;
+       }
+
+       switch (fbi->type) {
+       case FB_DEV_FB:
+               if (fbd_open(&s_fbdi) <0)
+                       return -1;
+
+               fbi->buf = s_fbdi.fb_buf;
+               fbi->w = s_fbdi.vi.xres;
+               fbi->h = s_fbdi.vi.yres;
+               fbi->sz = s_fbdi.fb_buf_size;
+               fbi->dev = (void*)&s_fbdi;
+               break;
+       case FB_DEV_DRM:
+               if (drmd_open(&s_drmdi) <0)
+                       return -1;
+
+               fbi->buf = s_drmdi.fb_buf;
+               fbi->w = s_drmdi.bo_width;
+               fbi->h = s_drmdi.bo_height;
+               fbi->sz = s_drmdi.bo_stride * s_drmdi.bo_height;
+               fbi->dev = (void*)&s_drmdi;
+               break;
+       default:
+               return -1;
+       }
+
+       return 0;
+}
+
+/*-----------------------------------------------------------------------------
+  fb_close()
+ ----------------------------------------------------------------------------*/
+void fb_close(FbInfo *fbi)
+{
+       switch (fbi->type) {
+       case FB_DEV_FB:
+               fbd_close(&s_fbdi);
+               break;
+       case FB_DEV_DRM:
+               drmd_close(&s_drmdi);
+               break;
+       default:
+               return;
+       }
+}
+
+
+/*-----------------------------------------------------------------------------
+  fb_clear_screen()
+ ----------------------------------------------------------------------------*/
+void fb_clear_screen(FbInfo *fbi, unsigned int color)
+{
+       unsigned int *fb_buf_cur = (unsigned int *)fbi->buf;
+       int loop_count = fbi->w * fbi->h;
+
+       while (loop_count--)
+               *(fb_buf_cur++) = color;
+}
+
+/*-----------------------------------------------------------------------------
+  fb_fill_rect()
+ ----------------------------------------------------------------------------*/
+void fb_fill_rect(FbInfo *fbi, int x1, int y1, int x2, int y2,
+                        unsigned int color)
+{
+       unsigned int *fb_buf_cur = (unsigned int *)fbi->buf;
+       unsigned int *fb_line_buf;
+       int screen_width = fbi->w;
+       int draw_width = x2 - x1 + 1;
+       int draw_height = y2 - y1 + 1;
+       int width_cnt;
+       int height_cnt;
+
+       fb_buf_cur += (x1 + y1 * screen_width);
+       fb_line_buf = fb_buf_cur;
+       width_cnt = draw_width;
+       while (width_cnt--) {
+               *(fb_buf_cur++) = color;
+       }
+
+       height_cnt = draw_height - 1;
+       fb_buf_cur -= draw_width;
+       while (height_cnt--) {
+               fb_buf_cur += screen_width;
+               memcpy((void *)fb_buf_cur, (void *)fb_line_buf, draw_width * 4);
+       }
+
+}
+
+/*-----------------------------------------------------------------------------
+  fb_draw_img_normal_charging()
+ ----------------------------------------------------------------------------*/
+void fb_draw_img_normal_charging(FbInfo *fbi)
+{
+       static int progress_cnt = 0;
+       static int batt_bar = 5;
+       char chg_img_filename[MAX_IMG_FILE_PATH];
+
+       if (progress_cnt == 0) {
+               batt_bar = batt_chg_level();
+
+               /* draw charging image based on batt_bar */
+               sprintf(chg_img_filename, "%s%s_%d.png",
+                       str_chg_img_dir, CHG_IMG_NORMAL_PREFIX, batt_bar);
+
+               if (read_png_file(chg_img_filename) < 0) {
+                       return;
+               }
+
+               draw_png_img_xy(fbi, s_normal_img_x, s_normal_img_y);
+               release_png_res();
+       }
+
+       /* draw charging image based on progress_cnt */
+       sprintf(chg_img_filename, "%s%s_%02d.png",
+               str_chg_img_dir, CHG_IMG_PROGRESS_PREFIX, progress_cnt + 1);
+
+       if (read_png_file(chg_img_filename) < 0) {
+               return;
+       }
+
+       draw_png_img_xy(fbi, s_progress_img_x, s_progress_img_y);
+       release_png_res();
+
+       progress_cnt++;
+       if (progress_cnt >= MAX_PROGRESS_CNT) {
+               progress_cnt = 0;
+       }
+
+}
+
+/*-----------------------------------------------------------------------------
+  fb_draw_img_full_charging()
+ ----------------------------------------------------------------------------*/
+void fb_draw_img_full_charging(FbInfo *fbi)
+{
+       char chg_img_filename[MAX_IMG_FILE_PATH];
+
+       /* draw charging image based on batt_bar & progress_cnt */
+       sprintf(chg_img_filename, "%s%s_100.png",
+               str_chg_img_dir, CHG_IMG_NORMAL_PREFIX);
+
+       if (read_png_file(chg_img_filename) < 0) {
+               return;
+       }
+
+       draw_png_img_xy(fbi, s_normal_img_x, s_normal_img_y);
+       release_png_res();
+
+}
+
+/*-----------------------------------------------------------------------------
+  fb_draw_img_batt_err_plug()
+ ----------------------------------------------------------------------------*/
+void fb_draw_img_batt_err_plug(FbInfo *fbi)
+{
+       char chg_img_filename[MAX_IMG_FILE_PATH];
+
+       /* draw charging image based on batt_bar & progress_cnt */
+       sprintf(chg_img_filename, "%s%s.png",
+               str_chg_img_dir, CHG_IMG_DISCONNECT);
+
+       if (read_png_file(chg_img_filename) < 0) {
+               return;
+       }
+
+       fb_clear_screen(fbi, 0x00000000);
+       draw_png_img_xy(fbi, s_err_img_x, s_err_img_y);
+       release_png_res();
+
+}
+
+/*-----------------------------------------------------------------------------
+  fb_draw_img_batt_err_temp()
+ ----------------------------------------------------------------------------*/
+void fb_draw_img_batt_err_temp(FbInfo *fbi)
+{
+       char chg_img_filename[MAX_IMG_FILE_PATH];
+
+       /* draw charging image based on batt_bar & progress_cnt */
+       sprintf(chg_img_filename, "%s%s.png",
+               str_chg_img_dir, CHG_IMG_TEMP_ERROR);
+
+       if (read_png_file(chg_img_filename) < 0) {
+               return;
+       }
+
+       fb_clear_screen(fbi, 0x00000000);
+       draw_png_img_xy(fbi, s_err_img_x, s_err_img_y);
+       release_png_res();
+
+}
+
diff --git a/src/chg_fbd.c b/src/chg_fbd.c
new file mode 100755 (executable)
index 0000000..d3c1650
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+Copyright 2012  Samsung Electronics Co., Ltd
+
+Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+
+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.
+*/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include "chg_common.h"
+#include "chg_fbd.h"
+#include "chg_env.h"
+
+/*-----------------------------------------------------------------------------
+  fbd_open()
+ ----------------------------------------------------------------------------*/
+int fbd_open(st_fbdi *fbdi)
+{
+       fbdi->fb_fd = open(chg_env_str[EN_ENV_DEV_FB], O_RDWR);
+       if (!fbdi->fb_fd) {
+               LOGD("Error: cannot open framebuffer device.\n");
+               return -1;
+       }
+
+       /* Get fixed screen information */
+       if (ioctl(fbdi->fb_fd, FBIOGET_FSCREENINFO, &fbdi->fi)) {
+               close(fbdi->fb_fd);
+               LOGD("Error reading fixed information.\n");
+               return -1;
+       }
+
+       /* Get variable screen information */
+       if (ioctl(fbdi->fb_fd, FBIOGET_VSCREENINFO, &fbdi->vi)) {
+               close(fbdi->fb_fd);
+               LOGD("Error reading fixed information.\n");
+               return -1;
+       }
+
+       /* Figure out the size of the screen in bytes */
+       fbdi->fb_buf_size =
+           fbdi->vi.xres * fbdi->vi.yres * fbdi->vi.bits_per_pixel / 8;
+
+       /* Map the device to memory */
+       fbdi->fb_buf =
+           (unsigned char *)mmap(0, fbdi->fb_buf_size,
+                                 PROT_READ | PROT_WRITE, MAP_SHARED,
+                                 fbdi->fb_fd, 0);
+       if ((int)fbdi->fb_buf == -1) {
+               close(fbdi->fb_fd);
+               LOGD("Error: failed to map framebuffer device to memory.\n");
+               return -1;
+       }
+
+       return 0;
+}
+
+/*-----------------------------------------------------------------------------
+  fbd_close()
+ ----------------------------------------------------------------------------*/
+void fbd_close(st_fbdi *fbdi)
+{
+       munmap((void *)fbdi->fb_buf, fbdi->fb_buf_size);
+       close(fbdi->fb_fd);
+}
+
diff --git a/src/chg_main.c b/src/chg_main.c
new file mode 100755 (executable)
index 0000000..05a133b
--- /dev/null
@@ -0,0 +1,260 @@
+/*
+Copyright 2012  Samsung Electronics Co., Ltd
+
+Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+
+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.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sched.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <sys/poll.h>
+#include <linux/input.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include "chg_common.h"
+#include "chg_fb.h"
+#include "chg_power.h"
+#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
+
+FbInfo fbi;
+
+/*-----------------------------------------------------------------------------
+  event_monitor_process()
+ ----------------------------------------------------------------------------*/
+int event_monitor_process(void *arg)
+{
+       int readcount, ret, fd;
+       struct pollfd pollevents;
+       struct input_event event;
+       static unsigned int sys_power_cnt = 0;
+       static int batt_full_charged = 0;
+       static int lcd_on_flag = 0;
+       struct timeval tv;
+       static int key_push_time = 0;
+       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];
+
+       if ((fd = open(key_dev_node, O_RDWR)) < 0) {
+               LOGD("%s: open error, fd = %d\n", key_dev_node, fd);
+               return -1;
+       }
+
+       memset(&pollevents, 0, sizeof(pollevents));
+       pollevents.fd = fd;
+       pollevents.events = POLLIN | POLLERR;
+
+       while (1) {
+
+               ret = poll(&pollevents, 1, 2000);
+
+               if (ret < 0)
+                       LOGD("poll error\n");
+
+               if (lcd_on_flag) {
+                       if (lcd_on_flag == 1) {
+                               lcd_on_flag++;
+                       } else {
+                               sys_power_wakeup(&fbi);
+
+                               if (lcd_br_state() == LCD_BR_DIMM) {
+                                       lcd_br_normal();
+                               }
+
+                               sys_power_cnt = LCD_DIMM_COUNT;
+                               lcd_on_flag = 0;
+                       }
+               }
+
+               if (!batt_full_charged) {
+                       if (is_batt_chg_full()) {
+                               LOGD("battery fully charged\n");
+                               lcd_on_flag = 1;
+                               batt_full_charged = 1;
+                       }
+               }
+
+               if (sys_power_cnt == LCD_DIMM_COUNT) {
+                       if (lcd_br_dimm() < 0)
+                               sys_power_cnt = 0;
+               }
+
+               if (sys_power_cnt >= LCD_OFF_COUNT
+                   && sys_power_state()!= SYS_POWER_OFF) {
+                       sys_power_sleep(&fbi);
+               }
+
+               if (sys_power_cnt > 0xFFFE)
+                       sys_power_cnt = 16;
+
+               sys_power_cnt++;
+
+               LOGD("poll event : %d\n", ret);
+
+               if (key_push_time) {
+                       gettimeofday(&tv, NULL);
+                       key_release_time = tv.tv_sec * 1000 + tv.tv_usec / 1000;
+
+                       if ((key_release_time - key_push_time) > 3000) {
+                               sys_power_reboot();
+                               break;
+                       }
+               }
+
+               if (pollevents.revents & POLLIN) {
+                       readcount = read(pollevents.fd, &event, sizeof(event));
+                       if (readcount != sizeof(event)) {
+                               LOGD("key read error\n");
+                               continue;
+                       }
+
+                       LOGD("key events happen\n");
+                       if (event.type == EV_KEY) {
+                               if (event.value == KEY_VAL_PRESS) {
+                                       if (event.code == KEY_CODE_POWER) {
+                                               gettimeofday(&tv, NULL);
+                                               key_push_time =
+                                                   tv.tv_sec * 1000 +
+                                                   tv.tv_usec / 1000;
+                                       }
+
+                                       sys_power_wakeup(&fbi);
+                                       lcd_br_normal();
+                                       sys_power_cnt = 0;
+                               }
+
+                               LOGD("keycod: 0x%x, value: %d\n",
+                                    event.code, event.value);
+
+                               if (event.value == KEY_VAL_RELEASE
+                                   && key_push_time
+                                   && event.code == KEY_CODE_POWER) {
+                                       key_push_time = 0;
+                                       key_release_time = 0;
+                               }
+
+                       } else if (event.type == EV_SYN) {
+                               LOGD("syn keycod: 0x%x, value: %d\n",
+                                    event.code, event.value);
+                       }
+
+               }
+       }
+       return 0;
+}
+
+/*-----------------------------------------------------------------------------
+  charging_animation_process()
+ ----------------------------------------------------------------------------*/
+int charging_animation_process(void)
+{
+       int charging_mode = 0;
+       int batt_err_temp_cnt = 0;
+
+       LOGD("[main] charging_animation_process() started. \n");
+
+       set_chg_img_params();
+
+       /* fill full screen with black color */
+       fb_clear_screen(&fbi, 0x00000000);
+
+       /* main loop for checking battery status
+          and draw apropriate charging images   */
+       while (1) {
+               charging_mode = batt_chg_state();
+               show_batt_info();
+               switch (charging_mode) {
+               case BATT_STATE_CHARGING:       /* Normal Charging */
+                       fb_draw_img_normal_charging(&fbi);
+                       break;
+               case BATT_STATE_FULL:   /* Charging Full */
+                       fb_draw_img_full_charging(&fbi);
+                       break;
+               case BATT_STATE_ERROR:  /* OverHeat */
+                       if (batt_err_temp_cnt % 2) {
+                               fb_draw_img_batt_err_temp(&fbi);
+                       } else {
+                               fb_draw_img_normal_charging(&fbi);
+                       }
+                       batt_err_temp_cnt++;
+                       break;
+               case BATT_STATE_DISCONNECT:     /* TA disconnected */
+                       if (lcd_bl_state() == LCD_BL_OFF) {
+                               lcd_bl_on(&fbi);
+                               if (lcd_br_state() == LCD_BR_DIMM)
+                                       lcd_br_normal();
+                               sleep(1);
+                       }
+                       fb_draw_img_batt_err_plug(&fbi);
+                       sleep(1);
+                       sys_power_off();
+                       break;
+               }
+               sleep(1);
+       }
+
+       return 0;
+}
+
+
+/*-----------------------------------------------------------------------------
+  main()
+ ----------------------------------------------------------------------------*/
+int main(int argc, char *argv[])
+{
+       int child_stack[4096];
+
+       chg_env_str_load();
+
+       if (fb_open(&fbi) < 0) {
+               LOGD("[main] fb_open() failed. \n");
+               return -1;
+       }
+
+       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) {
+               LOGD("[main] cannot creat thread ... \n");
+               goto main_exit;
+       }
+
+       charging_animation_process();
+
+main_exit:
+       LOGD("[main] terminate %s \n", argv[0]);
+       lcd_br_dimm();
+       lcd_bl_off(&fbi);
+       sys_power_sleep(&fbi);
+       fb_close(&fbi);
+       return -1;
+}
diff --git a/src/chg_misc.c b/src/chg_misc.c
new file mode 100755 (executable)
index 0000000..80dfe99
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+Copyright 2012  Samsung Electronics Co., Ltd
+
+Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+
+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.
+*/
+
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include "chg_common.h"
+#include "chg_misc.h"
+
+/*-----------------------------------------------------------------------------
+  read_from_file()
+ ----------------------------------------------------------------------------*/
+int read_from_file(const char *path, char *buf, size_t size)
+{
+       int fd;
+       size_t count;
+
+       if (!path)
+               return -1;
+
+       fd = open(path, O_RDONLY, 0);
+       if (fd == -1) {
+               LOGD("[read_from_file] Could not open '%s'", path);
+               return -1;
+       }
+
+       count = read(fd, buf, size);
+       if (count > 0) {
+               count = (count < size) ? count : size - 1;
+               while (count > 0 && buf[count - 1] == '\n')
+                       count--;
+               buf[count] = '\0';
+       } else {
+               buf[0] = '\0';
+       }
+
+       close(fd);
+
+       return count;
+}
+
+
+/*-----------------------------------------------------------------------------
+  write_to_file()
+ ----------------------------------------------------------------------------*/
+int write_to_file(const char *path, const char *buf)
+{
+       int fd;
+       size_t count;
+
+       if (!path)
+               return -1;
+
+       fd = open(path, O_WRONLY);
+       if (fd == -1) {
+               LOGD("[write_to_file] Could not open '%s'", path);
+               return -1;
+       }
+
+       count = write(fd, buf, strlen(buf));
+       close(fd);
+       if (count < 0) {
+               LOGD("[write_to_file] %s write error", path);
+               return count;
+       }
+
+       return 0;
+}
+
+/*-----------------------------------------------------------------------------
+  read_int_from_file()
+ ----------------------------------------------------------------------------*/
+int read_int_from_file(char *path)
+{
+       char buf[FILE_IO_BUF_SIZE];
+       int value = 0;
+       if (read_from_file((const char*)path, buf, FILE_IO_BUF_SIZE) > 0) {
+               value = atoi(buf);
+       }
+
+       return value;
+}
+
diff --git a/src/chg_png.c b/src/chg_png.c
new file mode 100755 (executable)
index 0000000..73ac1d4
--- /dev/null
@@ -0,0 +1,174 @@
+/*
+Copyright 2012  Samsung Electronics Co., Ltd
+
+Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+
+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.
+*/
+
+#include <stdlib.h>
+#include <png.h>
+#include "chg_common.h"
+#include "chg_png.h"
+
+int png_img_width;
+int png_img_height;
+png_byte color_type;
+png_byte bit_depth;
+
+png_structp png_ptr;
+png_infop info_ptr;
+int number_of_passes;
+png_bytep *row_pointers;
+
+/*-----------------------------------------------------------------------------
+  read_png_file()
+ ----------------------------------------------------------------------------*/
+int read_png_file(char *file_name)
+{
+       char header[8];         /* 8 is the maximum size that can be checked */
+       int y;
+
+       /* open file and test for it being a png */
+       FILE *fp = fopen(file_name, "rb");
+       if (!fp) {
+               LOGD("[read_png_file] File %s could not be opened"
+                       " for reading \n", file_name);
+               return -1;
+       }
+
+       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"
+                       " as a PNG file \n", file_name);
+               return -1;
+       }
+
+       /* initialize stuff */
+       png_ptr =
+           png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+       if (!png_ptr) {
+               fclose(fp);
+               LOGD("[read_png_file] png_create_read_struct failed \n");
+               return -1;
+       }
+
+       info_ptr = png_create_info_struct(png_ptr);
+       if (!info_ptr) {
+               png_destroy_read_struct(&png_ptr, NULL, NULL);
+               fclose(fp);
+               LOGD("[read_png_file] png_create_info_struct failed \n");
+               return -1;
+       }
+
+       if (setjmp(png_jmpbuf(png_ptr))) {
+               png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
+               fclose(fp);
+               LOGD("[read_png_file] Error during init_io \n");
+               return -1;
+       }
+
+       png_init_io(png_ptr, fp);
+       png_set_sig_bytes(png_ptr, 8);
+       png_read_info(png_ptr, info_ptr);
+
+       png_img_width = info_ptr->width;
+       png_img_height = info_ptr->height;
+       color_type = info_ptr->color_type;
+       bit_depth = info_ptr->bit_depth;
+
+       number_of_passes = png_set_interlace_handling(png_ptr);
+       png_read_update_info(png_ptr, info_ptr);
+
+       /* read file */
+       if (setjmp(png_jmpbuf(png_ptr))) {
+               png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
+               fclose(fp);
+               LOGD("[read_png_file] Error during read_image \n");
+               return -1;
+       }
+
+       row_pointers = (png_bytep *) malloc(sizeof(png_bytep)*png_img_height);
+       for (y = 0; y < png_img_height; y++)
+               row_pointers[y] = (png_byte *) malloc(info_ptr->rowbytes);
+
+       png_read_image(png_ptr, row_pointers);
+
+       fclose(fp);
+
+       return 0;
+}
+
+/*-----------------------------------------------------------------------------
+  draw_png_img_xy()
+ ----------------------------------------------------------------------------*/
+void draw_png_img_xy(FbInfo *fbi, int x1, int y1)
+{
+       unsigned int *fb_buf_cur = (unsigned int *)fbi->buf;
+       int bpp;
+       int x, y;
+
+       /* check out range */
+       if ((x1 + png_img_width > fbi->w) ||
+           (y1 + png_img_height > fbi->h)) {
+               LOGD("[draw_png_img_xy] "
+                       "output range exceeds frame buffer range \n");
+               return;
+       }
+
+       if (color_type == PNG_COLOR_TYPE_RGB)
+               bpp = 3;
+       else if (color_type == PNG_COLOR_TYPE_RGBA)
+               bpp = 4;
+       else {
+               LOGD("[draw_png_img_xy] "
+                       "png type does not match RGB or RGBA \n");
+               return;
+       }
+
+       fb_buf_cur += y1 * fbi->w;
+       fb_buf_cur += x1;
+       for (y = 0; y < png_img_height; y++) {
+               png_byte *row = (png_byte *) row_pointers[y];
+               for (x = 0; x < png_img_width; x++) {
+                       if (bit_depth == 8) {
+                               (*fb_buf_cur++) =
+                                   (row[0] << 16) | (row[1] << 8) | (row[2]);
+                               row += bpp;
+                       } else if (bit_depth == 16) {
+                               (*fb_buf_cur++) =
+                                   (row[0] << 16) | (row[2] << 8) | (row[4]);
+                               row += bpp*2;
+                       }
+               }
+               fb_buf_cur -= png_img_width;
+               fb_buf_cur += fbi->w;
+       }
+
+}
+
+/*-----------------------------------------------------------------------------
+  release_png_res()
+ ----------------------------------------------------------------------------*/
+void release_png_res(void)
+{
+       int y;
+
+       for (y = 0; y < png_img_height; y++)
+               free((void *)row_pointers[y]);
+       free((void *)row_pointers);
+
+       png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
+}
+
+
+
diff --git a/src/chg_power.c b/src/chg_power.c
new file mode 100755 (executable)
index 0000000..4f362b6
--- /dev/null
@@ -0,0 +1,215 @@
+/*
+Copyright 2012  Samsung Electronics Co., Ltd
+
+Licensed under the Flora License, Version 1.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.tizenopensource.org/license
+
+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.
+*/
+
+#include <string.h>
+#include <sys/reboot.h>
+#include "chg_common.h"
+#include "chg_power.h"
+#include "chg_misc.h"
+#include "chg_env.h"
+#include "chg_drmd.h"
+
+static int s_lcd_bl_state = LCD_BL_ON;
+static int s_lcd_br_state = LCD_BR_NORMAL;
+static int s_sys_power_state = SYS_POWER_ON;
+
+/*-----------------------------------------------------------------------------
+  fb_lcd_bl_on()
+ ----------------------------------------------------------------------------*/
+static int fb_lcd_bl_on(void)
+{
+       int ret;
+
+       if (strlen(chg_env_str[EN_ENV_LCD_BL_NORM_VAL]) > 0) {
+               ret = write_to_file(
+                       (const char*)chg_env_str[EN_ENV_LCD_BL_ONOFF],
+                       (const char*)chg_env_str[EN_ENV_LCD_BL_NORM_VAL]);
+               if (ret < 0)
+                       return -1;
+       }
+
+       ret = write_to_file((const char*)chg_env_str[EN_ENV_LCD_BL_ONOFF],
+               (const char*)chg_env_str[EN_ENV_LCD_BL_ON_VAL]);
+       if (ret < 0)
+               return -1;
+
+       return 0;
+}
+
+/*-----------------------------------------------------------------------------
+  fb_lcd_bl_off()
+ ----------------------------------------------------------------------------*/
+static int fb_lcd_bl_off(void)
+{
+       int ret;
+
+       if (strlen(chg_env_str[EN_ENV_LCD_BL_NORM_VAL]) > 0) {
+               ret = write_to_file(
+                       (const char*)chg_env_str[EN_ENV_LCD_BL_ONOFF],
+                       (const char*)chg_env_str[EN_ENV_LCD_BL_NORM_VAL]);
+               if (ret < 0)
+                       return -1;
+       }
+
+       ret = write_to_file((const char*)chg_env_str[EN_ENV_LCD_BL_ONOFF],
+               (const char*)chg_env_str[EN_ENV_LCD_BL_OFF_VAL]);
+       if (ret < 0)
+               return -1;
+
+       return 0;
+}
+/*-----------------------------------------------------------------------------
+  lcd_bl_on()
+ ----------------------------------------------------------------------------*/
+int lcd_bl_on(FbInfo *fbi)
+{
+       LOGD("lcd_bl_on() is called.\n");
+       if (s_lcd_bl_state == LCD_BL_ON)
+               return 0;
+
+       if (fbi->type == FB_DEV_FB) {
+               if (fb_lcd_bl_on() < 0)
+                       return -1;
+       } else if (fbi->type == FB_DEV_DRM) {
+               if (drmd_lcd_on((st_drmdi*)fbi->dev) < 0)
+                       return -1;
+       } else
+               return -1;
+
+       s_lcd_bl_state = LCD_BL_ON;
+       return 0;
+}
+
+/*-----------------------------------------------------------------------------
+  lcd_bl_off()
+ ----------------------------------------------------------------------------*/
+int lcd_bl_off(FbInfo *fbi)
+{
+       LOGD("lcd_bl_off() is called.\n");
+       if (s_lcd_bl_state == LCD_BL_OFF)
+               return 0;
+
+       if (fbi->type == FB_DEV_FB) {
+               if (fb_lcd_bl_off() < 0)
+                       return -1;
+       } else if (fbi->type == FB_DEV_DRM) {
+               if (drmd_lcd_off((st_drmdi*)fbi->dev) < 0)
+                       return -1;
+       } else
+               return -1;
+
+       s_lcd_bl_state = LCD_BL_OFF;
+       return 0;
+}
+
+/*-----------------------------------------------------------------------------
+  lcd_bl_state()
+ ----------------------------------------------------------------------------*/
+int lcd_bl_state(void)
+{
+       return s_lcd_bl_state;
+}
+
+
+/*-----------------------------------------------------------------------------
+  lcd_br_normal()
+ ----------------------------------------------------------------------------*/
+int lcd_br_normal(void)
+{
+       int ret;
+
+       LOGD("lcd_br_normal() is called.\n");
+       ret = write_to_file((const char*)chg_env_str[EN_ENV_LCD_BRIGHT],
+               (const char*)chg_env_str[EN_ENV_LCD_BR_NORM_VAL]);
+       if (ret < 0)
+               return -1;
+
+       s_lcd_br_state = LCD_BR_NORMAL;
+       return 0;
+}
+
+/*-----------------------------------------------------------------------------
+  lcd_br_dimm()
+ ----------------------------------------------------------------------------*/
+int lcd_br_dimm(void)
+{
+       int ret;
+
+       LOGD("lcd_br_dimm() is called.\n");
+       ret = write_to_file((const char*)chg_env_str[EN_ENV_LCD_BRIGHT],
+               (const char*)chg_env_str[EN_ENV_LCD_BR_DIMM_VAL]);
+       if (ret < 0)
+               return -1;
+
+       s_lcd_br_state = LCD_BR_DIMM;
+       return 0;
+}
+
+/*-----------------------------------------------------------------------------
+  lcd_br_state()
+ ----------------------------------------------------------------------------*/
+int lcd_br_state(void)
+{
+       return s_lcd_br_state;
+}
+
+/*-----------------------------------------------------------------------------
+  sys_power_wakeup()
+ ----------------------------------------------------------------------------*/
+int sys_power_wakeup(FbInfo *fbi)
+{
+       LOGD("sys_power_wakeup() is called.\n");
+       lcd_bl_on(fbi);
+       s_sys_power_state = SYS_POWER_ON;
+       return 0;
+}
+
+/*-----------------------------------------------------------------------------
+  sys_power_sleep()
+ ----------------------------------------------------------------------------*/
+int sys_power_sleep(FbInfo *fbi)
+{
+       LOGD("sys_power_sleep() is called.\n");
+       lcd_bl_off(fbi);
+       s_sys_power_state = SYS_POWER_OFF;
+       return 0;
+}
+
+/*-----------------------------------------------------------------------------
+  sys_power_state()
+ ----------------------------------------------------------------------------*/
+int sys_power_state(void)
+{
+       return s_sys_power_state;
+}
+
+/*-----------------------------------------------------------------------------
+  sys_power_reboot()
+ ----------------------------------------------------------------------------*/
+void sys_power_reboot(void)
+{
+       reboot(RB_AUTOBOOT);
+}
+
+/*-----------------------------------------------------------------------------
+  sys_power_off()
+ ----------------------------------------------------------------------------*/
+void sys_power_off(void)
+{
+       reboot(RB_POWER_OFF);
+}
+
+