Skip to content

Commit

Permalink
no more segfaults.... fingers crossed....
Browse files Browse the repository at this point in the history
  • Loading branch information
accellarando committed Dec 2, 2023
1 parent 70dd862 commit e48e131
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 67 deletions.
Binary file modified software/TagGang
Binary file not shown.
31 changes: 25 additions & 6 deletions software/drawable_canvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static gboolean configure_event_cb (GtkWidget *widget,
GdkEventConfigure *event,
gpointer data)
{
printf("configure\n");
if (surface)
cairo_surface_destroy (surface);

Expand All @@ -58,6 +59,10 @@ static gboolean configure_event_cb (GtkWidget *widget,
return TRUE;
}

static void destroy_widget(GtkWidget* widget, gpointer data){
gtk_widget_destroy(widget);
}

static gboolean draw_cb (GtkWidget *widget,
cairo_t *cr,
gpointer data);
Expand All @@ -72,15 +77,23 @@ static void advance_stage(){
cairo_surface_destroy (surface);
surface = NULL;
}
/* gtk_widget_destroy(widget); */
if(frame)
/* This segfaults, but if you don't destroy it then the tag selector doesn't show up.
* so like, what the fuck
if(frame){
gtk_widget_destroy(frame);
frame = NULL;
}
*/
if(drawing_area){
g_signal_handlers_disconnect_by_func(drawing_area, G_CALLBACK(draw_cb), NULL);
gtk_widget_destroy(drawing_area);
drawing_area = NULL;
}

g_signal_handlers_disconnect_by_func(window, G_CALLBACK(draw_cb), NULL);
//fuck it let's try it this way
//gtk_container_foreach(GTK_CONTAINER(window), destroy_widget, NULL);
//still nothing


if(joints_list != NULL)
skeltrack_joint_list_free(joints_list); //this segfaults sometimes???? idk.
Expand Down Expand Up @@ -108,8 +121,11 @@ static gboolean draw_cb (GtkWidget *widget,
cairo_t *cr,
gpointer data)
{
if(surface == NULL || drawing_area == NULL || cr == NULL)
return;
if(surface == NULL || drawing_area == NULL || cr == NULL){
printf("something was null\n");
return FALSE;
}
printf("draw cb\n");
cairo_set_source_surface (cr, surface, 0, 0);
cairo_paint (cr);

Expand All @@ -134,8 +150,9 @@ static gboolean draw_cb (GtkWidget *widget,
gtk_widget_queue_draw (widget);
}
if(event.number == BTN_RIGHT_Y){
printf("Advancing stage\n");
btn_available = 0;
advance_stage();
printf("Advancing stage\n");
return TRUE;
}
}
Expand Down Expand Up @@ -293,6 +310,7 @@ static gboolean button_release_event_cb (GtkWidget *widget,
GdkEventButton *event,
gpointer data)
{
printf("button release\n");
if (event->button == BUTTON_PEN_DOWN)
{
//printf("Button released\n");
Expand Down Expand Up @@ -335,6 +353,7 @@ void activate_canvas (GtkApplication *app,
void* i_forgot,
gpointer user_data)
{
printf("activate_canvas\n");
window = (GtkWidget*) user_data;

g_signal_connect (window, "destroy", G_CALLBACK (close_window), NULL);
Expand Down
Binary file modified software/drawing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions software/gcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ void activate_gcoder(GObject* self,

// todo: put a loading bar here that lets you keep track of progress. For now, just put some placeholder text.
label = gtk_label_new("Generating gcode!");
gtk_container_add(GTK_CONTAINER(window), label);
gtk_widget_show_all(window);
gtk_container_add(GTK_CONTAINER(frame), label);
//gtk_widget_show_all(window);

scale_paths(points_list, 10, 10);

Expand Down
1 change: 1 addition & 0 deletions software/include/drawable_canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ extern GList* points_list;
extern SkeltrackJointList joints_list;

extern GtkWidget* drawing_area;
extern GtkWidget* frame;
#endif
1 change: 1 addition & 0 deletions software/include/selector.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define WINDOW_WIDTH 800 // Increased window width to accommodate the image display area
#define WINDOW_HEIGHT 500

extern GtkWidget *selector_area;
void activate_selector(GtkApplication* self,
GParamSpec* pspec,
gpointer user_data);
Expand Down
11 changes: 6 additions & 5 deletions software/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ void scale_point_cloud(GtkApplication *app,
GList* paths = (GList*) data;
}

void activate_plotter(GtkApplication *app, void* hi, gpointer data){
}


/**
* This function routes Title Change signals to the appropriate
* function, based on the current state of the program.
Expand Down Expand Up @@ -274,7 +270,7 @@ volatile struct js_event event;
gboolean check_for_js_events(gpointer data){
int joystick_fd = *((int*)data);
if(read_event(joystick_fd, &event) == 0){
//g_print("Joystick event! type: %d, number: %d, value: %d\n", event.type, event.number, event.value);
g_print("Joystick event! type: %d, number: %d, value: %d\n", event.type, event.number, event.value);
if(event.type == JS_EVENT_BUTTON){
btn_available = 1;
}
Expand Down Expand Up @@ -303,8 +299,13 @@ gboolean check_for_js_events(gpointer data){
joy_y = 0;
}
}

}
if(selector_area != NULL){
gtk_widget_queue_draw(selector_area);
}
}

return G_SOURCE_CONTINUE;
}

Expand Down
59 changes: 12 additions & 47 deletions software/output.gcode
Original file line number Diff line number Diff line change
@@ -1,49 +1,14 @@
G1 L498.667424 R445.516779
G1 L217.503103 R1282.552845
G1 Z0.000000
G1 L503.965336 R451.133085
G1 L508.327650 R455.751029
G1 L505.040216 R452.253933
G1 L505.040216 R452.253933
G1 L502.008466 R448.945988
G1 L502.008466 R448.945988
G1 L500.285878 R447.086077
G1 L500.285878 R447.086077
G1 L500.309544 R447.005190
G1 L500.309544 R447.005190
G1 L500.500400 R447.151708
G1 L500.500400 R447.151708
G1 L500.680747 R447.326737
G1 L500.680747 R447.326737
G1 L500.810483 R447.471943
G1 L500.810483 R447.471943
G1 L499.852558 R446.910036
G1 L497.367570 R444.236986
G1 L498.430788 R445.130599
G1 L498.430788 R445.130599
G1 L498.061040 R444.810971
G1 L498.061040 R444.810971
G1 L499.642212 R446.325375
G1 L499.642212 R446.325375
G1 L498.694496 R445.412393
G1 L498.694496 R445.412393
G1 L501.296818 R448.203637
G1 L504.501992 R451.599668
G1 L504.501992 R451.599668
G1 L501.851024 R448.649585
G1 L501.851024 R448.649585
G1 L504.192106 R451.213564
G1 L504.547718 R451.610894
G1 L504.547718 R451.610894
G1 L504.012897 R451.039910
G1 L503.836412 R450.829380
G1 L503.836412 R450.829380
G1 L500.760112 R447.442387
G1 L500.760112 R447.442387
G1 L503.436997 R450.396281
G1 L500.973782 R447.694907
G1 L499.755030 R446.357581
G1 L499.755030 R446.357581
G1 L501.676360 R448.454201
G1 L502.554216 R449.422674
G1 L502.554216 R449.422674
G1 L215.923690 R1284.388430
G1 L211.820396 R1287.901891
G1 L211.875081 R1287.794491
G1 L214.965346 R1284.811153
G1 L213.762696 R1285.893421
G1 L214.126785 R1286.420180
G1 L251.149856 R1248.150251
G1 L243.232584 R1256.283682
G1 L205.472456 R1294.422392
G1 L213.201220 R1287.198415
G1 L212.870782 R1288.191434
G1 Z180.000000
24 changes: 17 additions & 7 deletions software/selector_v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <selector.h>
#include <stdio.h>

static GtkWidget *selector_area;
GtkWidget *selector_area;
static GtkWidget *image_display_area; // GtkImage widget for displaying the loaded image
static GtkWidget *vbox;
static double box_x = 0;
Expand All @@ -34,13 +34,20 @@ static void on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer user_da
static void finish_selector_stage();
static void save_coordinates(double x, double y);

static void destroy_widget(GtkWidget* widget, gpointer data){
gtk_widget_destroy(widget);
}

void activate_selector( GtkApplication* self,
GParamSpec* pspec,
gpointer user_data){


// make sure window is empty
//gtk_container_foreach(GTK_CONTAINER(window), destroy_widget, NULL);

// Create a vertical box to hold the drawing area and image display area
vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_container_add(GTK_CONTAINER(frame), vbox);

// Create drawing area
selector_area = gtk_drawing_area_new();
Expand All @@ -59,7 +66,6 @@ void activate_selector( GtkApplication* self,
g_signal_connect(G_OBJECT(selector_area), "draw", G_CALLBACK(on_draw), NULL);
g_signal_connect(window, "key-press-event", G_CALLBACK(on_key_press), NULL);

printf("IS_WIDGET: %d\n", GTK_IS_WIDGET(window));
gtk_widget_set_events(window, GDK_KEY_PRESS_MASK);
gtk_widget_show_all(window);
printf("Selector should be active now.\n");
Expand Down Expand Up @@ -118,7 +124,8 @@ static void move_box(double dx, double dy) {
static gdouble last_joy_time = 0;
static gboolean on_draw(GtkWidget *widget, cairo_t *cr, gpointer data) {
printf("Start on_draw\n");
if(last_joy_time == 0 || (g_get_monotonic_time() - last_joy_time) > 1000000/JOY_SPEED){
if(last_joy_time == 0 || (unsigned int)(g_get_monotonic_time() - last_joy_time) > 1000000/JOY_SPEED){
printf("joy x, y: %d %d\n", joy_x, joy_y);
move_box(joy_x*SNAP_INTERVAL, joy_y*SNAP_INTERVAL);
last_joy_time = g_get_monotonic_time();
}
Expand Down Expand Up @@ -163,9 +170,12 @@ static void save_coordinates(double x, double y) {

static void finish_selector_stage() {
// Clean up widgets
gtk_widget_destroy(vbox);
gtk_widget_destroy(selector_area);
/*
*/
gtk_widget_destroy(image_display_area);
gtk_widget_destroy(selector_area);
//gtk_widget_destroy(vbox);
selector_area = NULL;

// Disconnect signal handler for keypress
g_signal_handlers_disconnect_by_func(window, G_CALLBACK(on_key_press), NULL);
Expand Down

0 comments on commit e48e131

Please sign in to comment.