From 70e9349734bb25eed52e07e36d4d2f15dee339dd Mon Sep 17 00:00:00 2001 From: John Melton - G0ORX Date: Tue, 13 Jul 2021 12:31:36 +0100 Subject: [PATCH] Changes to actions selection for switches and encoders --- Makefile | 16 ++- action_dialog.c | 73 ++++++++++ action_dialog.h | 1 + actions.c | 106 +++++++-------- css.c | 5 +- css.h | 3 + discovery.c | 2 +- encoder_menu.c | 349 ++++++++++++++++++++++++++++++++++-------------- gpio.c | 40 +++--- main.c | 3 + midi2.c | 2 +- midi3.c | 2 + midi_menu.c | 214 ++++++++++++----------------- new_menu.c | 34 ++++- radio.c | 8 -- switch_menu.c | 102 +++++++------- toolbar_menu.c | 156 ++++++++++++++++++++++ toolbar_menu.h | 1 + vfo.c | 28 ++-- vfo_menu.c | 4 +- 20 files changed, 763 insertions(+), 386 deletions(-) create mode 100644 action_dialog.c create mode 100644 action_dialog.h create mode 100644 css.h create mode 100644 toolbar_menu.c create mode 100644 toolbar_menu.h diff --git a/Makefile b/Makefile index 72661a7..177adaf 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ GPIO_INCLUDE=GPIO PURESIGNAL_INCLUDE=PURESIGNAL # uncomment the line below to include MIDI support -MIDI_INCLUDE=MIDI +#MIDI_INCLUDE=MIDI # uncomment the line below to include USB Ozy support # USBOZY_INCLUDE=USBOZY @@ -29,7 +29,7 @@ MIDI_INCLUDE=MIDI #LOCALCW_INCLUDE=LOCALCW # uncomment the line below for SoapySDR -SOAPYSDR_INCLUDE=SOAPYSDR +#SOAPYSDR_INCLUDE=SOAPYSDR # uncomment the line to below include support for sx1509 i2c expander #SX1509_INCLUDE=sx1509 @@ -296,11 +296,13 @@ cwramp.c \ protocols.c \ css.c \ actions.c \ +action_dialog.c \ configure.c \ i2c.c \ gpio.c \ encoder_menu.c \ -switch_menu.c +switch_menu.c \ +toolbar_menu.c @@ -372,11 +374,13 @@ error_handler.h \ protocols.h \ css.h \ actions.h \ +action_dialog.h \ configure.h \ i2c.h \ gpio.h \ encoder_menu.h \ -switch_menu.h +switch_menu.h \ +toolbar_menu.h @@ -447,11 +451,13 @@ cwramp.o \ protocols.o \ css.o \ actions.o \ +action_dialog.o \ configure.o \ i2c.o \ gpio.o \ encoder_menu.o \ -switch_menu.o +switch_menu.o \ +toolbar_menu.o $(PROGRAM): $(OBJS) $(AUDIO_OBJS) $(REMOTE_OBJS) $(USBOZY_OBJS) $(SOAPYSDR_OBJS) \ $(LOCALCW_OBJS) $(PURESIGNAL_OBJS) \ diff --git a/action_dialog.c b/action_dialog.c new file mode 100644 index 0000000..a60fd71 --- /dev/null +++ b/action_dialog.c @@ -0,0 +1,73 @@ +#include +#include "actions.h" + +#define GRID_WIDTH 6 + +typedef struct _choice { + int action; + GtkWidget *button; + gulong signal_id; +} CHOICE; + +static GtkWidget *dialog; +static GtkWidget *previous_button; +static gulong previous_signal_id; +static int action; + +static void action_select_cb(GtkWidget *widget,gpointer data) { + CHOICE *choice=(CHOICE *)data; + g_signal_handler_block(G_OBJECT(previous_button),previous_signal_id); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(previous_button),FALSE); + g_signal_handler_unblock(G_OBJECT(previous_button),previous_signal_id); + previous_button=widget; + previous_signal_id=choice->signal_id; + action=choice->action; +} + +int action_dialog(GtkWidget *parent,int filter,int currentAction) { + int i,j; + + action=currentAction; + previous_button=NULL; + dialog=gtk_dialog_new_with_buttons("Action",GTK_WINDOW(parent),GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,("_OK"),GTK_RESPONSE_ACCEPT,("_Cancel"),GTK_RESPONSE_REJECT,NULL); + GtkWidget *content=gtk_dialog_get_content_area(GTK_DIALOG(dialog)); + GtkWidget *scrolled_window=gtk_scrolled_window_new(NULL,NULL); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),GTK_POLICY_AUTOMATIC,GTK_POLICY_ALWAYS); + gtk_widget_set_size_request(scrolled_window,790,380); + + GtkWidget *grid=gtk_grid_new(); + gtk_grid_set_column_spacing(GTK_GRID(grid),2); + gtk_grid_set_row_spacing(GTK_GRID(grid),2); + gtk_grid_set_column_homogeneous(GTK_GRID(grid),TRUE); + gtk_grid_set_row_homogeneous(GTK_GRID(grid),TRUE); + j=0; + for(i=0;iaction=i; + choice->button=button; + choice->signal_id=g_signal_connect(button,"toggled",G_CALLBACK(action_select_cb),choice); + if(ActionTable[i].action==currentAction) { + previous_button=button; + previous_signal_id=choice->signal_id; + } + j++; + } + } + gtk_container_add(GTK_CONTAINER(scrolled_window),grid); + gtk_container_add(GTK_CONTAINER(content),scrolled_window); + gtk_widget_show_all(content); + int result = gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy(dialog); + if(result!=GTK_RESPONSE_ACCEPT) { + action=currentAction; + } + return action; +} + diff --git a/action_dialog.h b/action_dialog.h new file mode 100644 index 0000000..c134e2e --- /dev/null +++ b/action_dialog.h @@ -0,0 +1 @@ +int action_dialog(GtkWidget *parent,int filter,int current); diff --git a/actions.c b/actions.c index 9d17398..b2a2e7e 100644 --- a/actions.c +++ b/actions.c @@ -42,35 +42,35 @@ ACTION_TABLE ActionTable[] = { {AF_GAIN_RX2, "AF GAIN\nRX2", NULL, MIDI_KNOB | MIDI_WHEEL | CONTROLLER_ENCODER}, {AGC, "AGC", "AGC", MIDI_KEY | CONTROLLER_SWITCH}, {AGC_GAIN, "AGC GAIN", NULL, MIDI_KNOB | MIDI_WHEEL | CONTROLLER_ENCODER}, - {AGC_GAIN_RX1, "AGC GAIN\nRX1", NULL, MIDI_KNOB | MIDI_WHEEL | CONTROLLER_ENCODER}, - {AGC_GAIN_RX2, "AGC GAIN\nRX2", NULL, MIDI_KNOB | MIDI_WHEEL | CONTROLLER_ENCODER}, + {AGC_GAIN_RX1, "AGC GAIN\nRX1", NULL, MIDI_KNOB | MIDI_WHEEL | CONTROLLER_ENCODER}, + {AGC_GAIN_RX2, "AGC GAIN\nRX2", NULL, MIDI_KNOB | MIDI_WHEEL | CONTROLLER_ENCODER}, {ANF, "ANF", "ANF", MIDI_KEY | CONTROLLER_SWITCH}, {ATTENUATION, "ATTEN", NULL, MIDI_KNOB | MIDI_WHEEL | CONTROLLER_ENCODER}, {B_TO_A, "Aaction,a->mode,a->val); + g_print("%s: action=%d mode=%d value=%d\n",__FUNCTION__,a->action,a->mode,a->val); switch(a->action) { case A_SWAP_B: diff --git a/css.c b/css.c index c8b9ae3..810492c 100644 --- a/css.c +++ b/css.c @@ -1,10 +1,11 @@ #include +#include "css.h" char *css= -" #small {\n" +" #small_button {\n" " padding: 0;\n" " font-family: Sans;\n" -" font-size: 12px;\n" +" font-size: 15px;\n" " }\n" ; diff --git a/css.h b/css.h new file mode 100644 index 0000000..148a8aa --- /dev/null +++ b/css.h @@ -0,0 +1,3 @@ +extern char *css; +extern void load_css(); + diff --git a/discovery.c b/discovery.c index c3a69bd..7fdfaa1 100644 --- a/discovery.c +++ b/discovery.c @@ -465,7 +465,7 @@ fprintf(stderr,"%p Protocol=%d name=%s\n",d,d->protocol,d->name); gtk_widget_override_font(start_button, pango_font_description_from_string("Sans 16")); gtk_widget_show(start_button); gtk_grid_attach(GTK_GRID(grid),start_button,3,row,1,1); - g_signal_connect(start_button,"button_press_event",G_CALLBACK(start_cb),(gpointer)d); + g_signal_connect(start_button,"button-press-event",G_CALLBACK(start_cb),(gpointer)d); // if not available then cannot start it if(d->status!=STATE_AVAILABLE) { diff --git a/encoder_menu.c b/encoder_menu.c index aa8aa59..933be4b 100644 --- a/encoder_menu.c +++ b/encoder_menu.c @@ -33,13 +33,16 @@ #include "vfo.h" #include "button_text.h" #include "actions.h" +#include "action_dialog.h" #include "gpio.h" #include "i2c.h" typedef struct _choice { int id; int action; + GtkWidget *initial_button; GtkWidget *button; + gulong signal_id; } CHOICE; static GtkWidget *parent_window=NULL; @@ -65,116 +68,54 @@ static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_d return FALSE; } -static void encoder_bottom_select_cb(GtkWidget *widget,gpointer data) { - CHOICE *choice=(CHOICE *)data; - encoders[choice->id].bottom_encoder_function=choice->action; - gtk_button_set_label(GTK_BUTTON(choice->button),ActionTable[choice->action].button_str); -} - -static void encoder_top_select_cb(GtkWidget *widget,gpointer data) { - CHOICE *choice=(CHOICE *)data; - encoders[choice->id].top_encoder_function=choice->action; - gtk_button_set_label(GTK_BUTTON(choice->button),ActionTable[choice->action].button_str); -} - -static void encoder_switch_select_cb(GtkWidget *widget,gpointer data) { - CHOICE *choice=(CHOICE *)data; - encoders[choice->id].switch_function=choice->action; - gtk_button_set_label(GTK_BUTTON(choice->button),ActionTable[choice->action].button_str); -} - static gboolean encoder_bottom_cb(GtkWidget *widget, GdkEvent *event, gpointer data) { - int encoder=GPOINTER_TO_INT(data); - int i; - - GtkWidget *menu=gtk_menu_new(); - for(i=0;iid=encoder; - choice->action=i; - choice->button=widget; - g_signal_connect(menu_item,"activate",G_CALLBACK(encoder_bottom_select_cb),choice); - gtk_menu_shell_append(GTK_MENU_SHELL(menu),menu_item); - } - } - gtk_widget_show_all(menu); -#if GTK_CHECK_VERSION(3,22,0) - gtk_menu_popup_at_pointer(GTK_MENU(menu),(GdkEvent *)event); -// the following line of code is to work around the problem of the popup menu not having scroll bars. - gtk_menu_reposition(GTK_MENU(menu)); -#else - gtk_menu_popup(GTK_MENU(menu),NULL,NULL,NULL,NULL,0,gtk_get_current_event_time()); -#endif + int en=GPOINTER_TO_INT(data); + int action=action_dialog(top_window,CONTROLLER_ENCODER,encoders[en].bottom_encoder_function); + gtk_button_set_label(GTK_BUTTON(widget),ActionTable[action].str); + encoders[en].bottom_encoder_function=action; return TRUE; } static gboolean encoder_top_cb(GtkWidget *widget, GdkEvent *event, gpointer data) { - int encoder=GPOINTER_TO_INT(data); - int i; - - GtkWidget *menu=gtk_menu_new(); - for(i=0;iid=encoder; - choice->action=i; - choice->button=widget; - g_signal_connect(menu_item,"activate",G_CALLBACK(encoder_top_select_cb),choice); - gtk_menu_shell_append(GTK_MENU_SHELL(menu),menu_item); - } - } - gtk_widget_show_all(menu); -#if GTK_CHECK_VERSION(3,22,0) - gtk_menu_popup_at_pointer(GTK_MENU(menu),(GdkEvent *)event); -// the following line of code is to work around the problem of the popup menu not having scroll bars. - gtk_menu_reposition(GTK_MENU(menu)); -#else - gtk_menu_popup(GTK_MENU(menu),NULL,NULL,NULL,NULL,0,gtk_get_current_event_time()); -#endif + int en=GPOINTER_TO_INT(data); + int action=action_dialog(dialog,CONTROLLER_ENCODER,encoders[en].top_encoder_function); + gtk_button_set_label(GTK_BUTTON(widget),ActionTable[action].str); + encoders[en].top_encoder_function=action; return TRUE; } static gboolean encoder_switch_cb(GtkWidget *widget, GdkEvent *event, gpointer data) { - int encoder=GPOINTER_TO_INT(data); - int i; - - GtkWidget *menu=gtk_menu_new(); - for(i=0;iid=encoder; - choice->action=i; - choice->button=widget; - g_signal_connect(menu_item,"activate",G_CALLBACK(encoder_switch_select_cb),choice); - gtk_menu_shell_append(GTK_MENU_SHELL(menu),menu_item); - } - } - gtk_widget_show_all(menu); -#if GTK_CHECK_VERSION(3,22,0) - gtk_menu_popup_at_pointer(GTK_MENU(menu),(GdkEvent *)event); -// the following line of code is to work around the problem of the popup menu not having scroll bars. - gtk_menu_reposition(GTK_MENU(menu)); -#else - gtk_menu_popup(GTK_MENU(menu),NULL,NULL,NULL,NULL,0,gtk_get_current_event_time()); -#endif + int en=GPOINTER_TO_INT(data); + int action=action_dialog(dialog,CONTROLLER_SWITCH,encoders[en].switch_function); + gtk_button_set_label(GTK_BUTTON(widget),ActionTable[action].str); + encoders[en].switch_function=action; return TRUE; } - void encoder_menu(GtkWidget *parent) { gint row=0; gint col=0; char label[32]; + GtkWidget *widget; dialog=gtk_dialog_new(); gtk_window_set_transient_for(GTK_WINDOW(dialog),GTK_WINDOW(parent)); //gtk_window_set_decorated(GTK_WINDOW(dialog),FALSE); char title[32]; - sprintf(title,"piHPSDR - Encoder Actions"); + switch(controller) { + case NO_CONTROLLER: + sprintf(title,"piHPSDR - No Encoders"); + break; + case CONTROLLER1: + sprintf(title,"piHPSDR - Controller 1 Encoder Actions"); + break; + case CONTROLLER2_V1: + sprintf(title,"piHPSDR - Controller 2 V1 Encoder Actions"); + break; + case CONTROLLER2_V2: + sprintf(title,"piHPSDR - Controller 2 V2 Encoder Actions"); + break; + } gtk_window_set_title(GTK_WINDOW(dialog),title); g_signal_connect (dialog, "delete_event", G_CALLBACK (delete_event), NULL); @@ -191,26 +132,238 @@ void encoder_menu(GtkWidget *parent) { row++; col=0; - gint max_encoders=MAX_ENCODERS; switch(controller) { case NO_CONTROLLER: - max_encoders=0; + // should never happen break; case CONTROLLER1: - max_encoders=4; + // 3 vertical single encoders with switches plus VFO + col=4; + for(int i=0;i<3;i++) { + widget=gtk_label_new(NULL); + gtk_widget_set_name(widget,"small_button"); + gtk_label_set_markup (GTK_LABEL(widget), "Switch"); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + col++; + widget=gtk_button_new_with_label(ActionTable[encoders[i].switch_function].str); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(encoder_switch_cb),GINT_TO_POINTER(i)); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + row++; + col=4; + + widget=gtk_label_new(NULL); + gtk_widget_set_name(widget,"small_button"); + gtk_label_set_markup (GTK_LABEL(widget),"Encoder"); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + col++; + widget=gtk_button_new_with_label(ActionTable[encoders[i].bottom_encoder_function].str); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(encoder_bottom_cb),GINT_TO_POINTER(i)); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + row++; + col=4; + } + + widget=gtk_label_new(NULL); + gtk_widget_set_name(widget,"small_button"); + gtk_label_set_markup (GTK_LABEL(widget),"Encoder"); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + col++; + widget=gtk_label_new(NULL); + gtk_widget_set_name(widget,"small_button"); + g_sprintf(label,"%s",ActionTable[encoders[3].bottom_encoder_function].str); + gtk_label_set_markup (GTK_LABEL(widget), label); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + row++; + col=0; break; case CONTROLLER2_V1: - max_encoders=5; + // 3 horizontal single encoders with switches + row=4; + col=0; + for(int i=0;i<3;i++) { + widget=gtk_label_new(NULL); + gtk_widget_set_name(widget,"small_button"); + gtk_label_set_markup (GTK_LABEL(widget), "Switch"); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + col++; + widget=gtk_button_new_with_label(ActionTable[encoders[i].switch_function].str); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(encoder_switch_cb),GINT_TO_POINTER(i)); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + col++; + } + row++; + col=0; + for(int i=0;i<3;i++) { + widget=gtk_label_new(NULL); + gtk_widget_set_name(widget,"small_button"); + gtk_label_set_markup (GTK_LABEL(widget),"Encoder"); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + col++; + widget=gtk_button_new_with_label(ActionTable[encoders[i].bottom_encoder_function].str); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(encoder_bottom_cb),GINT_TO_POINTER(i)); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + col++; + } + + // padding + row=1; + col=6; + widget=gtk_label_new(""); + gtk_widget_set_name(widget,"small_button"); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + + // 1 vertical single encoder with switch plus VFO encoder + row=1; + col=7; + widget=gtk_label_new(NULL); + gtk_widget_set_name(widget,"small_button"); + gtk_label_set_markup (GTK_LABEL(widget), "Switch"); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + col++; + widget=gtk_button_new_with_label(ActionTable[encoders[3].switch_function].str); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(encoder_switch_cb),GINT_TO_POINTER(3)); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + row++; + col=7; + widget=gtk_label_new(NULL); + gtk_widget_set_name(widget,"small_button"); + gtk_label_set_markup (GTK_LABEL(widget),"Encoder"); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + col++; + widget=gtk_button_new_with_label(ActionTable[encoders[3].bottom_encoder_function].str); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(encoder_bottom_cb),GINT_TO_POINTER(3)); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + + row=5; + col=7; + widget=gtk_label_new(NULL); + gtk_widget_set_name(widget,"small_button"); + gtk_label_set_markup (GTK_LABEL(widget),"Encoder"); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + col++; + widget=gtk_button_new_with_label(ActionTable[encoders[4].bottom_encoder_function].str); + gtk_widget_set_name(widget,"small_button"); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + break; case CONTROLLER2_V2: - max_encoders=5; + // 3 horizontal double encoders with switches + row=5; + col=0; + for(int i=0;i<3;i++) { + widget=gtk_label_new(NULL); + gtk_widget_set_name(widget,"small_button"); + gtk_label_set_markup (GTK_LABEL(widget), "Switch"); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + col++; + widget=gtk_button_new_with_label(ActionTable[encoders[i].switch_function].str); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(encoder_switch_cb),GINT_TO_POINTER(i)); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + col++; + } + row++; + col=0; + for(int i=0;i<3;i++) { + widget=gtk_label_new(NULL); + gtk_widget_set_name(widget,"small_button"); + gtk_label_set_markup (GTK_LABEL(widget),"Top"); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + col++; + widget=gtk_button_new_with_label(ActionTable[encoders[i].top_encoder_function].str); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(encoder_top_cb),GINT_TO_POINTER(i)); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + col++; + } + row++; + col=0; + for(int i=0;i<3;i++) { + widget=gtk_label_new(NULL); + gtk_widget_set_name(widget,"small_button"); + gtk_label_set_markup (GTK_LABEL(widget),"Bottom"); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + col++; + widget=gtk_button_new_with_label(ActionTable[encoders[i].bottom_encoder_function].str); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(encoder_bottom_cb),GINT_TO_POINTER(i)); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + col++; + } + + // padding + row=1; + col=6; + widget=gtk_label_new(""); + gtk_widget_set_name(widget,"small_button"); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + + // 1 vertical single double with switch plus VFO encoder + row=1; + col=7; + widget=gtk_label_new(NULL); + gtk_widget_set_name(widget,"small_button"); + gtk_label_set_markup (GTK_LABEL(widget), "Switch"); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + col++; + widget=gtk_button_new_with_label(ActionTable[encoders[3].switch_function].str); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(encoder_switch_cb),GINT_TO_POINTER(3)); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + row++; + col=7; + widget=gtk_label_new(NULL); + gtk_widget_set_name(widget,"small_button"); + gtk_label_set_markup (GTK_LABEL(widget),"Top"); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + col++; + widget=gtk_button_new_with_label(ActionTable[encoders[3].top_encoder_function].str); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(encoder_top_cb),GINT_TO_POINTER(3)); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + row++; + col=7; + widget=gtk_label_new(NULL); + gtk_widget_set_name(widget,"small_button"); + gtk_label_set_markup (GTK_LABEL(widget),"Bottom"); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + col++; + widget=gtk_button_new_with_label(ActionTable[encoders[3].bottom_encoder_function].str); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(encoder_bottom_cb),GINT_TO_POINTER(3)); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + + row=7; + col=7; + widget=gtk_label_new(NULL); + gtk_widget_set_name(widget,"small_button"); + gtk_label_set_markup (GTK_LABEL(widget),"Encoder"); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + col++; + widget=gtk_button_new_with_label(ActionTable[encoders[4].bottom_encoder_function].str); + gtk_widget_set_name(widget,"small_button"); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + break; } +/* + widget=gtk_label_new(NULL); + gtk_label_set_markup (GTK_LABEL(widget), controller==CONTROLLER2_V2?"Bottom Encoder":"Encoder"); + gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); + col++; + GtkWidget *widget=gtk_label_new(""); gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); col++; + widget=gtk_label_new(NULL); gtk_label_set_markup (GTK_LABEL(widget), controller==CONTROLLER2_V2?"Bottom Encoder":"Encoder"); gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); @@ -243,21 +396,21 @@ void encoder_menu(GtkWidget *parent) { gtk_label_set_markup (GTK_LABEL(widget), label); } else { widget=gtk_button_new_with_label(ActionTable[encoders[i].bottom_encoder_function].str); - g_signal_connect(widget,"button_press_event",G_CALLBACK(encoder_bottom_cb),GINT_TO_POINTER(i)); + g_signal_connect(widget,"button-press-event",G_CALLBACK(encoder_bottom_cb),GINT_TO_POINTER(i)); } gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); col++; if(controller==CONTROLLER2_V2) { widget=gtk_button_new_with_label(ActionTable[encoders[i].top_encoder_function].str); - g_signal_connect(widget,"button_press_event",G_CALLBACK(encoder_top_cb),GINT_TO_POINTER(i)); + g_signal_connect(widget,"button-press-event",G_CALLBACK(encoder_top_cb),GINT_TO_POINTER(i)); gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); col++; } if(i!=(max_encoders-1)) { widget=gtk_button_new_with_label(ActionTable[encoders[i].switch_function].str); - g_signal_connect(widget,"button_press_event",G_CALLBACK(encoder_switch_cb),GINT_TO_POINTER(i)); + g_signal_connect(widget,"button-press-event",G_CALLBACK(encoder_switch_cb),GINT_TO_POINTER(i)); gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); col++; } @@ -265,7 +418,7 @@ void encoder_menu(GtkWidget *parent) { row++; col=0; } - +*/ gtk_container_add(GTK_CONTAINER(content),grid); sub_menu=dialog; diff --git a/gpio.c b/gpio.c index 9eab905..5505c5b 100644 --- a/gpio.c +++ b/gpio.c @@ -410,7 +410,7 @@ static unsigned long switch_debounce; static void process_encoder(int e,int l,int addr,int val) { guchar pinstate; - //g_print("%s: encoder=%d level=%d addr=0x%02X val=%d\n",__FUNCTION__,e,l,addr,val); + g_print("%s: encoder=%d level=%d addr=0x%02X val=%d\n",__FUNCTION__,e,l,addr,val); g_mutex_lock(&encoder_mutex); switch(l) { case BOTTOM_ENCODER: @@ -419,7 +419,7 @@ static void process_encoder(int e,int l,int addr,int val) { encoders[e].bottom_encoder_a_value=val; pinstate=(encoders[e].bottom_encoder_b_value<<1) | encoders[e].bottom_encoder_a_value; encoders[e].bottom_encoder_state=encoder_state_table[encoders[e].bottom_encoder_state&0xf][pinstate]; - //g_print("%s: state=%02X\n",__FUNCTION__,encoders[e].bottom_encoder_state); + g_print("%s: state=%02X\n",__FUNCTION__,encoders[e].bottom_encoder_state); switch(encoders[e].bottom_encoder_state&0x30) { case DIR_NONE: break; @@ -433,13 +433,13 @@ static void process_encoder(int e,int l,int addr,int val) { break; } - //g_print("%s: %s BOTTOM pos=%d\n",__FUNCTION__,encoder_string[encoders[e].bottom_encoder_function],encoders[e].bottom_encoder_pos); + g_print("%s: %d BOTTOM pos=%d\n",__FUNCTION__,e,encoders[e].bottom_encoder_pos); break; case B: encoders[e].bottom_encoder_b_value=val; pinstate=(encoders[e].bottom_encoder_b_value<<1) | encoders[e].bottom_encoder_a_value; encoders[e].bottom_encoder_state=encoder_state_table[encoders[e].bottom_encoder_state&0xf][pinstate]; - //g_print("%s: state=%02X\n",__FUNCTION__,encoders[e].bottom_encoder_state); + g_print("%s: state=%02X\n",__FUNCTION__,encoders[e].bottom_encoder_state); switch(encoders[e].bottom_encoder_state&0x30) { case DIR_NONE: break; @@ -453,7 +453,7 @@ static void process_encoder(int e,int l,int addr,int val) { break; } - //g_print("%s: %s BOTTOM pos=%d\n",__FUNCTION__,encoder_string[encoders[e].bottom_encoder_function],encoders[e].bottom_encoder_pos); + g_print("%s: %d BOTTOM pos=%d\n",__FUNCTION__,e,encoders[e].bottom_encoder_pos); break; } @@ -464,7 +464,7 @@ static void process_encoder(int e,int l,int addr,int val) { encoders[e].top_encoder_a_value=val; pinstate=(encoders[e].top_encoder_b_value<<1) | encoders[e].top_encoder_a_value; encoders[e].top_encoder_state=encoder_state_table[encoders[e].top_encoder_state&0xf][pinstate]; - //g_print("%s: state=%02X\n",__FUNCTION__,encoders[e].top_encoder_state); + g_print("%s: state=%02X\n",__FUNCTION__,encoders[e].top_encoder_state); switch(encoders[e].top_encoder_state&0x30) { case DIR_NONE: break; @@ -477,13 +477,13 @@ static void process_encoder(int e,int l,int addr,int val) { default: break; } - //g_print("%s: %s TOP pos=%d\n",__FUNCTION__,encoder_string[encoders[e].top_encoder_function],encoders[e].top_encoder_pos); + g_print("%s: %d TOP pos=%d\n",__FUNCTION__,e,encoders[e].top_encoder_pos); break; case B: encoders[e].top_encoder_b_value=val; pinstate=(encoders[e].top_encoder_b_value<<1) | encoders[e].top_encoder_a_value; encoders[e].top_encoder_state=encoder_state_table[encoders[e].top_encoder_state&0xf][pinstate]; - //g_print("%s: state=%02X\n",__FUNCTION__,encoders[e].top_encoder_state); + g_print("%s: state=%02X\n",__FUNCTION__,encoders[e].top_encoder_state); switch(encoders[e].top_encoder_state&0x30) { case DIR_NONE: break; @@ -496,7 +496,7 @@ static void process_encoder(int e,int l,int addr,int val) { default: break; } - //g_print("%s: %s TOP pos=%d\n",__FUNCTION__,encoder_string[encoders[e].top_encoder_function],encoders[e].top_encoder_pos); + g_print("%s: %d TOP pos=%d\n",__FUNCTION__,e,encoders[e].top_encoder_pos); break; } @@ -528,22 +528,22 @@ static void process_edge(int offset,int value) { for(i=0;i #include +#include "main.h" #include "discovered.h" #include "mode.h" #include "filter.h" @@ -35,6 +36,7 @@ #include "dac.h" #include "radio.h" #include "actions.h" +#include "action_dialog.h" #include "midi.h" #include "alsa_midi.h" #include "new_menu.h" @@ -97,6 +99,13 @@ enum { UPDATE_EXISTING }; +typedef struct _choice { + int action; + GtkWidget *initial_button; + GtkWidget *button; + gulong signal_id; +} CHOICE; + static int update(void *data); static void load_store(); @@ -159,47 +168,27 @@ static void type_changed_cb(GtkWidget *widget, gpointer data) { // update actions available for the type gchar *type=gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widget)); + g_print("%s: %s\n",__FUNCTION__,type); + gtk_button_set_label(GTK_BUTTON(newAction),ActionTable[thisAction].str); // NONE +} - g_print("%s: type=%s action=%d\n",__FUNCTION__,type,thisAction); - gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(newAction)); - gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(newAction),NULL,ActionTable[0].str); +static gboolean action_cb(GtkWidget *widget,gpointer data) { + int selection=0; + gchar *type=gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(newType)); if(type==NULL || strcmp(type,"NONE")==0) { - // leave empty - gtk_combo_box_set_active (GTK_COMBO_BOX(newAction),0); + return TRUE; } else if(strcmp(type,"KEY")==0) { - // add all the Key actions - for(i=1;ichannel==thisChannel || cmd->channel==-1) && cmd->type==thisType && cmd->action==thisAction) { - g_print("%s: found cmd %p\n",__FUNCTION__,cmd); break; } cmd=cmd->next; @@ -476,7 +458,8 @@ static void load_store() { static void add_cb(GtkButton *widget,gpointer user_data) { gchar *str_type=gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(newType)); - gchar *str_action=gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(newAction)); + //gchar *str_action=gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(newAction)); + const gchar *str_action=gtk_button_get_label(GTK_BUTTON(newAction)); ; gint i; @@ -498,13 +481,11 @@ static void add_cb(GtkButton *widget,gpointer user_data) { } action=NO_ACTION; - i=1; - while(ActionTable[i].action!=NO_ACTION) { + for(i=0;ichannel=thisChannel; @@ -776,20 +756,20 @@ void midi_menu(GtkWidget *parent) { col++; g_signal_connect(newType,"changed",G_CALLBACK(type_changed_cb),NULL); newVal=gtk_label_new(""); - col++; gtk_grid_attach(GTK_GRID(grid),newVal,col,row,1,1); - newMin=gtk_label_new(""); col++; + newMin=gtk_label_new(""); gtk_grid_attach(GTK_GRID(grid),newMin,col,row,1,1); - newMax=gtk_label_new(""); col++; + newMax=gtk_label_new(""); gtk_grid_attach(GTK_GRID(grid),newMax,col,row,1,1); + col++; row++; col=col-4; - newAction=gtk_combo_box_text_new(); - gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(newAction),5); + newAction=gtk_button_new_with_label(" "); + g_signal_connect(newAction, "button-press-event", G_CALLBACK(action_cb),NULL); gtk_grid_attach(GTK_GRID(grid),newAction,col++,row,1,1); add_b=gtk_button_new_with_label("Add"); @@ -812,7 +792,7 @@ void midi_menu(GtkWidget *parent) { scrolled_window=gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),GTK_POLICY_AUTOMATIC,GTK_POLICY_ALWAYS); - gtk_widget_set_size_request(scrolled_window,400,300); + gtk_widget_set_size_request(scrolled_window,400,200); view=gtk_tree_view_new(); @@ -862,7 +842,6 @@ static int update(void *data) { switch(state) { case UPDATE_NEW: - g_print("%s: UPDATE_NEW\n",__FUNCTION__); switch(thisEvent) { case EVENT_NONE: gtk_label_set_text(GTK_LABEL(newEvent),"NONE"); @@ -898,24 +877,7 @@ static int update(void *data) { gtk_combo_box_set_active (GTK_COMBO_BOX(newType),0); break; } - gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(newAction)); - gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(newAction),NULL,"NONE"); - gtk_combo_box_set_active (GTK_COMBO_BOX(newAction),0); - if(thisEvent==MIDI_PITCH || thisEvent==MIDI_NOTE) { - i=1; - j=0; - while(ActionTable[i].action!=NO_ACTION) { - if(ActionTable[i].type&MIDI_KEY) { - gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(newAction),NULL,ActionTable[i].str); - if(ActionTable[i].action==thisAction) { - gtk_combo_box_set_active(GTK_COMBO_BOX(newAction),j); - } - j++; - } - i++; - } - - } + gtk_button_set_label(GTK_BUTTON(newAction),ActionTable[0].str); // NONE sprintf(text,"%d",thisVal); gtk_label_set_text(GTK_LABEL(newVal),text); sprintf(text,"%d",thisMin); @@ -929,7 +891,6 @@ static int update(void *data) { break; case UPDATE_CURRENT: - g_print("%s: UPDATE_CURRENT\n",__FUNCTION__); sprintf(text,"%d",thisVal); gtk_label_set_text(GTK_LABEL(newVal),text); sprintf(text,"%d",thisMin); @@ -939,7 +900,6 @@ static int update(void *data) { break; case UPDATE_EXISTING: - g_print("%s: UPDATE_EXISTING\n",__FUNCTION__); switch(thisEvent) { case EVENT_NONE: gtk_label_set_text(GTK_LABEL(newEvent),"NONE"); @@ -1013,21 +973,18 @@ void NewMidiConfigureEvent(enum MIDIevent event, int channel, int note, int val) char *str_note; char *str_type; char *str_action; + int i; gint tree_event; gint tree_channel; gint tree_note; - //g_print("%s: event=%d channel=%d note=%d val=%d\n", __FUNCTION__,event,channel,note,val); - if(event==thisEvent && channel==thisChannel && note==thisNote) { - //g_print("%s: current event\n",__FUNCTION__); thisVal=val; if(valthisMax) thisMax=val; g_idle_add(update,GINT_TO_POINTER(UPDATE_CURRENT)); } else { - //g_print("%s: new or existing event\n",__FUNCTION__); thisEvent=event; thisChannel=channel; thisNote=note; @@ -1046,8 +1003,6 @@ void NewMidiConfigureEvent(enum MIDIevent event, int channel, int note, int val) gtk_tree_model_get(model, &iter, TYPE_COLUMN, &str_type, -1); gtk_tree_model_get(model, &iter, ACTION_COLUMN, &str_action, -1); - //g_print("%s: %s %s %s %s %s\n",__FUNCTION__,str_event,str_channel,str_note,str_type,str_action); - if(str_event!=NULL && str_channel!=NULL && str_note!=NULL && str_type!=NULL && str_action!=NULL) { if(strcmp(str_event,"CTRL")==0) { tree_event=MIDI_CTRL; @@ -1075,13 +1030,11 @@ void NewMidiConfigureEvent(enum MIDIevent event, int channel, int note, int val) thisType=TYPE_NONE; } thisAction=NO_ACTION; - int i=1; - while(ActionTable[i].action!=NO_ACTION) { + for(i=0;isw].switch_function=choice->action; - GtkWidget *label=gtk_bin_get_child(GTK_BIN(choice->button)); - sprintf(text,"%s",ActionTable[choice->action].str); - gtk_label_set_markup (GTK_LABEL(label), text); - update_toolbar_labels(); -} - static gboolean switch_cb(GtkWidget *widget, GdkEvent *event, gpointer data) { int sw=GPOINTER_TO_INT(data); - int i; - - GtkWidget *menu=gtk_menu_new(); - for(i=0;isw=sw; - choice->action=i; - choice->button=widget; - g_signal_connect(menu_item,"activate",G_CALLBACK(switch_select_cb),choice); - gtk_menu_shell_append(GTK_MENU_SHELL(menu),menu_item); - } - } - gtk_widget_show_all(menu); -#if GTK_CHECK_VERSION(3,22,0) - gtk_menu_popup_at_pointer(GTK_MENU(menu),(GdkEvent *)event); -// the following line of code is to work around the problem of the popup menu not having scroll bars. - gtk_menu_reposition(GTK_MENU(menu)); -#else - gtk_menu_popup(GTK_MENU(menu),NULL,NULL,NULL,NULL,0,gtk_get_current_event_time()); -#endif + int action=action_dialog(top_window,CONTROLLER_SWITCH,temp_switches[sw].switch_function); + gtk_button_set_label(GTK_BUTTON(widget),ActionTable[action].str); + temp_switches[sw].switch_function=action; + update_toolbar_labels(); return TRUE; } @@ -127,7 +102,7 @@ void switch_menu(GtkWidget *parent) { gint function=0; - dialog=gtk_dialog_new_with_buttons("piHPSDR - Switch Actions",GTK_WINDOW(parent),GTK_DIALOG_DESTROY_WITH_PARENT,("OK"),GTK_RESPONSE_ACCEPT,NULL); + dialog=gtk_dialog_new_with_buttons("piHPSDR - Switch Actions",GTK_WINDOW(parent),GTK_DIALOG_DESTROY_WITH_PARENT,"_OK",GTK_RESPONSE_ACCEPT,NULL); g_signal_connect (dialog, "response", G_CALLBACK (response_event), NULL); GtkWidget *content=gtk_dialog_get_content_area(GTK_DIALOG(dialog)); @@ -142,9 +117,9 @@ next_function_set: grid=gtk_grid_new(); gtk_grid_set_column_homogeneous(GTK_GRID(grid),TRUE); - gtk_grid_set_row_homogeneous(GTK_GRID(grid),TRUE); - gtk_grid_set_column_spacing (GTK_GRID(grid),2); - gtk_grid_set_row_spacing (GTK_GRID(grid),2); + gtk_grid_set_row_homogeneous(GTK_GRID(grid),FALSE); + gtk_grid_set_column_spacing (GTK_GRID(grid),0); + gtk_grid_set_row_spacing (GTK_GRID(grid),0); row=0; @@ -177,74 +152,90 @@ next_function_set: row=row+5; col=0; widget=gtk_button_new_with_label(ActionTable[temp_switches[0].switch_function].str); - g_signal_connect(widget,"button_press_event",G_CALLBACK(switch_cb),GINT_TO_POINTER(0)); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(switch_cb),GINT_TO_POINTER(0)); gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); col++; widget=gtk_button_new_with_label(ActionTable[temp_switches[1].switch_function].str); - g_signal_connect(widget,"button_press_event",G_CALLBACK(switch_cb),GINT_TO_POINTER(1)); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(switch_cb),GINT_TO_POINTER(1)); gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); col++; widget=gtk_button_new_with_label(ActionTable[temp_switches[2].switch_function].str); - g_signal_connect(widget,"button_press_event",G_CALLBACK(switch_cb),GINT_TO_POINTER(2)); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(switch_cb),GINT_TO_POINTER(2)); gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); col++; widget=gtk_button_new_with_label(ActionTable[temp_switches[3].switch_function].str); - g_signal_connect(widget,"button_press_event",G_CALLBACK(switch_cb),GINT_TO_POINTER(3)); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(switch_cb),GINT_TO_POINTER(3)); gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); col++; widget=gtk_button_new_with_label(ActionTable[temp_switches[4].switch_function].str); - g_signal_connect(widget,"button_press_event",G_CALLBACK(switch_cb),GINT_TO_POINTER(4)); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(switch_cb),GINT_TO_POINTER(4)); gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); col++; widget=gtk_button_new_with_label(ActionTable[temp_switches[5].switch_function].str); - g_signal_connect(widget,"button_press_event",G_CALLBACK(switch_cb),GINT_TO_POINTER(5)); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(switch_cb),GINT_TO_POINTER(5)); gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); col++; widget=gtk_button_new_with_label(ActionTable[temp_switches[6].switch_function].str); - g_signal_connect(widget,"button_press_event",G_CALLBACK(switch_cb),GINT_TO_POINTER(6)); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(switch_cb),GINT_TO_POINTER(6)); gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); col++; row=original_row; col=8; widget=gtk_button_new_with_label(ActionTable[temp_switches[7].switch_function].str); - g_signal_connect(widget,"button_press_event",G_CALLBACK(switch_cb),GINT_TO_POINTER(7)); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(switch_cb),GINT_TO_POINTER(7)); gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); row++; col=7; widget=gtk_button_new_with_label(ActionTable[temp_switches[8].switch_function].str); - g_signal_connect(widget,"button_press_event",G_CALLBACK(switch_cb),GINT_TO_POINTER(8)); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(switch_cb),GINT_TO_POINTER(8)); gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); col++; widget=gtk_button_new_with_label(ActionTable[temp_switches[9].switch_function].str); - g_signal_connect(widget,"button_press_event",G_CALLBACK(switch_cb),GINT_TO_POINTER(9)); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(switch_cb),GINT_TO_POINTER(9)); gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); row++; col=7; widget=gtk_button_new_with_label(ActionTable[temp_switches[10].switch_function].str); - g_signal_connect(widget,"button_press_event",G_CALLBACK(switch_cb),GINT_TO_POINTER(10)); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(switch_cb),GINT_TO_POINTER(10)); gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); col++; widget=gtk_button_new_with_label(ActionTable[temp_switches[11].switch_function].str); - g_signal_connect(widget,"button_press_event",G_CALLBACK(switch_cb),GINT_TO_POINTER(11)); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(switch_cb),GINT_TO_POINTER(11)); gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); row++; col=7; widget=gtk_button_new_with_label(ActionTable[temp_switches[12].switch_function].str); - g_signal_connect(widget,"button_press_event",G_CALLBACK(switch_cb),GINT_TO_POINTER(12)); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(switch_cb),GINT_TO_POINTER(12)); gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); col++; widget=gtk_button_new_with_label(ActionTable[temp_switches[13].switch_function].str); - g_signal_connect(widget,"button_press_event",G_CALLBACK(switch_cb),GINT_TO_POINTER(13)); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(switch_cb),GINT_TO_POINTER(13)); gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); row++; col=7; widget=gtk_button_new_with_label(ActionTable[temp_switches[14].switch_function].str); - g_signal_connect(widget,"button_press_event",G_CALLBACK(switch_cb),GINT_TO_POINTER(14)); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(switch_cb),GINT_TO_POINTER(14)); gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); col++; widget=gtk_button_new_with_label(ActionTable[temp_switches[15].switch_function].str); - g_signal_connect(widget,"button_press_event",G_CALLBACK(switch_cb),GINT_TO_POINTER(15)); + gtk_widget_set_name(widget,"small_button"); + g_signal_connect(widget,"button-press-event",G_CALLBACK(switch_cb),GINT_TO_POINTER(15)); gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); gtk_container_add(GTK_CONTAINER(content),grid); @@ -253,12 +244,11 @@ next_function_set: for(int i=0;i%s",ActionTable[temp_switches[i].switch_function].str); - //gtk_label_set_markup (GTK_LABEL(widget), label); + // no signal for Function button } else { widget=gtk_button_new_with_label(ActionTable[temp_switches[i].switch_function].str); - g_signal_connect(widget,"button_press_event",G_CALLBACK(switch_cb),GINT_TO_POINTER(i)); + g_signal_connect(widget,"button-press-event",G_CALLBACK(switch_cb),GINT_TO_POINTER(i)); +g_print("%s: %d\n",__FUNCTION__,i); } gtk_grid_attach(GTK_GRID(grid),widget,col,row,1,1); col++; diff --git a/toolbar_menu.c b/toolbar_menu.c new file mode 100644 index 0000000..0297e36 --- /dev/null +++ b/toolbar_menu.c @@ -0,0 +1,156 @@ + +/* Copyright (C) +* 2016 - John Melton, G0ORX/N6LYT +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* +*/ + +#include +#include +#include +#include + +#include "main.h" +#include "new_menu.h" +#include "agc_menu.h" +#include "agc.h" +#include "band.h" +#include "channel.h" +#include "radio.h" +#include "receiver.h" +#include "vfo.h" +#include "button_text.h" +#include "toolbar.h" +#include "actions.h" +#include "action_dialog.h" +#include "gpio.h" +#include "i2c.h" + +typedef struct _choice { + int sw; + int action; + GtkWidget *initial_button; + GtkWidget *button; + gulong signal_id; +} CHOICE; + +static GtkWidget *parent_window=NULL; + +static GtkWidget *dialog=NULL; + +static SWITCH *temp_switches; + + +static void cleanup() { + if(dialog!=NULL) { + gtk_widget_destroy(dialog); + dialog=NULL; + active_menu=NO_MENU; + sub_menu=NULL; + } +} + +static gboolean close_cb (GtkWidget *widget, GdkEventButton *event, gpointer data) { + cleanup(); + return TRUE; +} + +static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data) { + cleanup(); + return FALSE; +} + +static void switch_page_cb(GtkNotebook *notebook,GtkWidget *page,guint page_num,gpointer user_data) { + temp_switches=switches_controller1[page_num]; +} + +static gboolean switch_cb(GtkWidget *widget, GdkEvent *event, gpointer data) { + int sw=GPOINTER_TO_INT(data); + int action=action_dialog(top_window,CONTROLLER_SWITCH,temp_switches[sw].switch_function); + gtk_button_set_label(GTK_BUTTON(widget),ActionTable[action].str); + temp_switches[sw].switch_function=action; + update_toolbar_labels(); + return TRUE; +} + +static void response_event(GtkWidget *dialog,gint id,gpointer user_data) { + gtk_widget_destroy(dialog); + dialog=NULL; + active_menu=NO_MENU; + sub_menu=NULL; +} + +void toolbar_menu(GtkWidget *parent) { + gint row; + gint col; + gchar label[64]; + GtkWidget *notebook; + GtkWidget *grid; + GtkWidget *widget; + gint function=0; + + + dialog=gtk_dialog_new_with_buttons("piHPSDR - Toolbar Actions",GTK_WINDOW(parent),GTK_DIALOG_DESTROY_WITH_PARENT,"_OK",GTK_RESPONSE_ACCEPT,NULL); + g_signal_connect (dialog, "response", G_CALLBACK (response_event), NULL); + + GtkWidget *content=gtk_dialog_get_content_area(GTK_DIALOG(dialog)); + + function=0; + + notebook=gtk_notebook_new(); + +next_function_set: + + grid=gtk_grid_new(); + gtk_grid_set_column_homogeneous(GTK_GRID(grid),TRUE); + gtk_grid_set_row_homogeneous(GTK_GRID(grid),FALSE); + gtk_grid_set_column_spacing (GTK_GRID(grid),0); + gtk_grid_set_row_spacing (GTK_GRID(grid),0); + + + row=0; + col=0; + + gint max_switches=MAX_SWITCHES; + max_switches=8; + temp_switches=switches_controller1[function]; + + for(int i=0;icompressor) { - sprintf(temp_text,"CMPR %d dB",(int) transmitter->compressor_level); - cairo_set_source_rgb(cr, 1.0, 1.0, 0.0); - cairo_show_text(cr, temp_text); + sprintf(temp_text,"CMPR %ddB",(int) transmitter->compressor_level); + cairo_set_source_rgb(cr, 1.0, 1.0, 0.0); + cairo_show_text(cr, temp_text); } else { - cairo_set_source_rgb(cr, 0.7, 0.7, 0.7); - cairo_show_text(cr, "CMPR OFF"); + cairo_set_source_rgb(cr, 0.7, 0.7, 0.7); + cairo_show_text(cr, "CMPR"); } } - cairo_move_to(cr, 500, 50); + cairo_move_to(cr, 505, 50); if(diversity_enabled) { cairo_set_source_rgb(cr, 1.0, 1.0, 0.0); } else { @@ -1143,7 +1143,7 @@ void vfo_update() { cairo_set_source_rgb(cr, 1.0, 1.0, 0.0); cairo_show_text(cr, temp_text); - cairo_move_to(cr, 430, 50); + cairo_move_to(cr, 405, 50); if(vfo[id].ctun) { cairo_set_source_rgb(cr, 1.0, 1.0, 0.0); } else { @@ -1151,7 +1151,17 @@ void vfo_update() { } cairo_show_text(cr, "CTUN"); - cairo_move_to(cr, 470, 50); +#ifdef MIDI + cairo_move_to(cr, 445, 50); + if(midi_enabled) { + cairo_set_source_rgb(cr, 1.0, 1.0, 0.0); + } else { + cairo_set_source_rgb(cr, 0.7, 0.7, 0.7); + } + cairo_show_text(cr, "MIDI"); +#endif + + cairo_move_to(cr, 475, 50); if(cat_control>0) { cairo_set_source_rgb(cr, 1.0, 1.0, 0.0); } else { @@ -1160,7 +1170,7 @@ void vfo_update() { cairo_show_text(cr, "CAT"); if(can_transmit) { - cairo_move_to(cr, 500, 15); + cairo_move_to(cr, 505, 15); if(vox_enabled) { cairo_set_source_rgb(cr, 1.0, 0.0, 0.0); } else { diff --git a/vfo_menu.c b/vfo_menu.c index b7eba43..2b4da08 100644 --- a/vfo_menu.c +++ b/vfo_menu.c @@ -291,13 +291,11 @@ void vfo_menu(GtkWidget *parent,int vfo) { gtk_grid_attach(GTK_GRID(grid),vfo_label,3,3,1,1); GtkWidget *vfo_b=gtk_combo_box_text_new(); - i=0; - while(steps[i]!=0) { + for(i=0;i<15;i++) { gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(vfo_b),NULL,step_labels[i]); if(steps[i]==step) { gtk_combo_box_set_active (GTK_COMBO_BOX(vfo_b), i); } - i++; } g_signal_connect(vfo_b,"changed",G_CALLBACK(vfo_cb),NULL); gtk_grid_attach(GTK_GRID(grid),vfo_b,4,3,1,1); -- 2.45.2