Introducing a plug-in for the Nokia N900 (untested)

This commit is contained in:
Pierre Pronchery 2011-08-18 02:40:36 +00:00
parent 5a3b1b052d
commit f7cf632a17
4 changed files with 152 additions and 4 deletions

View File

@ -100,6 +100,7 @@ dist:
$(PACKAGE)-$(VERSION)/src/plugins/engineering.c \
$(PACKAGE)-$(VERSION)/src/plugins/gprs.c \
$(PACKAGE)-$(VERSION)/src/plugins/locker.c \
$(PACKAGE)-$(VERSION)/src/plugins/n900.c \
$(PACKAGE)-$(VERSION)/src/plugins/openmoko.c \
$(PACKAGE)-$(VERSION)/src/plugins/oss.c \
$(PACKAGE)-$(VERSION)/src/plugins/panel.c \

View File

@ -1,5 +1,5 @@
SUBDIRS = 16x16 24x24 32x32 48x48
TARGETS = blacklist.so debug.so engineering.so gprs.so locker.so openmoko.so oss.so panel.so profiles.so smscrypt.so
TARGETS = blacklist.so debug.so engineering.so gprs.so locker.so n900.so openmoko.so oss.so panel.so profiles.so smscrypt.so
PREFIX = /usr/local
DESTDIR =
LIBDIR = $(PREFIX)/lib
@ -57,6 +57,13 @@ locker_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
locker.so: $(locker_OBJS)
$(LD) -o locker.so $(locker_OBJS) $(locker_LDFLAGS)
n900_OBJS = n900.o
n900_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
n900_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
n900.so: $(n900_OBJS)
$(LD) -o n900.so $(n900_OBJS) $(n900_LDFLAGS)
openmoko_OBJS = openmoko.o
openmoko_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) -I../modems $(CFLAGSF) $(CFLAGS) `pkg-config --cflags alsa`
openmoko_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) `pkg-config --libs alsa`
@ -107,6 +114,9 @@ gprs.o: gprs.c ../../include/Phone.h
locker.o: locker.c ../../include/Phone.h
$(CC) $(locker_CFLAGS) -c locker.c
n900.o: n900.c ../../include/Phone.h
$(CC) $(n900_CFLAGS) -c n900.c
openmoko.o: openmoko.c ../../include/Phone.h
$(CC) $(openmoko_CFLAGS) -c openmoko.c
@ -124,11 +134,11 @@ smscrypt.o: smscrypt.c ../../include/Phone.h
clean:
@for i in $(SUBDIRS); do (cd $$i && $(MAKE) clean) || exit; done
$(RM) -- $(blacklist_OBJS) $(debug_OBJS) $(engineering_OBJS) $(gprs_OBJS) $(locker_OBJS) $(openmoko_OBJS) $(oss_OBJS) $(panel_OBJS) $(profiles_OBJS) $(smscrypt_OBJS)
$(RM) -- $(blacklist_OBJS) $(debug_OBJS) $(engineering_OBJS) $(gprs_OBJS) $(locker_OBJS) $(n900_OBJS) $(openmoko_OBJS) $(oss_OBJS) $(panel_OBJS) $(profiles_OBJS) $(smscrypt_OBJS)
distclean:
@for i in $(SUBDIRS); do (cd $$i && $(MAKE) distclean) || exit; done
$(RM) -- $(blacklist_OBJS) $(debug_OBJS) $(engineering_OBJS) $(gprs_OBJS) $(locker_OBJS) $(openmoko_OBJS) $(oss_OBJS) $(panel_OBJS) $(profiles_OBJS) $(smscrypt_OBJS)
$(RM) -- $(blacklist_OBJS) $(debug_OBJS) $(engineering_OBJS) $(gprs_OBJS) $(locker_OBJS) $(n900_OBJS) $(openmoko_OBJS) $(oss_OBJS) $(panel_OBJS) $(profiles_OBJS) $(smscrypt_OBJS)
$(RM) -- $(TARGETS)
install: $(TARGETS)
@ -144,6 +154,8 @@ install: $(TARGETS)
$(MKDIR) $(DESTDIR)$(LIBDIR)/Phone/plugins
$(INSTALL) -m 0644 -- locker.so $(DESTDIR)$(LIBDIR)/Phone/plugins/locker.so
$(MKDIR) $(DESTDIR)$(LIBDIR)/Phone/plugins
$(INSTALL) -m 0644 -- n900.so $(DESTDIR)$(LIBDIR)/Phone/plugins/n900.so
$(MKDIR) $(DESTDIR)$(LIBDIR)/Phone/plugins
$(INSTALL) -m 0644 -- openmoko.so $(DESTDIR)$(LIBDIR)/Phone/plugins/openmoko.so
$(MKDIR) $(DESTDIR)$(LIBDIR)/Phone/plugins
$(INSTALL) -m 0644 -- panel.so $(DESTDIR)$(LIBDIR)/Phone/plugins/panel.so
@ -159,6 +171,7 @@ uninstall:
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/engineering.so
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/gprs.so
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/locker.so
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/n900.so
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/openmoko.so
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/panel.so
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/profiles.so

