# uncomment the following line to force 480x320 screen
#SMALL_SCREEN_OPTIONS=-D SMALL_SCREEN
-# uncomment the line below to include GPIO (For original piHPSDR Controller and Controller2 with i2c)
+# uncomment the line below to include GPIO
+# For support of:
+# CONTROLLER1 (Original Controller)
+# CONTROLLER2_V1 single encoders with MCP23017 switches
+# CONTROLLER2_V2 dual encoders with MCP23017 switches
+# CONTORLLER_I2C i2c controller using 7 I2C Encoder V2.1 boards from http://www.duppa.net/i2c-encoder-v2-1/
+# 7 encoders and 16 switches one LED
+#
GPIO_INCLUDE=GPIO
-# uncomment the following line to include support for the new i2c controller
-#I2C_CONTROLLER_INCLUDE=I2C_CONTROLLER
-
# uncomment the line below to include USB Ozy support
# USBOZY_INCLUDE=USBOZY
PTT_OPTIONS=-D PTT
endif
-ifeq ($(I2C_CONTROLLER_INCLUDE),I2C_CONTROLLER)
- I2C_CONTROLLER_OPTIONS=-D I2C_CONTROLLER
- I2C_CONTROLLER_LIBS=-lgpiod -li2c
- I2C_CONTROLLER_SOURCES= \
- i2c_controller.c \
- i2c_controller_menu.c
- I2C_CONTROLLER_HEADERS= \
- i2c_controller.h \
- i2c_controller_menu.h
- I2C_CONTROLLER_OBJS= \
- i2c_controller.o \
- i2c_controller_menu.o
-endif
-
ifeq ($(GPIO_INCLUDE),GPIO)
- GPIO_OPTIONS=-D GPIO
- GPIO_LIBS=-lgpiod -li2c
- GPIO_SOURCES= \
+GPIO_OPTIONS=-D GPIO
+GPIO_LIBS=-lgpiod -li2c
+GPIO_SOURCES= \
configure.c \
i2c.c \
gpio.c \
encoder_menu.c \
- switch_menu.c
- GPIO_HEADERS= \
+ switch_menu.c \
+ i2c_controller.c \
+ i2c_controller_menu.c
+
+GPIO_HEADERS= \
configure.h \
i2c.h \
gpio.h \
encoder_menu.h \
- switch_menu.h
- GPIO_OBJS= \
+ switch_menu.h \
+ i2c_controller.h \
+ i2c_controller_menu.h
+
+GPIO_OBJS= \
configure.o \
i2c.o \
gpio.o \
encoder_menu.o \
- switch_menu.o
+ switch_menu.o \
+ i2c_controller.o \
+ i2c_controller_menu.o
endif
#
#AUDIO_LIBS=-lsoundio
CFLAGS= -g -Wno-deprecated-declarations -O3
-OPTIONS=$(SMALL_SCREEN_OPTIONS) $(I2C_ENCODERS_OPTIONS) $(MIDI_OPTIONS) $(PURESIGNAL_OPTIONS) $(REMOTE_OPTIONS) $(USBOZY_OPTIONS) \
- $(I2C_CONTROLLER_OPTIONS) $(GPIO_OPTIONS) $(SOAPYSDR_OPTIONS) $(LOCALCW_OPTIONS) \
+OPTIONS=$(SMALL_SCREEN_OPTIONS) $(MIDI_OPTIONS) $(PURESIGNAL_OPTIONS) $(REMOTE_OPTIONS) $(USBOZY_OPTIONS) \
+ $(GPIO_OPTIONS) $(SOAPYSDR_OPTIONS) $(LOCALCW_OPTIONS) \
$(STEMLAB_OPTIONS) \
$(PTT_OPTIONS) \
$(SERVER_OPTIONS) \
-D GIT_DATE='"$(GIT_DATE)"' -D GIT_VERSION='"$(GIT_VERSION)"' $(DEBUG_OPTION) $(OSFLAG)
-LIBS=-lrt -lm -lwdsp -lpthread $(AUDIO_LIBS) $(USBOZY_LIBS) $(GTKLIBS) $(I2C_CONTROLLER_LIBS) $(GPIO_LIBS) $(SOAPYSDRLIBS) $(STEMLAB_LIBS) $(MIDI_LIBS)
+LIBS=-lrt -lm -lwdsp -lpthread $(AUDIO_LIBS) $(USBOZY_LIBS) $(GTKLIBS) $(GPIO_LIBS) $(SOAPYSDRLIBS) $(STEMLAB_LIBS) $(MIDI_LIBS)
INCLUDES=$(GTKINCLUDES)
COMPILE=$(CC) $(CFLAGS) $(OPTIONS) $(INCLUDES)
actions.o
$(PROGRAM): $(OBJS) $(REMOTE_OBJS) $(USBOZY_OBJS) $(SOAPYSDR_OBJS) \
- $(LOCALCW_OBJS) $(I2C_CONTROLLER_OBJS) $(GPIO_OBJS) $(PURESIGNAL_OBJS) \
+ $(LOCALCW_OBJS) $(GPIO_OBJS) $(PURESIGNAL_OBJS) \
$(MIDI_OBJS) $(STEMLAB_OBJS) $(SERVER_OBJS)
- $(LINK) -o $(PROGRAM) $(OBJS) $(REMOTE_OBJS) $(USBOZY_OBJS) $(I2C_CONTROLLER_OBJS) $(GPIO_OBJS) \
+ $(LINK) -o $(PROGRAM) $(OBJS) $(REMOTE_OBJS) $(USBOZY_OBJS) $(GPIO_OBJS) \
$(SOAPYSDR_OBJS) $(LOCALCW_OBJS) $(PURESIGNAL_OBJS) \
$(MIDI_OBJS) $(STEMLAB_OBJS) $(SERVER_OBJS) $(LIBS)
.PHONY: all
all: prebuild $(PROGRAM) $(HEADERS) $(USBOZY_HEADERS) $(SOAPYSDR_HEADERS) \
- $(LOCALCW_HEADERS) $(I2C_CONTROLLER_HEADERS) $(GPIO_HEADERS) \
+ $(LOCALCW_HEADERS) $(GPIO_HEADERS) \
$(PURESIGNAL_HEADERS) $(MIDI_HEADERS) $(STEMLAB_HEADERS) $(SERVER_HEADERS)\
$(SOURCES) \
- $(USBOZY_SOURCES) $(SOAPYSDR_SOURCES) $(LOCALCW_SOURCE) $(I2C_CONTROLLER_SOURCES) $(GPIO_SOURCES) \
+ $(USBOZY_SOURCES) $(SOAPYSDR_SOURCES) $(LOCALCW_SOURCE) $(GPIO_SOURCES) \
$(PURESIGNAL_SOURCES) $(MIDI_SOURCES) $(STEMLAB_SOURCES) $(SERVER_SOURCES)
.PHONY: prebuild
.PHONY: cppcheck
cppcheck:
cppcheck $(CPPOPTIONS) $(OPTIONS) $(CPPINCLUDES) $(SOURCES) $(REMOTE_SOURCES) \
- $(USBOZY_SOURCES) $(SOAPYSDR_SOURCES) $(I2C_CONTROLLER_SOURCES) $(GPIO_SOURCES) \
+ $(USBOZY_SOURCES) $(SOAPYSDR_SOURCES) $(GPIO_SOURCES) \
$(PURESIGNAL_SOURCES) $(MIDI_SOURCES) $(STEMLAB_SOURCES) $(LOCALCW_SOURCES) \
$(SERVER_SOURCES)
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(gpio),NULL,"Controller1");
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(gpio),NULL,"Controller2 V1");
gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(gpio),NULL,"Controller2 V2");
+ gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(gpio),NULL,"Controller I2C");
gtk_grid_attach(GTK_GRID(grid),gpio,0,row,1,1);
gtk_combo_box_set_active(GTK_COMBO_BOX(gpio),controller);
static GMutex encoder_mutex;
static GThread *monitor_thread_id;
-int controller=NO_CONTROLLER;
-
int I2C_INTERRUPT=15;
#define MAX_LINES 32
#define MAX_SWITCHES 16
#define MAX_FUNCTIONS 6
-enum {
- NO_CONTROLLER=0,
- CONTROLLER1,
- CONTROLLER2_V1,
- CONTROLLER2_V2,
-};
-
-extern int controller;
-
typedef struct _encoder {
gboolean bottom_encoder_enabled;
gboolean bottom_encoder_pullup;
#include <i2c/smbus.h>
#include <sys/ioctl.h>
#include <fcntl.h>
+#include "actions.h"
#include "i2c_controller.h"
#include "vfo.h"
#include "radio.h"
#include "new_menu.h"
+/*
char *encoder_string[ENCODER_ACTIONS] = {
"NO ACTION",
"AF GAIN",
"ZOOM -",
"ZOOM +",
};
+*/
-ENCODER encoder[MAX_ENCODERS]=
+I2C_ENCODER encoder[MAX_I2C_ENCODERS]=
{
{TRUE,0x11,0,ENCODER_AF_GAIN,TRUE,MODE_MENU,FALSE,NO_ACTION,FALSE,NO_ACTION,FALSE,NO_ACTION},
{TRUE,0x12,0,ENCODER_AGC_GAIN,TRUE,FILTER_MENU,FALSE,NO_ACTION,FALSE,NO_ACTION,FALSE,NO_ACTION},
{TRUE,0x10,0,ENCODER_VFO,TRUE,MENU_BAND,FALSE,NO_ACTION,FALSE,NO_ACTION,FALSE,NO_ACTION},
};
-char *gpio_device="/dev/gpiochip0";
+char *i2c_controller_gpio_device="/dev/gpiochip0";
int new_i2c_interrupt=4;
static struct gpiod_chip *chip=NULL;
static GMutex encoder_mutex;
static GThread *monitor_thread_id;
-char *i2c_device="/dev/i2c-1";
+char *i2c_controller_i2c_device="/dev/i2c-1";
static int fd=-1;
static int vfo_encoder_changed(void *data) {
if(!locked) {
- gint pos=(gint)data;
+ gint pos=GPOINTER_TO_INT(data);
vfo_step(pos);
}
return 0;
static gpointer rotary_encoder_thread(gpointer data) {
while(1) {
g_mutex_lock(&encoder_mutex);
- for(int i=0;i<MAX_ENCODERS;i++) {
+ for(int i=0;i<MAX_I2C_ENCODERS;i++) {
if(encoder[i].enabled) {
if(encoder[i].pos!=0) {
switch(encoder[i].encoder_function) {
if(active_menu==BAND_MENU) {
// move to next/previous band
} else {
- g_idle_add(vfo_encoder_changed,(gpointer)encoder[i].pos);
+ g_idle_add(vfo_encoder_changed,GINT_TO_POINTER(encoder[i].pos));
}
break;
case ENCODER_AF_GAIN:
if(af_gain>1.0) af_gain=1.0;
double *dp=g_new(double,1);
*dp=af_gain;
- g_idle_add(ext_set_af_gain,(gpointer)dp);
+ g_idle_add(ext_set_af_gain,dp);
}
break;
case ENCODER_AGC_GAIN:
if(agc_gain>120.0) agc_gain=120.0;
double *dp=g_new(double,1);
*dp=agc_gain;
- g_idle_add(ext_set_agc_gain,(gpointer)dp);
+ g_idle_add(ext_set_agc_gain,dp);
}
break;
case ENCODER_DRIVE:
if(drive>drive_max) drive=drive_max;
double *dp=g_new(double,1);
*dp=drive;
- g_idle_add(ext_set_drive,(gpointer)dp);
+ g_idle_add(ext_set_drive,dp);
}
break;
}
}
}
-int i2c_init() {
+static int i2c_init() {
int ret=0;
g_mutex_init(&encoder_mutex);
- g_print("%s: open i2c device %s\n",__FUNCTION__,i2c_device);
- fd=open(i2c_device, O_RDWR);
+ g_print("%s: open i2c device %s\n",__FUNCTION__,i2c_controller_i2c_device);
+ fd=open(i2c_controller_i2c_device, O_RDWR);
if(fd<0) {
- g_print("%s: open i2c device %s failed: %s\n",__FUNCTION__,i2c_device,g_strerror(errno));
+ g_print("%s: open i2c device %s failed: %s\n",__FUNCTION__,i2c_controller_i2c_device,g_strerror(errno));
goto end;
}
- g_print("%s: open i2c device %s fd=%d\n",__FUNCTION__,i2c_device,fd);
+ g_print("%s: open i2c device %s fd=%d\n",__FUNCTION__,i2c_controller_i2c_device,fd);
- for(int i=0;i<MAX_ENCODERS;i++) {
+ for(int i=0;i<MAX_I2C_ENCODERS;i++) {
if(encoder[i].enabled) {
if (ioctl(fd, I2C_SLAVE, encoder[i].address) < 0) {
}
}
-void i2c_interrupt(int line) {
+static void i2c_interrupt(int line) {
int length;
g_print("%s: line=%d fd=%d\n",__FUNCTION__,line,fd);
if(fd!=-1) {
g_mutex_lock(&encoder_mutex);
- for(int i=0;i<MAX_ENCODERS;i++) {
+ for(int i=0;i<MAX_I2C_ENCODERS;i++) {
if(encoder[i].enabled) {
if (ioctl(fd, I2C_SLAVE, encoder[i].address) < 0) {
g_print("%s: ioctl i2c slave %d failed: %s\n",__FUNCTION__,encoder[i].address,g_strerror(errno));
t.tv_sec=60;
t.tv_nsec=0;
- int ret=gpiod_ctxless_event_monitor(gpio_device,GPIOD_CTXLESS_EVENT_FALLING_EDGE,new_i2c_interrupt,FALSE,"encoder",&t,NULL,interrupt_cb,NULL);
+ int ret=gpiod_ctxless_event_monitor(i2c_controller_gpio_device,GPIOD_CTXLESS_EVENT_FALLING_EDGE,new_i2c_interrupt,FALSE,"encoder",&t,NULL,interrupt_cb,NULL);
if (ret<0) {
g_print("%s: ctxless event monitor failed: %s\n",__FUNCTION__,g_strerror(errno));
}
return NULL;
}
-int gpio_init() {
+static int gpio_init() {
int ret=0;
return ret;
}
-void gpio_close() {
+static void gpio_close() {
if(line!=NULL) gpiod_line_release(line);
if(chip!=NULL) gpiod_chip_close(chip);
}
#define GAMMA_2_6 6
#define GAMMA_2_8 7
+/*
enum {
ENCODER_NO_ACTION=0,
ENCODER_AF_GAIN,
};
extern char *sw_string[SWITCH_ACTIONS];
+*/
-typedef struct _encoder {
+typedef struct i2c_encoder {
gboolean enabled;
gint address;
gint pos;
gint gp2_function;
gboolean gp3_enabled;
gint gp3_function;
-} ENCODER;
+} I2C_ENCODER;
-#define MAX_ENCODERS 7
+#define MAX_I2C_ENCODERS 7
-extern ENCODER encoder[MAX_ENCODERS];
+extern I2C_ENCODER encoder[MAX_I2C_ENCODERS];
extern int i2c_controller_init();
#endif
#include <glib.h>
#include <glib/gprintf.h>
+#include "actions.h"
#include "i2c_controller.h"
#include "main.h"
#include "new_menu.h"
gtk_grid_set_column_spacing (GTK_GRID(grid),2);
gtk_grid_set_row_spacing (GTK_GRID(grid),2);
- for(int i=0;i<MAX_ENCODERS;i++) {
+ for(int i=0;i<MAX_I2C_ENCODERS;i++) {
row=i%3;
col=(i/3)*4;
gtk_grid_set_column_spacing (GTK_GRID(grid),2);
gtk_grid_set_row_spacing (GTK_GRID(grid),2);
- for(int i=0;i<MAX_ENCODERS;i++) {
+ for(int i=0;i<MAX_I2C_ENCODERS;i++) {
row=i%3;
col=(i/3)*4;
#include <sys/utsname.h>
extern struct utsname unameData;
+enum {
+ NO_CONTROLLER,
+ CONTROLLER1,
+ CONTROLLER2_V1,
+ CONTROLLER2_V2,
+ CONTROLLER_I2C
+};
+
+extern gint controller;
+
extern gint display_width;
extern gint display_height;
extern gint full_screen;
#include "actions.h"
#ifdef GPIO
#include "gpio.h"
+#include "i2c_controller_menu.h"
#endif
#include "old_protocol.h"
#include "new_protocol.h"
#ifdef CLIENT_SERVER
#include "server_menu.h"
#endif
-#ifdef I2C_CONTROLLER
-#include "i2c_controller_menu.h"
-#endif
static GtkWidget *menu_b=NULL;
return TRUE;
}
+#ifdef GPIO
static gboolean encoder_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
cleanup();
encoder_menu(top_window);
return TRUE;
}
+void start_i2c_controller() {
+ cleanup();
+ i2c_controller_menu(top_window);
+}
+
+static gboolean i2c_controller_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
+ start_i2c_controller();
+ return TRUE;
+}
+#endif
+
static gboolean cw_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
cleanup();
cw_menu(top_window);
}
#endif
-#ifdef GPIO
-/*
-void start_encoder(int encoder) {
- int old_menu=active_menu;
- cleanup();
- switch(encoder) {
- case 2:
- if(old_menu!=E2_MENU) {
- encoder_menu(top_window,encoder);
- active_menu=E2_MENU;
- }
- break;
- case 3:
- if(old_menu!=E3_MENU) {
- encoder_menu(top_window,encoder);
- active_menu=E3_MENU;
- }
- break;
- case 4:
- if(old_menu!=E4_MENU) {
- encoder_menu(top_window,encoder);
- active_menu=E4_MENU;
- }
- break;
- case 5:
- if(old_menu!=E5_MENU) {
- encoder_menu(top_window,encoder);
- active_menu=E5_MENU;
- }
- break;
- }
-}
-
-static gboolean encoder_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
- int encoder=(int)data;
- start_encoder(encoder);
- return TRUE;
-}
-*/
-#endif
-
void start_test() {
cleanup();
test_menu(top_window);
}
#endif
-#ifdef I2C_CONTROLLER
-void start_i2c_controller() {
- cleanup();
- i2c_controller_menu(top_window);
-}
-
-static gboolean i2c_controller_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) {
- start_i2c_controller();
- return TRUE;
-}
-#endif
-
void new_menu()
{
int i;
i++;
#ifdef GPIO
- if(controller!=NO_CONTROLLER) {
- GtkWidget *encoders_b=gtk_button_new_with_label("Encoders");
- g_signal_connect (encoders_b, "button-press-event", G_CALLBACK(encoder_cb), NULL);
- gtk_grid_attach(GTK_GRID(grid),encoders_b,(i%5),i/5,1,1);
- i++;
+ switch(controller) {
+ case NO_CONTROLLER:
+ break;
+ case CONTROLLER1:
+ case CONTROLLER2_V1:
+ case CONTROLLER2_V2:
+ {
+ GtkWidget *encoders_b=gtk_button_new_with_label("Encoders");
+ g_signal_connect (encoders_b, "button-press-event", G_CALLBACK(encoder_cb), NULL);
+ gtk_grid_attach(GTK_GRID(grid),encoders_b,(i%5),i/5,1,1);
+ i++;
- 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++;
+ 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 CONTROLLER_I2C:
+ {
+ GtkWidget *i2c_controller_b=gtk_button_new_with_label("I2C Controller");
+ g_signal_connect (i2c_controller_b, "button-press-event", G_CALLBACK(i2c_controller_cb), NULL);
+ gtk_grid_attach(GTK_GRID(grid),i2c_controller_b,(i%5),i/5,1,1);
+ i++;
+ }
+ break;
}
#endif
-#ifdef I2C_CONTROLLER
- GtkWidget *i2c_controller_b=gtk_button_new_with_label("I2C Controller");
- g_signal_connect (i2c_controller_b, "button-press-event", G_CALLBACK(i2c_controller_cb), NULL);
- gtk_grid_attach(GTK_GRID(grid),i2c_controller_b,(i%5),i/5,1,1);
- i++;
-#endif
-
//
// We need at least two receivers and two ADCs to do DIVERSITY
//
BAND *band=band_get_band(i);
if(strlen(band->title)>0) {
GtkWidget *band_label=gtk_label_new(NULL);
- char band_text[16];
+ char band_text[32];
sprintf(band_text,"<b>%s</b>",band->title);
gtk_label_set_markup(GTK_LABEL(band_label), band_text);
//gtk_widget_override_font(band_label, pango_font_description_from_string("Arial 18"));
#include "soapy_protocol.h"
#endif
#include "actions.h"
-#ifdef GPIO
#include "gpio.h"
-#endif
-#ifdef I2C_CONTROLLER
#include "i2c_controller.h"
-#endif
#include "vfo.h"
#include "vox.h"
#include "meter.h"
#define TOOLBAR_HEIGHT (30)
#define WATERFALL_HEIGHT (105)
+gint controller=NO_CONTROLLER;
+
GtkWidget *fixed;
static GtkWidget *vfo_panel;
static GtkWidget *meter;
#endif
}
-#ifdef I2C_CONTROLLER
- if(i2c_controller_init()<0) {
- g_print("%s: I2C_CONTROLLER failed to initialize i2c\n", __FUNCTION__);
+#ifdef GPIO
+ if(controller==CONTROLLER_I2C) {
+ if(i2c_controller_init()<0) {
+ g_print("%s: I2C_CONTROLLER failed to initialize i2c\n", __FUNCTION__);
+ }
}
#endif
vfo_encoder_divisor=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
}
+#ifdef GPIO
static void gpio_settle_value_changed_cb(GtkWidget *widget, gpointer data) {
settle_time=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
}
+#endif
/*
static void toolbar_dialog_buttons_cb(GtkWidget *widget, gpointer data) {
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
-#ifdef GPIO
#include "actions.h"
#include "gpio.h"
-#endif
#include "toolbar.h"
#include "mode.h"
#include "filter.h"