Przeglądaj źródła

Move fixed values to config

Per Mårtensson 3 miesięcy temu
rodzic
commit
c6c63d6231
1 zmienionych plików z 26 dodań i 14 usunięć
  1. 26 14
      src/rtl_airband.cpp

+ 26 - 14
src/rtl_airband.cpp

@@ -68,13 +68,6 @@
 #include <ncurses.h>
 
 
-#define START_ON_TIME 30
-#define OPEN_TIME   5
-#define PROLONG_TIME 10
-#define WAVE_OUT_LEVEL 0.1
-#define WAVE_IN_LEVEL 10
-#define BLINK_TIME 5
-
 using namespace std;
 using namespace libconfig;
 	struct gpiod_chip *chip;
@@ -89,6 +82,14 @@ sem_t mutex_sem, spooler_sem;
 pthread_mutex_t lock_data; 
 device_t* devices;
 mixer_t* mixers;
+
+int bel_start_on_time = 0;
+int bel_open_time = 0;
+int bel_prolong_time = 0;
+float bel_wave_out_level = 0;
+float bel_wave_in_level = 0;
+int bel_blink_time = 0;
+
 int squelch_status = 0;
 int audio_status = 0;
 int status_data = 0;
@@ -197,7 +198,7 @@ void* belysning_control_thread(void*){
                 sq_stop_time = tv.tv_sec;
                 sq_status = false;
             }
-            printf("ST %u, %u ",(status_data & 1),(status_data >> 1));
+            //printf("ST %u, %u ",(status_data & 1),(status_data >> 1));
             if ( (status_data >> 1) ){
                 audio_start_time = tv.tv_sec;   
             }
@@ -205,7 +206,7 @@ void* belysning_control_thread(void*){
             sem_post(&spooler_sem);
         }
         //printf("DATA %u, %ld, %ld, %ld %u\n",sq_status,sq_start_time,audio_start_time,tv.tv_sec,prolong);
-        if (sq_status == true && sq_start_time+OPEN_TIME < tv.tv_sec && audio_start_time+OPEN_TIME < tv.tv_sec){
+        if (sq_status == true && sq_start_time+bel_open_time < tv.tv_sec && audio_start_time+bel_open_time < tv.tv_sec){
             sq_start_time=sq_start_time;
             sq_stop_time=sq_stop_time;
             activate=true;
@@ -214,15 +215,15 @@ void* belysning_control_thread(void*){
         //First time activation
         if (active==false && activate==true){
             start_time=tv.tv_sec;
-            stop_time=tv.tv_sec+START_ON_TIME;
+            stop_time=tv.tv_sec+bel_start_on_time;
             active=true;
             printf("Start\n");
 
         }
-        // prolong
+        // Prolong
         if (active==true && prolong==true){
             if (tv.tv_sec+10 >= stop_time){
-                stop_time=tv.tv_sec+PROLONG_TIME;
+                stop_time=tv.tv_sec+bel_prolong_time;
                 printf("Prolong\n");
                 prolong = false;
             }
@@ -233,7 +234,7 @@ void* belysning_control_thread(void*){
             printf("Stop\n");
         }
         if (active)
-            if ((stop_time<tv.tv_sec+BLINK_TIME) && tv.tv_sec % 2 && BLINK_TIME )
+            if ((stop_time<tv.tv_sec+bel_blink_time) && tv.tv_sec % 2 && bel_blink_time )
                 gpiod_line_set_value(gpio26line, 0);  
             else
                 gpiod_line_set_value(gpio26line, 1);
@@ -660,7 +661,7 @@ void* demodulate(void* params) {
                                 fparms->agcavgfast *= 1.15f;
                             }
                             
-                            if ((abs(waveout)>WAVE_OUT_LEVEL && channel->wavein[j]>WAVE_IN_LEVEL) ){
+                            if ((abs(waveout)>bel_wave_out_level && channel->wavein[j]>bel_wave_in_level) ){
                                 gpiod_line_set_value(gpio20line, 1);                                
                                 audio_status=1;
                             }else{
@@ -996,6 +997,17 @@ int main(int argc, char* argv[]) {
             alpha = ((int)root["tau"] == 0 ? 0.0f : exp(-1.0f / (WAVE_RATE * 1e-6 * (int)root["tau"])));
 #endif /* NFM */
 
+        if (root.exists("bel_start_on_time"))
+            bel_start_on_time=(int)(root["bel_start_on_time"]);
+        if (root.exists("bel_open_time"))
+            bel_open_time=(int)(root["bel_open_time"]);
+        if (root.exists("bel_blink_time"))
+            bel_blink_time=(int)(root["bel_blink_time"]);
+        if (root.exists("bel_wave_out_levele"))
+            bel_wave_out_level=(float)(root["bel_wave_out_level"]);
+        if (root.exists("bel_wave_in_level"))
+            bel_wave_in_level=(float)(root["bel_wave_in_level"]);
+
         Setting& devs = config.lookup("devices");
         device_count = devs.getLength();
         if (device_count < 1) {