Connect the 3D-Editor with the great client library.

The editor is now an realtime tool for the LED-Cube!
This commit is contained in:
Aaron Mueller 2012-01-15 03:35:36 +01:00
parent 9b9caa98d6
commit bedbd1e4e6
6 changed files with 115 additions and 32 deletions

View file

@ -38,6 +38,7 @@ extern GLUquadricObj *quadric;
extern GdkGLConfig *glConfig; extern GdkGLConfig *glConfig;
extern GdkGLWindow *glWindow; extern GdkGLWindow *glWindow;
extern GdkGLContext *glContext; extern GdkGLContext *glContext;
extern GladeXML *xml;
// Dimensions, positions // Dimensions, positions
extern gfloat light0Pos[]; extern gfloat light0Pos[];
@ -45,5 +46,8 @@ extern gfloat light0Pos[];
// LED data // LED data
extern gint currentFrame[27]; extern gint currentFrame[27];
// Connection
extern gboolean isCubeConnected;
#endif #endif

View file

@ -3,10 +3,15 @@
#include <gdk/gdkgl.h> #include <gdk/gdkgl.h>
#include <gtk/gtkgl.h> #include <gtk/gtkgl.h>
#include <GL/glut.h> #include <GL/glut.h>
#include <glade/glade.h>
#include "config.h" #include "config.h"
#include "display.h" #include "display.h"
#include "../firmware/globals.h"
extern void lc_setMode(int);
extern void lc_setFrame(unsigned long);
void drawLEDs(gint mode) { void drawLEDs(gint mode) {
gint x, y, z; gint x, y, z;
@ -16,9 +21,9 @@ void drawLEDs(gint mode) {
glRotatef(90, 2, 0, 0); glRotatef(90, 2, 0, 0);
} }
for (z=-10; z<=10; z+=10) // Ebene for (z=10; z>=-10; z-=10) // Ebene
for (y=-10; y<=10; y+=10) // Zeile for (y=10; y>=-10; y-=10) // Zeile
for (x=-10; x<=10; x+=10) { // Spalte for (x=10; x>=-10; x-=10) { // Spalte
ledIndex++; ledIndex++;
if (mode == PICKING_MODE) { if (mode == PICKING_MODE) {
glColor3ub(0, 0, ledIndex*8); glColor3ub(0, 0, ledIndex*8);
@ -45,8 +50,8 @@ void drawLEDs(gint mode) {
void drawWires() { void drawWires() {
gint x, y; gint x, y;
for (y=-10; y<=10; y+=10) for (y=10; y>=-10; y-=10)
for (x=-10; x<=10; x+=10) { for (x=10; x>=-10; x-=10) {
glMaterialfv(GL_FRONT, GL_AMBIENT, ((x == 0 || y == 0) ? innerWireMaterial : wireMaterial)); glMaterialfv(GL_FRONT, GL_AMBIENT, ((x == 0 || y == 0) ? innerWireMaterial : wireMaterial));
// Front // 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);
}

View file

@ -1,6 +1,7 @@
#ifndef _DISPLAY_H #ifndef _DISPLAY_H
#define _DISPLAY_H #define _DISPLAY_H
// OpenGL Cube
void drawLEDs(gint mode); void drawLEDs(gint mode);
void drawWires(); void drawWires();
@ -8,5 +9,8 @@ void display(gboolean onlyForPicking);
void setScene(); void setScene();
// Hardware Cube
void displayCurrentFrame();
#endif #endif

View file

@ -3,14 +3,13 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gtk/gtkgl.h> #include <gtk/gtkgl.h>
#include <GL/glut.h> #include <GL/glut.h>
#include <glade/glade.h>
#include "config.h" #include "config.h"
#include "input.h" #include "input.h"
#include "display.h" #include "display.h"
#include "../firmware/globals.h" /* custom request numbers */ #include "../firmware/globals.h"
extern void lc_init(void);
void moveCameraPosition(gfloat direction) { void moveCameraPosition(gfloat direction) {
eyePos += 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); glReadPixels(x, viewport[3]-y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, (void*)pixel);
position = ((gint)pixel[2]/8)-1; // Selected LED position = ((gint)pixel[2]/8)-1; // Selected LED
printf("%d\n", position);
currentFrame[position] = currentFrame[position] == 0 ? 1 : 0; currentFrame[position] = currentFrame[position] == 0 ? 1 : 0;
printf("%d\n", currentFrame[position]); displayCurrentFrame();
} }

View file

@ -32,22 +32,40 @@ GLUquadricObj *quadric;
GdkGLConfig *glConfig; GdkGLConfig *glConfig;
GdkGLContext *glContext; GdkGLContext *glContext;
GtkWidget *window, *drawingArea; GtkWidget *window, *drawingArea;
GladeXML *xml;
// LED data // LED data
gint currentFrame[27] = {0}; gint currentFrame[27] = {0};
// Hardware
gboolean isCubeConnected = FALSE;
void* connectToLEDCube(void) {
int ret = NULL; void connectToLEDCube(void) {
while (ret == NULL || ret != SUCCESSFULLY_CONNECTED) { 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(); ret = lc_init();
g_print("connecting ..."); if (ret == SUCCESSFULLY_CONNECTED) {
sleep(3); 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[]) { gint main(gint argc, gchar *argv[]) {
GladeXML *xml;
GThread *connectThread; GThread *connectThread;
gtk_init(&argc, &argv); gtk_init(&argc, &argv);
@ -66,7 +84,8 @@ gint main(gint argc, gchar *argv[]) {
glLightfv(GL_LIGHT0, GL_AMBIENT, backgroundColor); glLightfv(GL_LIGHT0, GL_AMBIENT, backgroundColor);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
moveCameraPosition(0); currentFrame[13] = 1; // Initial sequence
moveCameraPosition(21);
// Configure the OpenGL widget // Configure the OpenGL widget
glConfig = gdk_gl_config_new_by_mode(GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH | GDK_GL_MODE_DOUBLE); 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); glade_xml_signal_autoconnect(xml);
if (g_thread_supported()) { if (g_thread_supported()) {
g_print("1");
g_thread_init(NULL); g_thread_init(NULL);
g_print("2");
gdk_threads_init(); gdk_threads_init();
g_print("3");
} else { } else {
g_error("Threads not supported, we die."); g_error("Threads not supported, we die.");
exit(1); exit(1);
} }
// Start the polling thread to try to connect to the LED-Cube.
GError *error; GError *error;
g_thread_init(NULL); 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."); g_error("Can't create the thread, we stop here.");
exit(1); exit(1);
} }
//g_thread_join(connectThread);
gtk_widget_show(window); gtk_widget_show(window);
gtk_main(); gtk_main();

View file

@ -18,15 +18,11 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="toolbar_style">both-horiz</property> <property name="toolbar_style">both-horiz</property>
<child> <child>
<widget class="GtkToolItem" id="combobox_frame"> <widget class="GtkToolButton" id="button_load">
<property name="visible">True</property> <property name="visible">True</property>
<property name="border_width">7</property> <property name="label" translatable="yes">toolbutton3</property>
<child> <property name="use_underline">True</property>
<widget class="GtkLabel" id="connection_label"> <property name="stock_id">gtk-open</property>
<property name="visible">True</property>
<property name="label" translatable="yes">LED Cube is not connected</property>
</widget>
</child>
</widget> </widget>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -34,7 +30,19 @@
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkSeparatorToolItem" id="saparator"> <widget class="GtkToolButton" id="button_save">
<property name="visible">True</property>
<property name="label" translatable="yes">toolbutton3</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-save</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<widget class="GtkSeparatorToolItem" id="saparator2">
<property name="visible">True</property> <property name="visible">True</property>
</widget> </widget>
<packing> <packing>
@ -66,6 +74,43 @@
<property name="homogeneous">True</property> <property name="homogeneous">True</property>
</packing> </packing>
</child> </child>
<child>
<widget class="GtkSeparatorToolItem" id="saparator1">
<property name="visible">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<widget class="GtkToolButton" id="button_upload">
<property name="visible">True</property>
<property name="label" translatable="yes">toolbutton3</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-execute</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<widget class="GtkToolItem" id="combobox_frame">
<property name="visible">True</property>
<property name="border_width">7</property>
<child>
<widget class="GtkLabel" id="connection_label">
<property name="visible">True</property>
<property name="label" translatable="yes">LED-Cube status line</property>
</widget>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
</widget> </widget>
</child> </child>
</widget> </widget>