From: Philipp Zabel Date: Wed, 19 May 2010 21:50:12 +0000 (+0200) Subject: Initial commit: 0.0.1-1 X-Git-Tag: v0.0.1 X-Git-Url: http://git.maemo.org/git/?p=chledclk;a=commitdiff_plain;h=cd0edf66a11d7c4addd73e043d99d0bc7c65379f Initial commit: 0.0.1-1 --- diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..803bd8c --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +chledclk: chledclk.vala + valac --disable-dbus-transformation --pkg dbus-glib-1 $^ + +install: chledclk + install -d ${DESTDIR}/usr/bin/ + install -m0755 chledclk ${DESTDIR}/usr/bin/chledclk + install -d ${DESTDIR}/etc/event.d/ + install -m0644 chledclk.upstart ${DESTDIR}/etc/event.d/chledclk + +clean: + rm -f chledclk + +.PHONY: clean install diff --git a/chledclk.upstart b/chledclk.upstart new file mode 100644 index 0000000..e2cedf0 --- /dev/null +++ b/chledclk.upstart @@ -0,0 +1,11 @@ +description "Charging LED Clock" +author "Philipp Zabel" + +start on started mce +stop on stopping xomap + +service +console none + +exec /usr/bin/chledclk + diff --git a/chledclk.vala b/chledclk.vala new file mode 100644 index 0000000..2420fcc --- /dev/null +++ b/chledclk.vala @@ -0,0 +1,164 @@ +class ChargingLEDClock : Object { + const string MCE_SERVICE = "com.nokia.mce"; + const string MCE_SIGNAL_PATH = "/com/nokia/mce/signal"; + const string MCE_SIGNAL_IFACE = "com.nokia.mce.signal"; + const string BME_SERVICE = "com.nokia.bme"; + const string BME_SIGNAL_PATH = "/com/nokia/bme/signal"; + const string BME_SIGNAL_IFACE = "com.nokia.bme.signal"; + const string BME_REQUEST_PATH = "/com/nokia/bme/request"; + const string BME_REQUEST_IFACE = "com.nokia.bme.request"; + + MainLoop loop; + dynamic DBus.Object mce; + dynamic DBus.Object bme; + + bool display_off; + bool charger_connected; + bool battery_full; + + bool sysfs_write (string filename, string contents) { + var f = FileStream.open (filename, "w"); + if (f == null) { + stderr.printf ("failed to open '%s' for writing\n", filename); + return false; + } + f.printf ("%s", contents); + return true; + } + + void set_led_pattern (bool on, Time time) { + + print ("setting led pattern: %s\n", on ? "on" : "off"); + + sysfs_write ("/sys/class/i2c-adapter/i2c-2/2-0032/engine1_mode", "disabled"); + sysfs_write ("/sys/class/i2c-adapter/i2c-2/2-0032/engine2_mode", "disabled"); + sysfs_write ("/sys/class/leds/lp5523:r/brightness", "0"); + sysfs_write ("/sys/class/leds/lp5523:g/brightness", "0"); + sysfs_write ("/sys/class/leds/lp5523:b/brightness", "0"); + + if (!on) + return; + + string pattern = "9d804000"; + int jump = 2; + if (time.hour >= 20) { + pattern += "087f09ffa082"; + jump += 3; + } else if (time.hour >= 10) { + pattern += "087f09ff"; + jump += 2; + } + if ((time.hour % 10) > 1) { + pattern += "047f05ffa%03x".printf (((time.hour % 10 - 1) << 7) + jump); + jump += 3; + } else if ((time.hour % 10) == 1) { + pattern += "047f05ff"; + jump += 2; + } + pattern += "11ff"; + jump += 1; + if (time.minute >= 20) + pattern += "047f05ffa%03x".printf (((time.minute / 10 - 1) << 7) + jump); + else if (time.minute >= 10) + pattern += "047f05ff"; + if ((time.minute % 10) >= 5) + pattern += "043f057f"; + pattern += "71050000"; + + print ("setting pattern: %s\n", pattern); + + sysfs_write ("/sys/class/i2c-adapter/i2c-2/2-0032/engine1_mode", "load"); + sysfs_write ("/sys/class/i2c-adapter/i2c-2/2-0032/engine1_leds", battery_full ? "000001000" : "000001100"); + sysfs_write ("/sys/class/i2c-adapter/i2c-2/2-0032/engine1_load", pattern); + sysfs_write ("/sys/class/i2c-adapter/i2c-2/2-0032/engine2_mode", "load"); + sysfs_write ("/sys/class/i2c-adapter/i2c-2/2-0032/engine2_leds", "000000000"); + sysfs_write ("/sys/class/i2c-adapter/i2c-2/2-0032/engine2_load", "9d800000"); + sysfs_write ("/sys/class/i2c-adapter/i2c-2/2-0032/engine2_mode", "run"); + sysfs_write ("/sys/class/i2c-adapter/i2c-2/2-0032/engine1_mode", "run"); + if (battery_full) { + sysfs_write ("/sys/class/leds/lp5523:r/led_current", "20"); + sysfs_write ("/sys/class/leds/lp5523:g/led_current", "2"); + sysfs_write ("/sys/class/leds/lp5523:b/led_current", "0"); + } else { + sysfs_write ("/sys/class/leds/lp5523:r/led_current", "2"); + sysfs_write ("/sys/class/leds/lp5523:g/led_current", "2"); + sysfs_write ("/sys/class/leds/lp5523:b/led_current", "2"); + } + } + + bool update_led_pattern () { + TimeVal now = TimeVal (); + var time = Time.local (now.tv_sec); + + print ("current time: %d:%02d h\n", time.hour, time.minute); + + if (charger_connected && display_off) { + set_led_pattern (true, time); + + Timeout.add (1000 * (60 - time.second), update_led_pattern); + } else { + set_led_pattern (false, time); + } + + return false; + } + + void on_mce_display_status_ind (dynamic DBus.Object mce, string mode) { + print ("display_status_ind: %s\n", mode); + display_off = (mode == "off"); + + if (charger_connected && display_off) { + print ("setting led pattern in 100 ms ...\n"); + Timeout.add (100, update_led_pattern); + } + } + + void on_bme_charger_connected (dynamic DBus.Object bme) { + print ("charger_connected\n"); + charger_connected = true; + } + + void on_bme_charger_disconnected (dynamic DBus.Object bme) { + print ("charger_disconnected\n"); + charger_connected = false; + battery_full = false; + } + + void on_bme_battery_full (dynamic DBus.Object bme) { + print ("battery_full\n"); + battery_full = true; + } + + public ChargingLEDClock (DBus.Connection bus) { + loop = new MainLoop (null); + + mce = bus.get_object (MCE_SERVICE, MCE_SIGNAL_PATH, MCE_SIGNAL_IFACE); + mce.display_status_ind.connect (on_mce_display_status_ind); + + bme = bus.get_object (BME_SERVICE, BME_SIGNAL_PATH, BME_SIGNAL_IFACE); + bme.charger_connected.connect (on_bme_charger_connected); + bme.charger_disconnected.connect (on_bme_charger_disconnected); + bme.battery_full.connect (on_bme_battery_full); + + dynamic DBus.Object bme_req; + bme_req = bus.get_object (BME_SERVICE, BME_REQUEST_PATH, BME_REQUEST_IFACE); + bme_req.status_info_req (); + } + + public int run () { + loop.run (); + return 0; + } + + static int main (string[] args) { + try { + var bus = DBus.Bus.get (DBus.BusType.SYSTEM); + var app = new ChargingLEDClock (bus); + return app.run (); + } catch (DBus.Error e) { + stderr.printf ("Error: %s\n", e.message); + return 1; + } + } +} + diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..8c89b1b --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +chledclk (0.0.1-1) unstable; urgency=low + + * Initial release + + -- Philipp Zabel Tue, 18 May 2010 21:57:17 +0200 diff --git a/debian/chledclk.install b/debian/chledclk.install new file mode 100644 index 0000000..78a8f40 --- /dev/null +++ b/debian/chledclk.install @@ -0,0 +1,2 @@ +usr/bin/chledclk +etc/event.d/chledclk diff --git a/debian/chledclk.postinst b/debian/chledclk.postinst new file mode 100644 index 0000000..dab45f8 --- /dev/null +++ b/debian/chledclk.postinst @@ -0,0 +1,2 @@ +#!/bin/sh +start chledclk diff --git a/debian/chledclk.prerm b/debian/chledclk.prerm new file mode 100644 index 0000000..b7b8667 --- /dev/null +++ b/debian/chledclk.prerm @@ -0,0 +1,2 @@ +#!/bin/sh +stop chledclk diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..bd031bf --- /dev/null +++ b/debian/control @@ -0,0 +1,15 @@ +Source: chledclk +Section: user/system +Priority: extra +Maintainer: Philipp Zabel +Build-Depends: vala (>= 0.8.0), debhelper (>= 5), libdbus-glib-1-dev (>= 0.78) +Standards-Version: 5 +XSBC-Bugtracker: philipp.zabel@gmail.com + +Package: chledclk +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +XB-Description: Modifies the charging LED pattern to indicate time + The charging and battery full LED batterns blink to indicate the current + hour and minute with 5 minute precision. +XB-Maemo-Display-Name: Charging LED Clock diff --git a/debian/optify b/debian/optify new file mode 100644 index 0000000..865faf1 --- /dev/null +++ b/debian/optify @@ -0,0 +1 @@ +auto diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..94703e2 --- /dev/null +++ b/debian/rules @@ -0,0 +1,82 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# GNU copyright 1997 to 1999 by Joey Hess. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 +export DH_COMPAT=5 +export DH_OPTIONS + +DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE) +DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) +DEB_BUILD_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH) + +CFLAGS = -Wall -g + +ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) + CFLAGS += -O0 +else + CFLAGS += -O2 +endif +ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS))) + INSTALL_PROGRAM += -s +endif + +config.status: configure + dh_testdir + # Add here commands to configure the package. + #CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \ + # --prefix=/usr $(conf_opt) + +build: build-stamp + +build-stamp: config.status + dh_testdir + + # Add here commands to compile the package. + $(MAKE) + touch $@ + +clean: + dh_testdir + dh_testroot + rm -f build-stamp + + # Add here commands to clean up after the build process. + -$(MAKE) clean + + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/tmp + $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install + + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: install + dh_testdir + dh_testroot + dh_install --sourcedir=debian/tmp + dh_link + dh_strip + dh_compress + dh_fixperms + dh_makeshlibs + dh_installdeb + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-arch binary-indep binary install configure diff --git a/welcome b/welcome deleted file mode 100644 index e69de29..0000000