From e8d7089d7c9e1e2c06e3711a25557385a2e67535 Mon Sep 17 00:00:00 2001
From: Tom Greig <tag2y19@soton.ac.uk>
Date: Mon, 17 Mar 2025 10:16:43 +0000
Subject: [PATCH] Add NO_WIRINGPI option for PC debugging

Pass -n to configure.sh for it.  Just useful for checking the draw
function as none of the other features will work.  Probably necessary to
adjust the window init function to put it in the state you want to see.
---
 configure.sh | 18 ++++++++++++++----
 src/main.c   | 16 ++++++++++++++++
 src/window.c | 22 ++++++++++++++++++++++
 3 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/configure.sh b/configure.sh
index 25ce9f2..81ad84d 100755
--- a/configure.sh
+++ b/configure.sh
@@ -5,7 +5,8 @@ set -e
 usage() {
 
 	printf 'Usage %s ' "${1}";
-	printf '[-h|--help] [-d|--debug] \n\t\t[-c \033[4mcflags\033[m] ';
+	printf '[-h|--help] [-d|--debug] [-n|--no-wiringpi]\n';
+	printf '\t\t[-c \033[4mcflags\033[m] ';
 	printf '[-l \033[4mldlibs\033[m] ';
 	printf '[--ldflags \033[4mldflags\033[m]\n\t\t';
 	printf '[-p \033[4mpkgconfig package\033[m] ';
@@ -14,8 +15,8 @@ usage() {
 
 }
 
-ARGS=$(getopt -o "hdc:l:p:" \
-	--long "help,debug,cflags:,ldlibs:,ldflags:,pkg:,cc:" \
+ARGS=$(getopt -o "hdnc:l:p:" \
+	--long "help,debug,no-wiringpi,cflags:,ldlibs:,ldflags:,pkg:,cc:" \
 	-n "$0" -- "$@");
 if [ "$?" -ne "0" ]; then
 	exit 1;
@@ -39,6 +40,12 @@ while true; do
 			shift;
 			;;
 
+		'-n'|'--no-wiringpi')
+			CFLAGS="${CFLAGS} -DNO_WIRINGPI";
+			NO_WIRINGPI=1;
+			shift;
+			;;
+
 		'-c'|'--cflags')
 			CFLAGS="${CFLAGS} ${2}";
 			shift 2;
@@ -107,7 +114,10 @@ CFLAGS="${CFLAGS} -Wno-expansion-to-defined";
 CFLAGS="${CFLAGS} -D_GNU_SOURCE";
 CFLAGS="${CFLAGS} -I${srcdir}/inc -Iinc";
 CFLAGS="${CFLAGS} $(pkg-config --cflags ${PKGS})";
-LDLIBS="${LDLIBS} -lm -lwiringPi $(pkg-config --libs ${PKGS})";
+LDLIBS="${LDLIBS} -lm $(pkg-config --libs ${PKGS})";
+if [ -z "${NO_WIRINGPI}" ]; then
+	LDLIBS="${LDLIBS} -lwiringPi"
+fi
 
 {
 
diff --git a/src/main.c b/src/main.c
index 5ee8f2d..c1d6d93 100644
--- a/src/main.c
+++ b/src/main.c
@@ -4,7 +4,9 @@
 
 #include <adwaita.h>
 #include <stdio.h>
+#ifndef NO_WIRINGPI
 #include <wiringPi.h>
+#endif
 
 /* BAD GLOBAL VARIABLES */
 
@@ -12,17 +14,21 @@ static GameApp* app = NULL;
 
 /* PROTOTYPES!!! */
 
+#ifndef NO_WIRINGPI
 static int button_down_cb( void* pin );
 static int button_up_cb( void* pin );
 static void isr_g1();
 static void isr_r1();
 static void isr_g2();
 static void isr_r2();
+#endif
 
 /* PUBLIC FUNK!!! */
 
 int main( int argc, char** argv ) {
 
+#ifndef NO_WIRINGPI
+
 	wiringPiSetupPinType( WPI_PIN_BCM );
 
 	pinMode( LED_G1, OUTPUT );
@@ -53,9 +59,13 @@ int main( int argc, char** argv ) {
 	wiringPiISR( BUTTON_G2, INT_EDGE_BOTH, &isr_g2 );
 	wiringPiISR( BUTTON_R2, INT_EDGE_BOTH, &isr_r2 );
 
+#endif
+
 	app = game_app_new();
 	int ret = g_application_run( G_APPLICATION( app ), argc, argv );
 
+#ifndef NO_WIRINGPI
+
 	digitalWrite( LED_G1, LOW );
 	digitalWrite( LED_R1, LOW );
 	digitalWrite( LED_G2, LOW );
@@ -65,12 +75,16 @@ int main( int argc, char** argv ) {
 	digitalWrite( LED_G4, LOW );
 	digitalWrite( LED_R4, LOW );
 
+#endif
+
 	return ret;
 
 }
 
 /* PRIVATE FUNK!!! */
 
+#ifndef NO_WIRINGPI
+
 static int button_down_cb( void* pin ) {
 
 	game_app_button_press( app, *( (int*) pin ) );
@@ -130,3 +144,5 @@ static void isr_r2() {
 	}
 
 }
+
+#endif
diff --git a/src/window.c b/src/window.c
index f0c0a68..394f045 100644
--- a/src/window.c
+++ b/src/window.c
@@ -5,7 +5,9 @@
 #include <assert.h>
 #include <librsvg/rsvg.h>
 #include <pango/pangocairo.h>
+#ifndef NO_WIRINGPI
 #include <wiringPi.h>
+#endif
 
 /* TYPES!!! */
 
@@ -71,7 +73,9 @@ static void draw( GtkDrawingArea* area, cairo_t* cr,
 static void set_cario_colour( cairo_t* cr, enum colour colour );
 
 static int bounce_reset( void* data );
+#ifndef NO_WIRINGPI
 static int light( void* data );
+#endif
 
 /* PUBLIC FUNK!!! */
 
@@ -232,6 +236,8 @@ static void realise( GtkWidget* widget, void* data ) {
 
 static void handle_press( GameWindow* window, int pin ) {
 
+#ifndef NO_WIRINGPI
+
 	if ( !digitalRead( BUTTON_G1 ) && !digitalRead( BUTTON_R1 ) &&
 			!digitalRead( BUTTON_G2 ) && !digitalRead( BUTTON_R2 ) ) {
 
@@ -397,6 +403,12 @@ static void handle_press( GameWindow* window, int pin ) {
 
 	}
 
+#else
+
+	(void) pin;
+
+#endif
+
 	gtk_widget_queue_draw( GTK_WIDGET( window->area ) );
 
 }
@@ -520,6 +532,8 @@ static void set_cario_colour( cairo_t* cr, enum colour colour ) {
 
 static int bounce_reset( void* data ) {
 
+#ifndef NO_WIRINGPI
+
 	struct button_state* state = (struct button_state*) data;
 
 	state->bouncing = false;
@@ -554,10 +568,17 @@ static int bounce_reset( void* data ) {
 		fprintf( stderr, "\n" );
 	}
 
+#else
+
+	(void) data;
+
+#endif
+
 	return G_SOURCE_REMOVE;
 
 }
 
+#ifndef NO_WIRINGPI
 static int light( void* data ) {
 
 	GameWindow* window = (GameWindow*) data;
@@ -584,3 +605,4 @@ static int light( void* data ) {
 	return G_SOURCE_REMOVE;
 
 }
+#endif
-- 
GitLab