126
src/plugins/n900.c Normal file
View File

@ -0,0 +1,126 @@
/* $Id$ */
/* Copyright (c) 2011 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Desktop Phone */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* This code is inspired by existing work by Sebastian Reichel <sre@debian.org>,
* see https://elektranox.org/n900/libisi */
/* TODO:
* - test on actual hardware */
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <gtk/gtk.h>
#include <System.h>
#include "Phone.h"
/* N900 */
/* prototypes */
/* plug-in */
static int _n900_event(PhonePlugin * plugin, PhoneEvent * event);
/* public */
/* variables */
PhonePlugin plugin =
{
NULL,
"Nokia N900",
NULL,
NULL,
NULL,
_n900_event,
NULL,
NULL
};
/* private */
/* n900_event */
static int _event_power_on(PhonePlugin * plugin, gboolean power);
static int _n900_event(PhonePlugin * plugin, PhoneEvent * event)
{
switch(event->type)
{
case PHONE_EVENT_TYPE_OFFLINE:
_event_power_on(plugin, FALSE);
break;
case PHONE_EVENT_TYPE_ONLINE:
_event_power_on(plugin, TRUE);
break;
default:
break;
}
return 0;
}
static int _event_power_on(PhonePlugin * plugin, gboolean power)
{
int ret = 0;
char const root[] = "/sys/devices/platform/gpio-switch";
struct
{
char const * name;
int enable;
int disable;
unsigned int delay;
} commands[] = {
{ "cmt_apeslpx", 0, 0, 0 },
{ "cmt_rst_rq", 0, 0, 0 },
{ "cmt_bsi", 0, -1, 0 },
{ "cmt_rst", 0, 0, 0 },
{ "cmt_en", 1, 0, 0 },
{ "cmt_rst", 1, 1, 0 },
{ "cmt_rst_eq", 1, -1, 0 },
{ "cmt_en", 1, -1, 5 },
};
size_t i;
int fd;
char path[256];
char buf[256];
int len;
for(i = 0; i < sizeof(commands) / sizeof(*commands) && ret == 0; i++)
{
if((power ? commands[i].enable : commands[i].disable) < 0)
continue;
if(commands[i].delay > 0)
/* FIXME freezes the application for as long */
sleep(commands[i].delay);
snprintf(path, sizeof(path), "%s/%s/%s", root, commands[i].name,
"state");
if((fd = open(path, O_WRONLY)) < 0)
{
snprintf(buf, sizeof(buf), "%s: %s", path, strerror(
errno));
ret = plugin->helper->error(NULL, buf, 1);
break;
}
len = snprintf(buf, sizeof(buf), "%s", power ? "active"
: "inactive");
if(write(fd, buf, len) != len)
{
snprintf(buf, sizeof(buf), "%s: %s", path,
strerror(errno));
ret = plugin->helper->error(NULL, buf, 1);
}
close(fd);
}
return ret;
}

View File

@ -1,5 +1,5 @@
subdirs=16x16,24x24,32x32,48x48
targets=blacklist,debug,engineering,gprs,locker,openmoko,oss,panel,profiles,smscrypt
targets=blacklist,debug,engineering,gprs,locker,n900,openmoko,oss,panel,profiles,smscrypt
cppflags_force=-I ../../include
cppflags=
cflags_force=-W `pkg-config --cflags libSystem gtk+-2.0`
@ -46,6 +46,14 @@ install=$(LIBDIR)/Phone/plugins
[locker.c]
depends=../../include/Phone.h
[n900]
type=plugin
sources=n900.c
install=$(LIBDIR)/Phone/plugins
[n900.c]
depends=../../include/Phone.h
[openmoko]
type=plugin
sources=openmoko.c