From: John Melton G0ORX Date: Fri, 11 Dec 2020 14:04:13 +0000 (+0000) Subject: Removed all i2c_controller references X-Git-Url: https://git.rkrishnan.org/pf/vdrive/simplejson/%3C?a=commitdiff_plain;h=33b6bb5beae464346fa7949722c0970489aa4404;p=pihpsdr.git Removed all i2c_controller references --- diff --git a/Makefile b/Makefile index a900f01..7c41f2c 100644 --- a/Makefile +++ b/Makefile @@ -15,8 +15,6 @@ endif # 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 @@ -132,25 +130,19 @@ GPIO_SOURCES= \ i2c.c \ gpio.c \ encoder_menu.c \ - switch_menu.c \ - i2c_controller.c \ - i2c_controller_menu.c + switch_menu.c GPIO_HEADERS= \ configure.h \ i2c.h \ gpio.h \ encoder_menu.h \ - switch_menu.h \ - i2c_controller.h \ - i2c_controller_menu.h + switch_menu.h GPIO_OBJS= \ configure.o \ i2c.o \ gpio.o \ encoder_menu.o \ - switch_menu.o \ - i2c_controller.o \ - i2c_controller_menu.o + switch_menu.o endif # diff --git a/i2c_controller.c b/i2c_controller.c deleted file mode 100644 index f06ca5c..0000000 --- a/i2c_controller.c +++ /dev/null @@ -1,475 +0,0 @@ -/* Copyright (C) -* 2020 - 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 -#include -#include -#include -#include -#include -#include -#include -#include "actions.h" -#include "i2c_controller.h" -#include "vfo.h" -#include "radio.h" -#include "ext.h" -#include "sliders.h" -#include "new_menu.h" - - -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,0x13,0,ENCODER_RIT,FALSE,NO_ACTION,FALSE,NO_ACTION,FALSE,NO_ACTION,FALSE,NO_ACTION}, - {TRUE,0x14,0,ENCODER_DRIVE,FALSE,NO_ACTION,FALSE,NO_ACTION,FALSE,NO_ACTION,FALSE,NO_ACTION}, - {TRUE,0x15,0,ENCODER_IF_SHIFT,FALSE,NO_ACTION,FALSE,NO_ACTION,FALSE,NO_ACTION,FALSE,NO_ACTION}, - {TRUE,0x16,0,ENCODER_IF_WIDTH,FALSE,NO_ACTION,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 *i2c_controller_gpio_device="/dev/gpiochip0"; -int new_i2c_interrupt=4; - -static struct gpiod_chip *chip=NULL; -static struct gpiod_line *line=NULL; - -static GMutex encoder_mutex; -static GThread *monitor_thread_id; - -char *i2c_controller_i2c_device="/dev/i2c-1"; - -static int fd=-1; - -static GThread *rotary_encoder_thread_id; - -static int vfo_encoder_changed(void *data) { - if(!locked) { - 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;iaction=encoder[i].encoder_function; - a->mode=RELATIVE; - a->val=encoder[i].pos; - g_idle_add(encoder_action,a); - encoder[i].pos=0; - } - } - } - g_mutex_unlock(&encoder_mutex); - usleep(100000); - } -} - -static int i2c_init() { - int ret=0; - - g_mutex_init(&encoder_mutex); - - 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_controller_i2c_device,g_strerror(errno)); - goto end; - } - g_print("%s: open i2c device %s fd=%d\n",__FUNCTION__,i2c_controller_i2c_device,fd); - - for(int i=0;i>8)&0xFF)<0) { - g_print("%s: write REG_GCONF2 config failed: addr=%02X %s\n",__FUNCTION__,encoder[i].address,g_strerror(errno)); - encoder[i].enabled=FALSE; - continue; - } - - int v=0; // initial value - - //g_print("%s: write counter value\n",__FUNCTION__); - if(i2c_smbus_write_i2c_block_data(fd, REG_CVALB4, 4, (const __u8 *)&v)<0) { - g_print("%s: counter CVALB1 config failed: %s\n",__FUNCTION__,g_strerror(errno)); - encoder[i].enabled=FALSE; - continue; - } - - v=1024; // max value - - //g_print("%s: write max value\n",__FUNCTION__); - if(i2c_smbus_write_i2c_block_data(fd, REG_CMAXB4, 4, (const __u8 *)&v)<0) { - g_print("%s: counter CMAXB1 config failed: %s\n",__FUNCTION__,g_strerror(errno)); - encoder[i].enabled=FALSE; - continue; - } - - v=-1024; // min value - - //g_print("%s: write min value\n",__FUNCTION__); - if(i2c_smbus_write_i2c_block_data(fd, REG_CMINB4, 4, (const __u8 *)&v)<0) { - g_print("%s: counter CMINB1 config failed: %s\n",__FUNCTION__,g_strerror(errno)); - encoder[i].enabled=FALSE; - continue; - } - - v=1; // step value - - //g_print("%s: write step value\n",__FUNCTION__); - if(i2c_smbus_write_i2c_block_data(fd, REG_ISTEPB4, 4, (const __u8 *)&v)<0) { - g_print("%s: counter CISTEPB4 config failed: %s\n",__FUNCTION__,g_strerror(errno)); - encoder[i].enabled=FALSE; - continue; - } - - v=8; - - //g_print("%s: write antibounce value\n",__FUNCTION__); - if(i2c_smbus_write_byte_data(fd, REG_ANTBOUNC, v&0xFF)<0) { - g_print("%s: counter REG_ANTBOUNC config failed: %s\n",__FUNCTION__,g_strerror(errno)); - encoder[i].enabled=FALSE; - continue; - } - - v=30; - - //g_print("%s: write double push value\n",__FUNCTION__); - if(i2c_smbus_write_byte_data(fd, REG_DPPERIOD, v&0xFF)<0) { - g_print("%s: counter REG_DPPERIOD config failed: %s\n",__FUNCTION__,g_strerror(errno)); - encoder[i].enabled=FALSE; - continue; - } - - - int int_config=0; - if(encoder[i].gp1_enabled) { - g_print("%s: encoder %d (0x%02X) GP1 enabled\n",__FUNCTION__,i,encoder[i].address); - v=GP_IN | GP_PULL_EN | GP_INT_NE; - int_config=INT_2; - } else { - g_print("%s: encoder %d (0x%02X) GP1 not enabled\n",__FUNCTION__,i,encoder[i].address); - v=GP_IN | GP_PULL_EN | GP_INT_DI; - } - if(i2c_smbus_write_byte_data(fd, REG_GP1CONF, v&0xFF)<0) { - g_print("%s: counter REG_GP1CONF config failed: %s\n",__FUNCTION__,g_strerror(errno)); - continue; - } - if(encoder[i].gp2_enabled) { - g_print("%s: encoder %d (0x%02X) GP2 enabled\n",__FUNCTION__,i,encoder[i].address); - v=GP_IN | GP_PULL_EN | GP_INT_NE; - int_config=INT_2; - } else { - g_print("%s: encoder %d (0x%02X) GP2 not enabled\n",__FUNCTION__,i,encoder[i].address); - v=GP_IN | GP_PULL_EN | GP_INT_DI; - } - if(i2c_smbus_write_byte_data(fd, REG_GP2CONF, v&0xFF)<0) { - g_print("%s: counter REG_GP2CONF config failed: %s\n",__FUNCTION__,g_strerror(errno)); - continue; - } - if(encoder[i].gp3_enabled) { - g_print("%s: encoder %d (0x%02X) GP3 enabled\n",__FUNCTION__,i,encoder[i].address); - v=GP_IN | GP_PULL_EN | GP_INT_NE; - int_config=INT_2; - } else { - g_print("%s: encoder %d (0x%02X) GP3 not enabled\n",__FUNCTION__,i,encoder[i].address); - v=GP_IN | GP_PULL_EN | GP_INT_DI; - } - if(i2c_smbus_write_byte_data(fd, REG_GP3CONF, v&0xFF)<0) { - g_print("%s: counter REG_GP3CONF config failed: %s\n",__FUNCTION__,g_strerror(errno)); - continue; - } - - int_config=PUSHR | PUSHP | PUSHD | RINC | RDEC /*| RMAX | RMIN | INT_2*/; - //g_print("%s: write interrupt config %02X\n",__FUNCTION__, int_config&0xFF); - if(i2c_smbus_write_byte_data(fd,REG_INTCONF,int_config&0xFF)<0) { - g_print("%s: counter CMINB1 config failed: %s\n",__FUNCTION__,g_strerror(errno)); - encoder[i].enabled=FALSE; - continue; - } - - __s32 id=i2c_smbus_read_byte_data(fd,REG_IDCODE); - g_print("%s: board addr=%02X id=%02X\n",__FUNCTION__,encoder[i].address,id&0xFF); - - __s32 ver=i2c_smbus_read_byte_data(fd,REG_VERSION); - g_print("%s: board addr=%02X version=%02X\n",__FUNCTION__,encoder[i].address,ver&0xFF); - } - } - - rotary_encoder_thread_id = g_thread_new( "encoders", rotary_encoder_thread, NULL); - if(!rotary_encoder_thread_id ) { - g_print("%s: g_thread_new failed on rotary_encoder_thread\n",__FUNCTION__); - ret=-1; - goto error; - } - - goto end; - -error: - if(fd>=0) { - close(fd); - fd=-1; - } - -end: - return ret; -} - -void i2c_close() { - if(fd>0) { - close(fd); - fd=-1; - } -} - -static void encoder_switch_pushed(int i) { - switch(encoder[i].push_sw_function) { - case MENU_BAND: - g_idle_add(ext_band_update,NULL); - break; - } -} - -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;iaction=encoder[i].gp1_function; - a->state=PRESSED; - g_idle_add(switch_action,a); - } - if(i2status&GP1_POS && encoder[i].gp1_enabled) { - SWITCH_ACTION *a=g_new(SWITCH_ACTION,1); - a->action=encoder[i].gp1_function; - a->state=RELEASED; - g_idle_add(switch_action,a); - } - if(i2status&GP2_NEG && encoder[i].gp2_enabled) { - SWITCH_ACTION *a=g_new(SWITCH_ACTION,1); - a->action=encoder[i].gp2_function; - a->state=PRESSED; - g_idle_add(switch_action,a); - } - if(i2status&GP2_POS && encoder[i].gp2_enabled) { - SWITCH_ACTION *a=g_new(SWITCH_ACTION,1); - a->action=encoder[i].gp2_function; - a->state=RELEASED; - g_idle_add(switch_action,a); - } - if(i2status&GP3_NEG && encoder[i].gp3_enabled) { - SWITCH_ACTION *a=g_new(SWITCH_ACTION,1); - a->action=encoder[i].gp3_function; - a->state=PRESSED; - g_idle_add(switch_action,a); - } - if(i2status&GP3_POS && encoder[i].gp3_enabled) { - SWITCH_ACTION *a=g_new(SWITCH_ACTION,1); - a->action=encoder[i].gp3_function; - a->state=RELEASED; - g_idle_add(switch_action,a); - } - } - } - } - g_mutex_unlock(&encoder_mutex); - } - //g_print("%s: exit\n",__FUNCTION__); -} - -static int interrupt_cb(int event_type, unsigned int line, const struct timespec *timeout, void* data) { - //g_print("%s: event=%d line=%d\n",__FUNCTION__,event_type,line); - switch(event_type) { - case GPIOD_CTXLESS_EVENT_CB_TIMEOUT: - // timeout - ignore - //g_print("%s: Ignore timeout\n",__FUNCTION__); - break; - case GPIOD_CTXLESS_EVENT_CB_RISING_EDGE: - // not expected - //g_print("%s: Ignore RISING EDGE\n",__FUNCTION__); - break; - case GPIOD_CTXLESS_EVENT_CB_FALLING_EDGE: - // process - //g_print("%s: Process FALLING EDGE\n",__FUNCTION__); - i2c_interrupt(line); - break; - } - return GPIOD_CTXLESS_EVENT_CB_RET_OK; -} - -static gpointer monitor_thread(gpointer arg) { - struct timespec t; - - // thread to monitor gpio events - g_print("%s: start event monitor\n",__FUNCTION__); - t.tv_sec=60; - t.tv_nsec=0; - - 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)); - } - - g_print("%s: exit\n",__FUNCTION__); - return NULL; -} - -static int gpio_init() { - int ret=0; - - - chip=NULL; - line=NULL; - -//g_print("%s: open gpio 0\n",__FUNCTION__); - chip=gpiod_chip_open_by_number(0); - if(chip==NULL) { - g_print("%s: open chip failed: %s\n",__FUNCTION__,g_strerror(errno)); - ret=1; - goto end; - } - -//g_print("%s: get line %d\n",__FUNCTION__,new_i2c_interrupt); - line = gpiod_chip_get_line(chip, new_i2c_interrupt); - if (!line) { - g_print("%s: get line failed: %s\n",__FUNCTION__,g_strerror(errno)); - ret = -1; - goto end; - } - -//g_print("%s: line request falling edge\n",__FUNCTION__); - ret=gpiod_line_request_falling_edge_events(line,"encoder"); - if (ret<0) { - g_print("%s: line request falling edge events failed: %s\n",__FUNCTION__,g_strerror(errno)); - ret = -1; - goto end; - } - if(line!=NULL) { - gpiod_line_release(line); - line=NULL; - } - if(chip!=NULL) { - gpiod_chip_close(chip); - chip=NULL; - } - - monitor_thread_id = g_thread_new( "gpiod monitor", monitor_thread, NULL); - if(!monitor_thread_id ) { - g_print("%s: g_thread_new failed for monitor_thread\n",__FUNCTION__); - } - return 0; - -g_print("%s: end\n",__FUNCTION__); -end: - if(line!=NULL) { - gpiod_line_release(line); - line=NULL; - } - if(chip!=NULL) { - gpiod_chip_close(chip); - chip=NULL; - } - return ret; -} - -static void gpio_close() { - if(line!=NULL) gpiod_line_release(line); - if(chip!=NULL) gpiod_chip_close(chip); -} - - - -int i2c_controller_init() { - int rc=0; - - rc=gpio_init(); - if(rc<0) goto end; - - rc=i2c_init(); - -end: - return rc; -} diff --git a/i2c_controller.h b/i2c_controller.h deleted file mode 100644 index 31ee497..0000000 --- a/i2c_controller.h +++ /dev/null @@ -1,266 +0,0 @@ -/* Copyright (C) -* 2020 - 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. -* -*/ - -#ifndef I2C_CONTROLLER_H -#define I2C_CONTROLLER_H - - -// Encoder register definition -#define REG_GCONF 0x00 -#define REG_GP1CONF 0x01 -#define REG_GP2CONF 0x02 -#define REG_GP3CONF 0x03 -#define REG_INTCONF 0x04 -#define REG_ESTATUS 0x05 -#define REG_I2STATUS 0x06 -#define REG_FSTATUS 0x07 -#define REG_CVALB4 0x08 -#define REG_CVALB3 0x09 -#define REG_CVALB2 0x0A -#define REG_CVALB1 0x0B -#define REG_CMAXB4 0x0C -#define REG_CMAXB3 0x0D -#define REG_CMAXB2 0x0E -#define REG_CMAXB1 0x0F -#define REG_CMINB4 0x10 -#define REG_CMINB3 0x11 -#define REG_CMINB2 0x12 -#define REG_CMINB1 0x13 -#define REG_ISTEPB4 0x14 -#define REG_ISTEPB3 0x15 -#define REG_ISTEPB2 0x16 -#define REG_ISTEPB1 0x17 -#define REG_RLED 0x18 -#define REG_GLED 0x19 -#define REG_BLED 0x1A -#define REG_GP1REG 0x1B -#define REG_GP2REG 0x1C -#define REG_GP3REG 0x1D -#define REG_ANTBOUNC 0x1E -#define REG_DPPERIOD 0x1F -#define REG_FADERGB 0x20 -#define REG_FADEGP 0x21 -#define REG_GAMRLED 0x27 -#define REG_GAMGLED 0x28 -#define REG_GAMBLED 0x29 -#define REG_GAMMAGP1 0x2A -#define REG_GAMMAGP2 0x2B -#define REG_GAMMAGP3 0x2C -#define REG_GCONF2 0x30 -#define REG_IDCODE 0x70 -#define REG_VERSION 0x71 -#define REG_EEPROMS 0x80 - - -// Encoder configuration bit. Use with GCONF -#define FLOAT_DATA 0x0001 -#define INT_DATA 0x0000 -#define WRAP_ENABLE 0x0002 -#define WRAP_DISABLE 0x0000 -#define DIRE_LEFT 0x0004 -#define DIRE_RIGHT 0x0000 -#define IPUP_DISABLE 0x0008 -#define IPUP_ENABLE 0x0000 -#define RMOD_X2 0x0010 -#define RMOD_X1 0x0000 -#define RGB_ENCODER 0x0020 -#define STD_ENCODER 0x0000 -#define EEPROM_BANK1 0x0040 -#define EEPROM_BANK2 0x0000 -#define RESET 0x0080 -#define CLK_STRECH_ENABLE 0x0100 -#define CLK_STRECH_DISABLE 0x0000 -#define REL_MODE_ENABLE 0x0200 -#define REL_MODE_DISABLE 0x0000 - -// Encoder status bits and setting. Use with: INTCONF for set and with ESTATUS for read the bits -#define PUSHR 0x01 -#define PUSHP 0x02 -#define PUSHD 0x04 -#define RINC 0x08 -#define RDEC 0x10 -#define RMAX 0x20 -#define RMIN 0x40 -#define INT_2 0x80 - -// Encoder Int2 bits. Use to read the bits of I2STATUS -#define GP1_POS 0x01 -#define GP1_NEG 0x02 -#define GP2_POS 0x04 -#define GP2_NEG 0x08 -#define GP3_POS 0x10 -#define GP3_NEG 0x20 -#define FADE_INT 0x40 - -// Encoder Fade status bits. Use to read the bits of FSTATUS -#define FADE_R 0x01 -#define FADE_G 0x02 -#define FADE_B 0x04 -#define FADE_GP1 0x08 -#define FADE_GP2 0x10 -#define FADE_GP3 0x20 - -// GPIO Configuration. USe with GP1CONF,GP2CONF,GP3CONF -#define GP_PWM 0x00 -#define GP_OUT 0x01 -#define GP_AN 0x02 -#define GP_IN 0x03 - -#define GP_PULL_EN 0x04 -#define GP_PULL_DI 0x00 - -#define GP_INT_DI 0x00 -#define GP_INT_PE 0x08 -#define GP_INT_NE 0x10 -#define GP_INT_BE 0x18 - -// Gamma configuration - -#define GAMMA_OFF 0 -#define GAMMA_1 1, -#define GAMMA_1_8 2 -#define GAMMA_2 3 -#define GAMMA_2_2 4 -#define GAMMA_2_4 5 -#define GAMMA_2_6 6 -#define GAMMA_2_8 7 - -/* -enum { - ENCODER_NO_ACTION=0, - ENCODER_AF_GAIN, - ENCODER_AF_GAIN_RX1, - ENCODER_AF_GAIN_RX2, - ENCODER_AGC_GAIN, - ENCODER_AGC_GAIN_RX1, - ENCODER_AGC_GAIN_RX2, - ENCODER_ATTENUATION, - ENCODER_COMP, - ENCODER_CW_FREQUENCY, - ENCODER_CW_SPEED, - ENCODER_DIVERSITY_GAIN, - ENCODER_DIVERSITY_GAIN_COARSE, - ENCODER_DIVERSITY_GAIN_FINE, - ENCODER_DIVERSITY_PHASE, - ENCODER_DIVERSITY_PHASE_COARSE, - ENCODER_DIVERSITY_PHASE_FINE, - ENCODER_DRIVE, - ENCODER_IF_SHIFT, - ENCODER_IF_SHIFT_RX1, - ENCODER_IF_SHIFT_RX2, - ENCODER_IF_WIDTH, - ENCODER_IF_WIDTH_RX1, - ENCODER_IF_WIDTH_RX2, - ENCODER_MIC_GAIN, - ENCODER_PAN, - ENCODER_PANADAPTER_HIGH, - ENCODER_PANADAPTER_LOW, - ENCODER_PANADAPTER_STEP, - ENCODER_RF_GAIN, - ENCODER_RF_GAIN_RX1, - ENCODER_RF_GAIN_RX2, - ENCODER_RIT, - ENCODER_RIT_RX1, - ENCODER_RIT_RX2, - ENCODER_SQUELCH, - ENCODER_SQUELCH_RX1, - ENCODER_SQUELCH_RX2, - ENCODER_TUNE_DRIVE, - ENCODER_VFO, - ENCODER_WATERFALL_HIGH, - ENCODER_WATERFALL_LOW, - ENCODER_XIT, - ENCODER_ZOOM, - ENCODER_ACTIONS -}; - -extern char *encoder_string[ENCODER_ACTIONS]; - -enum { - NO_ACTION=0, - A_TO_B, - A_SWAP_B, - AGC, - ANF, - B_TO_A, - BAND_MINUS, - BAND_PLUS, - BANDSTACK_MINUS, - BANDSTACK_PLUS, - CTUN, - DIVERSITY, - FILTER_MINUS, - FILTER_PLUS, - FUNCTION, - LOCK, - MENU_BAND, - MENU_BANDSTACK, - MENU_DIVERSITY, - MENU_FILTER, - MENU_FREQUENCY, - MENU_MEMORY, - MENU_MODE, - MENU_PS, - MODE_MINUS, - MODE_PLUS, - MOX, - MUTE, - NB, - NR, - PAN_MINUS, - PAN_PLUS, - PS, - RIT, - RIT_CLEAR, - SAT, - SNB, - SPLIT, - TUNE, - TWO_TONE, - XIT, - XIT_CLEAR, - ZOOM_MINUS, - ZOOM_PLUS, - SWITCH_ACTIONS -}; - -extern char *sw_string[SWITCH_ACTIONS]; -*/ - -typedef struct i2c_encoder { - gboolean enabled; - gint address; - gint pos; - gint encoder_function; - gboolean push_sw_enabled; - gint push_sw_function; - gboolean gp1_enabled; - gint gp1_function; - gboolean gp2_enabled; - gint gp2_function; - gboolean gp3_enabled; - gint gp3_function; -} I2C_ENCODER; - -#define MAX_I2C_ENCODERS 7 - -extern I2C_ENCODER encoder[MAX_I2C_ENCODERS]; - -extern int i2c_controller_init(); -#endif diff --git a/i2c_controller_menu.c b/i2c_controller_menu.c deleted file mode 100644 index fd90aeb..0000000 --- a/i2c_controller_menu.c +++ /dev/null @@ -1,171 +0,0 @@ -#include -#include -#include - -#include "actions.h" -#include "i2c_controller.h" -#include "main.h" -#include "new_menu.h" - -typedef struct _choice { - int id; - int action; - GtkWidget *button; -} CHOICE; - -static void response_event(GtkWidget *dialog,gint id,gpointer user_data) { - g_print("%s: id=%d\n",__FUNCTION__,id); - if(id==GTK_RESPONSE_ACCEPT) { - g_print("%s: ACCEPT\n",__FUNCTION__); - } - gtk_widget_destroy(dialog); - dialog=NULL; - active_menu=NO_MENU; - sub_menu=NULL; -} - -static void encoder_select_cb(GtkWidget *widget,gpointer data) { - CHOICE *choice=(CHOICE *)data; - encoder[choice->id].encoder_function=choice->action; - gtk_button_set_label(GTK_BUTTON(choice->button),encoder_string[choice->action]); -} - -static gboolean encoder_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_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 - - return TRUE; -} - -static void push_sw_select_cb(GtkWidget *widget, gpointer data) { - CHOICE *choice=(CHOICE *)data; - encoder[choice->id].push_sw_function=choice->action; - gtk_button_set_label(GTK_BUTTON(choice->button),sw_string[choice->action]); -} - -static gboolean push_sw_cb(GtkWidget *widget, GdkEvent *event, gpointer data) { - int sw=GPOINTER_TO_INT(data); - int i; - - GtkWidget *menu=gtk_menu_new(); - for(i=0;iid=sw; - choice->action=i; - choice->button=widget; - g_signal_connect(menu_item,"activate",G_CALLBACK(push_sw_select_cb),choice); - gtk_menu_shell_append(GTK_MENU_SHELL(menu),menu_item); -fprintf(stderr,"%d=%s\n",i,sw_string[i]); - } - 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 - return TRUE; -} - -void i2c_controller_menu(GtkWidget *parent_window) { - gint row=0; - gint col=0; - - GtkWidget *dialog=gtk_dialog_new_with_buttons("piHPSDR - I2C Controller",GTK_WINDOW(parent_window),GTK_DIALOG_DESTROY_WITH_PARENT,("OK"),GTK_RESPONSE_ACCEPT,"Cancel",GTK_RESPONSE_REJECT,NULL); - - g_signal_connect (dialog, "response", G_CALLBACK (response_event), NULL); - - GtkWidget *content=gtk_dialog_get_content_area(GTK_DIALOG(dialog)); - - GtkWidget *notebook=gtk_notebook_new(); - - - // Encoders - GtkWidget *grid=gtk_grid_new(); - - gtk_grid_set_column_homogeneous(GTK_GRID(grid),FALSE); - 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); - - for(int i=0;i0X%02X",encoder[i].address); - gtk_label_set_markup (GTK_LABEL(address), addr); - gtk_grid_attach(GTK_GRID(grid),address,col,row,1,1); - col++; - - GtkWidget *enable=gtk_check_button_new_with_label("Enable"); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable), encoder[i].enabled); - gtk_grid_attach(GTK_GRID(grid),enable,col,row,1,1); - col++; - - GtkWidget *function=gtk_button_new_with_label(encoder_string[encoder[i].encoder_function]); - g_signal_connect(function,"button_press_event",G_CALLBACK(encoder_cb),GINT_TO_POINTER(i)); - gtk_grid_attach(GTK_GRID(grid),function,col,row,1,1); - col++; - } - gtk_notebook_append_page(GTK_NOTEBOOK(notebook),grid,gtk_label_new("Encoders")); - - // Encoder Push buttons - grid=gtk_grid_new(); - - gtk_grid_set_column_homogeneous(GTK_GRID(grid),FALSE); - 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); - - for(int i=0;i0X%02X",encoder[i].address); - gtk_label_set_markup (GTK_LABEL(address), addr); - gtk_grid_attach(GTK_GRID(grid),address,col,row,1,1); - col++; - - GtkWidget *push_sw_enable=gtk_check_button_new(); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (push_sw_enable), encoder[i].push_sw_enabled); - gtk_grid_attach(GTK_GRID(grid),push_sw_enable,col,row,1,1); - col++; - - GtkWidget *push_sw_function=gtk_button_new_with_label(sw_string[encoder[i].push_sw_function]); - g_signal_connect(push_sw_function,"button_press_event",G_CALLBACK(push_sw_cb),GINT_TO_POINTER(i)); - gtk_grid_attach(GTK_GRID(grid),push_sw_function,col,row,1,1); - col++; - } - gtk_notebook_append_page(GTK_NOTEBOOK(notebook),grid,gtk_label_new("Encoder Switches")); - - gtk_container_add(GTK_CONTAINER(content),notebook); - - sub_menu=dialog; - gtk_widget_show_all(dialog); -} - diff --git a/i2c_controller_menu.h b/i2c_controller_menu.h deleted file mode 100644 index 9a4718f..0000000 --- a/i2c_controller_menu.h +++ /dev/null @@ -1,3 +0,0 @@ - -extern void i2c_controller_menu(GtkWidget *parent); - diff --git a/new_menu.c b/new_menu.c index 98fe564..24a819c 100644 --- a/new_menu.c +++ b/new_menu.c @@ -60,7 +60,6 @@ #include "actions.h" #ifdef GPIO #include "gpio.h" -#include "i2c_controller_menu.h" #endif #include "old_protocol.h" #include "new_protocol.h" @@ -201,15 +200,6 @@ static gboolean switch_cb (GtkWidget *widget, GdkEventButton *event, gpointer da 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) { @@ -615,14 +605,6 @@ void new_menu() 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 diff --git a/radio.c b/radio.c index b148f7e..5bbc536 100644 --- a/radio.c +++ b/radio.c @@ -56,7 +56,6 @@ #endif #include "actions.h" #include "gpio.h" -#include "i2c_controller.h" #include "vfo.h" #include "vox.h" #include "meter.h" @@ -601,14 +600,6 @@ if(!radio_is_remote) { #endif } -#ifdef GPIO - if(controller==CONTROLLER_I2C) { - if(i2c_controller_init()<0) { - g_print("%s: I2C_CONTROLLER failed to initialize i2c\n", __FUNCTION__); - } - } -#endif - #ifdef LOCALCW // init local keyer if enabled if (cw_keyer_internal == 0) {