Added support for Linux on the Openmoko Freerunner
This commit is contained in:
parent
a4bb2e501a
commit
67cfb24e77
|
@ -15,7 +15,7 @@
|
|||
|
||||
|
||||
|
||||
#ifdef __NetBSD__
|
||||
#if defined(__NetBSD__)
|
||||
# include <sys/types.h>
|
||||
# include <sys/ioctl.h>
|
||||
# include <bluetooth.h>
|
||||
|
@ -23,6 +23,11 @@
|
|||
# include <stdio.h>
|
||||
# include <string.h>
|
||||
# include <errno.h>
|
||||
#elif defined(__Linux__)
|
||||
# include <fcntl.h>
|
||||
# include <unistd.h>
|
||||
# include <string.h>
|
||||
# include <errno.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <System.h>
|
||||
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user