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:
parent
9b9caa98d6
commit
bedbd1e4e6
6 changed files with 115 additions and 32 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -3,10 +3,15 @@
|
|||
#include <gdk/gdkgl.h>
|
||||
#include <gtk/gtkgl.h>
|
||||
#include <GL/glut.h>
|
||||
#include <glade/glade.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -3,14 +3,13 @@
|
|||
#include <gtk/gtk.h>
|
||||
#include <gtk/gtkgl.h>
|
||||
#include <GL/glut.h>
|
||||
#include <glade/glade.h>
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -18,15 +18,11 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="toolbar_style">both-horiz</property>
|
||||
<child>
|
||||
<widget class="GtkToolItem" id="combobox_frame">
|
||||
<widget class="GtkToolButton" id="button_load">
|
||||
<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 is not connected</property>
|
||||
</widget>
|
||||
</child>
|
||||
<property name="label" translatable="yes">toolbutton3</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-open</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -34,7 +30,19 @@
|
|||
</packing>
|
||||
</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>
|
||||
</widget>
|
||||
<packing>
|
||||
|
@ -66,6 +74,43 @@
|
|||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</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>
|
||||
</child>
|
||||
</widget>
|
||||
|
|
Loading…
Reference in a new issue