aboutsummaryrefslogtreecommitdiffstats
path: root/fsodeviced
diff options
context:
space:
mode:
authorMichael 'Mickey' Lauer <mickey@vanille-media.de>2009-04-09 00:17:04 +0200
committerMichael 'Mickey' Lauer <mickey@vanille-media.de>2009-04-09 00:17:04 +0200
commit8ac2650299b6cf21fef67966871aca93225ff393 (patch)
tree6ab6fc1b91824f976c1c5b4a404c42a2fe08e2f6 /fsodeviced
parentde740627c94869b047b5ba6dcd870942428f9985 (diff)
downloadcornucopia-8ac2650299b6cf21fef67966871aca93225ff393.tar.gz
cornucopia-8ac2650299b6cf21fef67966871aca93225ff393.tar.bz2
cornucopia-8ac2650299b6cf21fef67966871aca93225ff393.zip
fsodevice: kernel26_display: overhaul
* fix API semantics (we're using percentages, not absolute values) * get rid of display-helpers and use Posix.ioctl instead
Diffstat (limited to 'fsodeviced')
-rw-r--r--fsodeviced/src/plugins/kernel26_display/Makefile.am5
-rw-r--r--fsodeviced/src/plugins/kernel26_display/display-helpers.c38
-rw-r--r--fsodeviced/src/plugins/kernel26_display/display-helpers.vapi4
-rw-r--r--fsodeviced/src/plugins/kernel26_display/plugin.vala204
-rw-r--r--fsodeviced/src/plugins/kernel26_leds/plugin.vala2
5 files changed, 112 insertions, 141 deletions
diff --git a/fsodeviced/src/plugins/kernel26_display/Makefile.am b/fsodeviced/src/plugins/kernel26_display/Makefile.am
index 40444f84..fc67dd62 100644
--- a/fsodeviced/src/plugins/kernel26_display/Makefile.am
+++ b/fsodeviced/src/plugins/kernel26_display/Makefile.am
@@ -16,15 +16,14 @@ VALAC_ARGS = \
--pkg glib-2.0 \
--pkg dbus-glib-1 \
--pkg fsoframework-2.0 \
- --vapidir ./ \
- --pkg display-helpers
+ --pkg posix
#
# plugin
#
modlibexecdir = $(libdir)/cornucopia/modules/fsodevice
modlibexec_LTLIBRARIES = kernel26_display.la
-kernel26_display_la_SOURCES = plugin.c plugin.h display.c
+kernel26_display_la_SOURCES = plugin.c plugin.h
kernel26_display_la_VALASOURCES = plugin.vala
$(kernel26_display_la_SOURCES): $(kernel26_display_la_VALASOURCES)
$(VALAC) -C $(VALAC_ARGS) $^
diff --git a/fsodeviced/src/plugins/kernel26_display/display-helpers.c b/fsodeviced/src/plugins/kernel26_display/display-helpers.c
deleted file mode 100644
index 0af614e5..00000000
--- a/fsodeviced/src/plugins/kernel26_display/display-helpers.c
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * display-helpers.c
- * Written by Sudharshan "Sup3rkiddo" S <sudharsh@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
deleted file mode 100644
index f68737b4..00000000
--- a/fsodeviced/src/plugins/kernel26_display/display-helpers.vapi
+++ /dev/null
@@ -1,4 +0,0 @@
-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
index 6f7c7709..ca60ca81 100644
--- a/fsodeviced/src/plugins/kernel26_display/plugin.vala
+++ b/fsodeviced/src/plugins/kernel26_display/plugin.vala
@@ -20,142 +20,156 @@
*/
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 ) );
+class Display : FsoFramework.Device.Display, FsoFramework.AbstractObject
+{
+ private FsoFramework.Subsystem subsystem;
+ static uint counter;
- this.subsystem = subsystem;
- this.sysfsnode = sysfsnode;
- this.max_brightness = FsoFramework.FileHandling.read(this.sysfsnode + "/max_brightness").to_int();
+ private int max_brightness;
+ private int current_brightness;
+ private string sysfsnode;
+ private int fb_fd = -1;
- 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);
- }
+ const int FBIOBLANK = 0x4611;
+ const int FB_BLANK_UNBLANK = 0;
+ const int FB_BLANK_POWERDOWN = 4;
+ public Display(FsoFramework.Subsystem subsystem, string sysfsnode)
+ {
+ this.subsystem = subsystem;
+ this.sysfsnode = sysfsnode;
+ this.max_brightness = FsoFramework.FileHandling.read( this.sysfsnode + "/max_brightness" ).to_int();
- subsystem.registerServiceName( FsoFramework.Device.ServiceDBusName );
- subsystem.registerServiceObject( FsoFramework.Device.ServiceDBusName,
- "%s/%u".printf( FsoFramework.Device.DisplayServicePath, counter++ ),
- this );
+ this.current_brightness = GetBrightness();
- }
+ fb_fd = Posix.open( dev_fb0, Posix.O_RDONLY );
+ if ( fb_fd == -1 )
+ logger.warning( "Can't open %s. Full display power control not available.".printf( dev_fb0 ) );
+ subsystem.registerServiceName( FsoFramework.Device.ServiceDBusName );
+ subsystem.registerServiceObject( FsoFramework.Device.ServiceDBusName,
+ "%s/%u".printf( FsoFramework.Device.DisplayServicePath, counter++ ),
+ this );
- public void SetBrightness(int brightness)
- {
- int value = GetBrightness();
+ logger.info( "Created new Display object, max brightness = %d".printf( max_brightness ) );
+ }
- 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;
- }
+ public override string repr()
+ {
+ return "<FsoFramework.Device.Display @ %s>".printf( this.sysfsnode );
+ }
- 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));
- }
+ private void _setBacklightPower( bool on )
+ {
+ if ( fb_fd != -1 )
+ Posix.ioctl( fb_fd, FBIOBLANK, on ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN );
+ }
+ private int _valueToPercent( int value )
+ {
+ double max = max_brightness;
+ double v = value;
+ return (int)(100.0 / max * v);
+ }
- public int GetBrightness()
- {
- return FsoFramework.FileHandling.read(this.sysfsnode + "/actual_brightness").to_int();
- }
+ private int _percentToValue( int percent )
+ {
+ double p = percent;
+ double max = max_brightness;
+ double value;
+ if ( percent >= 100 )
+ value = max_brightness;
+ else if ( percent <= 0 )
+ value = 0;
+ else
+ value = p / 100.0 * max;
+ return (int)value;
+ }
+ public void SetBrightness( int brightness )
+ {
+ var value = _percentToValue( brightness );
- public bool GetBacklightPower()
+ if ( current_brightness != value )
{
- return FsoFramework.FileHandling.read(this.sysfsnode + "/bl_power").to_int() == 0;
+ FsoFramework.FileHandling.write( value.to_string(), this.sysfsnode + "/brightness" );
+ if ( current_brightness == 0 ) // previously we were off
+ _setBacklightPower( true );
+ else if ( value == 0 ) // now we are off
+ _setBacklightPower( false );
+ current_brightness = value;
}
+ logger.debug( "Brightness set to %d".printf( brightness ) );
+ }
+ public int GetBrightness()
+ {
+ var value = FsoFramework.FileHandling.read( this.sysfsnode + "/actual_brightness" ).to_int();
+ return _valueToPercent( value );
+ }
- 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 bool GetBacklightPower()
+ {
+ return FsoFramework.FileHandling.read( this.sysfsnode + "/bl_power" ).to_int() == 0;
+ }
+ public void SetBacklightPower( bool power )
+ {
+ var value = power ? "0" : "1";
+ FsoFramework.FileHandling.write( value, this.sysfsnode + "/bl_power" );
+ }
- public HashTable<string, Value?> GetInfo()
+ public HashTable<string, Value?> GetInfo()
+ {
+ string _leaf;
+ var val = Value( typeof(string) );
+ HashTable<string, Value?> info_table = new HashTable<string, Value?>( str_hash, str_equal );
+ /* Just read all the files in the sysfs path and return it as a{ss} */
+ try
{
- 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)
{
- Dir dir = Dir.open (this.sysfsnode, 0);
- while ((_leaf = dir.read_name()) != null)
+ if( FileUtils.test (this.sysfsnode + "/" + _leaf, FileTest.IS_REGULAR) && _leaf != "uevent" )
{
- 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);
- }
+ 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;
}
-
+ catch ( GLib.Error error )
+ {
+ logger.warning( error.message );
+ }
+ return info_table;
}
-
}
+}
+static string dev_fb0;
+static string sys_class_backlight;
List<Kernel26.Display> instances;
-
public static string fso_factory_function( FsoFramework.Subsystem subsystem ) throws Error
{
+ // grab sysfs and dev paths
+ var config = FsoFramework.theMasterKeyFile();
+ var sysfs_root = config.stringValue( "cornucopia", "sysfs_root", "/sys" );
+ sys_class_backlight = "%s/class/backlight".printf( sysfs_root );
+ var dev_root = config.stringValue( "cornucopia", "dev_root", "/dev" );
+ dev_fb0 = "%s/fb0".printf( dev_root );
+
// scan sysfs path for leds
- Dir dir = Dir.open( Kernel26.SYS_CLASS_DISPLAY, 0 );
+ var dir = Dir.open( sys_class_backlight, 0 );
string entry = dir.read_name();
while ( entry != null )
{
- var filename = Path.build_filename( Kernel26.SYS_CLASS_DISPLAY, entry );
+ var filename = Path.build_filename( sys_class_backlight, entry );
instances.append( new Kernel26.Display( subsystem, filename ) );
entry = dir.read_name();
}
diff --git a/fsodeviced/src/plugins/kernel26_leds/plugin.vala b/fsodeviced/src/plugins/kernel26_leds/plugin.vala
index fccfb07f..4b8b193c 100644
--- a/fsodeviced/src/plugins/kernel26_leds/plugin.vala
+++ b/fsodeviced/src/plugins/kernel26_leds/plugin.vala
@@ -156,7 +156,7 @@ public static string fso_factory_function( FsoFramework.Subsystem subsystem ) th
[ModuleInit]
public static void fso_register_function( TypeModule module )
{
- debug( "yo" );
+ debug( "kernel26_leds fso_register_function()" );
}
/**