From 7fff836df7b9dd65be2aa3c6fb6cabaa8a33460e Mon Sep 17 00:00:00 2001 From: sq8mvy Date: Sat, 21 Mar 2020 17:02:11 +0000 Subject: [PATCH] Added pin configuration for TOP E2 to E5 encoders in the "Configure GPIO" menu for Controller2_2 --- configure.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++---- gpio.c | 32 +++++++++++++ i2c.c | 4 +- 3 files changed, 152 insertions(+), 11 deletions(-) diff --git a/configure.c b/configure.c index b3deb42..8701873 100644 --- a/configure.c +++ b/configure.c @@ -159,18 +159,33 @@ static gboolean save_cb (GtkWidget *widget, GdkEventButton *event, gpointer data ENABLE_E2_PULLUP=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b_enable_E2_pullup))?1:0; E2_FUNCTION=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(E2_sw)); + if(controller==CONTROLLER2_V2) { + E2_TOP_ENCODER_A=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(E2_top_a)); + E2_TOP_ENCODER_B=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(E2_top_b)); + } + ENABLE_E3_ENCODER=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b_enable_E3_encoder))?1:0; E3_ENCODER_A=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(E3_a)); E3_ENCODER_B=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(E3_b)); ENABLE_E3_PULLUP=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b_enable_E3_pullup))?1:0; E3_FUNCTION=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(E3_sw)); + if(controller==CONTROLLER2_V2) { + E3_TOP_ENCODER_A=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(E3_top_a)); + E3_TOP_ENCODER_B=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(E3_top_b)); + } + ENABLE_E4_ENCODER=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b_enable_E4_encoder))?1:0; E4_ENCODER_A=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(E4_a)); E4_ENCODER_B=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(E4_b)); ENABLE_E4_PULLUP=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b_enable_E4_pullup))?1:0; E4_FUNCTION=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(E4_sw)); + if(controller==CONTROLLER2_V2) { + E4_TOP_ENCODER_A=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(E4_top_a)); + E4_TOP_ENCODER_B=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(E4_top_b)); + } + if(controller==CONTROLLER2_V1 || controller==CONTROLLER2_V2) { ENABLE_E5_ENCODER=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b_enable_E5_encoder))?1:0; E5_ENCODER_A=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(E5_a)); @@ -178,6 +193,11 @@ static gboolean save_cb (GtkWidget *widget, GdkEventButton *event, gpointer data ENABLE_E5_PULLUP=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b_enable_E5_pullup))?1:0; E5_FUNCTION=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(E5_sw)); + if(controller==CONTROLLER2_V2) { + E5_TOP_ENCODER_A=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(E5_top_a)); + E5_TOP_ENCODER_B=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(E5_top_b)); + } + const char *temp=gtk_entry_get_text(GTK_ENTRY(i2c_device_text)); i2c_device=g_new(char,strlen(temp)+1); strcpy(i2c_device,temp); @@ -346,7 +366,29 @@ void configure_gpio(GtkWidget *parent) { row++; - + + if(controller==CONTROLLER2_V2) { + E2_top_a_label=gtk_label_new("GPIO A:"); + gtk_widget_show(E2_top_a_label); + gtk_grid_attach(GTK_GRID(grid1),E2_top_a_label,1,row,1,1); + + E2_top_a=gtk_spin_button_new_with_range (0.0,100.0,1.0); + gtk_spin_button_set_value (GTK_SPIN_BUTTON(E2_top_a),E2_TOP_ENCODER_A); + gtk_widget_show(E2_top_a); + gtk_grid_attach(GTK_GRID(grid1),E2_top_a,2,row,1,1); + + E2_top_b_label=gtk_label_new("GPIO B:"); + gtk_widget_show(E2_top_b_label); + gtk_grid_attach(GTK_GRID(grid1),E2_top_b_label,3,row,1,1); + + E2_top_b=gtk_spin_button_new_with_range (0.0,100.0,1.0); + gtk_spin_button_set_value (GTK_SPIN_BUTTON(E2_top_b),E2_TOP_ENCODER_B); + gtk_widget_show(E2_top_b); + gtk_grid_attach(GTK_GRID(grid1),E2_top_b,4,row,1,1); + + row++; + } + b_enable_E3_encoder=gtk_check_button_new_with_label("Enable E3"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (b_enable_E3_encoder), ENABLE_E3_ENCODER); gtk_widget_show(b_enable_E3_encoder); @@ -385,7 +427,29 @@ void configure_gpio(GtkWidget *parent) { gtk_grid_attach(GTK_GRID(grid1),b_enable_E3_pullup,7,row,1,1); row++; - + + if(controller==CONTROLLER2_V2) { + E3_top_a_label=gtk_label_new("GPIO A:"); + gtk_widget_show(E3_top_a_label); + gtk_grid_attach(GTK_GRID(grid1),E3_top_a_label,1,row,1,1); + + E3_top_a=gtk_spin_button_new_with_range (0.0,100.0,1.0); + gtk_spin_button_set_value (GTK_SPIN_BUTTON(E3_top_a),E3_TOP_ENCODER_A); + gtk_widget_show(E3_top_a); + gtk_grid_attach(GTK_GRID(grid1),E3_top_a,2,row,1,1); + + E3_top_b_label=gtk_label_new("GPIO B:"); + gtk_widget_show(E3_top_b_label); + gtk_grid_attach(GTK_GRID(grid1),E3_top_b_label,3,row,1,1); + + E3_top_b=gtk_spin_button_new_with_range (0.0,100.0,1.0); + gtk_spin_button_set_value (GTK_SPIN_BUTTON(E3_top_b),E3_TOP_ENCODER_B); + gtk_widget_show(E3_top_b); + gtk_grid_attach(GTK_GRID(grid1),E3_top_b,4,row,1,1); + + row++; + } + b_enable_E4_encoder=gtk_check_button_new_with_label("Enable E4"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (b_enable_E4_encoder), ENABLE_E4_ENCODER); gtk_widget_show(b_enable_E4_encoder); @@ -424,26 +488,49 @@ void configure_gpio(GtkWidget *parent) { gtk_grid_attach(GTK_GRID(grid1),b_enable_E4_pullup,7,row,1,1); row++; - + + if(controller==CONTROLLER2_V2) + { + E4_top_a_label=gtk_label_new("GPIO A:"); + gtk_widget_show(E4_top_a_label); + gtk_grid_attach(GTK_GRID(grid1),E4_top_a_label,1,row,1,1); + + E4_top_a=gtk_spin_button_new_with_range (0.0,100.0,1.0); + gtk_spin_button_set_value (GTK_SPIN_BUTTON(E4_top_a),E4_TOP_ENCODER_A); + gtk_widget_show(E4_top_a); + gtk_grid_attach(GTK_GRID(grid1),E4_top_a,2,row,1,1); + + E4_top_b_label=gtk_label_new("GPIO B:"); + gtk_widget_show(E4_top_b_label); + gtk_grid_attach(GTK_GRID(grid1),E4_top_b_label,3,row,1,1); + + E4_top_b=gtk_spin_button_new_with_range (0.0,100.0,1.0); + gtk_spin_button_set_value (GTK_SPIN_BUTTON(E4_top_b),E4_TOP_ENCODER_B); + gtk_widget_show(E4_top_b); + gtk_grid_attach(GTK_GRID(grid1),E4_top_b,4,row,1,1); + + row++; + } + if(controller==CONTROLLER2_V1 || controller==CONTROLLER2_V2) { b_enable_E5_encoder=gtk_check_button_new_with_label("Enable E5"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (b_enable_E5_encoder), ENABLE_E5_ENCODER); gtk_widget_show(b_enable_E5_encoder); gtk_grid_attach(GTK_GRID(grid1),b_enable_E5_encoder,0,row,1,1); - + E5_a_label=gtk_label_new("GPIO A:"); gtk_widget_show(E5_a_label); gtk_grid_attach(GTK_GRID(grid1),E5_a_label,1,row,1,1); - + E5_a=gtk_spin_button_new_with_range (0.0,100.0,1.0); gtk_spin_button_set_value (GTK_SPIN_BUTTON(E5_a),E5_ENCODER_A); gtk_widget_show(E5_a); gtk_grid_attach(GTK_GRID(grid1),E5_a,2,row,1,1); - + E5_b_label=gtk_label_new("GPIO B:"); gtk_widget_show(E5_b_label); gtk_grid_attach(GTK_GRID(grid1),E5_b_label,3,row,1,1); - + E5_b=gtk_spin_button_new_with_range (0.0,100.0,1.0); gtk_spin_button_set_value (GTK_SPIN_BUTTON(E5_b),E5_ENCODER_B); gtk_widget_show(E5_b); @@ -452,16 +539,38 @@ void configure_gpio(GtkWidget *parent) { E5_sw_label=gtk_label_new("SW:"); gtk_widget_show(E5_sw_label); gtk_grid_attach(GTK_GRID(grid1),E5_sw_label,5,row,1,1); - + E5_sw=gtk_spin_button_new_with_range (0.0,100.0,1.0); gtk_spin_button_set_value (GTK_SPIN_BUTTON(E5_sw),E5_FUNCTION); gtk_widget_show(E5_sw); gtk_grid_attach(GTK_GRID(grid1),E5_sw,6,row,1,1); - + b_enable_E5_pullup=gtk_check_button_new_with_label("Enable Pull-up"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (b_enable_E5_pullup), ENABLE_E5_PULLUP); gtk_widget_show(b_enable_E5_pullup); gtk_grid_attach(GTK_GRID(grid1),b_enable_E5_pullup,7,row,1,1); + + if(controller==CONTROLLER2_V2) { + row++; + + E5_top_a_label=gtk_label_new("GPIO A:"); + gtk_widget_show(E5_top_a_label); + gtk_grid_attach(GTK_GRID(grid1),E5_top_a_label,1,row,1,1); + + E5_top_a=gtk_spin_button_new_with_range (0.0,100.0,1.0); + gtk_spin_button_set_value (GTK_SPIN_BUTTON(E5_top_a),E5_TOP_ENCODER_A); + gtk_widget_show(E5_top_a); + gtk_grid_attach(GTK_GRID(grid1),E5_top_a,2,row,1,1); + + E5_top_b_label=gtk_label_new("GPIO B:"); + gtk_widget_show(E5_top_b_label); + gtk_grid_attach(GTK_GRID(grid1),E5_top_b_label,3,row,1,1); + + E5_top_b=gtk_spin_button_new_with_range (0.0,100.0,1.0); + gtk_spin_button_set_value (GTK_SPIN_BUTTON(E5_top_b),E5_TOP_ENCODER_B); + gtk_widget_show(E5_top_b); + gtk_grid_attach(GTK_GRID(grid1),E5_top_b,4,row,1,1); + } } gtk_notebook_append_page(GTK_NOTEBOOK(notebook),grid1,gtk_label_new("Encoders")); diff --git a/gpio.c b/gpio.c index e37d90a..9d24dcb 100644 --- a/gpio.c +++ b/gpio.c @@ -1196,6 +1196,10 @@ void gpio_restore_state() { if(value) E2_ENCODER_A=atoi(value); value=getProperty("E2_ENCODER_B"); if(value) E2_ENCODER_B=atoi(value); + value=getProperty("E2_TOP_ENCODER_A"); + if(value) E2_TOP_ENCODER_A=atoi(value); + value=getProperty("E2_TOP_ENCODER_B"); + if(value) E2_TOP_ENCODER_B=atoi(value); value=getProperty("ENABLE_E3_ENCODER"); if(value) ENABLE_E3_ENCODER=atoi(value); value=getProperty("ENABLE_E3_PULLUP"); @@ -1204,6 +1208,10 @@ void gpio_restore_state() { if(value) E3_ENCODER_A=atoi(value); value=getProperty("E3_ENCODER_B"); if(value) E3_ENCODER_B=atoi(value); + value=getProperty("E3_TOP_ENCODER_A"); + if(value) E3_TOP_ENCODER_A=atoi(value); + value=getProperty("E3_TOP_ENCODER_B"); + if(value) E3_TOP_ENCODER_B=atoi(value); value=getProperty("ENABLE_E4_ENCODER"); if(value) ENABLE_E4_ENCODER=atoi(value); value=getProperty("ENABLE_E4_PULLUP"); @@ -1212,6 +1220,10 @@ void gpio_restore_state() { if(value) E4_ENCODER_A=atoi(value); value=getProperty("E4_ENCODER_B"); if(value) E4_ENCODER_B=atoi(value); + value=getProperty("E4_TOP_ENCODER_A"); + if(value) E4_TOP_ENCODER_A=atoi(value); + value=getProperty("E4_TOP_ENCODER_B"); + if(value) E4_TOP_ENCODER_B=atoi(value); value=getProperty("ENABLE_E5_ENCODER"); if(value) ENABLE_E5_ENCODER=atoi(value); value=getProperty("ENABLE_E5_PULLUP"); @@ -1220,6 +1232,10 @@ void gpio_restore_state() { if(value) E5_ENCODER_A=atoi(value); value=getProperty("E5_ENCODER_B"); if(value) E5_ENCODER_B=atoi(value); + value=getProperty("E5_TOP_ENCODER_A"); + if(value) E5_TOP_ENCODER_A=atoi(value); + value=getProperty("E5_TOP_ENCODER_B"); + if(value) E5_TOP_ENCODER_B=atoi(value); value=getProperty("ENABLE_S1_BUTTON"); if(value) ENABLE_S1_BUTTON=atoi(value); value=getProperty("S1_BUTTON"); @@ -1405,6 +1421,10 @@ void gpio_save_state() { setProperty("E2_ENCODER_A",value); sprintf(value,"%d",E2_ENCODER_B); setProperty("E2_ENCODER_B",value); + sprintf(value,"%d",E2_TOP_ENCODER_A); + setProperty("E2_TOP_ENCODER_A",value); + sprintf(value,"%d",E2_TOP_ENCODER_B); + setProperty("E2_TOP_ENCODER_B",value); sprintf(value,"%d",ENABLE_E3_ENCODER); setProperty("ENABLE_E3_ENCODER",value); sprintf(value,"%d",ENABLE_E3_PULLUP); @@ -1413,6 +1433,10 @@ void gpio_save_state() { setProperty("E3_ENCODER_A",value); sprintf(value,"%d",E3_ENCODER_B); setProperty("E3_ENCODER_B",value); + sprintf(value,"%d",E3_TOP_ENCODER_A); + setProperty("E3_TOP_ENCODER_A",value); + sprintf(value,"%d",E3_TOP_ENCODER_B); + setProperty("E3_TOP_ENCODER_B",value); sprintf(value,"%d",ENABLE_E4_ENCODER); setProperty("ENABLE_E4_ENCODER",value); sprintf(value,"%d",ENABLE_E4_PULLUP); @@ -1421,6 +1445,10 @@ void gpio_save_state() { setProperty("E4_ENCODER_A",value); sprintf(value,"%d",E4_ENCODER_B); setProperty("E4_ENCODER_B",value); + sprintf(value,"%d",E4_TOP_ENCODER_A); + setProperty("E4_TOP_ENCODER_A",value); + sprintf(value,"%d",E4_TOP_ENCODER_B); + setProperty("E4_TOP_ENCODER_B",value); sprintf(value,"%d",ENABLE_E5_ENCODER); setProperty("ENABLE_E5_ENCODER",value); sprintf(value,"%d",ENABLE_E5_PULLUP); @@ -1429,6 +1457,10 @@ void gpio_save_state() { setProperty("E5_ENCODER_A",value); sprintf(value,"%d",E5_ENCODER_B); setProperty("E5_ENCODER_B",value); + sprintf(value,"%d",E5_TOP_ENCODER_A); + setProperty("E5_TOP_ENCODER_A",value); + sprintf(value,"%d",E5_TOP_ENCODER_B); + setProperty("E5_TOP_ENCODER_B",value); sprintf(value,"%d",ENABLE_S1_BUTTON); setProperty("ENABLE_S1_BUTTON",value); sprintf(value,"%d",S1_BUTTON); diff --git a/i2c.c b/i2c.c index b686347..7798b8e 100644 --- a/i2c.c +++ b/i2c.c @@ -242,9 +242,9 @@ void i2c_init() { int flags, ints; -fprintf(stderr,"i2c_init\n"); +fprintf(stderr,"i2c_init: %s\n",i2c_device); - fd=wiringPiI2CSetup(i2c_address_1); + fd=wiringPiI2CSetupInterface(i2c_device, i2c_address_1); if(fd<0) { g_print("i2c_init failed: fd=%d\n",fd); return; -- 2.45.2