Skip to content

Commit

Permalink
Light UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ali1234 committed Apr 28, 2015
1 parent 1cb0318 commit ae974fc
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 8 deletions.
36 changes: 36 additions & 0 deletions control.cpp
Expand Up @@ -53,6 +53,42 @@ void control_set_lights(signed short l)
g_mutex_unlock (&control_mutex);
}

void control_set_headlights(gboolean on)
{
g_mutex_lock (&control_mutex);

if (on)
lights |= 1;
else
lights &= ~1;

g_mutex_unlock (&control_mutex);
}

void control_set_taillights(gboolean on)
{
g_mutex_lock (&control_mutex);

if (on)
lights |= 2;
else
lights &= ~2;

g_mutex_unlock (&control_mutex);
}

void control_set_hazardlights(gboolean on)
{
g_mutex_lock (&control_mutex);

if (on)
lights |= 4;
else
lights &= ~4;

g_mutex_unlock (&control_mutex);
}

void control_set_flags(signed short f)
{
g_mutex_lock (&control_mutex);
Expand Down
5 changes: 5 additions & 0 deletions control.h
@@ -1,5 +1,10 @@
void control_set_motors(signed short *m);

void control_set_lights(signed short l);
void control_set_headlights(gboolean on);
void control_set_taillights(gboolean on);
void control_set_hazardlights(gboolean on);

void control_set_flags(signed short f);
void control_get_packet(char *buf);
void control_start(void);
Expand Down
62 changes: 55 additions & 7 deletions main.cpp
Expand Up @@ -39,16 +39,62 @@ static void window_closed (GtkWidget *widget, GdkEvent *event, gpointer user_dat
gtk_main_quit ();
}

static gboolean do_nothing (GstElement *pipeline, gboolean ignored)
void toggle_headlights (GtkToggleToolButton *toggletoolbutton, gpointer user_data)
{
return TRUE;
control_set_headlights(gtk_toggle_tool_button_get_active(toggletoolbutton));
}

void toggle_taillights (GtkToggleToolButton *toggletoolbutton, gpointer user_data)
{
control_set_taillights(gtk_toggle_tool_button_get_active(toggletoolbutton));
}

void toggle_hazardlights (GtkToggleToolButton *toggletoolbutton, gpointer user_data)
{
control_set_hazardlights(gtk_toggle_tool_button_get_active(toggletoolbutton));
}

GtkWidget *make_toolbar(void)
{
GtkWidget *toolbar;

GtkToolItem *headlights;
GtkToolItem *taillights;
GtkToolItem *hazardlights;

toolbar = gtk_toolbar_new ();
gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);

headlights = gtk_toggle_tool_button_new();
gtk_tool_button_set_label (GTK_TOOL_BUTTON (headlights), "Head Lights");
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), headlights, -1);

taillights = gtk_toggle_tool_button_new();
gtk_tool_button_set_label (GTK_TOOL_BUTTON (taillights), "Tail Lights");
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), taillights, -1);

hazardlights = gtk_toggle_tool_button_new();
gtk_tool_button_set_label (GTK_TOOL_BUTTON (hazardlights), "Hazard Lights");
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), hazardlights, -1);



g_signal_connect(G_OBJECT(headlights), "toggled",
G_CALLBACK(toggle_headlights), NULL);

g_signal_connect(G_OBJECT(taillights), "toggled",
G_CALLBACK(toggle_taillights), NULL);

g_signal_connect(G_OBJECT(hazardlights), "toggled",
G_CALLBACK(toggle_hazardlights), NULL);

return toolbar;
}

int main (int argc, char **argv)
{
GdkWindow *video_window_xwindow;
GtkWidget *window, *video_window;
GtkWidget *window, *video_window, *vbox;
GstElement *pipeline, *sink;
gulong embed_xid;
GstStateChangeReturn sret;
Expand All @@ -71,9 +117,13 @@ int main (int argc, char **argv)
gtk_window_set_default_size (GTK_WINDOW (window), 1000, 600);
gtk_window_set_title (GTK_WINDOW (window), "PiRover Control");

vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), vbox);

gtk_box_pack_start(GTK_BOX(vbox), make_toolbar(), FALSE, FALSE, 5);

video_window = gtk_drawing_area_new ();
gtk_container_add (GTK_CONTAINER (window), video_window);
gtk_container_set_border_width (GTK_CONTAINER (window), 0);
gtk_container_add (GTK_CONTAINER (vbox), video_window);

gtk_widget_show_all (window);

Expand All @@ -91,8 +141,6 @@ int main (int argc, char **argv)

/* TODO: everything else */

g_timeout_add_seconds (1, (GSourceFunc)do_nothing, pipeline);

control_start();
net_start();

Expand Down
5 changes: 4 additions & 1 deletion net.cpp
Expand Up @@ -30,7 +30,10 @@ static gboolean send_controls(gpointer unused, gboolean ignored)
GError *err = NULL;

control_get_packet(buf);
g_print("%02x%02x%02x%02x%02x%02x%02x%02x\n", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
g_print("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
buf[0], buf[1], buf[2], buf[3],
buf[4], buf[5], buf[6], buf[7],
buf[8], buf[9], buf[10], buf[11]);
g_socket_send(socket, buf, 12, NULL, &err);
return TRUE;
}
Expand Down

0 comments on commit ae974fc

Please sign in to comment.