1 // Copyright (c) <2012> <Leif Asbrink>
2 //
3 // Permission is hereby granted, free of charge, to any person
4 // obtaining a copy of this software and associated documentation
5 // files (the "Software"), to deal in the Software without restriction,
6 // including without limitation the rights to use, copy, modify,
7 // merge, publish, distribute, sublicense, and/or sell copies of
8 // the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21 // OR OTHER DEALINGS IN THE SOFTWARE.
22 
23 
24 #include <string.h>
25 #include "globdef.h"
26 #include "uidef.h"
27 #include "fft1def.h"
28 #include "sigdef.h"
29 #include "screendef.h"
30 #include "rusage.h"
31 #include "thrdef.h"
32 #include "vernr.h"
33 
34 #define MG_MIN_WIDTH 5.5*text_width
35 #define MG_MIN_HEIGHT 8*text_height
36 
37 void make_meter_graph(int clear_old);
38 int meter_graph_scro;
39 int mg_old_y1;
40 int mg_old_y2;
41 int mg_old_x1;
42 int mg_old_x2;
43 #define MG_MIN_SCALESEP 1.2
44 #define DB2DBM 106
45 
46 
change_meter_cal(void)47 void change_meter_cal(void)
48 {
49 if(mg.scale_type == MG_SCALE_DBM)mg.cal_dbm=numinput_float_data;
50 if(mg.scale_type == MG_SCALE_STON)mg.cal_ston=numinput_float_data;
51 if(mg.scale_type == MG_SCALE_SUNITS)mg.cal_s_units=numinput_float_data;
52 make_meter_graph(TRUE);
53 }
54 
change_meter_ston_sigshift(void)55 void change_meter_ston_sigshift(void)
56 {
57 mg.cal_ston_sigshift=numinput_float_data;
58 make_meter_graph(TRUE);
59 }
60 
61 
help_on_meter_graph(void)62 void help_on_meter_graph(void)
63 {
64 int mmg_no;
65 int event_no;
66 // Nothing is selected in the data area.
67 mmg_no=312;
68 for(event_no=0; event_no<MAX_MGBUTT; event_no++)
69   {
70   if( mgbutt[event_no].x1 <= mouse_x &&
71       mgbutt[event_no].x2 >= mouse_x &&
72       mgbutt[event_no].y1 <= mouse_y &&
73       mgbutt[event_no].y2 >= mouse_y)
74     {
75     switch (event_no)
76       {
77       case MG_TOP:
78       case MG_BOTTOM:
79       case MG_LEFT:
80       case MG_RIGHT:
81       mmg_no=102;
82       break;
83 
84       case MG_CHANGE_CAL:
85       mmg_no=90;
86       break;
87 
88       case MG_CHANGE_TYPE:
89       mmg_no=91;
90       break;
91 
92       case MG_INCREASE_AVGN:
93       mmg_no=92;
94       break;
95 
96       case MG_DECREASE_AVGN:
97       mmg_no=93;
98       break;
99 
100       case MG_INCREASE_GAIN:
101       mmg_no=94;
102       break;
103 
104       case MG_DECREASE_GAIN:
105       mmg_no=95;
106       break;
107 
108       case MG_INCREASE_YREF:
109       mmg_no=96;
110       break;
111 
112       case MG_DECREASE_YREF:
113       mmg_no=97;
114       break;
115 
116       case MG_CHANGE_TRACKS:
117       mmg_no=98;
118       break;
119 
120       case MG_SCALE_STON_SIGSHIFT:
121       mmg_no=341;
122       break;
123       }
124     }
125   }
126 help_message(mmg_no);
127 }
128 
mouse_continue_meter_graph(void)129 void mouse_continue_meter_graph(void)
130 {
131 int j, ypix;
132 switch (mouse_active_flag-1)
133   {
134   case MG_TOP:
135   if(mg.ytop!=mouse_y)
136     {
137     pause_screen_and_hide_mouse();
138     graph_borders((void*)&mg,0);
139     mg.ytop=mouse_y;
140     j=mg.ybottom-MG_MIN_HEIGHT;
141     if(j<0)j=0;
142     if(mg.ytop > j)mg.ytop=j;
143     if(mg_old_y1 > mg.ytop)mg_old_y1=mg.ytop;
144     graph_borders((void*)&mg,15);
145     resume_thread(THREAD_SCREEN);
146     }
147   break;
148 
149   case MG_BOTTOM:
150   if(mg.ybottom!=mouse_y)
151     {
152     pause_screen_and_hide_mouse();
153     graph_borders((void*)&mg,0);
154     mg.ybottom=mouse_y;
155     j=mg.ytop+MG_MIN_HEIGHT;
156     if(j>=screen_height)j=screen_height-1;
157     if(mg.ybottom < j)mg.ybottom=j;
158     if(mg_old_y2 < mg.ybottom)mg_old_y2=mg.ybottom;
159     graph_borders((void*)&mg,15);
160     resume_thread(THREAD_SCREEN);
161     }
162   break;
163 
164   case MG_LEFT:
165   if(mg.xleft!=mouse_x)
166     {
167     pause_screen_and_hide_mouse();
168     graph_borders((void*)&mg,0);
169     mg.xleft=mouse_x;
170     j=mg.xright-MG_MIN_WIDTH;
171     if(j<0)j=0;
172     if(mg.xleft > j)mg.xleft=j;
173     if(mg_old_x1 > mg.xleft)mg_old_x1=mg.xleft;
174     graph_borders((void*)&mg,15);
175     resume_thread(THREAD_SCREEN);
176     }
177   break;
178 
179   case MG_RIGHT:
180   if(mg.xright!=mouse_x)
181     {
182     pause_screen_and_hide_mouse();
183     graph_borders((void*)&mg,0);
184     mg.xright=mouse_x;
185     j=mg.xleft+MG_MIN_WIDTH;
186     if(j >= screen_width)j=screen_width-1;
187     if(mg.xright < j)mg.xright=j;
188     if(mg_old_x2 < mg.xright)mg_old_x2=mg.xright;
189     graph_borders((void*)&mg,15);
190     resume_thread(THREAD_SCREEN);
191     }
192   break;
193 
194   default:
195   goto await_release;
196   }
197 if(leftpressed == BUTTON_RELEASED)goto finish;
198 return;
199 await_release:;
200 if(leftpressed != BUTTON_RELEASED) return;
201 switch (mouse_active_flag-1)
202   {
203   case MG_CHANGE_CAL:
204   mouse_active_flag=1;
205   numinput_xpix=mgbutt[MG_CHANGE_CAL].x1+text_width/2-1;
206   numinput_ypix=mgbutt[MG_CHANGE_CAL].y1+2;
207   numinput_chars=6;
208   erase_numinput_txt();
209   numinput_flag=FIXED_FLOAT_PARM;
210   par_from_keyboard_routine=change_meter_cal;
211   return;
212 
213   case MG_CHANGE_TYPE:
214   mg.scale_type++;
215   if(genparm[SECOND_FFT_ENABLE] == 0 &&
216                              mg.scale_type == MG_SCALE_STON)mg.scale_type++;
217   if(mg.scale_type >= MG_SCALE_MAX)mg.scale_type=0;
218   break;
219 
220   case MG_INCREASE_AVGN:
221   mg.avgnum<<=1;
222   timf2_blockpower_px=-1;
223   break;
224 
225   case MG_DECREASE_AVGN:
226   mg.avgnum>>=1;
227   if(mg.avgnum ==0)mg.avgnum=1;
228   timf2_blockpower_px=-1;
229   break;
230 
231   case MG_INCREASE_GAIN:
232   ypix=mg.yzero+mg.ygain*mg_midscale;;
233   mg.ygain*=1.3;
234   mg.yzero=ypix-mg.ygain*mg_midscale;;
235   break;
236 
237   case MG_DECREASE_GAIN:
238   ypix=mg.yzero+mg.ygain*mg_midscale;;
239   mg.ygain/=1.4;
240   mg.yzero=ypix-mg.ygain*mg_midscale;;
241   break;
242 
243 
244   case MG_INCREASE_YREF:
245   mg.yzero-=0.09*(mg.ybottom-mg.ytop);
246   break;
247 
248   case MG_DECREASE_YREF:
249   mg.yzero+=0.1*(mg.ybottom-mg.ytop);
250   break;
251 
252   case MG_SCALE_STON_SIGSHIFT:
253   if(mg.scale_type == MG_SCALE_STON)
254     {
255     mouse_active_flag=1;
256     numinput_xpix=mgbutt[MG_SCALE_STON_SIGSHIFT].x1+text_width/2-1;
257     numinput_ypix=mgbutt[MG_SCALE_STON_SIGSHIFT].y1+2;
258     numinput_chars=6;
259     erase_numinput_txt();
260     numinput_flag=FIXED_FLOAT_PARM;
261     par_from_keyboard_routine=change_meter_ston_sigshift;
262     return;
263     }
264 
265   case MG_CHANGE_TRACKS:
266   mg.tracks++;
267   if(mg.tracks >= 3)mg.tracks=0;
268   break;
269   }
270 finish:;
271 leftpressed=BUTTON_IDLE;
272 make_meter_graph(TRUE);
273 mouse_active_flag=0;
274 }
275 
276 int mg_stonavg_x1;
277 
mg_compute_stonavg(void)278 void mg_compute_stonavg(void)
279 {
280 int ia, ib, i, ix, iy, n;
281 float t1, t2, r1, r2;
282 char s[80];
283 // mgw_p points to the screen position corresponding to mg_px
284 // in the mg_ arrays.
285 if(rightpressed == BUTTON_IDLE)
286   {
287   if(leftpressed == BUTTON_RELEASED)
288     {
289     lir_line(mouse_x,mg.ytop,mouse_x,mg.ybottom,13);
290     ia=(mg_stonavg_x1-mgw_p+mg_px+mg_size)&mg_mask;
291     ib=(mouse_x-mgw_p+mg_px+mg_size)&mg_mask;
292     i=ia;
293     t1=0;
294     t2=0;
295     n=(ib-ia+mg_size)&mg_mask;
296     ix=mg_stonavg_x1+text_width/2;
297     if(ix+16*text_width > screen_width)goto skip;
298     iy=mg.ytop+2*text_height;
299     if(sw_onechan)
300       {
301       while(i != ib)
302         {
303         t1+=mg_rms_meter[i];
304         i=(i+1)&mg_mask;
305         }
306       t1/=n;
307       i=ia;
308       while(i != ib)
309         {
310         t2+=(mg_rms_meter[i]-t1)*(mg_rms_meter[i]-t1);
311         i=(i+1)&mg_mask;
312         }
313       t2/=n;
314       t2=10*sqrt(t2);
315       t1=10*t1;
316       if(mg.scale_type == MG_SCALE_STON)
317         {
318         t1-=mg.cal_ston;
319         sprintf(s,"S/N %.4fdB",t1);
320         }
321       else
322         {
323         if(mg.scale_type == MG_SCALE_DBM)t1-=DB2DBM+mg.cal_dbm;
324         sprintf(s,"RMS %.4fdB",t1);
325         }
326       lir_pixwrite(ix,iy,s);
327       iy+=text_height;
328       sprintf(s,"RMS %.4fdB",t2);
329       lir_pixwrite(ix,iy,s);
330       iy+=text_height;
331       sprintf(s,"N = %d",n);
332       lir_pixwrite(ix,iy,s);
333       }
334     else
335       {
336       r1=0;
337       r2=0;
338       while(i != ib)
339         {
340         t1+=mg_rms_meter[2*i  ];
341         r1+=mg_rms_meter[2*i+1];
342         i=(i+1)&mg_mask;
343         }
344       t1/=n;
345       r1/=n;
346       i=ia;
347       while(i != ib)
348         {
349         t2+=(mg_rms_meter[2*i  ]-t1)*(mg_rms_meter[2*i  ]-t1);
350         r2+=(mg_rms_meter[2*i+1]-r1)*(mg_rms_meter[2*i+1]-r1);
351         i=(i+1)&mg_mask;
352         }
353       t2/=n;
354       r2/=n;
355       t2=10*sqrt(t2);
356       r2=10*sqrt(r2);
357       t1=10*t1;
358       r1=10*r1;
359       if(mg.scale_type == MG_SCALE_STON)
360         {
361         t1-=mg.cal_ston;
362         r1-=mg.cal_ston;
363         sprintf(s,"S/N ");
364         }
365       else
366         {
367         if(mg.scale_type == MG_SCALE_DBM)
368           {
369           t1-=DB2DBM+mg.cal_dbm;
370           r1-=DB2DBM+mg.cal_dbm;
371           sprintf(s,"RMS ");
372           }
373         }
374       sprintf(&s[4],"%.4fdB",t1);
375       lir_pixwrite(ix,iy,s);
376       iy+=text_height;
377       sprintf(&s[4],"%.4fdB",r1);
378       lir_pixwrite(ix,iy,s);
379       iy+=text_height;
380       sprintf(s,"RMS %.4fdB",t2);
381       lir_pixwrite(ix,iy,s);
382       iy+=text_height;
383       sprintf(s,"RMS %.4fdB",r2);
384       lir_pixwrite(ix,iy,s);
385       iy+=text_height;
386       sprintf(s,"N = %d",n);
387       iy+=text_height;
388       lir_pixwrite(ix,iy,s);
389       iy+=text_height;
390       }
391 skip:;
392     leftpressed=BUTTON_IDLE;
393     mouse_active_flag=0;
394     }
395   }
396 else
397   {
398   if(rightpressed == BUTTON_RELEASED)
399     {
400     rightpressed=BUTTON_IDLE;
401     mouse_active_flag=0;
402     }
403   }
404 }
405 
406 
mouse_on_meter_graph(void)407 void mouse_on_meter_graph(void)
408 {
409 int event_no;
410 // First find out is we are on a button or border line.
411 for(event_no=0; event_no<MAX_MGBUTT; event_no++)
412   {
413   if( mgbutt[event_no].x1 <= mouse_x &&
414       mgbutt[event_no].x2 >= mouse_x &&
415       mgbutt[event_no].y1 <= mouse_y &&
416       mgbutt[event_no].y2 >= mouse_y)
417     {
418     mg_old_y1=mg.ytop;
419     mg_old_y2=mg.ybottom;
420     mg_old_x1=mg.xleft;
421     mg_old_x2=mg.xright;
422     mouse_active_flag=1+event_no;
423     current_mouse_activity=mouse_continue_meter_graph;
424     return;
425     }
426   }
427 // Not button or border.
428 if(mouse_x >= mg_first_xpixel && mouse_x < mg_last_xpixel)
429   {
430   mg_stonavg_x1=mouse_x;
431   lir_line(mouse_x,mg.ytop,mouse_x,mg.ybottom,12);
432   current_mouse_activity=mg_compute_stonavg;
433   }
434 else
435   {
436   current_mouse_activity=mouse_nothing;
437   }
438 mouse_active_flag=1;
439 }
440 
441 void check_mg(int n);
442 
make_meter_graph(int clear_old)443 void make_meter_graph(int clear_old)
444 {
445 int i, ypix, sunit_flag;
446 double t1, t2;
447 if(clear_old)
448   {
449   pause_thread(THREAD_SCREEN);
450   hide_mouse(mg_old_x1,mg_old_x2,mg_old_y1,mg_old_y2);
451   lir_fillbox(mg_old_x1,mg_old_y1,mg_old_x2-mg_old_x1+1,
452                                                     mg_old_y2-mg_old_y1+1,0);
453   }
454 current_graph_minh=MG_MIN_HEIGHT;
455 current_graph_minw=MG_MIN_WIDTH;
456 check_graph_placement((void*)(&mg));
457 clear_button(mgbutt, MAX_MGBUTT);
458 scro[meter_graph_scro].no=METER_GRAPH;
459 scro[meter_graph_scro].x1=mg.xleft;
460 scro[meter_graph_scro].x2=mg.xright;
461 scro[meter_graph_scro].y1=mg.ytop;
462 scro[meter_graph_scro].y2=mg.ybottom;
463 // Each border line is treated as a button.
464 // That is for the mouse to get hold of them so the window can be moved.
465 mgbutt[MG_LEFT].x1=mg.xleft;
466 mgbutt[MG_LEFT].x2=mg.xleft+2;
467 mgbutt[MG_LEFT].y1=mg.ytop;
468 mgbutt[MG_LEFT].y2=mg.ybottom;
469 mgbutt[MG_RIGHT].x1=mg.xright-2;
470 mgbutt[MG_RIGHT].x2=mg.xright;
471 mgbutt[MG_RIGHT].y1=mg.ytop;
472 mgbutt[MG_RIGHT].y2=mg.ybottom;
473 mgbutt[MG_TOP].x1=mg.xleft;
474 mgbutt[MG_TOP].x2=mg.xright;
475 mgbutt[MG_TOP].y1=mg.ytop;
476 mgbutt[MG_TOP].y2=mg.ytop+2;
477 mgbutt[MG_BOTTOM].x1=mg.xleft;
478 mgbutt[MG_BOTTOM].x2=mg.xright;
479 mgbutt[MG_BOTTOM].y1=mg.ybottom-2;
480 mgbutt[MG_BOTTOM].y2=mg.ybottom;
481 mg_first_xpixel=mg.xleft+7*text_width;
482 mg_last_xpixel=mg.xright-1;
483 if(mg.xright-mg.xleft < 12.5*text_width)
484   {
485   mg_bar=TRUE;
486   }
487 else
488   {
489   if(mg_bar)
490     {
491     mg_pa=0;
492     mg_px=0;
493     mgw_p=mg_first_xpixel;
494     }
495   mg_bar=FALSE;
496   make_button(mg.xright-3*text_width,mg.ybottom-text_height/2-2,
497                                                   mgbutt,MG_INCREASE_AVGN,27);
498   make_button(mg.xright-5*text_width,mg.ybottom-text_height/2-2,
499                                                   mgbutt,MG_DECREASE_AVGN,26);
500   make_button(mg.xleft+text_width,mg.ytop+text_height/2+2,
501                                                   mgbutt,MG_INCREASE_GAIN,24);
502   make_button(mg.xleft+text_width,mg.ybottom-text_height/2-2,
503                                                   mgbutt,MG_DECREASE_GAIN,25);
504   make_button(mg.xright-text_width,mg.ybottom-text_height/2-2,
505                                                   mgbutt,MG_INCREASE_YREF,25);
506   make_button(mg.xright-text_width,mg.ytop+text_height/2+2,
507                                                   mgbutt,MG_DECREASE_YREF,24);
508   make_button(mg.xright-3*text_width,mg.ytop+text_height/2+2,
509                                                  mgbutt,MG_CHANGE_TRACKS,' ');
510   mgbutt[MG_CHANGE_CAL].y1=mg.ytop+1;
511   mgbutt[MG_CHANGE_CAL].y2=mg.ytop+text_height+2;
512   if(mg.scale_type != MG_SCALE_DB)
513     {
514     mgbutt[MG_CHANGE_CAL].x1=mg.xleft+2*text_width;
515     mgbutt[MG_CHANGE_CAL].x2=mg.xleft+8.5*text_width;
516     }
517   else
518     {
519     mgbutt[MG_CHANGE_CAL].x1=screen_width+1;
520     mgbutt[MG_CHANGE_CAL].x2=screen_width+1;
521     }
522   if(mg.scale_type == MG_SCALE_STON)
523     {
524     mgbutt[MG_SCALE_STON_SIGSHIFT].x1=mgbutt[MG_CHANGE_CAL].x2+text_width/2;
525     mgbutt[MG_SCALE_STON_SIGSHIFT].x2=
526                            mgbutt[MG_SCALE_STON_SIGSHIFT].x1+6.5*text_width;
527     mgbutt[MG_SCALE_STON_SIGSHIFT].y1=mgbutt[MG_CHANGE_CAL].y1;
528     mgbutt[MG_SCALE_STON_SIGSHIFT].y2=mgbutt[MG_CHANGE_CAL].y2;
529     }
530   mgbutt[MG_CHANGE_TYPE].x1=mg.xleft+2*text_width;
531   mgbutt[MG_CHANGE_TYPE].y1=mg.ybottom-3-text_height;
532   mgbutt[MG_CHANGE_TYPE].y2=mg.ybottom-2;
533   switch (mg.scale_type)
534     {
535     case MG_SCALE_DB:
536     mgbutt[MG_CHANGE_TYPE].x2=mg.xleft+4.5*text_width;
537     break;
538 
539     case MG_SCALE_DBM:
540     case MG_SCALE_STON:
541     mgbutt[MG_CHANGE_TYPE].x2=mg.xleft+5.5*text_width;
542     break;
543 
544     case MG_SCALE_SUNITS:
545     mgbutt[MG_CHANGE_TYPE].x2=mg.xleft+3.5*text_width;
546     break;
547     }
548   }
549 // ************************************************
550 // Make an Y-scale in dB, dBm or S-units.
551 // ************************************************
552 // The separation between scale lines, has to be at least
553 // MG_MIN_SCALESEP*text_height. In dB this corresponds to mg_dbstep.
554 mg_dbstep=10*MG_MIN_SCALESEP*text_height/mg.ygain;
555 if(mg.scale_type == MG_SCALE_SUNITS)
556   {
557   i=1+mg_dbstep/6;
558   mg_dbstep=6*i;
559   }
560 else
561   {
562   adjust_scale(&mg_dbstep);
563   }
564 // Make mg_dbscale_start the dB value for the first pixel in the graph (mg_rms_meter[]=0)
565 // Then make it a multiple of mg_dbstep and make sure we have enough
566 // space to write text.
567 mg_scale_offset=0;
568 if(mg.scale_type == MG_SCALE_DBM)mg_scale_offset=DB2DBM+mg.cal_dbm;
569 if(mg.scale_type == MG_SCALE_STON)mg_scale_offset=mg.cal_ston;
570 if(mg.scale_type == MG_SCALE_SUNITS)mg_scale_offset=6+mg.cal_s_units;
571 mg_dbscale_start=-10*mg.yzero/mg.ygain-mg_scale_offset;
572 mg_dbscale_start/=mg_dbstep;
573 mg_dbscale_start=(int)mg_dbscale_start;
574 mg_dbscale_start*=mg_dbstep;
575 for(i=0; i<screen_height; i++)mg_behind_meter[i]=0;
576 mg_ymin=mg.ybottom-5-text_height;
577 mg_ymax=mg.ytop+3+text_height;
578 ypix=mg.yzero+0.1*mg.ygain*(mg_dbscale_start+mg_scale_offset);
579 mg_midscale=mg_dbscale_start;
580 t1=mg_dbscale_start;
581 t2=mg_dbstep;
582 sunit_flag=0;
583 mg_bar_x1=mg.xleft+2*text_width;
584 mg_bar_x2=mg_bar_x1+3*text_width;
585 mg_bar_y=mg.ybottom-2;
586 mg_y0=mg.ybottom-1;
587 while(mg_ymin-ypix > mg_ymax)
588   {
589   if(ypix >=0)
590     {
591     if(mg.scale_type == MG_SCALE_SUNITS)
592       {
593       if(t1 > 54.111 && sunit_flag == 0)
594         {
595         sunit_flag=1;
596         i=1+mg_dbstep/5;
597         t2=5*i;
598         t1=54+t2;
599         ypix=mg.yzero+0.1*mg.ygain*(t1+mg_scale_offset);
600         }
601       }
602     if(mg_ymin-ypix >  mg_ymax && mg_ymin-ypix < mg_ymin)
603       {
604       mg_behind_meter[mg_ymin-ypix]=57;
605       }
606     }
607   t1+=t2;
608   ypix=mg.yzero+0.1*mg.ygain*(t1+mg_scale_offset);
609   }
610 mg_midscale=0.1*(mg_scale_offset+(mg_midscale+t1-t2)*0.5);
611 make_modepar_file(GRAPHTYPE_MG);
612 for(i=0; i<ui.rx_rf_channels*mg_size; i++)
613   {
614   mg_peak_ypix[i]=mg_ymin;
615   mg_rms_ypix[i]=mg_ymin;
616   }
617 sc[SC_MG_REDRAW]++;
618 if(clear_old) resume_thread(THREAD_SCREEN);
619 }
620 
init_meter_graph(void)621 void init_meter_graph(void)
622 {
623 if (read_modepar_file(GRAPHTYPE_MG) == 0)
624   {
625 mg_default:;
626   mg.xright=screen_width-1;
627   mg.xleft=mg.xright-14*text_width;
628   mg.ytop=wg.ybottom+1;
629   mg.ybottom=mg.ytop+22*text_height;
630   mg.scale_type=MG_SCALE_SUNITS;
631   mg.avgnum=baseband_sampling_speed*0.05;
632   if(mg.avgnum < 1)mg.avgnum=1;
633   make_power_of_two(&mg.avgnum);
634   mg.ygain=(1.01+MG_MIN_SCALESEP)*text_height;
635   mg.yzero=-26;
636   mg.cal_dbm=0;
637   mg.cal_ston=0;
638   mg.cal_ston_sigshift=0;
639   mg.cal_s_units=0;
640   mg.tracks=0;
641   mg.check=MG_VERNR;
642   }
643 if(mg.ygain<=0)goto mg_default;
644 if(mg.scale_type < 0 || mg.scale_type >= MG_SCALE_MAX)goto mg_default;
645 if(genparm[SECOND_FFT_ENABLE] == 0 &&
646                               mg.scale_type == MG_SCALE_STON)goto mg_default;
647 if(mg.avgnum < 1 || mg.avgnum > baseband_sampling_speed*3600)goto mg_default;
648 if(mg.ygain < 0.01 || mg.ygain > 100000)goto mg_default;
649 if(fabs(mg.cal_dbm) > 1000)goto mg_default;
650 if(fabs(mg.cal_ston) > 1000)goto mg_default;
651 if(fabs(mg.cal_ston_sigshift) > 1000)goto mg_default;
652 if(fabs(mg.cal_s_units) > 100)goto mg_default;
653 if(mg.check != MG_VERNR)goto mg_default;
654 if(mg.tracks < 0 || mg.tracks > 3)goto mg_default;
655 make_meter_graph(FALSE);
656 mg_pa=0;
657 mg_px=0;
658 mgw_p=mg_first_xpixel;
659 baseb_pm=baseb_pa;
660 mg_flag=1;
661 }
662 
663 
manage_meter_graph(void)664 void manage_meter_graph(void)
665 {
666 sc[SC_UPDATE_METER_GRAPH]=sd[SC_UPDATE_METER_GRAPH];
667 if(cg.meter_graph_on == 1)
668   {
669   if(mg_flag==0)
670     {
671     mg_clear_flag=TRUE;
672     init_meter_graph();
673     make_meter_graph(FALSE);
674     }
675   }
676 else
677   {
678   if(mg_flag==1)
679     {
680     mg_flag=0;
681     lir_fillbox(mg.xleft,mg.ytop,mg.xright-mg.xleft+1,mg.ybottom-mg.ytop+1,0);
682     clear_button(mgbutt, MAX_MGBUTT);
683     }
684   }
685 }
686