From 67cfb24e77b8b957f64ae2eb8bb912e88a064733 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Wed, 27 Jan 2010 14:22:39 +0000 Subject: [PATCH] Added support for Linux on the Openmoko Freerunner --- src/applets/bluetooth.c | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/applets/bluetooth.c b/src/applets/bluetooth.c index bb8b0dd..493a0fe 100644 --- a/src/applets/bluetooth.c +++ b/src/applets/bluetooth.c @@ -15,7 +15,7 @@ -#ifdef __NetBSD__ +#if defined(__NetBSD__) # include # include # include @@ -23,6 +23,11 @@ # include # include # include +#elif defined(__Linux__) +# include +# include +# include +# include #endif #include #include @@ -37,7 +42,7 @@ typedef struct _Bluetooth PanelAppletHelper * helper; GtkWidget * image; guint timeout; -#ifdef __NetBSD__ +#if defined(__NetBSD__) || defined(__Linux__) int fd; #endif } Bluetooth; @@ -80,7 +85,7 @@ static GtkWidget * _bluetooth_init(PanelApplet * applet) applet->priv = bluetooth; bluetooth->helper = applet->helper; bluetooth->timeout = 0; -#ifdef __NetBSD__ +#if defined(__NetBSD__) || defined(__Linux__) bluetooth->fd = -1; #endif bluetooth->image = gtk_image_new_from_icon_name("network-wireless", @@ -98,7 +103,7 @@ static void _bluetooth_destroy(PanelApplet * applet) if(bluetooth->timeout > 0) g_source_remove(bluetooth->timeout); -#ifdef __NetBSD__ +#if defined(__NetBSD__) || defined(__Linux__) if(bluetooth->fd != -1) close(bluetooth->fd); #endif @@ -118,7 +123,7 @@ static void _bluetooth_set(Bluetooth * bluetooth, gboolean on) /* callbacks */ /* on_timeout */ -#ifdef __NetBSD__ +#if defined(__NetBSD__) static gboolean _bluetooth_get(Bluetooth * bluetooth) { struct btreq btr; @@ -144,6 +149,29 @@ static gboolean _bluetooth_get(Bluetooth * bluetooth) bluetooth->fd = -1; return TRUE; } +#elif defined(__Linux__) +static gboolean _bluetooth_get(Bluetooth * bluetooth) +{ + /* XXX currently hard-coded for the Openmoko Freerunner */ + const char dev[] = "/sys/bus/platform/devices/neo1973-pm-bt.0/power_on"; + char on; + + if(bluetooth->fd == -1 && (bluetooth->fd = open(dev, O_RDONLY)) == -1) + { + error_set("%s: %s", dev, strerror(errno)); + return FALSE; + } + errno = ENODATA; /* in case the pseudo-file is empty */ + if(lseek(bluetooth->fd, 0, SEEK_SET) != 0 + || read(bluetooth->fd, &on, sizeof(on)) != 1) + { + error_set("%s: %s", dev, strerror(errno)); + close(bluetooth->fd); + bluetooth->fd = -1; + return FALSE; + } + return (on == '1') ? TRUE : FALSE; +} #else static gboolean _bluetooth_get(Bluetooth * bluetooth) {