diff options
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/accelerometers.c | 39 | ||||
-rw-r--r-- | src/accelerometers.h | 1 | ||||
-rw-r--r-- | src/main.c | 10 | ||||
-rw-r--r-- | src/mainwindow.c | 31 | ||||
-rw-r--r-- | src/physics.c | 57 | ||||
-rw-r--r-- | src/physics.h | 39 | ||||
-rw-r--r-- | src/types.h | 13 |
10 files changed, 53 insertions, 143 deletions
diff --git a/Makefile.am b/Makefile.am index 12f6b12..22c7450 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -EXTRA_DIST = configure src/mainwindow.h src/types.h src/accelerometers.h src/audio.h src/physics.h data/moo.wav \ +EXTRA_DIST = configure src/mainwindow.h src/types.h src/accelerometers.h src/physics.h data/moo.wav \ openmoocow.control data/cow.png data/icon.png data/openmoocow.desktop SUBDIRS = src data diff --git a/configure.ac b/configure.ac index a32c9c1..67820d3 100644 --- a/configure.ac +++ b/configure.ac @@ -41,7 +41,7 @@ else fi CFLAGS="$CFLAGS $GTK_CFLAGS $LIBSDL_CFLAGS" -LIBS="$LIBS $GTK_LIBS $LIBSDL_LIBS" +LIBS="$LIBS $GTK_LIBS $LIBSDL_LIBS -lgthread-2.0" AC_OUTPUT(Makefile src/Makefile data/Makefile) diff --git a/src/Makefile.am b/src/Makefile.am index e125111..f631315 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ bin_PROGRAMS = openmoocow -openmoocow_SOURCES = main.c mainwindow.c accelerometers.c audio.c physics.c +openmoocow_SOURCES = main.c mainwindow.c accelerometers.c audio.c openmoocow_LDADD = @LIBS@ moosynth_SOURCES = moosynth.c diff --git a/src/accelerometers.c b/src/accelerometers.c index 7d8b0f2..054e870 100644 --- a/src/accelerometers.c +++ b/src/accelerometers.c @@ -29,8 +29,10 @@ #include <stdio.h> #include <stdlib.h> #include <stdint.h> +#include <unistd.h> #include "types.h" +#include "audio.h" struct input_event { struct timeval time; @@ -143,3 +145,40 @@ void accelerometer_update(AccelHandle *accel) { } +/* The accelerometer work thread */ +static void *accel_work(void *data) { + + AccelHandle *accel; + AudioContext *audio; + int pos = 0; + + accel = accelerometer_open(); + audio = audio_setup(); + + while ( 1 ) { + + accelerometer_update(accel); + + if ( accel->lval > 1000 ) pos = 1000; + if ( (accel->lval < -1000) && (pos == 1000) ) { + pos = 0; + audio_trigger_moo(audio); + } + + usleep(250000); + } + + audio_shutdown(audio); + + return NULL; + +} + +void accelerometer_start() { + + GThread *work_thread; + + work_thread = g_thread_create(accel_work, NULL, TRUE, NULL); + +} + diff --git a/src/accelerometers.h b/src/accelerometers.h index f83149a..602dd1e 100644 --- a/src/accelerometers.h +++ b/src/accelerometers.h @@ -33,6 +33,7 @@ extern AccelHandle *accelerometer_open(void); extern void accelerometer_update(AccelHandle *accel); +extern void accelerometer_start(void); #endif /* ACCELEROMETERS_H */ @@ -30,16 +30,26 @@ #include <stdlib.h> #include <stdarg.h> #include <stdio.h> +#include <glib.h> #include "types.h" #include "mainwindow.h" +#include "accelerometers.h" int main(int argc, char *argv[]) { MainWindow *mw; gtk_init(&argc, &argv); + g_thread_init(NULL); + + /* Start the accelerometer thread */ + accelerometer_start(); + + /* Open the window */ mw = mainwindow_open(); + + /* Wait "forever" */ if ( mw != NULL ) { gtk_main(); } diff --git a/src/mainwindow.c b/src/mainwindow.c index 8c2b256..f226049 100644 --- a/src/mainwindow.c +++ b/src/mainwindow.c @@ -28,33 +28,10 @@ #include <gtk/gtk.h> #include <stdlib.h> -#include <stdarg.h> -#include <stdio.h> -#include <math.h> #include "types.h" -#include "accelerometers.h" -#include "audio.h" -#include "physics.h" - -static gboolean mainwindow_timeout(gpointer data) { - - MainWindow *mw = data; - - accelerometer_update(mw->accel); - - physics_update(mw->physics, mw->accel->lval); - if ( mw->physics->moo ) { - audio_trigger_moo(mw->audio); - mw->physics->moo = 0; - } - - return TRUE; /* Call back again */ - -} static gint mainwindow_closed(GtkWidget *widget, MainWindow *mw) { - audio_shutdown(mw->audio); gtk_exit(0); return 0; } @@ -62,7 +39,6 @@ static gint mainwindow_closed(GtkWidget *widget, MainWindow *mw) { MainWindow *mainwindow_open(void) { MainWindow *mw; - GtkWidget *label; mw = malloc(sizeof(*mw)); if ( mw == NULL ) return NULL; @@ -74,13 +50,6 @@ MainWindow *mainwindow_open(void) { mw->cow = gtk_image_new_from_file(PIXMAPDIR"/cow.png"); gtk_container_add(GTK_CONTAINER(mw->window), mw->cow); - mw->accel = accelerometer_open(); - mw->accel_timeout = g_timeout_add(10, mainwindow_timeout, mw); - accelerometer_update(mw->accel); - - mw->audio = audio_setup(); - mw->physics = physics_setup(); - g_signal_connect(G_OBJECT(mw->window), "destroy", G_CALLBACK(mainwindow_closed), mw); gtk_widget_show_all(mw->window); diff --git a/src/physics.c b/src/physics.c deleted file mode 100644 index 40aca38..0000000 --- a/src/physics.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * physics.c - * - * Moobox physics simulation - * - * (c) 2008 Thomas White <taw27@srcf.ucam.org> - * - * This file is part of OpenMooCow - accelerometer moobox simulator - * - * OpenMooCow 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, either version 3 of the License, or - * (at your option) any later version. - * - * OpenMooCow 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 OpenMooCow. If not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdlib.h> - -#include "types.h" - -PhysicsContext *physics_setup() { - - PhysicsContext *ctx; - - ctx = malloc(sizeof(PhysicsContext)); - if ( ctx == NULL ) return NULL; - - ctx->pos = 0; - ctx->moo = 0; - - return ctx; - -} - -/* lval = acceleration upwards in cm/s/s */ -void physics_update(PhysicsContext *ctx, int lval) { - - if ( lval > 1000 ) ctx->pos = 1000; - if ( (lval < -1000) && (ctx->pos == 1000) ) { - ctx->pos = 0; - ctx->moo = 1; - } - -} - diff --git a/src/physics.h b/src/physics.h deleted file mode 100644 index 07b89aa..0000000 --- a/src/physics.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * physics.h - * - * Moobox physics simulation - * - * (c) 2008 Thomas White <taw27@srcf.ucam.org> - * - * This file is part of OpenMooCow - accelerometer moobox simulator - * - * OpenMooCow 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, either version 3 of the License, or - * (at your option) any later version. - * - * OpenMooCow 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 OpenMooCow. If not, see <http://www.gnu.org/licenses/>. - * - */ - -#ifndef PHYSICS_H -#define PHYSICS_H - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "types.h" - -extern PhysicsContext *physics_setup(void); -extern void physics_update(PhysicsContext *ctx, int lval); - - -#endif /* PHYSICS_H */ - diff --git a/src/types.h b/src/types.h index d4a2f62..3ed2873 100644 --- a/src/types.h +++ b/src/types.h @@ -65,13 +65,6 @@ typedef struct { typedef struct { - int pos; /* Slider position, 0=bottom, 1000=top */ - int moo; - -} PhysicsContext; - -typedef struct { - GtkWidget *window; GtkWidget *notebook; GtkWidget *acceldata; @@ -85,12 +78,6 @@ typedef struct { GtkWidget *bz; GtkWidget *moo; - AccelHandle *accel; - guint accel_timeout; - - AudioContext *audio; - PhysicsContext *physics; - } MainWindow; #endif /* TYPES_H */ |