From bedbd1e4e66a95975dead917b3d468c72ad52e2b Mon Sep 17 00:00:00 2001 From: Aaron Mueller Date: Sun, 15 Jan 2012 03:35:36 +0100 Subject: [PATCH] Connect the 3D-Editor with the great client library. The editor is now an realtime tool for the LED-Cube! --- editor/config.h | 4 +++ editor/display.c | 26 ++++++++++++++---- editor/display.h | 4 +++ editor/input.c | 8 +++--- editor/main.c | 42 ++++++++++++++++++++--------- editor/main_gui.glade | 63 ++++++++++++++++++++++++++++++++++++------- 6 files changed, 115 insertions(+), 32 deletions(-) diff --git a/editor/config.h b/editor/config.h index fc7128e..614c7bf 100644 --- a/editor/config.h +++ b/editor/config.h @@ -38,6 +38,7 @@ extern GLUquadricObj *quadric; extern GdkGLConfig *glConfig; extern GdkGLWindow *glWindow; extern GdkGLContext *glContext; +extern GladeXML *xml; // Dimensions, positions extern gfloat light0Pos[]; @@ -45,5 +46,8 @@ extern gfloat light0Pos[]; // LED data extern gint currentFrame[27]; +// Connection +extern gboolean isCubeConnected; + #endif diff --git a/editor/display.c b/editor/display.c index 3e6b56b..122d017 100644 --- a/editor/display.c +++ b/editor/display.c @@ -3,10 +3,15 @@ #include #include #include +#include #include "config.h" #include "display.h" +#include "../firmware/globals.h" + +extern void lc_setMode(int); +extern void lc_setFrame(unsigned long); void drawLEDs(gint mode) { gint x, y, z; @@ -16,9 +21,9 @@ void drawLEDs(gint mode) { glRotatef(90, 2, 0, 0); } - for (z=-10; z<=10; z+=10) // Ebene - for (y=-10; y<=10; y+=10) // Zeile - for (x=-10; x<=10; x+=10) { // Spalte + for (z=10; z>=-10; z-=10) // Ebene + for (y=10; y>=-10; y-=10) // Zeile + for (x=10; x>=-10; x-=10) { // Spalte ledIndex++; if (mode == PICKING_MODE) { glColor3ub(0, 0, ledIndex*8); @@ -45,8 +50,8 @@ void drawLEDs(gint mode) { void drawWires() { gint x, y; - for (y=-10; y<=10; y+=10) - for (x=-10; x<=10; x+=10) { + for (y=10; y>=-10; y-=10) + for (x=10; x>=-10; x-=10) { glMaterialfv(GL_FRONT, GL_AMBIENT, ((x == 0 || y == 0) ? innerWireMaterial : wireMaterial)); // Front @@ -105,3 +110,14 @@ void display(gboolean onlyForPicking) { } } + +void displayCurrentFrame() { + int i; + unsigned long frame = 0; + for (i=0; i<27; ++i) { + if (currentFrame[i] == 1) frame |= (1 << i); + } + lc_setMode(MODE_ANIMATION_STOP); + lc_setFrame(frame); +} + diff --git a/editor/display.h b/editor/display.h index 4af3c5d..ee4586a 100644 --- a/editor/display.h +++ b/editor/display.h @@ -1,6 +1,7 @@ #ifndef _DISPLAY_H #define _DISPLAY_H +// OpenGL Cube void drawLEDs(gint mode); void drawWires(); @@ -8,5 +9,8 @@ void display(gboolean onlyForPicking); void setScene(); +// Hardware Cube +void displayCurrentFrame(); + #endif diff --git a/editor/input.c b/editor/input.c index e47c228..a68a851 100644 --- a/editor/input.c +++ b/editor/input.c @@ -3,14 +3,13 @@ #include #include #include +#include #include "config.h" #include "input.h" #include "display.h" -#include "../firmware/globals.h" /* custom request numbers */ - -extern void lc_init(void); +#include "../firmware/globals.h" void moveCameraPosition(gfloat direction) { eyePos += direction; @@ -34,8 +33,7 @@ void mouse(gint x, gint y) { glReadPixels(x, viewport[3]-y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, (void*)pixel); position = ((gint)pixel[2]/8)-1; // Selected LED - printf("%d\n", position); currentFrame[position] = currentFrame[position] == 0 ? 1 : 0; - printf("%d\n", currentFrame[position]); + displayCurrentFrame(); } diff --git a/editor/main.c b/editor/main.c index 367eb7a..d91c9e3 100644 --- a/editor/main.c +++ b/editor/main.c @@ -32,22 +32,40 @@ GLUquadricObj *quadric; GdkGLConfig *glConfig; GdkGLContext *glContext; GtkWidget *window, *drawingArea; +GladeXML *xml; // LED data gint currentFrame[27] = {0}; +// Hardware +gboolean isCubeConnected = FALSE; -void* connectToLEDCube(void) { - int ret = NULL; - while (ret == NULL || ret != SUCCESSFULLY_CONNECTED) { + +void connectToLEDCube(void) { + char message[255]; + int ret = 0; + int attempts = 0; + GtkLabel *statusLine = GTK_LABEL(glade_xml_get_widget(xml, "connection_label")); + + // We wait till the User connects the cube + while (ret == 0 || ret != SUCCESSFULLY_CONNECTED) { + attempts++; + sprintf(message, "Try to detect the LED-Cube ... %d", attempts); + gtk_label_set_text(statusLine, message); ret = lc_init(); - g_print("connecting ..."); - sleep(3); + if (ret == SUCCESSFULLY_CONNECTED) { + displayCurrentFrame(); + break; + } + sleep(2); } + isCubeConnected = TRUE; + gtk_label_set_text(statusLine, "LED-Cube successfully connected!"); + + //TODO: Start the watchdog } gint main(gint argc, gchar *argv[]) { - GladeXML *xml; GThread *connectThread; gtk_init(&argc, &argv); @@ -66,7 +84,8 @@ gint main(gint argc, gchar *argv[]) { glLightfv(GL_LIGHT0, GL_AMBIENT, backgroundColor); glMatrixMode(GL_MODELVIEW); - moveCameraPosition(0); + currentFrame[13] = 1; // Initial sequence + moveCameraPosition(21); // Configure the OpenGL widget glConfig = gdk_gl_config_new_by_mode(GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH | GDK_GL_MODE_DOUBLE); @@ -89,24 +108,21 @@ 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); } + // Start the polling thread to try to connect to the LED-Cube. GError *error; - g_thread_init(NULL); - if (connectThread = g_thread_create((GThreadFunc)connectToLEDCube, NULL, TRUE, &error) == NULL) { + connectThread = g_thread_create((GThreadFunc)connectToLEDCube, NULL, TRUE, &error); + if (connectThread == NULL) { g_error("Can't create the thread, we stop here."); exit(1); } - //g_thread_join(connectThread); gtk_widget_show(window); gtk_main(); diff --git a/editor/main_gui.glade b/editor/main_gui.glade index e759a7a..53125a5 100644 --- a/editor/main_gui.glade +++ b/editor/main_gui.glade @@ -18,15 +18,11 @@ True both-horiz - + True - 7 - - - True - LED Cube is not connected - - + toolbutton3 + True + gtk-open False @@ -34,7 +30,19 @@ - + + True + toolbutton3 + True + gtk-save + + + False + True + + + + True @@ -66,6 +74,43 @@ True + + + True + + + False + True + + + + + True + toolbutton3 + True + gtk-execute + + + False + True + + + + + True + 7 + + + True + LED-Cube status line + + + + + False + True + +