Hi all,
Attaching a couple of patches,
1.) Adding Display abstract interface to libfsoframework
2.) Adding kernel26_display plugin to fsodevice

-- 
Regards
Sudharshan S
Blog : http://www.sudharsh.wordpress.com
IRC   : Sup3rkiddo @ Freenode, Gimpnet

From b8acb2a5492d1a43dc38641d07adab1ac5b769f0 Mon Sep 17 00:00:00 2001
From: Sudharshan 'Sup3rkiddo' S <sudha...@gmail.com>
Date: Sat, 4 Apr 2009 19:25:21 +0530
Subject: [PATCH] Add Display Interface to libfsoframework


Signed-off-by: Sudharshan 'Sup3rkiddo' S <sudha...@gmail.com>
---
 libfsoframework/fsoframework/fsoframework-2.0.vapi |   13 +++++++++++++
 libfsoframework/fsoframework/interfaces.vala       |   16 +++++++++++++++-
 2 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/libfsoframework/fsoframework/fsoframework-2.0.vapi b/libfsoframework/fsoframework/fsoframework-2.0.vapi
index b9a20d5..01b8ced 100644
--- a/libfsoframework/fsoframework/fsoframework-2.0.vapi
+++ b/libfsoframework/fsoframework/fsoframework-2.0.vapi
@@ -5,6 +5,15 @@ namespace FsoFramework {
 	[CCode (cprefix = "FsoFrameworkDevice", lower_case_cprefix = "fso_framework_device_")]
 	namespace Device {
 		[CCode (cheader_filename = "fsoframework/interfaces.h")]
+		[DBus (name = "org.freesmartphone.Device.Display")]
+		public interface Display : GLib.Object {
+			public abstract bool GetBacklightPower ();
+			public abstract int GetBrightness ();
+			public abstract GLib.HashTable<string,GLib.Value?> GetInfo ();
+			public abstract void SetBacklightPower (bool power);
+			public abstract void SetBrightness (int brightness);
+		}
+		[CCode (cheader_filename = "fsoframework/interfaces.h")]
 		[DBus (name = "org.freesmartphone.Device.LED")]
 		public interface LED : GLib.Object {
 			public abstract string GetName ();
@@ -13,6 +22,10 @@ namespace FsoFramework {
 			public abstract void SetNetworking (string iface, string mode) throws DBus.Error;
 		}
 		[CCode (cheader_filename = "fsoframework/interfaces.h")]
+		public const string DisplayServiceFace;
+		[CCode (cheader_filename = "fsoframework/interfaces.h")]
+		public const string DisplayServicePath;
+		[CCode (cheader_filename = "fsoframework/interfaces.h")]
 		public const string LedServiceFace;
 		[CCode (cheader_filename = "fsoframework/interfaces.h")]
 		public const string LedServicePath;
diff --git a/libfsoframework/fsoframework/interfaces.vala b/libfsoframework/fsoframework/interfaces.vala
index 5dd12ad..1214dd3 100644
--- a/libfsoframework/fsoframework/interfaces.vala
+++ b/libfsoframework/fsoframework/interfaces.vala
@@ -32,7 +32,11 @@ namespace FsoFramework
 
         public const string LedServiceFace = ServiceFacePrefix + ".LED";
         public const string LedServicePath = ServicePathPrefix + "/LED";
-
+		
+	public const string DisplayServiceFace = ServiceFacePrefix + ".Display";
+	public const string DisplayServicePath = ServicePathPrefix + "/Display";
+		
+		
         [DBus (name = "org.freesmartphone.Device.LED")]
         public abstract interface LED : GLib.Object
         {
@@ -41,5 +45,15 @@ namespace FsoFramework
             public abstract void SetBlinking( int delay_on, int delay_off ) throws DBus.Error;
             public abstract void SetNetworking( string iface, string mode ) throws DBus.Error;
         }
+
+	[DBus (name = "org.freesmartphone.Device.Display")]
+	public abstract interface Display : GLib.Object
+	{
+		public abstract void SetBrightness(int brightness);
+		public abstract int GetBrightness();
+		public abstract bool GetBacklightPower();
+		public abstract void SetBacklightPower(bool power);
+		public abstract HashTable<string, Value?> GetInfo();
+	}
     }
 }
-- 
1.6.0.6

From bfac604756e4e81c4f4d16b57f380d03a0ae1a8d Mon Sep 17 00:00:00 2001
From: Sudharshan 'Sup3rkiddo' S <sudha...@gmail.com>
Date: Sat, 4 Apr 2009 19:27:22 +0530
Subject: [PATCH] add kernel26_display plugin


Signed-off-by: Sudharshan 'Sup3rkiddo' S <sudha...@gmail.com>
---
 fsodeviced/configure.ac                            |    1 +
 fsodeviced/src/plugins/Makefile.am                 |    1 +
 .../src/plugins/kernel26_display/Makefile.am       |   45 ++++++
 .../src/plugins/kernel26_display/display-helpers.c |   38 +++++
 .../plugins/kernel26_display/display-helpers.vapi  |    4 +
 .../src/plugins/kernel26_display/plugin.vala       |  164 ++++++++++++++++++++
 6 files changed, 253 insertions(+), 0 deletions(-)
 create mode 100644 fsodeviced/src/plugins/kernel26_display/Makefile.am
 create mode 100644 fsodeviced/src/plugins/kernel26_display/display-helpers.c
 create mode 100644 fsodeviced/src/plugins/kernel26_display/display-helpers.vapi
 create mode 100644 fsodeviced/src/plugins/kernel26_display/plugin.vala

diff --git a/fsodeviced/configure.ac b/fsodeviced/configure.ac
index 9308b70..538a359 100644
--- a/fsodeviced/configure.ac
+++ b/fsodeviced/configure.ac
@@ -53,6 +53,7 @@ AC_CONFIG_FILES([
   src/bin/Makefile
   src/plugins/Makefile
   src/plugins/kernel26_leds/Makefile
+  src/plugins/kernel26_display/Makefile
   tests/Makefile
 ])
 
diff --git a/fsodeviced/src/plugins/Makefile.am b/fsodeviced/src/plugins/Makefile.am
index fc72b0b..d03c4e1 100644
--- a/fsodeviced/src/plugins/Makefile.am
+++ b/fsodeviced/src/plugins/Makefile.am
@@ -4,4 +4,5 @@ AUTOMAKE_OPTIONS = subdir-objects
 
 SUBDIRS = \
 	kernel26_leds \
+	kernel26_display \
 	$(NULL)
diff --git a/fsodeviced/src/plugins/kernel26_display/Makefile.am b/fsodeviced/src/plugins/kernel26_display/Makefile.am
new file mode 100644
index 0000000..40444f8
--- /dev/null
+++ b/fsodeviced/src/plugins/kernel26_display/Makefile.am
@@ -0,0 +1,45 @@
+NULL =
+
+AM_CPPFLAGS = \
+	-I$(top_srcdir) \
+	$(FSO_CFLAGS) \
+	$(DBUS_CFLAGS) \
+	$(NULL)
+
+noinst_PROGRAMS = $(TEST_PROGS)
+
+progs_ldadd = $(FSO_LIBS) $(DBUS_LIBS) $(top_srcdir)/src/lib/libfsodevice.la
+
+VALAC_ARGS = \
+	--basedir $(top_srcdir) \
+	--vapidir $(top_srcdir)/fsoframework \
+	--pkg glib-2.0 \
+	--pkg dbus-glib-1 \
+	--pkg fsoframework-2.0 \
+	--vapidir ./ \
+	--pkg display-helpers
+
+#
+# plugin
+#
+modlibexecdir = $(libdir)/cornucopia/modules/fsodevice
+modlibexec_LTLIBRARIES = kernel26_display.la
+kernel26_display_la_SOURCES = plugin.c plugin.h display.c
+kernel26_display_la_VALASOURCES = plugin.vala
+$(kernel26_display_la_SOURCES): $(kernel26_display_la_VALASOURCES)
+	$(VALAC) -C $(VALAC_ARGS) $^
+	touch $@
+kernel26_display_la_LIBADD = $(progs_ldadd)
+kernel26_display_la_LDFLAGS = -no-undefined -module -avoid-version
+kernel26_display_la_LIBTOOLFLAGS = --tag=disable-static
+
+CLEANFILES = \
+    *.c \
+    *.h \
+    *.la \
+    *.lo \
+    $(NULL)
+
+MAINTAINERCLEANFILES = \
+  Makefile.in \
+  $(NULL)
diff --git a/fsodeviced/src/plugins/kernel26_display/display-helpers.c b/fsodeviced/src/plugins/kernel26_display/display-helpers.c
new file mode 100644
index 0000000..0af614e
--- /dev/null
+++ b/fsodeviced/src/plugins/kernel26_display/display-helpers.c
@@ -0,0 +1,38 @@
+/* 
+ * display-helpers.c
+ * Written by Sudharshan "Sup3rkiddo" S <sudha...@gmail.com>
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */ 
+
+/* Display helpers */
+#include <glib.h>
+#include "display.h"
+#include <fcntl.h>
+#include <sys/ioctl.h>
+
+#define FBIOBLANK 0x4611
+#define FB_BLANK_UNBLANK 0
+#define FB_BLANK_POWERDOWN 4
+
+void fb_set_power(gboolean enable, int fd) {
+	if(enable)
+		ioctl(fd, FBIOBLANK, FB_BLANK_UNBLANK);
+	else
+		ioctl(fd, FBIOBLANK, FB_BLANK_POWERDOWN);
+}
+	
diff --git a/fsodeviced/src/plugins/kernel26_display/display-helpers.vapi b/fsodeviced/src/plugins/kernel26_display/display-helpers.vapi
new file mode 100644
index 0000000..f68737b
--- /dev/null
+++ b/fsodeviced/src/plugins/kernel26_display/display-helpers.vapi
@@ -0,0 +1,4 @@
+namespace DisplayHelpers {
+	[CCode (cname = "fb_set_power")]
+	public void set_fb (bool enable, int fd);
+}
diff --git a/fsodeviced/src/plugins/kernel26_display/plugin.vala b/fsodeviced/src/plugins/kernel26_display/plugin.vala
new file mode 100644
index 0000000..5565445
--- /dev/null
+++ b/fsodeviced/src/plugins/kernel26_display/plugin.vala
@@ -0,0 +1,164 @@
+/* 
+ * plugin.vala
+ * Written by Sudharshan "Sup3rkiddo" S <sudha...@gmail.com>
+ * All Rights Reserved
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */ 
+
+using GLib;
+using DisplayHelpers;
+
+
+namespace Kernel26 {
+
+	static const string SYS_CLASS_DISPLAY = "/sys/class/backlight";
+	
+	class Display : FsoFramework.Device.Display, GLib.Object {
+
+		private FsoFramework.Subsystem subsystem;
+		static FsoFramework.Logger logger;
+		static uint counter;
+
+		private int max_brightness;
+		private int curr_brightness;
+		private string sysfsnode;
+		private int fb_fd;
+
+		
+		public Display(FsoFramework.Subsystem subsystem, string sysfsnode) {
+			
+			if (logger == null)
+				logger = FsoFramework.createLogger( "fsodevice.kernel26_leds" );
+			logger.info( "Created new Display for %s".printf( sysfsnode ) );
+
+			this.subsystem = subsystem;
+			this.sysfsnode = sysfsnode;
+			this.max_brightness = FsoFramework.FileHandling.read(this.sysfsnode + "/max_brightness").to_int();
+
+			this.curr_brightness = this.GetBrightness();
+			try {
+				var _fb = new IOChannel.file ("/dev/fb0", "r");
+				this.fb_fd = _fb.unix_get_fd();
+			}
+			catch (GLib.Error error) {
+				this.fb_fd = -1;
+				logger.warning (error.message);
+			}
+
+			subsystem.registerServiceObject( FsoFramework.Device.DisplayServicePath,
+							"%s/%u".printf( FsoFramework.Device.DisplayServicePath, counter++ ),
+							 this );
+
+
+		   
+		}
+
+		
+		public void SetBrightness(int brightness) {
+			int value = GetBrightness();
+
+			if(brightness > this.max_brightness) {
+				logger.warning("Required brightness %d is greater than the maximum brighness supported by the display : %s".printf(brightness, this.sysfsnode));
+				return;
+			}
+
+			if(this.curr_brightness!=value) {
+				FsoFramework.FileHandling.write(brightness.to_string(), this.sysfsnode + "/brightness");
+				if (this.curr_brightness == 0) 
+					DisplayHelpers.set_fb(true, this.fb_fd);
+				else if(value == 0)
+					DisplayHelpers.set_fb(false, this.fb_fd);
+				this.curr_brightness = value;
+			}
+			logger.debug("Brightness set to %d".printf(brightness));
+		}
+
+		
+		public int GetBrightness() {
+			return FsoFramework.FileHandling.read(this.sysfsnode + "/actual_brightness").to_int();
+		}
+
+		
+		public bool GetBacklightPower() {
+			return FsoFramework.FileHandling.read(this.sysfsnode + "/bl_power").to_int() == 0;
+		}
+
+		
+		public void SetBacklightPower(bool power) {
+			int _val;
+			if (power)
+			_val = 0;
+			else
+				_val = 1;
+			FsoFramework.FileHandling.write(_val.to_string(), this.sysfsnode + "/bl_power");
+						
+		}
+
+
+		public HashTable<string, Value?> GetInfo() {
+			string _leaf;
+			Value val = new Value(typeof(string));
+			HashTable<string, Value?> info_table = new HashTable<string, Value?>((HashFunc)str_hash,
+																				 (EqualFunc)str_equal);
+			/* Just read all the files in the sysfs path and return it as a{ss} */
+			try {
+				Dir dir = Dir.open (this.sysfsnode, 0);
+				while ((_leaf = dir.read_name()) != null) {
+					if(FileUtils.test (this.sysfsnode + "/" + _leaf, FileTest.IS_REGULAR) && _leaf != "uevent") {
+						val.take_string(FsoFramework.FileHandling.read(this.sysfsnode + "/" + _leaf).strip());
+						info_table.insert (_leaf, val);
+					}
+				}
+			}
+			catch (GLib.Error error) {
+				logger.warning (error.message);
+			}
+			return info_table;
+			
+		}
+
+
+	}
+
+}
+
+
+List<Kernel26.Display> instances;
+
+
+public static string fso_factory_function( FsoFramework.Subsystem subsystem ) throws Error
+{
+    // scan sysfs path for leds
+    Dir dir = Dir.open( Kernel26.SYS_CLASS_DISPLAY, 0 );
+    string entry = dir.read_name();
+    while ( entry != null )
+    {
+        var filename = Path.build_filename( Kernel26.SYS_CLASS_DISPLAY, entry );
+        instances.append( new Kernel26.Display( subsystem, filename ) );
+        entry = dir.read_name();
+    }
+    return "fsodevice.kernel26_display";
+}
+
+[ModuleInit]
+public static void fso_register_function( TypeModule module )
+{
+    debug( "I am in your plugins registering your modules" );
+}
+
+	
+	
\ No newline at end of file
-- 
1.6.0.6

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Smartphones-userland mailing list
Smartphones-userland@linuxtogo.org
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/smartphones-userland

Reply via email to