Merge branch 'master' of github.com:klaute/Cthn.de-MiniLEDCube
This commit is contained in:
commit
805d8a8af3
10 changed files with 134 additions and 60 deletions
|
@ -1,16 +1,19 @@
|
||||||
CC=gcc
|
CC = gcc-4.4
|
||||||
CFLAGS=-Wall
|
CFLAGS = -Wall
|
||||||
LINKER_FLAGS=-lglut -export-dynamic
|
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`
|
CFLAGS += `pkg-config --cflags --libs gtk+-2.0 gtkglext-1.0 libglade-2.0 gmodule-export-2.0`
|
||||||
SRCDIR=src
|
|
||||||
|
CFLAGS += `libusb-config --cflags`
|
||||||
|
LINKER_FLAGS += `libusb-config --libs`
|
||||||
|
|
||||||
all:
|
all:
|
||||||
$(CC) $(CFLAGS) $(GTKLIBS) -c $(SRCDIR)/display.c
|
$(CC) $(CFLAGS) -c display.c
|
||||||
$(CC) $(CFLAGS) $(GTKLIBS) -c $(SRCDIR)/input.c
|
$(CC) $(CFLAGS) -c input.c
|
||||||
$(CC) $(CFLAGS) $(GTKLIBS) -c $(SRCDIR)/usb.c
|
$(CC) $(CFLAGS) -c main.c
|
||||||
$(CC) $(CFLAGS) $(GTKLIBS) -c $(SRCDIR)/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
|
chmod +x ledcube-edit
|
||||||
#strip ledcube-edit
|
#strip ledcube-edit
|
||||||
|
|
||||||
|
@ -18,4 +21,3 @@ clean:
|
||||||
rm -f *.o
|
rm -f *.o
|
||||||
rm -f gui
|
rm -f gui
|
||||||
rm -f ledcube-edit
|
rm -f ledcube-edit
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,11 @@
|
||||||
#define MOVE_SPEED 7
|
#define MOVE_SPEED 7
|
||||||
#define ZOOM_LEVEL 25
|
#define ZOOM_LEVEL 25
|
||||||
|
|
||||||
#define PI 3.1415926535897932
|
// LEDCube constants
|
||||||
|
#define NOT_CONNECTED_ERROR -1
|
||||||
|
#define DEVICE_NOT_FOUND_ERROR -2
|
||||||
|
|
||||||
|
#define SUCCESSFULLY_CONNECTED 1
|
||||||
|
|
||||||
// Poor Man's enums
|
// Poor Man's enums
|
||||||
#define TOP_ORIENTATION 0x01
|
#define TOP_ORIENTATION 0x01
|
||||||
|
@ -18,16 +22,16 @@
|
||||||
#define PICKING_MODE 0x02
|
#define PICKING_MODE 0x02
|
||||||
|
|
||||||
// Materials
|
// Materials
|
||||||
extern float ledOnMaterial[];
|
extern gfloat ledOnMaterial[];
|
||||||
extern float ledOffMaterial[];
|
extern gfloat ledOffMaterial[];
|
||||||
extern float wireMaterial[];
|
extern gfloat wireMaterial[];
|
||||||
extern float innerWireMaterial[];
|
extern gfloat innerWireMaterial[];
|
||||||
extern float backgroundColor[];
|
extern gfloat backgroundColor[];
|
||||||
|
|
||||||
// Movement
|
// Movement
|
||||||
extern float lookX, lookZ;
|
extern gfloat lookX, lookZ;
|
||||||
extern float eyePos, eyeAngle;
|
extern gfloat eyePos, eyeAngle;
|
||||||
extern int ledOrientation;
|
extern gint ledOrientation;
|
||||||
|
|
||||||
// Objects
|
// Objects
|
||||||
extern GLUquadricObj *quadric;
|
extern GLUquadricObj *quadric;
|
||||||
|
@ -36,10 +40,10 @@ extern GdkGLWindow *glWindow;
|
||||||
extern GdkGLContext *glContext;
|
extern GdkGLContext *glContext;
|
||||||
|
|
||||||
// Dimensions, positions
|
// Dimensions, positions
|
||||||
extern float light0Pos[];
|
extern gfloat light0Pos[];
|
||||||
|
|
||||||
// LED data
|
// LED data
|
||||||
extern int currentFrame[27];
|
extern gint currentFrame[27];
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
|
||||||
|
|
||||||
void drawLEDs(int mode) {
|
void drawLEDs(gint mode) {
|
||||||
int x, y, z;
|
gint x, y, z;
|
||||||
int ledIndex = 0;
|
gint ledIndex = 0;
|
||||||
|
|
||||||
if (ledOrientation == TOP_ORIENTATION) {
|
if (ledOrientation == TOP_ORIENTATION) {
|
||||||
glRotatef(90, 2, 0, 0);
|
glRotatef(90, 2, 0, 0);
|
||||||
|
@ -44,7 +44,7 @@ void drawLEDs(int mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawWires() {
|
void drawWires() {
|
||||||
int 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));
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef _DISPLAY_H
|
#ifndef _DISPLAY_H
|
||||||
#define _DISPLAY_H
|
#define _DISPLAY_H
|
||||||
|
|
||||||
void drawLEDs(int mode);
|
void drawLEDs(gint mode);
|
||||||
void drawWires();
|
void drawWires();
|
||||||
|
|
||||||
void display(gboolean onlyForPicking);
|
void display(gboolean onlyForPicking);
|
|
@ -3,10 +3,45 @@
|
||||||
#include <GL/glut.h>
|
#include <GL/glut.h>
|
||||||
#include <gdk/gdkkeysyms.h>
|
#include <gdk/gdkkeysyms.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "../firmware/globals.h"
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "display.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) {
|
void on_main_window_delete_event(GtkObject *object, gpointer userData) {
|
||||||
gtk_main_quit();
|
gtk_main_quit();
|
||||||
}
|
}
|
|
@ -8,28 +8,31 @@
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
|
||||||
|
#include "../firmware/globals.h" /* custom request numbers */
|
||||||
|
|
||||||
void moveCameraPosition(float direction) {
|
extern void lc_init(void);
|
||||||
|
|
||||||
|
void moveCameraPosition(gfloat direction) {
|
||||||
eyePos += direction;
|
eyePos += direction;
|
||||||
if (eyePos > 360.0) eyePos = 0.0;
|
if (eyePos > 360.0) eyePos = 0.0;
|
||||||
|
|
||||||
lookX = sin(eyePos * PI/180.0)*70.0;
|
lookX = sin(eyePos * M_PI/180.0)*70.0;
|
||||||
lookZ = cos(eyePos * PI/180.0)*70.0;
|
lookZ = cos(eyePos * M_PI/180.0)*70.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void moveCameraAngle(float angle) {
|
void moveCameraAngle(gfloat angle) {
|
||||||
eyeAngle += angle;
|
eyeAngle += angle;
|
||||||
if (eyeAngle > 120) eyeAngle = 120;
|
if (eyeAngle > 120) eyeAngle = 120;
|
||||||
if (eyeAngle < 0) eyeAngle = 0;
|
if (eyeAngle < 0) eyeAngle = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouse(int x, int y) {
|
void mouse(gint x, gint y) {
|
||||||
int position, viewport[4];
|
gint position, viewport[4];
|
||||||
GLubyte pixel[3];
|
GLubyte pixel[3];
|
||||||
|
|
||||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||||
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 = ((int)pixel[2]/8)-1; // Selected LED
|
position = ((gint)pixel[2]/8)-1; // Selected LED
|
||||||
|
|
||||||
printf("%d\n", position);
|
printf("%d\n", position);
|
||||||
currentFrame[position] = currentFrame[position] == 0 ? 1 : 0;
|
currentFrame[position] = currentFrame[position] == 0 ? 1 : 0;
|
10
editor/input.h
Normal file
10
editor/input.h
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#ifndef _INPUT_H
|
||||||
|
#define _INPUT_H
|
||||||
|
|
||||||
|
void moveCameraPosition(gfloat direction);
|
||||||
|
void moveCameraAngle(gfloat angle);
|
||||||
|
|
||||||
|
void mouse(gint x, gint y);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -12,22 +12,20 @@
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "event_callbacks.c"
|
#include "event_callbacks.c"
|
||||||
|
|
||||||
// TODO: Refactor to GLib-Datatypes (page 747)
|
|
||||||
|
|
||||||
// Materials
|
// Materials
|
||||||
float ledOnMaterial[] = {0.0, 0.0, 1.0, 0.4};
|
gfloat ledOnMaterial[] = {0.0, 0.0, 1.0, 0.4};
|
||||||
float ledOffMaterial[] = {0.1, 0.1, 0.1, 0.0};
|
gfloat ledOffMaterial[] = {0.1, 0.1, 0.1, 0.0};
|
||||||
float wireMaterial[] = {0.7, 0.7, 0.7, 1.0};
|
gfloat wireMaterial[] = {0.7, 0.7, 0.7, 1.0};
|
||||||
float innerWireMaterial[] = {0.3, 0.3, 0.3, 0.3};
|
gfloat innerWireMaterial[] = {0.3, 0.3, 0.3, 0.3};
|
||||||
|
|
||||||
// Colors
|
// Colors
|
||||||
float backgroundColor[] = {0.3, 0.3, 0.3, 0.4};
|
gfloat backgroundColor[] = {0.3, 0.3, 0.3, 0.4};
|
||||||
|
|
||||||
// Positions
|
// Positions
|
||||||
float light0Pos[] = {70, 70, 70, 0.0};
|
gfloat light0Pos[] = {70, 70, 70, 0.0};
|
||||||
float lookX = 0.0, lookZ = 0.0;
|
gfloat lookX = 0.0, lookZ = 0.0;
|
||||||
float eyePos = 0.0, eyeAngle = 45.0;
|
gfloat eyePos = 0.0, eyeAngle = 45.0;
|
||||||
int ledOrientation = TOP_ORIENTATION;
|
gint ledOrientation = TOP_ORIENTATION;
|
||||||
|
|
||||||
// Objects
|
// Objects
|
||||||
GLUquadricObj *quadric;
|
GLUquadricObj *quadric;
|
||||||
|
@ -36,11 +34,21 @@ GdkGLContext *glContext;
|
||||||
GtkWidget *window, *drawingArea;
|
GtkWidget *window, *drawingArea;
|
||||||
|
|
||||||
// LED data
|
// LED data
|
||||||
int currentFrame[27] = {0};
|
gint currentFrame[27] = {0};
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
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;
|
GladeXML *xml;
|
||||||
|
GThread *connectThread;
|
||||||
|
|
||||||
gtk_init(&argc, &argv);
|
gtk_init(&argc, &argv);
|
||||||
gdk_gl_init(&argc, &argv);
|
gdk_gl_init(&argc, &argv);
|
||||||
|
@ -63,10 +71,10 @@ int main(int argc, char *argv[]) {
|
||||||
// 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);
|
||||||
if (glConfig == NULL) {
|
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);
|
glConfig = gdk_gl_config_new_by_mode(GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH);
|
||||||
if (glConfig == NULL) {
|
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);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,9 +88,31 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
glade_xml_signal_autoconnect(xml);
|
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_widget_show(window);
|
||||||
gtk_main();
|
gtk_main();
|
||||||
|
|
||||||
|
lc_close();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
#ifndef _INPUT_H
|
|
||||||
#define _INPUT_H
|
|
||||||
|
|
||||||
void moveCameraPosition(float direction);
|
|
||||||
void moveCameraAngle(float angle);
|
|
||||||
|
|
||||||
void mouse(int x, int y);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
Loading…
Reference in a new issue