Tizen 2.0 Release tizen_2.0 accepted/tizen_2.0/20130215.204701 submit/tizen_2.0/20130215.191519
authorHyungKyu Song <hk76.song@samsung.com>
Fri, 15 Feb 2013 15:00:10 +0000 (00:00 +0900)
committerHyungKyu Song <hk76.song@samsung.com>
Fri, 15 Feb 2013 15:00:10 +0000 (00:00 +0900)
55 files changed:
AUTHORS [new file with mode: 0644]
CMakeLists.txt [new file with mode: 0755]
LICENSE.Flora [new file with mode: 0755]
NOTICE.Flora [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.changes [new file with mode: 0644]
packaging/charging-animation.conf [new file with mode: 0644]
packaging/charging-animation.spec [new file with mode: 0755]
packaging/charging-mode.service [new file with mode: 0644]
packaging/charging-mode.target [new file with mode: 0644]
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..87223f1
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
+Yongchul Park <yc1216.park at samsung dot 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.Flora b/LICENSE.Flora
new file mode 100755 (executable)
index 0000000..9c95663
--- /dev/null
@@ -0,0 +1,206 @@
+Flora License
+
+Version 1.0, May, 2012
+
+http://floralicense.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://floralicense.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/NOTICE.Flora b/NOTICE.Flora
new file mode 100755 (executable)
index 0000000..3997999
--- /dev/null
@@ -0,0 +1,4 @@
+Copyright (c) Samsung Electronics Co., Ltd. All rights reserved.
+Except as noted, this software is licensed under Flora License, Version 1.
+Please, see the LICENSE file for Flora License terms and conditions.
+
diff --git a/config/common.cfg b/config/common.cfg
new file mode 100755 (executable)
index 0000000..ebda2ac
--- /dev/null
@@ -0,0 +1,10 @@
+CHG_ENV_BATT_CAP=/sys/class/power_supply/battery/capacity
+CHG_ENV_BATT_VOL_NOW=/sys/class/power_supply/battery/voltage_now
+CHG_ENV_BATT_CHG_NOW=/sys/class/power_supply/battery/charge_now
+CHG_ENV_BATT_TEMP=/sys/class/power_supply/battery/temp
+CHG_ENV_BATT_CHG_FULL=/sys/class/power_supply/battery/charge_full
+CHG_ENV_BATT_ONLINE=/sys/class/power_supply/battery/online
+CHG_ENV_BATT_HEALTH=/sys/class/power_supply/battery/health
+CHG_ENV_BATT_PRESENT=/sys/class/power_supply/battery/present
+
+CHG_ENV_POWER_STATE=/sys/power/state
diff --git a/config/tizen.cfg b/config/tizen.cfg
new file mode 100755 (executable)
index 0000000..b89f00d
--- /dev/null
@@ -0,0 +1,19 @@
+CHG_ENV_SUPPORT_FB=0
+CHG_ENV_SUPPORT_DRM=1
+
+CHG_ENV_DEV_FB=
+CHG_ENV_DEV_DRM_NAME=exynos
+
+CHG_ENV_LCD_BRIGHT=/sys/class/backlight/s6e8aa0-bl/brightness
+CHG_ENV_LCD_BR_DIMM_VAL=0
+CHG_ENV_LCD_BR_NORM_VAL=10
+
+CHG_ENV_LCD_BL_ONOFF=/sys/class/graphics/fb3/blank
+CHG_ENV_LCD_BL_ON_VAL=0
+CHG_ENV_LCD_BL_OFF_VAL=4
+CHG_ENV_LCD_BL_NORM_VAL=
+
+CHG_ENV_LCD_XRES=720
+CHG_ENV_LCD_YRES=1280
+
+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..1db5c63
--- /dev/null
@@ -0,0 +1,18 @@
+Source: charging-animation
+Section: devel
+Priority: extra
+Maintainer: YongChul Park <yc1216.park@samsung.com>
+Uploaders: YoungJin Lee <yj0701.lee@samsung.com>, Dongil Park <dongil01.park@samsung.com>
+Build-Depends: debhelper (>= 5), libpng-dev, libdrm-dev
+Standards-Version: 0.1.0
+
+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..8e134b1
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+Copyright 2012-2013  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://floralicense.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..a83fa70
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+Copyright 2012-2013  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://floralicense.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>
+#include <errno.h>
+
+#define DEBUG_MSG      printf
+#if 0
+#define CHG_LOG_TAG "CHG_ANI"
+#include <dlog.h>
+#include <time.h>
+#include <sys/time.h>
+#include <libgen.h>
+#include <stdio.h>
+#include <errno.h>
+
+#define DEBUG_MSG(format,args...) \
+do {\
+       LOG(LOG_DEBUG, CHG_LOG_TAG, "[%s:%d] "format"", __func__, __LINE__, ##args);\
+}while(0)
+#endif
+
+#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..fd7d4ef
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+Copyright 2012-2013  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://floralicense.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[2];
+       struct kms_bo *bo[2];
+       unsigned char *fb_buf;
+       unsigned char *fb_buf2;
+       unsigned int bo_stride;
+       unsigned int bo_handle;
+       unsigned int bo_width, bo_height;
+} st_drmdi;
+
+enum {
+       FRAME_BUFFER1 = 0,
+       FRAME_BUFFER2
+};
+
+extern st_drmdi s_drmdi;
+extern drmEventContext evctx;
+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);
+extern void page_flip_handler(int fd, unsigned int frame, unsigned int sec, unsigned int usec, void * data);
+
+#endif /* __CHG_DRMD_H__ */
diff --git a/include/chg_env.h b/include/chg_env.h
new file mode 100755 (executable)
index 0000000..588e100
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+Copyright 2012-2013  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://floralicense.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..492a1ce
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+Copyright 2012-2013  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://floralicense.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, *buf2;
+       unsigned int current_fb_id;
+       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);
+extern void fb_draw_img_batt_err_charging(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..1d4a3e2
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+Copyright 2012-2013  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://floralicense.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..e2f400c
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+Copyright 2012-2013  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://floralicense.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, int size);
+extern int write_to_file(const char *path, const char *buf);
+extern int read_int_from_file(char *path);
+extern int system_cmd_wait(const char *command);
+extern int system_cmd_nowait(const char *command);
+
+#endif /* __CHG_MISC_H__ */
diff --git a/include/chg_png.h b/include/chg_png.h
new file mode 100755 (executable)
index 0000000..f781a61
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+Copyright 2012-2013  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://floralicense.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"
+#include "chg_drmd.h"
+
+extern int png_img_width;
+extern int png_img_height;
+/* clear screen based on img size */
+//extern int png_img_width_batt_normal;
+//extern int png_img_height_batt_normal;
+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..50985da
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+Copyright 2012-2013  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://floralicense.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.changes b/packaging/charging-animation.changes
new file mode 100644 (file)
index 0000000..5b3116c
--- /dev/null
@@ -0,0 +1,2 @@
+* Fri Jul 28 2012 Yin Kangkai <kangkai.yin@intel.com>
+- Port from sysV rc script based to systemd based.
diff --git a/packaging/charging-animation.conf b/packaging/charging-animation.conf
new file mode 100644 (file)
index 0000000..b89f00d
--- /dev/null
@@ -0,0 +1,19 @@
+CHG_ENV_SUPPORT_FB=0
+CHG_ENV_SUPPORT_DRM=1
+
+CHG_ENV_DEV_FB=
+CHG_ENV_DEV_DRM_NAME=exynos
+
+CHG_ENV_LCD_BRIGHT=/sys/class/backlight/s6e8aa0-bl/brightness
+CHG_ENV_LCD_BR_DIMM_VAL=0
+CHG_ENV_LCD_BR_NORM_VAL=10
+
+CHG_ENV_LCD_BL_ONOFF=/sys/class/graphics/fb3/blank
+CHG_ENV_LCD_BL_ON_VAL=0
+CHG_ENV_LCD_BL_OFF_VAL=4
+CHG_ENV_LCD_BL_NORM_VAL=
+
+CHG_ENV_LCD_XRES=720
+CHG_ENV_LCD_YRES=1280
+
+CHG_ENV_KEY_EVENT=/dev/event1
diff --git a/packaging/charging-animation.spec b/packaging/charging-animation.spec
new file mode 100755 (executable)
index 0000000..0db83ee
--- /dev/null
@@ -0,0 +1,62 @@
+Name:       charging-animation
+Summary:    charging-animation
+ExclusiveArch:  %{arm}
+Version:    0.0.6
+Release:    1
+Group:      misc
+License:    Flora Software License
+Source0:    %{name}-%{version}.tar.gz
+Source100:  charging-mode.target
+Source101:  charging-mode.service
+Source102:  charging-animation.conf
+
+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
+
+# temoprary HW configuration. it should be seperated.
+mkdir -p %{buildroot}/etc/sysconfig
+install -m 644 %{SOURCE102} %{buildroot}/etc/sysconfig/charging-animation
+
+
+# systemd related
+mkdir -p %{buildroot}%{_libdir}/systemd/system/
+install -m 0644 %{SOURCE100} %{buildroot}%{_libdir}/systemd/system/
+install -m 0644 %{SOURCE101} %{buildroot}%{_libdir}/systemd/system/
+mkdir -p %{buildroot}%{_libdir}/systemd/system/charging-mode.target.wants
+ln -s ../charging-mode.service %{buildroot}%{_libdir}/systemd/system/charging-mode.target.wants/charging-mode.service
+
+%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,-)
+%attr(755,-,-) %{_sysconfdir}/rc.d/init.d/run-chg-ani
+%{_sysconfdir}/*
+%{_bindir}/*
+%dir %{_libdir}/systemd/system/charging-mode.target.wants
+%{_libdir}/systemd/system/*
+%{_datadir}/*
diff --git a/packaging/charging-mode.service b/packaging/charging-mode.service
new file mode 100644 (file)
index 0000000..c074f6a
--- /dev/null
@@ -0,0 +1,12 @@
+[Unit]
+Description=Charging Mode Service
+OnFailure=basic.target
+
+[Service]
+Type=simple
+EnvironmentFile=-/usr/share/charging-animation/config/common.cfg
+EnvironmentFile=-/etc/sysconfig/charging-animation
+ExecStartPre=-/bin/bash -c '/bin/echo powersave > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor'
+ExecStart=/usr/bin/charging-animation
+Restart=always
+RestartSec=5
diff --git a/packaging/charging-mode.target b/packaging/charging-mode.target
new file mode 100644 (file)
index 0000000..901502a
--- /dev/null
@@ -0,0 +1,7 @@
+[Unit]
+Description=Charging Mode
+Conflicts=graphical.target
+AllowIsolate=yes
+
+[Install]
+Alias=default.target
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..4ccd869
--- /dev/null
@@ -0,0 +1,57 @@
+#! /bin/sh
+#
+# For Charging Boot
+
+set -a
+
+do_charging_ani() {
+       echo "charging animation ..."
+
+#export HW-dependent ENV variables which are read by charging-animation
+       HW_NAME=`cat /proc/cpuinfo | grep Hardware | awk -F ':' '{print $2}' | tr -d ' '`
+       if [ "${HW_NAME}" = "TRATS" ]; then
+               source @CFGDIR@/tizen.cfg
+       else
+               source @CFGDIR@/tizen.cfg
+       fi
+
+       source @CFGDIR@/common.cfg
+
+       # export the platform specific variables
+       source /etc/sysconfig/charging-animation
+
+       echo powersave > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
+
+       INPUT_SEARCH_BASE=/sys/class/input
+       CANDIDATE=`ls ${INPUT_SEARCH_BASE} | grep input`
+
+       FOUND=
+       for f in ${CANDIDATE}
+       do
+       DEV_NAME=`cat ${INPUT_SEARCH_BASE}/${f}/name`
+       if [ "${DEV_NAME}" = "gpio-keys" ]; then
+               FOUND=${f}
+                       break
+               fi
+       done
+       if [ "X${FOUND}" = "X" ]; then
+        echo "[error] cannot find key input event node"
+       fi
+       FOUND_NUM=${FOUND##input}
+       KEY_EVENT=/dev/input/event${FOUND_NUM}
+
+       /usr/bin/charging-animation $KEY_EVENT &
+}
+
+
+charging_boot=`grep charger_detect_boot /proc/cmdline`
+if [ "z$charging_boot" != "z" ]; then
+
+# for logs
+       mount -a
+       syslogd -b 5 -O  /opt/var/log/messages-chrg
+       klogd
+
+       do_charging_ani
+
+fi
diff --git a/src/chg_battery.c b/src/chg_battery.c
new file mode 100755 (executable)
index 0000000..ca20ecf
--- /dev/null
@@ -0,0 +1,157 @@
+/*
+Copyright 2012-2013 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://floralicense.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]);
+
+       DEBUG_MSG("[capacity] %d\n", bat_soc);
+       DEBUG_MSG("[voltage_now] %d\n", bat_vol);
+       DEBUG_MSG("[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..ab1a6ee
--- /dev/null
@@ -0,0 +1,437 @@
+/*
+Copyright 2012-2013  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://floralicense.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.
+*/
+
+#define _GNU_SOURCE
+#define __USE_GNU
+#include <string.h>
+#include <unistd.h>
+#include "chg_common.h"
+#include "chg_drmd.h"
+#include "chg_env.h"
+
+drmEventContext evctx;
+/*-----------------------------------------------------------------------------
+  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 == NULL) {
+                       DEBUG_MSG("[find_connector] connector is NULL)\n");
+                       continue;
+               }
+               if(connector->connector_type == type)
+                       break;
+
+               drmModeFreeConnector(connector);
+               connector = NULL;
+       }
+
+       if(!connector) {
+               DEBUG_MSG("[find_connector] Cannot find connector:%d\n", type);
+               return -1;
+       }
+
+       if(connector->connection != DRM_MODE_CONNECTED) {
+               DEBUG_MSG("[find_connector] connector is not connected (%d)\n",
+                       (int)connector->connection);
+               return -1;
+       }
+
+       /* find default encoder */
+       encoder = drmModeGetEncoder(fd, connector->encoder_id);
+       if(!encoder) {
+               DEBUG_MSG("[find_connector] Cannot get encoder:%d\n", type);
+               return -1;
+       }
+
+       /* find default crtc */
+       crtc = drmModeGetCrtc(fd, encoder->crtc_id);
+       if(!crtc) {
+               DEBUG_MSG("[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,int i)
+{
+       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[i])) {
+               DEBUG_MSG("[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[i], KMS_PITCH, &drmdi->bo_stride);
+       kms_bo_get_prop(drmdi->bo[i], KMS_HANDLE, &drmdi->bo_handle);
+
+       /* add drm framebuffer */
+       if(drmModeAddFB(drmdi->fd, drmdi->bo_width, drmdi->bo_height,
+               24, 32, drmdi->bo_stride, drmdi->bo_handle, &drmdi->fb_id[i])) {
+               DEBUG_MSG("[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, 0
+                       , &drmdi->connector->connector_id, 1
+                       , drmdi->connector->modes)) {
+               DEBUG_MSG("[set_drm_mode] Cannot set drm mode\n");
+               return -1;
+       }
+
+       return 0;
+}
+
+/*-----------------------------------------------------------------------------
+  init_drm()
+ ----------------------------------------------------------------------------*/
+static void free_drm_res(st_drmdi *drmdi)
+{
+       int i = 0;
+       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);
+
+
+       for( i = 0 ;i <FRAME_BUFFER2 ; i++) {
+               if(drmdi->fb_id[i])
+                       drmModeRmFB(drmdi->fd, drmdi->fb_id[i]);
+               if(drmdi->bo[i])
+                       kms_bo_destroy(&drmdi->bo[i]);
+       }
+
+       if(drmdi->kms)
+               kms_destroy(&drmdi->kms);
+
+       drmClose(drmdi->fd);
+}
+
+void page_flip_handler(int fd, unsigned int frame,
+                 unsigned int sec, unsigned int usec, void *data)
+{
+//     DEBUG_MSG("page_flip_handler~\n");
+       return;
+}
+
+/*-----------------------------------------------------------------------------
+  drmd_open()
+ ----------------------------------------------------------------------------*/
+int drmd_open(st_drmdi *drmdi)
+{
+       drm_magic_t magic;
+       void *ptr, *ptr2;
+       int ret;
+
+       if (drmdi == NULL) {
+               DEBUG_MSG("[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) {
+               DEBUG_MSG("[drmd_open] Cannot open drm:%s\n",
+                       chg_env_str[EN_ENV_DEV_DRM_NAME]);
+               return -1;
+       }
+       else {
+               DEBUG_MSG("[drmd_open] drmdi->fd : %d ",drmdi->fd);
+       }
+
+       drmdi->driver_name = drmGetDeviceNameFromFd(drmdi->fd);
+       DEBUG_MSG("[drmd_open] Init DRM(name:%s, fd:%d)...OK\n",
+               drmdi->driver_name, drmdi->fd);
+
+       /* Auth DRM */
+       if(drmGetMagic(drmdi->fd, &magic)) {
+               DEBUG_MSG("[drmd_open] Cannot get magic\n");
+               goto drm_err_exit;
+       }
+
+       if(drmAuthMagic(drmdi->fd, magic)) {
+               DEBUG_MSG("[drmd_open] Cannot auth magic\n");
+               goto drm_err_exit;
+       }
+
+       /* Create KMS */
+       if(kms_create(drmdi->fd, &drmdi->kms)) {
+               DEBUG_MSG("[drmd_open] Cannot create kms\n");
+               goto drm_err_exit;
+       }
+
+       /* Get drmmode resource */
+       drmdi->res_mode = drmModeGetResources(drmdi->fd);
+       if(!drmdi->res_mode) {
+               DEBUG_MSG("[drmd_open] Cannot get drmmode resources\n");
+               goto drm_err_exit;
+       }
+
+       ret = find_connector(drmdi, DRM_MODE_CONNECTOR_LVDS);
+       if(ret < 0) {
+               DEBUG_MSG("[drmd_open] Cannot get default(LVDS) connector\n");
+               goto drm_err_exit;
+       }
+
+       /* Create framebuffer */
+       ret = create_framebuffer(drmdi, FRAME_BUFFER1);
+       if(ret < 0) {
+               DEBUG_MSG("[drmd_open] Cannot create frame buffer\n");
+               goto drm_err_exit;
+       }
+
+       if (kms_bo_map(drmdi->bo[FRAME_BUFFER1], &ptr)) {
+               DEBUG_MSG("[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);
+       kms_bo_unmap(drmdi->bo[FRAME_BUFFER1]);
+
+       /* Set mode */
+       ret = set_drm_mode(drmdi);
+       if(ret < 0) {
+               DEBUG_MSG("[drmd_open] Cannot set drm mode\n");
+               goto drm_err_exit;
+       }
+
+       /* Create framebuffer 2 */
+       ret = create_framebuffer(drmdi, FRAME_BUFFER2);
+       if(ret < 0) {
+               DEBUG_MSG("[drmd_open] Cannot create frame buffer\n");
+               goto drm_err_exit;
+       }
+
+       if (kms_bo_map(drmdi->bo[FRAME_BUFFER2], &ptr2)) {
+               DEBUG_MSG("[drmd_open] kms_bo_map() failed. \n");
+               goto drm_err_exit;
+       }
+
+       drmdi->fb_buf2 = ptr2;
+       memset(ptr2, 0x00, drmdi->bo_stride * drmdi->bo_height);
+       kms_bo_unmap(drmdi->bo[FRAME_BUFFER2]);
+
+
+       ret = drmModePageFlip(drmdi->fd, drmdi->crtc->crtc_id, drmdi->fb_id[0],
+                             DRM_MODE_PAGE_FLIP_EVENT, drmdi);
+       if (ret) {
+               DEBUG_MSG("failed to page flip: %s\n", strerror(errno));
+               return -1;
+       }
+
+       memset(&evctx, 0, sizeof evctx);
+       evctx.version = DRM_EVENT_CONTEXT_VERSION;
+       evctx.vblank_handler = NULL;
+       evctx.page_flip_handler = page_flip_handler;
+
+       {
+               struct timeval timeout = { .tv_sec = 3, .tv_usec = 0 };
+               fd_set fds;
+
+
+               FD_ZERO(&fds);
+               FD_SET(0, &fds);
+               FD_SET(drmdi->fd, &fds);
+               ret = select(drmdi->fd + 1, &fds, NULL, NULL, &timeout);
+
+               if (ret <= 0) {
+                       DEBUG_MSG("select timed out or error (ret %d)\n",
+                               ret);
+               } else if (FD_ISSET(0, &fds)) {
+       //              break;
+                       DEBUG_MSG("drmHandleEvent.. \n");
+               }
+
+               drmHandleEvent(drmdi->fd, &evctx);
+       }
+
+       return 0;
+
+drm_err_exit:
+       DEBUG_MSG("drm_err_exit\n");
+       free_drm_res(drmdi);
+       return -1;
+}
+
+/*-----------------------------------------------------------------------------
+  drmd_close()
+ ----------------------------------------------------------------------------*/
+void drmd_close(st_drmdi *drmdi)
+{
+       int i;
+       for( i = 0 ;i <FRAME_BUFFER2 ; i++) {
+               kms_bo_unmap(drmdi->bo[i]);
+       }
+       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) {
+               DEBUG_MSG("[drmd_set_dpms_mode] drmdi is NULL\n");
+               return -1;
+       }
+
+       connector = drmdi->connector;
+
+       if (dpms_mode == DPMSModeStandby || dpms_mode == DPMSModeSuspend) {
+               DEBUG_MSG("[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) {
+               DEBUG_MSG("[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) {
+               DEBUG_MSG("[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..23c3b51
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+Copyright 2012-2013  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://floralicense.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);
+       }
+
+       DEBUG_MSG("[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..a354bd6
--- /dev/null
@@ -0,0 +1,510 @@
+/*
+Copyright 2012-2013  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://floralicense.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)) {
+               DEBUG_MSG("[get_lcd_resolution] E_LCD_RES_320x480 \n");
+               ret_lcd_res = E_LCD_RES_320x480;
+       } else if ((xres == 1024) && (yres == 600)) {
+               DEBUG_MSG("[get_lcd_resolution] E_LCD_RES_1024x600 \n");
+               ret_lcd_res = E_LCD_RES_1024x600;
+       } else if ((xres == 720) && (yres == 1280)) {
+               DEBUG_MSG("[get_lcd_resolution] E_LCD_RES_720x1280 \n");
+               ret_lcd_res = E_LCD_RES_720x1280;
+       } else if ((xres == 1280) && (yres == 800)) {
+               DEBUG_MSG("[get_lcd_resolution] E_LCD_RES_1280x800 \n");
+               ret_lcd_res = E_LCD_RES_1280x800;
+       } else {
+               DEBUG_MSG("[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)) {
+               DEBUG_MSG("[fb_open] fb device is detected. \n");
+               fbi->type = FB_DEV_FB;
+       } else if ((support_fb == 0) && (support_drm == 1)) {
+               DEBUG_MSG("[fb_open] drm device is detected. \n");
+               fbi->type = FB_DEV_DRM;
+       } else {
+               DEBUG_MSG("[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->buf2 = s_drmdi.fb_buf2;
+               fbi->current_fb_id = s_drmdi.fb_id[0];
+               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;
+       int loop_count = fbi->w * fbi->h;
+
+       if (fbi->current_fb_id == s_drmdi.fb_id[0])
+               fb_buf_cur = (unsigned int *)fbi->buf;
+       else
+               fb_buf_cur = (unsigned int *)fbi->buf2;
+
+       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 *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;
+
+       if (fbi->current_fb_id == s_drmdi.fb_id[0])
+               fb_buf_cur = (unsigned int *)fbi->buf;
+       else
+               fb_buf_cur = (unsigned int *)fbi->buf2;
+
+       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 (fbi->current_fb_id == s_drmdi.fb_id[0])
+               fbi->current_fb_id = s_drmdi.fb_id[1];
+       else
+               fbi->current_fb_id = s_drmdi.fb_id[0];
+
+       /* fill full screen with black color */
+       fb_clear_screen(fbi, 0x00000000);
+
+       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;
+       }
+
+       DEBUG_MSG("[fb_draw_img_normal_charging] current_fb_id :%d\n",\
+               fbi->current_fb_id);
+       drmModePageFlip(s_drmdi.fd, s_drmdi.crtc->crtc_id, fbi->current_fb_id,\
+               DRM_MODE_PAGE_FLIP_EVENT, NULL);
+       drmHandleEvent(s_drmdi.fd, &evctx);
+}
+
+/*-----------------------------------------------------------------------------
+  fb_draw_img_full_charging()
+ ----------------------------------------------------------------------------*/
+void fb_draw_img_full_charging(FbInfo *fbi)
+{
+       char chg_img_filename[MAX_IMG_FILE_PATH];
+
+
+       if (fbi->current_fb_id == s_drmdi.fb_id[0])
+               fbi->current_fb_id = s_drmdi.fb_id[1];
+       else
+               fbi->current_fb_id = s_drmdi.fb_id[0];
+
+       /* fill full screen with black color */
+       fb_clear_screen(fbi, 0x00000000);
+
+       /* 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();
+
+       DEBUG_MSG("[fb_draw_img_full_charging] current_fb_id :%d\n",\
+               fbi->current_fb_id);
+       drmModePageFlip(s_drmdi.fd, s_drmdi.crtc->crtc_id, fbi->current_fb_id,\
+               DRM_MODE_PAGE_FLIP_EVENT, NULL);
+       drmHandleEvent(s_drmdi.fd, &evctx);
+
+}
+
+/*-----------------------------------------------------------------------------
+  fb_draw_img_batt_err_plug()
+ ----------------------------------------------------------------------------*/
+void fb_draw_img_batt_err_plug(FbInfo *fbi)
+{
+       char chg_img_filename[MAX_IMG_FILE_PATH];
+
+       if (fbi->current_fb_id == s_drmdi.fb_id[0])
+               fbi->current_fb_id = s_drmdi.fb_id[1];
+       else
+               fbi->current_fb_id = s_drmdi.fb_id[0];
+
+       /* fill full screen with black color */
+       fb_clear_screen(fbi, 0x00000000);
+
+       /* 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;
+       }
+
+       draw_png_img_xy(fbi, s_err_img_x, s_err_img_y);
+       release_png_res();
+
+       DEBUG_MSG("[fb_draw_img_batt_err_plug]new_fb_id : %d\n",\
+               fbi->current_fb_id);
+       drmModePageFlip(s_drmdi.fd, s_drmdi.crtc->crtc_id, fbi->current_fb_id,\
+               DRM_MODE_PAGE_FLIP_EVENT, NULL);
+       drmHandleEvent(s_drmdi.fd, &evctx);
+}
+
+/*-----------------------------------------------------------------------------
+  fb_draw_img_batt_err_temp()
+ ----------------------------------------------------------------------------*/
+void fb_draw_img_batt_err_temp(FbInfo *fbi)
+{
+       char chg_img_filename[MAX_IMG_FILE_PATH];
+
+       if (fbi->current_fb_id == s_drmdi.fb_id[0])
+               fbi->current_fb_id = s_drmdi.fb_id[1];
+       else
+               fbi->current_fb_id = s_drmdi.fb_id[0];
+
+       /* fill full screen with black color */
+       fb_clear_screen(fbi, 0x00000000);
+
+       /* draw charging image based on batt_bar & progress_cnt */
+       sprintf(chg_img_filename, "%s%s.png",
+               str_chg_img_dir, CHG_IMG_TEMP_ERROR);
+
+       /* clear screen based on normal_img & progress_img */
+       /* fb_fill_rect(fbi, s_normal_img_x, s_normal_img_y,\
+                       s_normal_img_x + png_img_width_batt_normal,\
+                       s_normal_img_y + png_img_height_batt_normal,\
+                       0x00000000);
+       fb_fill_rect(fbi, s_progress_img_x, s_progress_img_y,\
+                       s_progress_img_x + png_img_width,\
+                       s_progress_img_y + png_img_height, 0x00000000);*/
+       if (read_png_file(chg_img_filename) < 0) {
+               return;
+       }
+
+       draw_png_img_xy(fbi, s_err_img_x, s_err_img_y);
+       release_png_res();
+
+       DEBUG_MSG("[fb_draw_img_batt_err_temp]new_fb_id : %d\n",\
+               fbi->current_fb_id);
+       drmModePageFlip(s_drmdi.fd, s_drmdi.crtc->crtc_id, fbi->current_fb_id,\
+               DRM_MODE_PAGE_FLIP_EVENT, NULL);
+       drmHandleEvent(s_drmdi.fd, &evctx);
+
+}
+
+/*-----------------------------------------------------------------------------
+  fb_draw_img_batt_err_charging()
+ ----------------------------------------------------------------------------*/
+void fb_draw_img_batt_err_charging(FbInfo *fbi)
+{
+       static int progress_cnt = 0;
+       static int batt_bar = 5;
+       char chg_img_filename[MAX_IMG_FILE_PATH];
+
+       if (fbi->current_fb_id == s_drmdi.fb_id[0])
+               fbi->current_fb_id = s_drmdi.fb_id[1];
+       else
+               fbi->current_fb_id = s_drmdi.fb_id[0];
+
+       /* fill full screen with black color */
+       fb_clear_screen(fbi, 0x00000000);
+
+       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);
+
+       /* clear screen based on err_img */
+       /* fb_fill_rect(fbi, s_err_img_x, s_err_img_y,\
+                       s_err_img_x + png_img_width,\
+                       s_err_img_y + png_img_height, 0x00000000);*/
+
+       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();
+
+//     png_img_width_batt_normal = png_img_width;
+//     png_img_height_batt_normal = png_img_height;
+
+       /* 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;
+       }
+
+       DEBUG_MSG("[fb_draw_img_batt_err_charging]new_fb_id : %d\n",\
+               fbi->current_fb_id);
+       drmModePageFlip(s_drmdi.fd, s_drmdi.crtc->crtc_id, fbi->current_fb_id,\
+               DRM_MODE_PAGE_FLIP_EVENT, NULL);
+       drmHandleEvent(s_drmdi.fd, &evctx);
+}
diff --git a/src/chg_fbd.c b/src/chg_fbd.c
new file mode 100755 (executable)
index 0000000..c74ea1e
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+Copyright 2012-2013  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://floralicense.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) {
+               DEBUG_MSG("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);
+               DEBUG_MSG("Error reading fixed information.\n");
+               return -1;
+       }
+
+       /* Get variable screen information */
+       if (ioctl(fbdi->fb_fd, FBIOGET_VSCREENINFO, &fbdi->vi)) {
+               close(fbdi->fb_fd);
+               DEBUG_MSG("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 ((void*)fbdi->fb_buf == (void*)-1) {
+               close(fbdi->fb_fd);
+               DEBUG_MSG("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..c1da0a9
--- /dev/null
@@ -0,0 +1,269 @@
+/*
+Copyright 2012-2013  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://floralicense.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.
+*/
+
+#define _GNU_SOURCE
+#define __USE_GNU
+#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 KEY_VAL_PRESS          1
+#define KEY_VAL_RELEASE        0
+#define KEY_CODE_POWER         116
+
+#define EVT_LOOP_DURATION      1000
+
+#define LCD_DIMM_TIME          10000
+#define LCD_OFF_TIME           30000
+#define LCD_DIMM_COUNT         (LCD_DIMM_TIME/EVT_LOOP_DURATION)
+#define LCD_OFF_COUNT          (LCD_OFF_TIME/EVT_LOOP_DURATION)
+
+#define KEY_INPUT_PATH         "/dev/input/event1"
+
+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;
+
+       DEBUG_MSG("[main] event_monitor_process() started. %s\n", (char *)arg);
+
+       if ((fd = open(arg, O_RDWR)) < 0) {
+               DEBUG_MSG("%s: open error, fd = %d\n", (char *)arg, fd);
+               return -1;
+       }
+
+       memset(&pollevents, 0, sizeof(pollevents));
+       pollevents.fd = fd;
+       pollevents.events = POLLIN | POLLERR;
+
+       while (1) {
+
+               ret = poll(&pollevents, 1, EVT_LOOP_DURATION);
+
+               if (ret < 0)
+                       DEBUG_MSG("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()) {
+                               DEBUG_MSG("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 = LCD_OFF_COUNT;
+
+               sys_power_cnt++;
+
+               DEBUG_MSG("poll event : %d, fd : %d sys_power_cnt : %d, arg : %s\n" \
+                        , ret, pollevents.fd, sys_power_cnt, (char *) arg);
+
+               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) > 2000) {
+                               sys_power_reboot();
+                               break;
+                       }
+               }
+
+               if (pollevents.revents & POLLIN) {
+                       readcount = read(pollevents.fd, &event, sizeof(event));
+                       if (readcount != sizeof(event)) {
+                               DEBUG_MSG("key read error\n");
+                               continue;
+                       }
+
+                       DEBUG_MSG("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;
+                               }
+
+                               DEBUG_MSG("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) {
+                               DEBUG_MSG("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;
+
+       DEBUG_MSG("[main] charging_animation_process() started. \n");
+
+       set_chg_img_params();
+
+       /* 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_batt_err_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];
+       char key_path[256];
+
+       if (argc > 1)
+               strncpy(key_path, argv[1], 255);
+       else
+               strncpy(key_path, KEY_INPUT_PATH, 255);
+
+       chg_env_str_load();
+
+       if (fb_open(&fbi) < 0) {
+               DEBUG_MSG("[main] fb_open() failed. \n");
+               return -1;
+       }
+
+       DEBUG_MSG("charging-animation main function called.");
+
+       sys_power_wakeup(&fbi);
+       lcd_bl_on(&fbi);
+       lcd_br_normal();
+
+       if (clone(event_monitor_process, (void *)(child_stack + 4095),
+                 CLONE_VM | CLONE_THREAD | CLONE_SIGHAND, key_path) < 0) {
+               DEBUG_MSG("[main] cannot creat thread ... \n");
+               goto main_exit;
+       }
+
+       charging_animation_process();
+
+main_exit:
+       DEBUG_MSG("[main] terminate \n");
+       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..501aa69
--- /dev/null
@@ -0,0 +1,172 @@
+/*
+Copyright 2012-2013  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://floralicense.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 <sys/types.h>
+#include <sys/wait.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, int size)
+{
+       int fd;
+       int count;
+
+       if (!path)
+               return -1;
+
+       fd = open(path, O_RDONLY, 0);
+       if (fd == -1) {
+               DEBUG_MSG("[read_from_file] Could not open '%s'", path);
+               return -1;
+       }
+
+       count = (int)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;
+       ssize_t count;
+
+       if (!path)
+               return -1;
+
+       fd = open(path, O_WRONLY);
+       if (fd == -1) {
+               DEBUG_MSG("[write_to_file] Could not open '%s'", path);
+               return -1;
+       }
+
+       count = write(fd, buf, strlen(buf));
+       close(fd);
+       if (count < 0) {
+               DEBUG_MSG("[write_to_file] %s write error", path);
+               return (int)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;
+}
+
+/*-----------------------------------------------------------------------------
+  system_cmd_wait()
+ ----------------------------------------------------------------------------*/
+int system_cmd_wait(const char *command)
+{
+
+       int pid = 0;
+       int status = 0;
+       char* const environ[2] = {"DISPLAY=:0", NULL };
+
+       if (command == NULL)
+               return -1;
+
+       pid = fork();
+
+       if (pid == -1)
+               return -1;
+
+       if (pid == 0) {
+               char *argv[4];
+               argv[0] = "sh";
+               argv[1] = "-c";
+               argv[2] = (char*)command;
+               argv[3] = 0;
+               execve("/bin/sh", argv, environ);
+               exit(127);
+       }
+
+       do {
+               if (waitpid(pid, &status, 0) == -1) {
+                       if (errno != EINTR)
+                               return -1;
+               } else {
+                       return status;
+               }
+       } while(1);
+}
+
+/*-----------------------------------------------------------------------------
+  system_cmd_nowait()
+ ----------------------------------------------------------------------------*/
+int system_cmd_nowait(const char *command)
+{
+
+       int pid = 0;
+       char* const environ[2] = {"DISPLAY=:0", NULL };
+
+       if (command == NULL)
+               return -1;
+
+       pid = fork();
+
+       if (pid == -1)
+               return -1;
+
+       if (pid == 0) {
+               char *argv[4];
+               argv[0] = "sh";
+               argv[1] = "-c";
+               argv[2] = (char*)command;
+               argv[3] = 0;
+               execve("/bin/sh", argv, environ);
+               exit(127);
+       } else if (pid < 0) {
+               DEBUG_MSG("execve fail : '%s'", command);
+               return -1;
+       }
+
+       return 0;
+}
+
+
diff --git a/src/chg_png.c b/src/chg_png.c
new file mode 100755 (executable)
index 0000000..2189970
--- /dev/null
@@ -0,0 +1,181 @@
+/*
+Copyright 2012-2013  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://floralicense.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;
+/* clear screen based on img size */
+//int png_img_width_batt_normal;
+//int png_img_height_batt_normal;
+
+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) {
+               DEBUG_MSG("[read_png_file] File %s could not be opened"
+                       " for reading \n", file_name);
+               return -1;
+       }
+
+       (void)fread(header, 1, 8, fp);
+       if (png_sig_cmp((png_bytep)header, 0, 8)) {
+               fclose(fp);
+               DEBUG_MSG("[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);
+               DEBUG_MSG("[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);
+               DEBUG_MSG("[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);
+               DEBUG_MSG("[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);
+               DEBUG_MSG("[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;
+       int bpp;
+       int x, y;
+
+       if (fbi->current_fb_id == s_drmdi.fb_id[0])
+               fb_buf_cur = (unsigned int *)fbi->buf;
+       else
+               fb_buf_cur = (unsigned int *)fbi->buf2;
+
+       /* check out range */
+       if ((x1 + png_img_width > fbi->w) ||
+           (y1 + png_img_height > fbi->h)) {
+               DEBUG_MSG("[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 {
+               DEBUG_MSG("[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..c802857
--- /dev/null
@@ -0,0 +1,218 @@
+/*
+Copyright 2012-2013  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://floralicense.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)
+{
+       DEBUG_MSG("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)
+{
+       DEBUG_MSG("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;
+
+       DEBUG_MSG("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;
+
+       DEBUG_MSG("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)
+{
+       DEBUG_MSG("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)
+{
+       DEBUG_MSG("sys_power_sleep() is called.\n");
+       lcd_bl_off(fbi);
+       s_sys_power_state = SYS_POWER_OFF;
+//     system_cmd_nowait("echo mem > /sys/power/state");
+       return 0;
+}
+
+/*-----------------------------------------------------------------------------
+  sys_power_state()
+ ----------------------------------------------------------------------------*/
+int sys_power_state(void)
+{
+       return s_sys_power_state;
+}
+
+/*-----------------------------------------------------------------------------
+  sys_power_reboot()
+ ----------------------------------------------------------------------------*/
+void sys_power_reboot(void)
+{
+       DEBUG_MSG("sys_power_reboot() is called.\n");
+       reboot(RB_AUTOBOOT);
+}
+
+/*-----------------------------------------------------------------------------
+  sys_power_off()
+ ----------------------------------------------------------------------------*/
+void sys_power_off(void)
+{
+       DEBUG_MSG("sys_power_off() is called.\n");
+       reboot(RB_POWER_OFF);
+}
+
+