From 2c5b305c1d58ea74f63fc1a4d4bf07a5868204ad Mon Sep 17 00:00:00 2001
From: c vw <dl1ycf@darc.de>
Date: Wed, 2 Jun 2021 14:53:32 +0200
Subject: [PATCH] second-last step in the "big merge"

---
 Makefile        | 20 +++++++++++++++-----
 actions.c       |  3 +++
 actions.h       |  3 +++
 css.c           | 26 ++++++++++++++++++++++++++
 discovery.c     |  1 +
 exit_menu.c     |  1 +
 main.c          |  7 +++++++
 main.h          |  2 +-
 new_menu.c      |  9 +++++++++
 radio_menu.c    |  3 +++
 switch_menu.c   |  8 +++++++-
 toolbar.h       |  2 +-
 tx_panadapter.c |  1 +
 13 files changed, 78 insertions(+), 8 deletions(-)
 create mode 100644 actions.c
 create mode 100644 actions.h
 create mode 100644 css.c

diff --git a/Makefile b/Makefile
index 8d27d2b..4ce22b9 100644
--- a/Makefile
+++ b/Makefile
@@ -122,17 +122,21 @@ PTT_OPTIONS=-D PTT
 endif
 
 ifeq ($(GPIO_INCLUDE),GPIO)
-  GPIO_OPTIONS=-D GPIO
-  GPIO_LIBS=-lwiringPi
-  GPIO_SOURCES= \
+GPIOD_VERSION=$(shell pkg-config --modversion libgpiod)
+ifeq ($(GPIOD_VERSION),1.2)
+GPIOD_OPTIONS=-D OLD_GPIOD
+endif
+GPIO_OPTIONS=-D GPIO
+GPIO_LIBS=-lwiringPi
+GPIO_SOURCES= \
   configure.c \
   i2c.c \
   encoder_menu.c
-  GPIO_HEADERS= \
+GPIO_HEADERS= \
   configure.h \
   i2c.h \
   encoder_menu.h
-  GPIO_OBJS= \
+GPIO_OBJS= \
   configure.o \
   i2c.o \
   encoder_menu.o
@@ -310,6 +314,8 @@ ext.c \
 error_handler.c \
 cwramp.c \
 protocols.c \
+css.c \
+actions.c \
 switch_menu.c \
 gpio.c
 
@@ -381,6 +387,8 @@ led.h \
 ext.h \
 error_handler.h \
 protocols.h \
+css.h \
+actions.h \
 switch_menu.h \
 gpio.h
 
@@ -451,6 +459,8 @@ ext.o \
 error_handler.o \
 cwramp.o \
 protocols.o \
+css.o \
+actions.o \
 switch_menu.o \
 gpio.o
 
