diff --git a/editor/Makefile b/editor/Makefile index 7b797c2..543f7df 100644 --- a/editor/Makefile +++ b/editor/Makefile @@ -1,15 +1,19 @@ -CC=gcc-4.4 -CFLAGS=-Wall -LINKER_FLAGS=-lglut -lGL -lGLU -export-dynamic -GTKLIBS=`pkg-config --cflags --libs gtk+-2.0 gtkglext-1.0 libglade-2.0 gmodule-export-2.0` -SRCDIR=src +CC = gcc-4.4 +CFLAGS = -Wall +LINKER_FLAGS = -lglut -lGL -lGLU -export-dynamic +CFLAGS += `pkg-config --cflags --libs gtk+-2.0 gtkglext-1.0 libglade-2.0 gmodule-export-2.0` + +CFLAGS += `libusb-config --cflags` +LINKER_FLAGS += `libusb-config --libs` all: - $(CC) $(CFLAGS) $(GTKLIBS) -c $(SRCDIR)/display.c - $(CC) $(CFLAGS) $(GTKLIBS) -c $(SRCDIR)/input.c - $(CC) $(CFLAGS) $(GTKLIBS) -c $(SRCDIR)/main.c + $(CC) $(CFLAGS) -c display.c + $(CC) $(CFLAGS) -c input.c + $(CC) $(CFLAGS) -c main.c + $(CC) $(CFLAGS) -c ../client/ledcube.c + $(CC) $(CFLAGS) -c ../client/opendevice.c - $(CC) $(CFLAGS) $(LINKER_FLAGS) $(GTKLIBS) -o ledcube-edit main.o display.o input.o + $(CC) $(CFLAGS) $(LINKER_FLAGS) -o ledcube-edit main.o display.o input.o ledcube.o opendevice.o chmod +x ledcube-edit #strip ledcube-edit @@ -17,4 +21,3 @@ clean: rm -f *.o rm -f gui rm -f ledcube-edit - diff --git a/editor/src/config.h b/editor/config.h similarity index 86% rename from editor/src/config.h rename to editor/config.h index 44f40b3..fc7128e 100644 --- a/editor/src/config.h +++ b/editor/config.h @@ -8,6 +8,12 @@ #define MOVE_SPEED 7 #define ZOOM_LEVEL 25 +// LEDCube constants +#define NOT_CONNECTED_ERROR -1 +#define DEVICE_NOT_FOUND_ERROR -2 + +#define SUCCESSFULLY_CONNECTED 1 + // Poor Man's enums #define TOP_ORIENTATION 0x01 #define SIDE_ORIENTATION 0x02 diff --git a/editor/src/display.c b/editor/display.c similarity index 100% rename from editor/src/display.c rename to editor/display.c diff --git a/editor/src/display.h b/editor/display.h similarity index 100% rename from editor/src/display.h rename to editor/display.h diff --git a/editor/src/event_callbacks.c b/editor/event_callbacks.c similarity index 71% rename from editor/src/event_callbacks.c rename to editor/event_callbacks.c index cfe49cc..4123dab 100644 --- a/editor/src/event_callbacks.c +++ b/editor/event_callbacks.c @@ -3,10 +3,45 @@ #include #include +#include + +#include "../firmware/globals.h" + #include "config.h" #include "input.h" #include "display.h" +extern int lc_setFrame(unsigned long); +extern int lc_setMode(int); +extern int lc_saveFrame(unsigned long, int, int); +extern int lc_init(void); +extern int lc_close(void); + + +// "Live" Mode. If a user clicks a LED, the frame needs to re-send to +// the LEDCube. +void on_change_led() { + int success = lc_init(); + if (success == SUCCESSFULLY_CONNECTED) { + // Reorder the frame array to a 32bit int? + unsigned long frame = 0; + gint i = 0; + for (i=0; i<27; ++i) { + frame |= (currentFrame[i] << i); + } + + // Send it to the cube + lc_setFrame(frame); + } +} + +// TODO: Make it work on the GUI (button etc.) +void on_change_mode(int newMode) { + lc_setMode(newMode); +} + + + void on_main_window_delete_event(GtkObject *object, gpointer userData) { gtk_main_quit(); } diff --git a/editor/src/input.c b/editor/input.c similarity index 90% rename from editor/src/input.c rename to editor/input.c index 2b58f91..e47c228 100644 --- a/editor/src/input.c +++ b/editor/input.c @@ -8,6 +8,9 @@ #include "input.h" #include "display.h" +#include "../firmware/globals.h" /* custom request numbers */ + +extern void lc_init(void); void moveCameraPosition(gfloat direction) { eyePos += direction; diff --git a/editor/src/input.h b/editor/input.h similarity index 100% rename from editor/src/input.h rename to editor/input.h diff --git a/editor/src/main.c b/editor/main.c similarity index 70% rename from editor/src/main.c rename to editor/main.c index c610d5f..6ac8ce4 100644 --- a/editor/src/main.c +++ b/editor/main.c @@ -37,8 +37,18 @@ GtkWidget *window, *drawingArea; gint currentFrame[27] = {0}; +void* connectToLEDCube(void) { + int ret = NULL; + while (ret == NULL || ret != SUCCESSFULLY_CONNECTED) { + ret = lc_init(); + g_print("connecting ..."); + sleep(3); + } +} + gint main(gint argc, gchar *argv[]) { GladeXML *xml; + GThread *connectThread; gtk_init(&argc, &argv); gdk_gl_init(&argc, &argv); @@ -61,10 +71,10 @@ gint main(gint argc, gchar *argv[]) { // Configure the OpenGL widget glConfig = gdk_gl_config_new_by_mode(GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH | GDK_GL_MODE_DOUBLE); if (glConfig == NULL) { - g_warning("EEE Double buffer not available, trying single buffer."); + g_warning("Double buffer not available, trying single buffer."); glConfig = gdk_gl_config_new_by_mode(GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH); if (glConfig == NULL) { - g_error("EEE Sorry, can't configure the OpenGL window. Giving up."); + g_error("Sorry, can't configure the OpenGL window. Giving up."); exit(1); } } @@ -78,9 +88,31 @@ gint main(gint argc, gchar *argv[]) { glade_xml_signal_autoconnect(xml); + if (g_thread_supported()) { + g_print("1"); + g_thread_init(NULL); + g_print("2"); + gdk_threads_init(); + g_print("3"); + } else { + g_error("Threads not supported, we die."); + exit(1); + } + + GError *error; + + g_thread_init(NULL); + if (connectThread = g_thread_create((GThreadFunc)connectToLEDCube, NULL, TRUE, &error) == NULL) { + g_error("Can't create the thread, we stop here."); + exit(1); + } + //g_thread_join(connectThread); + + g_print("asdf"); gtk_widget_show(window); gtk_main(); + lc_close(); return 0; } diff --git a/editor/src/main_gui.glade b/editor/main_gui.glade similarity index 100% rename from editor/src/main_gui.glade rename to editor/main_gui.glade