Browse Source

Fix for relay

Per Mårtensson 1 month ago
parent
commit
e9d14793ee
1 changed files with 34 additions and 22 deletions
  1. 34 22
      src/rtl_airband.cpp

+ 34 - 22
src/rtl_airband.cpp

@@ -71,10 +71,11 @@
 using namespace std;
 using namespace libconfig;
 	struct gpiod_chip *chip;
-	struct gpiod_line *gpio16line;
-    struct gpiod_line *gpio20line;
-    struct gpiod_line *gpio26line;
-
+	struct gpiod_line *led_squ;
+    struct gpiod_line *led_vox;
+    struct gpiod_line *led_control;
+    struct gpiod_line *relay1;
+    struct gpiod_line *relay2;
 
 #define MAX_BUFFERS 10
 
@@ -239,12 +240,16 @@ void* belysning_control_thread(void*){
         }
         if (active)
             if ((stop_time<tv.tv_sec+bel_blink_time) && tv.tv_sec % 2 && bel_blink_time ){
-                gpiod_line_set_value(gpio26line, 0);  
+                gpiod_line_set_value(led_control, 0);  
+                gpiod_line_set_value(relay1, 1); 
             }else{
-                gpiod_line_set_value(gpio26line, 1);
+                gpiod_line_set_value(led_control, 1);
+                gpiod_line_set_value(relay1, 0);
             }
-        else
-            gpiod_line_set_value(gpio26line, 0);  
+        else{
+            gpiod_line_set_value(led_control, 0); 
+            gpiod_line_set_value(relay1, 1);  
+        }
     }
     return 0;
 }
@@ -667,10 +672,10 @@ void* demodulate(void* params) {
                             }
                             
                             if ((abs(waveout)>bel_wave_out_level && channel->wavein[j]>bel_wave_in_level) ){
-                                gpiod_line_set_value(gpio20line, 1);                                
+                                gpiod_line_set_value(led_vox, 1);                                
                                 audio_status=1;
                             }else{
-                                gpiod_line_set_value(gpio20line, 0);
+                                gpiod_line_set_value(led_vox, 0);
                                 audio_status=0;
 
                             }
@@ -767,10 +772,10 @@ void* demodulate(void* params) {
                         //printf("%4.0f/%3.0f%c ", level_to_dBFS(fparms->squelch.signal_level()), level_to_dBFS(fparms->squelch.noise_level()), symbol);
                     }
                     if (symbol=='*'){
-                        gpiod_line_set_value(gpio16line, 1);
+                        gpiod_line_set_value(led_squ, 1);
                         squelch_status = 1;
                     }else{
-                        gpiod_line_set_value(gpio16line, 0);
+                        gpiod_line_set_value(led_squ, 0);
                         squelch_status = 0;
                     }
                     int temp_status = squelch_status + (audio_status << 1);
@@ -864,21 +869,28 @@ int main(int argc, char* argv[]) {
 	unsigned int gpio16 = 16;
     unsigned int gpio20 = 20;
     unsigned int gpio26 = 26;
-
+    unsigned int gpio24 = 24;
+    unsigned int gpio25 = 25;
 	chip = gpiod_chip_open_by_name(chipname);
     if (!chip) {
         perror("gpiod_chip_open_by_name");
         return 1;
     }
-	gpio16line = gpiod_chip_get_line(chip, gpio16);
-    gpio20line = gpiod_chip_get_line(chip, gpio20);
-    gpio26line = gpiod_chip_get_line(chip, gpio26);
-	gpiod_line_request_output(gpio16line, "Consumer1", 0);
-	gpiod_line_set_value(gpio16line, 0);
-    gpiod_line_request_output(gpio20line, "Consumer2", 0);
-	gpiod_line_set_value(gpio20line, 0);
-    gpiod_line_request_output(gpio26line, "Consumer3", 0);
-	gpiod_line_set_value(gpio26line, 0);
+	led_squ = gpiod_chip_get_line(chip, gpio26);
+    led_vox = gpiod_chip_get_line(chip, gpio20);
+    led_control = gpiod_chip_get_line(chip, gpio16);
+    relay1 = gpiod_chip_get_line(chip, gpio25);
+    relay2 = gpiod_chip_get_line(chip, gpio24);
+	gpiod_line_request_output(led_squ, "Consumer1", 0);
+	gpiod_line_set_value(led_squ, 0);
+    gpiod_line_request_output(led_vox, "Consumer2", 0);
+	gpiod_line_set_value(led_vox, 0);
+    gpiod_line_request_output(led_control, "Consumer3", 0);
+	gpiod_line_set_value(led_control, 0);
+    gpiod_line_request_output(relay1, "Consumer4", 0);
+	gpiod_line_set_value(relay1, 1);
+    gpiod_line_request_output(relay2, "Consumer5", 0);
+	gpiod_line_set_value(relay2, 1);
 #pragma GCC diagnostic ignored "-Wwrite-strings"
     char* cfgfile = CFGFILE;
     char* pidfile = PIDFILE;