diff --git a/actions.c b/actions.c
new file mode 100644
index 0000000..6d4177f
--- /dev/null
+++ b/actions.c
@@ -0,0 +1,3 @@
+/*
+ * This file left empty intentionally
+ */
diff --git a/actions.h b/actions.h
new file mode 100644
index 0000000..6d4177f
--- /dev/null
+++ b/actions.h
@@ -0,0 +1,3 @@
+/*
+ * This file left empty intentionally
+ */
diff --git a/css.c b/css.c
new file mode 100644
index 0000000..c8b9ae3
--- /dev/null
+++ b/css.c
@@ -0,0 +1,26 @@
+#include <gtk/gtk.h>
+
+char *css=
+"  #small {\n"
+"    padding: 0;\n"
+"    font-family: Sans;\n"
+"    font-size: 12px;\n"
+"    }\n"
+;
+
+void load_css() {
+  GtkCssProvider *provider;
+  GdkDisplay *display;
+  GdkScreen *screen;
+
+  g_print("%s\n",__FUNCTION__);
+  provider = gtk_css_provider_new ();
+  display = gdk_display_get_default ();
+  screen = gdk_display_get_default_screen (display);
+  gtk_style_context_add_provider_for_screen (screen,
+                                             GTK_STYLE_PROVIDER(provider),
+                                             GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+
+  gtk_css_provider_load_from_data(provider, css, -1, NULL);
+  g_object_unref (provider);
+}
diff --git a/discovery.c b/discovery.c
index d6e9ab7..ef80114 100644
--- a/discovery.c
+++ b/discovery.c
@@ -44,6 +44,7 @@
 #endif
 #include "ext.h"
 #ifdef GPIO
+#include "actions.h"
 #include "gpio.h"
 #include "configure.h"
 #endif
diff --git a/exit_menu.c b/exit_menu.c
index 0ba81a3..8811ed7 100644
--- a/exit_menu.c
+++ b/exit_menu.c
@@ -32,6 +32,7 @@
 #ifdef SOAPYSDR
 #include "soapy_protocol.h"
 #endif
+#include "actions.h"
 #include "gpio.h"
 
 static GtkWidget *parent_window=NULL;
diff --git a/main.c b/main.c
index ec18f8a..4fb2ced 100644
--- a/main.c
+++ b/main.c
@@ -41,8 +41,11 @@
 #include "main.h"
 #include "channel.h"
 #include "discovered.h"
+#ifdef GPIO
+#include "actions.h"
 #include "configure.h"
 #include "gpio.h"
+#endif
 #include "wdsp.h"
 #include "new_menu.h"
 #include "radio.h"
@@ -177,6 +180,10 @@ static int init(void *data) {
 
   audio_get_cards();
 
+  // wait for get_cards to complete
+  //g_mutex_lock(&audio_mutex);
+  //g_mutex_unlock(&audio_mutex);
+
   cursor_arrow=gdk_cursor_new(GDK_ARROW);
   cursor_watch=gdk_cursor_new(GDK_WATCH);
 
diff --git a/main.h b/main.h
index 91bf17e..bf1e33f 100644
--- a/main.h
+++ b/main.h
@@ -24,7 +24,7 @@
 extern struct utsname unameData;
 
 enum {
-  NO_CONTROLLER=0,
+  NO_CONTROLLER,
   CONTROLLER1,
   CONTROLLER2_V1,
   CONTROLLER2_V2
diff --git a/new_menu.c b/new_menu.c
index c732a50..b8311cb 100644
--- a/new_menu.c
+++ b/new_menu.c
@@ -57,7 +57,10 @@
 #include "vfo_menu.h"
 #include "fft_menu.h"
 #include "main.h"
+#ifdef GPIO
 #include "gpio.h"
+#include "actions.h"
+#endif
 #include "old_protocol.h"
 #include "new_protocol.h"
 #ifdef CLIENT_SERVER
@@ -590,6 +593,12 @@ void new_menu()
 
     switch(controller) {
       case NO_CONTROLLER:
+	{
+        GtkWidget *switches_b=gtk_button_new_with_label("Switches");
+        g_signal_connect (switches_b, "button-press-event", G_CALLBACK(switch_cb), NULL);
+        gtk_grid_attach(GTK_GRID(grid),switches_b,(i%5),i/5,1,1);
+        i++;
+        }
         break;
       case CONTROLLER1:
       case CONTROLLER2_V1:
diff --git a/radio_menu.c b/radio_menu.c
index dfea4cb..8145b7d 100644
--- a/radio_menu.c
+++ b/radio_menu.c
@@ -39,7 +39,10 @@
 #ifdef SOAPYSDR
 #include "soapy_protocol.h"
 #endif
+#ifdef GPIO
+#include "actions.h"
 #include "gpio.h"
+#endif
 #include "vfo.h"
 #include "ext.h"
 #ifdef CLIENT_SERVER
diff --git a/switch_menu.c b/switch_menu.c
index 19db837..68b71c2 100644
--- a/switch_menu.c
+++ b/switch_menu.c
@@ -134,7 +134,13 @@ void switch_menu(GtkWidget *parent) {
   col=0;
 
   switch(controller) {
-    default:
+    case NO_CONTROLLER:
+      // Nothing to do in this pihpsdr version
+      {
+      GtkWidget *text_w=gtk_label_new("Nothing to do here with the  'No Controller' option!     ");
+      gtk_grid_attach(GTK_GRID(grid),text_w,1,1,3,1);
+      col++;
+      }
       break;
     case CONTROLLER1:
       {
diff --git a/toolbar.h b/toolbar.h
index 5a1b887..bc54496 100644
--- a/toolbar.h
+++ b/toolbar.h
@@ -20,11 +20,11 @@
 #ifndef _TOOLBAR_H
 #define _TOOLBAR_H
 
+#include "gpio.h"
 #define MAX_FUNCTION 5
 
 extern int function;
 
-
 void update_toolbar_labels();
 void ptt_update(int state);
 void mox_update(int state);
diff --git a/tx_panadapter.c b/tx_panadapter.c
index 2174604..8c272c6 100644
--- a/tx_panadapter.c
+++ b/tx_panadapter.c
@@ -35,6 +35,7 @@
 #include "tx_panadapter.h"
 #include "vfo.h"
 #include "mode.h"
+#include "actions.h"
 #ifdef GPIO
 #include "gpio.h"
 #endif
-- 
2.45.2