]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
VFO divisor corrections by John.
authorc vw <dl1ycf@darc.de>
Thu, 25 Nov 2021 08:27:59 +0000 (09:27 +0100)
committerc vw <dl1ycf@darc.de>
Thu, 25 Nov 2021 08:27:59 +0000 (09:27 +0100)
gpio.c

diff --git a/gpio.c b/gpio.c
index 880d5b98a88032e6f339fc0414ef80c1ce3b51f9..749993370f79121fc97f4ab85e09a5d323d5de86 100644 (file)
--- a/gpio.c
+++ b/gpio.c
@@ -372,12 +372,12 @@ static gpointer rotary_encoder_thread(gpointer data) {
         a->mode=RELATIVE;
        if(a->action==VFO && vfo_encoder_divisor>1) {
           a->val=encoders[i].bottom_encoder_pos/vfo_encoder_divisor;
-          encoders[i].bottom_encoder_pos -= (a->val*vfo_encoder_divisor);
+          encoders[i].bottom_encoder_pos=encoders[i].bottom_encoder_pos-(a->val*vfo_encoder_divisor);
         } else {
           a->val=encoders[i].bottom_encoder_pos;
           encoders[i].bottom_encoder_pos=0;
        }
-       if(a->val!=0) g_idle_add(process_action,a);
+       if(a->val!=0) g_idle_add(process_action,a); else g_free(a);
       }
       if(encoders[i].top_encoder_enabled && encoders[i].top_encoder_pos!=0) {
         //g_print("%s: TOP encoder %d pos=%d\n",__FUNCTION__,i,encoders[i].top_encoder_pos);
@@ -386,12 +386,12 @@ static gpointer rotary_encoder_thread(gpointer data) {
         a->mode=RELATIVE;
        if(a->action==VFO && vfo_encoder_divisor>1) {
           a->val=encoders[i].top_encoder_pos/vfo_encoder_divisor;
-          encoders[i].top_encoder_pos -= (a->val*vfo_encoder_divisor);
+          encoders[i].top_encoder_pos=encoders[i].top_encoder_pos-(a->val*vfo_encoder_divisor);
         } else {
           a->val=encoders[i].top_encoder_pos;
           encoders[i].top_encoder_pos=0;
        }
-       if(a->val!=0) g_idle_add(process_action,a);
+       if(a->val!=0) g_idle_add(process_action,a); else g_free(a);
       }
     }
     g_mutex_unlock(&encoder_mutex);
@@ -413,7 +413,7 @@ int process_function_switch(void *data) {
 
 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:
@@ -422,7 +422,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;
@@ -436,13 +436,13 @@ static void process_encoder(int e,int l,int addr,int val) {
               break;
           }
 
-          g_print("%s: %d BOTTOM pos=%d\n",__FUNCTION__,e,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;
@@ -456,7 +456,7 @@ static void process_encoder(int e,int l,int addr,int val) {
               break;
           }
 
-          g_print("%s: %d BOTTOM pos=%d\n",__FUNCTION__,e,encoders[e].bottom_encoder_pos);
+          //g_print("%s: %d BOTTOM pos=%d\n",__FUNCTION__,e,encoders[e].bottom_encoder_pos);
 
           break;
       }
@@ -467,7 +467,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;
@@ -480,13 +480,13 @@ static void process_encoder(int e,int l,int addr,int val) {
             default:
               break;
           }
-          g_print("%s: %d TOP pos=%d\n",__FUNCTION__,e,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;
@@ -499,7 +499,7 @@ static void process_encoder(int e,int l,int addr,int val) {
             default:
               break;
           }
-          g_print("%s: %d TOP pos=%d\n",__FUNCTION__,e,encoders[e].top_encoder_pos);
+          //g_print("%s: %d TOP pos=%d\n",__FUNCTION__,e,encoders[e].top_encoder_pos);
 
           break;
       }
@@ -679,6 +679,7 @@ void gpio_set_defaults(int ctrlr) {
       ENABLE_GPIO_SIDETONE=0;
       ENABLE_CW_BUTTONS=0;
 #endif
+
       encoders=encoders_controller2_v2;
       switches=switches_controller2_v2;
       break;
@@ -1143,7 +1144,7 @@ void gpio_cw_sidetone_set(int level) {
 #else
     if((rc=gpiod_ctxless_set_value_ext(gpio_device,SIDETONE_GPIO,level,FALSE,consumer,NULL,NULL,0))<0) {
 #endif
-       g_print("%s: err=%d\n",__FUNCTION__,rc);
+       g_print("%s: err=%d\n",__FUNCTION__,rc);
     }
 #endif
   }