From 2ffe6586ddaf6f670e2db45d376569ea8f00a7ec Mon Sep 17 00:00:00 2001
From: c vw <dl1ycf@darc.de>
Date: Wed, 4 Mar 2020 11:19:27 +0100
Subject: [PATCH] added Restart button (only if compiled with -D
 RESTART_BUTTON, experimental feature)

---
 new_menu.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/new_menu.c b/new_menu.c
index 4b943c1..90b92df 100644
--- a/new_menu.c
+++ b/new_menu.c
@@ -58,6 +58,10 @@
 #include "fft_menu.h"
 #include "main.h"
 #include "gpio.h"
+#ifdef RESTART_BUTTON
+#include "old_protocol.h"
+#include "new_protocol.h"
+#endif
 
 
 static GtkWidget *menu_b=NULL;
@@ -98,6 +102,32 @@ static gboolean close_cb (GtkWidget *widget, GdkEventButton *event, gpointer dat
   return TRUE;
 }
 
+#ifdef RESTART_BUTTON
+//
+// To recover from certain error conditions, this function
+// restart the protocol.
+//
+static gboolean restart_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
+  cleanup();
+  switch(protocol) {
+    case ORIGINAL_PROTOCOL:
+      old_protocol_stop();
+      usleep(200000);
+      old_protocol_run();
+      break;
+    case NEW_PROTOCOL:
+      new_protocol_restart();
+      break;
+#ifdef SOAPYSDR
+    case SOAPYSDR_PROTOCOL:
+      // dunno how to do this for soapy
+      break;
+#endif
+  }
+  return TRUE;
+}
+#endif
+
 static gboolean about_b_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
   cleanup();
   about_menu(top_window);
@@ -464,6 +494,16 @@ void new_menu()
     g_signal_connect (close_b, "button-press-event", G_CALLBACK(close_cb), NULL);
     gtk_grid_attach(GTK_GRID(grid),close_b,0,0,2,1);
 
+#ifdef RESTART_BUTTON
+    //
+    // The new "Restart" button activates a function that restarts
+    // the protocol and closes the menu window
+    //
+    GtkWidget *restart_b=gtk_button_new_with_label("Restart");
+    g_signal_connect (restart_b, "button-press-event", G_CALLBACK(restart_cb), NULL);
+    gtk_grid_attach(GTK_GRID(grid),restart_b,2,0,2,1);
+#endif
+
     GtkWidget *exit_b=gtk_button_new_with_label("Exit piHPSDR");
     g_signal_connect (exit_b, "button-press-event", G_CALLBACK(exit_cb), NULL);
     gtk_grid_attach(GTK_GRID(grid),exit_b,4,0,2,1);
-- 
2.45.2