Added code to set the volume level on Linux (untested)
This commit is contained in:
parent
6c68560f52
commit
5459f4ddaf
@ -40,18 +40,18 @@ engineering.so: $(engineering_OBJS)
|
|||||||
$(LD) -o engineering.so $(engineering_OBJS)
|
$(LD) -o engineering.so $(engineering_OBJS)
|
||||||
|
|
||||||
openmoko_OBJS = openmoko.o
|
openmoko_OBJS = openmoko.o
|
||||||
openmoko_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
openmoko_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) `pkg-config --cflags alsa`
|
||||||
openmoko_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
openmoko_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) `pkg-config --libs alsa`
|
||||||
|
|
||||||
openmoko.so: $(openmoko_OBJS)
|
openmoko.so: $(openmoko_OBJS)
|
||||||
$(LD) -o openmoko.so $(openmoko_OBJS)
|
$(LD) -o openmoko.so $(openmoko_OBJS) `pkg-config --libs alsa`
|
||||||
|
|
||||||
oss_OBJS = oss.o
|
oss_OBJS = oss.o
|
||||||
oss_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
oss_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||||
oss_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) -lossaudio
|
oss_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||||
|
|
||||||
oss.so: $(oss_OBJS)
|
oss.so: $(oss_OBJS)
|
||||||
$(LD) -o oss.so $(oss_OBJS) -lossaudio
|
$(LD) -o oss.so $(oss_OBJS)
|
||||||
|
|
||||||
panel_OBJS = panel.o
|
panel_OBJS = panel.o
|
||||||
panel_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
panel_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||||
@ -114,8 +114,6 @@ install: all
|
|||||||
$(MKDIR) $(DESTDIR)$(LIBDIR)/Phone/plugins
|
$(MKDIR) $(DESTDIR)$(LIBDIR)/Phone/plugins
|
||||||
$(INSTALL) -m 0644 -- openmoko.so $(DESTDIR)$(LIBDIR)/Phone/plugins/openmoko.so
|
$(INSTALL) -m 0644 -- openmoko.so $(DESTDIR)$(LIBDIR)/Phone/plugins/openmoko.so
|
||||||
$(MKDIR) $(DESTDIR)$(LIBDIR)/Phone/plugins
|
$(MKDIR) $(DESTDIR)$(LIBDIR)/Phone/plugins
|
||||||
$(INSTALL) -m 0644 -- oss.so $(DESTDIR)$(LIBDIR)/Phone/plugins/oss.so
|
|
||||||
$(MKDIR) $(DESTDIR)$(LIBDIR)/Phone/plugins
|
|
||||||
$(INSTALL) -m 0644 -- panel.so $(DESTDIR)$(LIBDIR)/Phone/plugins/panel.so
|
$(INSTALL) -m 0644 -- panel.so $(DESTDIR)$(LIBDIR)/Phone/plugins/panel.so
|
||||||
$(MKDIR) $(DESTDIR)$(LIBDIR)/Phone/plugins
|
$(MKDIR) $(DESTDIR)$(LIBDIR)/Phone/plugins
|
||||||
$(INSTALL) -m 0644 -- profiles.so $(DESTDIR)$(LIBDIR)/Phone/plugins/profiles.so
|
$(INSTALL) -m 0644 -- profiles.so $(DESTDIR)$(LIBDIR)/Phone/plugins/profiles.so
|
||||||
@ -127,7 +125,6 @@ uninstall:
|
|||||||
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/debug.so
|
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/debug.so
|
||||||
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/engineering.so
|
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/engineering.so
|
||||||
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/openmoko.so
|
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/openmoko.so
|
||||||
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/oss.so
|
|
||||||
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/panel.so
|
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/panel.so
|
||||||
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/profiles.so
|
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/profiles.so
|
||||||
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/smscrypt.so
|
$(RM) -- $(DESTDIR)$(LIBDIR)/Phone/plugins/smscrypt.so
|
||||||
|
@ -21,12 +21,16 @@
|
|||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <System.h>
|
#include <System.h>
|
||||||
|
#ifdef __linux__
|
||||||
|
# include <alsa/asoundlib.h>
|
||||||
|
#endif
|
||||||
#include "Phone.h"
|
#include "Phone.h"
|
||||||
#include "../../config.h"
|
#include "../../config.h"
|
||||||
|
|
||||||
@ -48,16 +52,26 @@ typedef struct _Openmoko
|
|||||||
{
|
{
|
||||||
GtkWidget * window;
|
GtkWidget * window;
|
||||||
GtkWidget * deepsleep;
|
GtkWidget * deepsleep;
|
||||||
|
#ifdef __linux__
|
||||||
|
|
||||||
|
/* alsa support */
|
||||||
|
snd_mixer_t * mixer;
|
||||||
|
snd_mixer_elem_t * mixer_elem;
|
||||||
|
#endif
|
||||||
} Openmoko;
|
} Openmoko;
|
||||||
|
|
||||||
|
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
|
/* plugins */
|
||||||
static int _openmoko_init(PhonePlugin * plugin);
|
static int _openmoko_init(PhonePlugin * plugin);
|
||||||
static int _openmoko_destroy(PhonePlugin * plugin);
|
static int _openmoko_destroy(PhonePlugin * plugin);
|
||||||
static int _openmoko_event(PhonePlugin * plugin, PhoneEvent event, ...);
|
static int _openmoko_event(PhonePlugin * plugin, PhoneEvent event, ...);
|
||||||
static void _openmoko_deepsleep(PhonePlugin * plugin);
|
static void _openmoko_deepsleep(PhonePlugin * plugin);
|
||||||
static void _openmoko_settings(PhonePlugin * plugin);
|
static void _openmoko_settings(PhonePlugin * plugin);
|
||||||
|
|
||||||
|
static int _openmoko_mixer_open(PhonePlugin * plugin);
|
||||||
|
static int _openmoko_mixer_close(PhonePlugin * plugin);
|
||||||
|
|
||||||
|
|
||||||
/* public */
|
/* public */
|
||||||
/* variables */
|
/* variables */
|
||||||
@ -85,6 +99,7 @@ static int _openmoko_init(PhonePlugin * plugin)
|
|||||||
return 1;
|
return 1;
|
||||||
plugin->priv = openmoko;
|
plugin->priv = openmoko;
|
||||||
openmoko->window = NULL;
|
openmoko->window = NULL;
|
||||||
|
_openmoko_mixer_open(plugin);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,6 +109,7 @@ static int _openmoko_destroy(PhonePlugin * plugin)
|
|||||||
{
|
{
|
||||||
Openmoko * openmoko = plugin->priv;
|
Openmoko * openmoko = plugin->priv;
|
||||||
|
|
||||||
|
_openmoko_mixer_close(plugin);
|
||||||
if(openmoko->window != NULL)
|
if(openmoko->window != NULL)
|
||||||
gtk_widget_destroy(openmoko->window);
|
gtk_widget_destroy(openmoko->window);
|
||||||
free(openmoko);
|
free(openmoko);
|
||||||
@ -105,9 +121,13 @@ static int _openmoko_destroy(PhonePlugin * plugin)
|
|||||||
static int _event_mixer_set(PhonePlugin * plugin, char const * filename);
|
static int _event_mixer_set(PhonePlugin * plugin, char const * filename);
|
||||||
static int _event_power_on(PhonePlugin * plugin, gboolean power);
|
static int _event_power_on(PhonePlugin * plugin, gboolean power);
|
||||||
static int _event_vibrator(PhonePlugin * plugin, gboolean vibrate);
|
static int _event_vibrator(PhonePlugin * plugin, gboolean vibrate);
|
||||||
|
static int _event_volume_set(PhonePlugin * plugin, gdouble level);
|
||||||
|
|
||||||
static int _openmoko_event(PhonePlugin * plugin, PhoneEvent event, ...)
|
static int _openmoko_event(PhonePlugin * plugin, PhoneEvent event, ...)
|
||||||
{
|
{
|
||||||
|
va_list ap;
|
||||||
|
gdouble level;
|
||||||
|
|
||||||
switch(event)
|
switch(event)
|
||||||
{
|
{
|
||||||
case PHONE_EVENT_CALL_ESTABLISHED:
|
case PHONE_EVENT_CALL_ESTABLISHED:
|
||||||
@ -144,6 +164,12 @@ static int _openmoko_event(PhonePlugin * plugin, PhoneEvent event, ...)
|
|||||||
case PHONE_EVENT_ONLINE:
|
case PHONE_EVENT_ONLINE:
|
||||||
_event_power_on(plugin, TRUE);
|
_event_power_on(plugin, TRUE);
|
||||||
break;
|
break;
|
||||||
|
case PHONE_EVENT_SET_VOLUME:
|
||||||
|
va_start(ap, event);
|
||||||
|
level = va_arg(ap, gdouble);
|
||||||
|
va_end(ap);
|
||||||
|
_event_volume_set(plugin, level);
|
||||||
|
break;
|
||||||
case PHONE_EVENT_SPEAKER_ON:
|
case PHONE_EVENT_SPEAKER_ON:
|
||||||
/* XXX assumes there's an ongoing call */
|
/* XXX assumes there's an ongoing call */
|
||||||
_event_mixer_set(plugin, "gsmspeakerout.state");
|
_event_mixer_set(plugin, "gsmspeakerout.state");
|
||||||
@ -238,6 +264,18 @@ static int _event_vibrator(PhonePlugin * plugin, gboolean vibrate)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int _event_volume_set(PhonePlugin * plugin, gdouble level)
|
||||||
|
{
|
||||||
|
#ifdef __linux__
|
||||||
|
Openmoko * openmoko = plugin->priv;
|
||||||
|
|
||||||
|
if(openmoko->mixer_elem == NULL)
|
||||||
|
return 0;
|
||||||
|
snd_mixer_selem_set_playback_volume_all(openmoko->mixer_elem, level);
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* openmoko_deepsleep */
|
/* openmoko_deepsleep */
|
||||||
static void _openmoko_deepsleep(PhonePlugin * plugin)
|
static void _openmoko_deepsleep(PhonePlugin * plugin)
|
||||||
@ -255,6 +293,64 @@ static void _openmoko_deepsleep(PhonePlugin * plugin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* openmoko_mixer_close */
|
||||||
|
static int _openmoko_mixer_close(PhonePlugin * plugin)
|
||||||
|
{
|
||||||
|
#ifdef __linux__
|
||||||
|
Openmoko * openmoko = plugin->priv;
|
||||||
|
|
||||||
|
openmoko->mixer_elem = NULL;
|
||||||
|
if(openmoko->mixer != NULL)
|
||||||
|
snd_mixer_close(openmoko->mixer);
|
||||||
|
openmoko->mixer = NULL;
|
||||||
|
#endif /* __linux__ */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* openmoko_mixer_open */
|
||||||
|
static int _openmoko_mixer_open(PhonePlugin * plugin)
|
||||||
|
{
|
||||||
|
#ifdef __linux__
|
||||||
|
Openmoko * openmoko = plugin->priv;
|
||||||
|
char const * audio_device;
|
||||||
|
char const * audio_control;
|
||||||
|
snd_mixer_elem_t * elem;
|
||||||
|
|
||||||
|
openmoko->mixer_elem = NULL;
|
||||||
|
if((audio_device = plugin->helper->config_get(plugin->helper->phone,
|
||||||
|
"openmoko", "audio_device")) == NULL)
|
||||||
|
audio_device = "neo1973-gta02";
|
||||||
|
if((audio_control = plugin->helper->config_get(plugin->helper->phone,
|
||||||
|
"openmoko", "audio_control")) == NULL)
|
||||||
|
audio_control = "Speaker";
|
||||||
|
if(snd_mixer_open(&openmoko->mixer, 0) != 0)
|
||||||
|
{
|
||||||
|
openmoko->mixer = NULL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if(snd_mixer_attach(openmoko->mixer, audio_device) != 0
|
||||||
|
|| snd_mixer_selem_register(openmoko->mixer, NULL, NULL)
|
||||||
|
|| snd_mixer_load(openmoko->mixer) != 0)
|
||||||
|
{
|
||||||
|
_openmoko_mixer_close(plugin);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
for(elem = snd_mixer_first_elem(openmoko->mixer); elem != NULL;
|
||||||
|
elem = snd_mixer_elem_next(elem))
|
||||||
|
if(strcmp(snd_mixer_selem_get_name(elem), audio_control) == 0)
|
||||||
|
break;
|
||||||
|
if(elem == NULL)
|
||||||
|
{
|
||||||
|
_openmoko_mixer_close(plugin);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
openmoko->mixer_elem = elem;
|
||||||
|
#endif /* __linux__ */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* openmoko_settings */
|
/* openmoko_settings */
|
||||||
static void _on_settings_cancel(gpointer data);
|
static void _on_settings_cancel(gpointer data);
|
||||||
static gboolean _on_settings_closex(gpointer data);
|
static gboolean _on_settings_closex(gpointer data);
|
||||||
@ -326,9 +422,8 @@ static void _on_settings_cancel(gpointer data)
|
|||||||
static gboolean _on_settings_closex(gpointer data)
|
static gboolean _on_settings_closex(gpointer data)
|
||||||
{
|
{
|
||||||
PhonePlugin * plugin = data;
|
PhonePlugin * plugin = data;
|
||||||
Openmoko * openmoko = plugin->priv;
|
|
||||||
|
|
||||||
gtk_widget_hide(openmoko->window);
|
_on_settings_cancel(plugin);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@ depends=../../include/Phone.h
|
|||||||
[openmoko]
|
[openmoko]
|
||||||
type=plugin
|
type=plugin
|
||||||
sources=openmoko.c
|
sources=openmoko.c
|
||||||
|
cflags=`pkg-config --cflags alsa`
|
||||||
|
ldflags=`pkg-config --libs alsa`
|
||||||
install=$(LIBDIR)/Phone/plugins
|
install=$(LIBDIR)/Phone/plugins
|
||||||
|
|
||||||
[openmoko.c]
|
[openmoko.c]
|
||||||
@ -40,8 +42,7 @@ depends=../../include/Phone.h
|
|||||||
[oss]
|
[oss]
|
||||||
type=plugin
|
type=plugin
|
||||||
sources=oss.c
|
sources=oss.c
|
||||||
ldflags=-lossaudio
|
#ldflags=-lossaudio
|
||||||
install=$(LIBDIR)/Phone/plugins
|
|
||||||
|
|
||||||
[oss.c]
|
[oss.c]
|
||||||
depends=../../include/Phone.h
|
depends=../../include/Phone.h
|
||||||
|
Loading…
Reference in New Issue
Block a user