@@ -85,6 +85,14 @@ struct w_info {
85
85
const char * const name ;
86
86
};
87
87
88
+ /* Container for passing both the progress bar and fraction to
89
+ * set_calibration_progress_ui.
90
+ * Allocated by caller, freed by callee. */
91
+ struct set_calibration_progress_params {
92
+ GtkProgressBar * pbar ;
93
+ float fraction ;
94
+ };
95
+
88
96
static struct w_info attrs [] = {
89
97
{SPINBUTTON , "adi,agc-adc-large-overload-exceed-counter" },
90
98
{SPINBUTTON , "adi,agc-adc-large-overload-inc-steps" },
@@ -814,17 +822,76 @@ static int get_cal_samples(long long cal_tone, long long cal_freq)
814
822
return env_samples ;
815
823
}
816
824
825
+ static bool set_calibration_progress_ui (struct set_calibration_progress_params * params ) {
826
+ if (gtk_widget_get_visible (GTK_WIDGET (params -> pbar ))) {
827
+ char ptext [64 ];
828
+
829
+ snprintf (ptext , sizeof (ptext ), "Calibration Progress (%.2f %%)" , params -> fraction * 100 );
830
+ gtk_progress_bar_set_text (params -> pbar , ptext );
831
+ gtk_progress_bar_set_fraction (params -> pbar , params -> fraction );
832
+ }
833
+
834
+ free (params );
835
+
836
+ return false;
837
+ }
838
+
817
839
static void set_calibration_progress (GtkProgressBar * pbar , float fraction )
818
840
{
819
- if (gtk_widget_get_visible (GTK_WIDGET (pbar ))) {
820
- char ptext [64 ];
841
+ struct set_calibration_progress_params * params = malloc (sizeof (struct set_calibration_progress_params ));
842
+ params -> pbar = pbar ;
843
+ params -> fraction = fraction ;
844
+
845
+ gdk_threads_add_idle (G_SOURCE_FUNC (set_calibration_progress_ui ), params );
846
+ }
821
847
822
- gdk_threads_enter ();
823
- snprintf (ptext , sizeof (ptext ), "Calibration Progress (%.2f %%)" , fraction * 100 );
824
- gtk_progress_bar_set_text (pbar , ptext );
825
- gtk_progress_bar_set_fraction (pbar , fraction );
826
- gdk_threads_leave ();
848
+ struct calibration_failed_ui_param {
849
+ gpointer button ;
850
+ int ret ;
851
+ };
852
+
853
+ /* UI actions after a failed calibration
854
+ Parameter struct is allocated by caller and freed by callee
855
+ Not thread safe by itself - should be queued using gdk_threads_add_idle(), not g_idle_add_full() */
856
+ static gboolean calibration_failed_ui (gpointer p ) {
857
+ struct calibration_failed_ui_param * param = (struct calibration_failed_ui_param * ) p ;
858
+
859
+ reload_settings ();
860
+
861
+ if (param -> ret ) {
862
+ create_blocking_popup (GTK_MESSAGE_INFO , GTK_BUTTONS_CLOSE ,
863
+ "FMCOMMS5" , "Calibration failed" );
864
+ auto_calibrate = -1 ;
865
+ } else {
866
+ /* set completed flag for testing */
867
+ auto_calibrate = 1 ;
827
868
}
869
+
870
+ osc_plot_destroy (plot_xcorr_4ch );
871
+ if (param -> button )
872
+ gtk_widget_show (GTK_WIDGET (param -> button ));
873
+
874
+ free (p );
875
+
876
+ return false;
877
+ }
878
+
879
+ struct calibration_prepare_plot_param {
880
+ int samples ;
881
+ };
882
+
883
+ /* Prepare xcorr_4ch plot
884
+ Parameter struct is allocated by caller and freed by callee
885
+ Not thread safe by itself - should be queued using gdk_threads_add_idle(), not g_idle_add_full() */
886
+ static gboolean calibration_prepare_plot (gpointer p ) {
887
+ struct calibration_prepare_plot_param * param = (struct calibration_prepare_plot_param * ) p ;
888
+
889
+ osc_plot_set_sample_count (plot_xcorr_4ch , param -> samples );
890
+ osc_plot_draw_start (plot_xcorr_4ch );
891
+
892
+ free (p );
893
+
894
+ return false;
828
895
}
829
896
830
897
static void calibrate (gpointer button )
@@ -834,6 +901,8 @@ static void calibrate (gpointer button)
834
901
struct iio_channel * in0 , * in0_slave ;
835
902
long long cal_tone , cal_freq ;
836
903
int ret , samples ;
904
+ struct calibration_prepare_plot_param * calib_prep_param ;
905
+ struct calibration_failed_ui_param * calib_failed_param ;
837
906
838
907
in0 = iio_device_find_channel (dev , "voltage0" , false);
839
908
in0_slave = iio_device_find_channel (dev_slave , "voltage0" , false);
@@ -877,10 +946,9 @@ static void calibrate (gpointer button)
877
946
878
947
DBG ("cal_tone %lld cal_freq %lld samples %d" , cal_tone , cal_freq , samples );
879
948
880
- gdk_threads_enter ();
881
- osc_plot_set_sample_count (plot_xcorr_4ch , samples );
882
- osc_plot_draw_start (plot_xcorr_4ch );
883
- gdk_threads_leave ();
949
+ calib_prep_param = malloc (sizeof (struct calibration_prepare_plot_param ));
950
+ calib_prep_param -> samples = samples ;
951
+ gdk_threads_add_idle (calibration_prepare_plot , (gpointer ) calib_prep_param );
884
952
885
953
/* Turn off quadrature tracking while the sync is going on */
886
954
iio_channel_attr_write (in0 , "quadrature_tracking_en" , "0" );
@@ -957,22 +1025,10 @@ static void calibrate (gpointer button)
957
1025
iio_channel_attr_write (in0_slave , "quadrature_tracking_en" , "1" );
958
1026
}
959
1027
960
- gdk_threads_enter ();
961
- reload_settings ();
962
-
963
- if (ret ) {
964
- create_blocking_popup (GTK_MESSAGE_INFO , GTK_BUTTONS_CLOSE ,
965
- "FMCOMMS5" , "Calibration failed" );
966
- auto_calibrate = -1 ;
967
- } else {
968
- /* set completed flag for testing */
969
- auto_calibrate = 1 ;
970
- }
971
-
972
- osc_plot_destroy (plot_xcorr_4ch );
973
- if (button )
974
- gtk_widget_show (GTK_WIDGET (button ));
975
- gdk_threads_leave ();
1028
+ calib_failed_param = malloc (sizeof (struct calibration_failed_ui_param ));
1029
+ calib_failed_param -> button = button ;
1030
+ calib_failed_param -> ret = ret ;
1031
+ gdk_threads_add_idle (calibration_failed_ui , (gpointer ) calib_failed_param );
976
1032
977
1033
/* reset progress bar */
978
1034
gtk_progress_bar_set_fraction (calib_progress , 0.0 );
0 commit comments