@@ -167,7 +167,6 @@ unsigned global_enabled_channels_mask(struct iio_device *dev, struct iio_channel
167
167
unsigned mask = 0 ;
168
168
int scan_i = 0 ;
169
169
unsigned int i = 0 ;
170
- //struct iio_channels_mask *ch_mask = iio_create_channels_mask(iio_device_get_channels_count(dev));
171
170
172
171
for (; i < iio_device_get_channels_count (dev ); i ++ ) {
173
172
struct iio_channel * chn = iio_device_get_channel (dev , i );
@@ -1630,7 +1629,6 @@ static void plot_destroyed_cb(OscPlot *plot)
1630
1629
{
1631
1630
plot_list = g_list_remove (plot_list , plot );
1632
1631
stop_sampling ();
1633
- // !!! capture_setup();
1634
1632
if (num_capturing_plots )
1635
1633
capture_start ();
1636
1634
restart_all_running_plots ();
@@ -2543,14 +2541,8 @@ struct iio_context * osc_create_context(void)
2543
2541
{
2544
2542
if (!ctx )
2545
2543
return iio_create_context (NULL , NULL );
2546
- else {
2547
- // !!!! context clone causes seg fault
2548
- // const struct iio_context_params * ctx_params = iio_context_get_params(ctx);
2549
- // const struct iio_attr *ctx_uri = iio_context_find_attr(ctx, "uri");
2550
- // const char *uri_val = iio_attr_get_static_value(ctx_uri);
2551
- // ctx = iio_create_context(ctx_params, uri_val);
2544
+ else
2552
2545
return ctx ;
2553
- }
2554
2546
}
2555
2547
2556
2548
void osc_destroy_context (struct iio_context * _ctx )
@@ -2577,29 +2569,36 @@ void osc_process_gtk_events(unsigned int msecs)
2577
2569
}
2578
2570
}
2579
2571
2580
- /* Test something, according to:
2572
+ /* The format below no longer works
2573
+ * with libiio v1.0 API for channel attrs
2574
+ * Test something, according to:
2581
2575
* test.device.attribute.type = min max
2576
+ * A channel attr should be tested :
2577
+ * test.device.ch-(id/index/name).0/1.attribute.type = min max
2582
2578
*/
2583
2579
int osc_test_value (struct iio_context * _ctx , int line ,
2584
2580
const char * attribute , const char * value )
2585
2581
{
2586
2582
struct iio_device * dev ;
2587
2583
struct iio_channel * chn ;
2588
- const char * attr ;
2589
- const char * filename ;
2584
+ const struct iio_attr * attrib ;
2585
+ const char * attr = attribute ;
2590
2586
long long min_i = -1 , max_i = -1 , val_i ;
2591
2587
double min_d , max_d , val_d ;
2592
- unsigned int i ;
2588
+ int i , j ;
2593
2589
int ret = - EINVAL ;
2594
2590
2595
- gchar * * elems = g_strsplit (attribute , "." , 4 );
2591
+ for (j = 0 ; attr [j ]; attr [j ]== '.' ? j ++ : * attr ++ );
2592
+
2593
+
2594
+ gchar * * elems = g_strsplit (attribute , "." , j + 1 );
2596
2595
if (!elems )
2597
2596
goto err_popup ;
2598
2597
2599
2598
if (!elems [0 ] || strcmp (elems [0 ], "test" ))
2600
2599
goto cleanup ;
2601
2600
2602
- for (i = 1 ; i < 4 ; i ++ )
2601
+ for (i = 1 ; i < j + 1 ; i ++ )
2603
2602
if (!elems [i ])
2604
2603
goto cleanup ;
2605
2604
@@ -2609,27 +2608,25 @@ int osc_test_value(struct iio_context *_ctx, int line,
2609
2608
goto cleanup ;
2610
2609
}
2611
2610
2612
- const struct iio_attr * attrib = iio_device_find_attr (dev , elems [2 ]);
2613
- filename = iio_attr_get_filename (attrib );
2614
- ret = iio_err (filename );
2615
- //ret = iio_device_identify_filename(dev, elems[2], &chn, &attr);
2611
+ if (j == 3 ) {
2612
+ attrib = iio_device_find_attr (dev , elems [2 ]);
2613
+ } else if (j == 5 ) {
2614
+ chn = iio_device_find_channel (dev , elems [2 ],elems [3 ]);
2615
+ attrib = iio_channel_find_attr (chn , elems [4 ]);
2616
+ }
2617
+
2616
2618
if (ret < 0 )
2617
2619
goto cleanup ;
2618
2620
2619
- if (!strcmp (elems [3 ], "int" )) {
2621
+ if (!strcmp (elems [j - 1 ], "int" )) {
2620
2622
ret = sscanf (value , "%lli %lli" , & min_i , & max_i );
2621
2623
if (ret != 2 ) {
2622
2624
ret = - EINVAL ;
2623
2625
goto cleanup ;
2624
2626
}
2625
2627
2626
- //attrib = iio_channel_find_attr()
2627
- //ret = iio_attr_read_longlong()
2628
2628
ret = iio_attr_read_longlong (attrib , & val_i );
2629
- // if (chn)
2630
- // ret = iio_channel_attr_read_longlong(chn, attr, &val_i);
2631
- // else
2632
- // ret = iio_device_attr_read_longlong(dev, attr, &val_i);
2629
+
2633
2630
if (ret < 0 )
2634
2631
goto cleanup ;
2635
2632
@@ -2644,7 +2641,7 @@ int osc_test_value(struct iio_context *_ctx, int line,
2644
2641
"Value read = %lli\n" ,
2645
2642
line , attribute , min_i , max_i , val_i );
2646
2643
2647
- } else if (!strcmp (elems [3 ], "double" )) {
2644
+ } else if (!strcmp (elems [j - 1 ], "double" )) {
2648
2645
gchar * end1 , * end2 ;
2649
2646
min_d = g_ascii_strtod (value , & end1 );
2650
2647
if (end1 == value ) {
@@ -2659,10 +2656,7 @@ int osc_test_value(struct iio_context *_ctx, int line,
2659
2656
}
2660
2657
2661
2658
ret = iio_attr_read_double (attrib , & val_d );
2662
- // if (chn)
2663
- // ret = iio_channel_attr_read_double(chn, attr, &val_d);
2664
- // else
2665
- // ret = iio_device_attr_read_double(dev, attr, &val_d);
2659
+
2666
2660
if (ret < 0 )
2667
2661
goto cleanup ;
2668
2662
@@ -2741,10 +2735,8 @@ int osc_identify_attrib(struct iio_context *_ctx, const char *attrib,
2741
2735
goto cleanup ;
2742
2736
}
2743
2737
const struct iio_attr * attribute = iio_channel_find_attr (* chn , * attr );
2744
- file = iio_attr_get_filename (attribute );
2745
- ret = iio_err (file );
2746
- //ret = iio_device_identify_filename(device, filename, chn, attr);
2747
- if (!ret ) {
2738
+ ret = iio_err (attribute );
2739
+ if (ret == 0 ) {
2748
2740
* debug = is_debug ;
2749
2741
* dev = device ;
2750
2742
}
@@ -2759,6 +2751,7 @@ static int osc_read_nonenclosed_value(struct iio_context *_ctx,
2759
2751
{
2760
2752
struct iio_device * dev ;
2761
2753
struct iio_channel * chn ;
2754
+ const struct iio_attr * attribute ;
2762
2755
const char * attr ;
2763
2756
char * pend ;
2764
2757
bool debug ;
@@ -2773,15 +2766,17 @@ static int osc_read_nonenclosed_value(struct iio_context *_ctx,
2773
2766
}
2774
2767
if (ret < 0 )
2775
2768
return ret ;
2776
- const struct iio_attr * attribute ;
2777
- attribute = iio_device_find_attr (dev , attr );
2778
- ret = iio_attr_read_longlong (attribute , out );
2779
- // if (chn)
2780
- // ret = iio_channel_attr_read_longlong(chn, attr, out);
2781
- // else if (debug)
2782
- // ret = iio_device_debug_attr_read_longlong(dev, attr, out);
2783
- // else
2784
- // ret = iio_device_attr_read_longlong(dev, attr, out);
2769
+
2770
+ if (chn ) {
2771
+ attribute = iio_channel_find_attr (chn , attr );
2772
+ ret = iio_attr_read_longlong (attribute , out );
2773
+ } else if (debug ) {
2774
+ attribute = iio_channel_find_attr (chn , attr );
2775
+ ret = iio_attr_read_longlong (attribute , out );
2776
+ } else {
2777
+ attribute = iio_device_find_attr (dev , attr );
2778
+ ret = iio_attr_read_longlong (attribute , out );
2779
+ }
2785
2780
return ret < 0 ? ret : 0 ;
2786
2781
}
2787
2782
@@ -2929,6 +2924,7 @@ int osc_plugin_default_handle(struct iio_context *_ctx,
2929
2924
{
2930
2925
struct iio_device * dev ;
2931
2926
struct iio_channel * chn ;
2927
+ const struct iio_attr * attribute ;
2932
2928
const char * attr ;
2933
2929
bool debug ;
2934
2930
int ret ;
@@ -2960,20 +2956,26 @@ int osc_plugin_default_handle(struct iio_context *_ctx,
2960
2956
return ret ;
2961
2957
}
2962
2958
2963
- // if (chn)
2964
- // ret = iio_channel_attr_write_longlong(chn, attr, lval);
2965
- // else if (debug)
2966
- // ret = iio_device_debug_attr_write_longlong(dev, attr, lval);
2967
- // else
2968
- const struct iio_attr * attrib = iio_device_find_attr (dev , attr );
2969
- ret = iio_attr_write_longlong (attrib , lval );
2970
- } /*else if (chn)
2971
- ret = iio_channel_attr_write(chn, attr, value);
2972
- else if (debug)
2973
- ret = iio_device_debug_attr_write(dev, attr, value);*/
2974
- else {
2975
- const struct iio_attr * attrib = iio_device_find_attr (dev , attr );
2976
- ret = iio_attr_write (attrib ,value );
2959
+ if (chn ) {
2960
+ attribute = iio_channel_find_attr (chn , attr );
2961
+ ret = iio_attr_write_longlong (attribute , lval );
2962
+ } else if (debug ) {
2963
+ attribute = iio_device_find_debug_attr (dev , attr );
2964
+ ret = iio_attr_write_longlong (attribute , lval );
2965
+ }
2966
+ else {
2967
+ attribute = iio_device_find_attr (dev , attr );
2968
+ ret = iio_attr_write_longlong (attribute , lval );
2969
+ }
2970
+ } else if (chn ) {
2971
+ attribute = iio_channel_find_attr (chn , attr );
2972
+ ret = iio_attr_write (attribute , value );
2973
+ } else if (debug ) {
2974
+ attribute = iio_device_find_debug_attr (dev , attr );
2975
+ ret = iio_attr_write (attribute , value );
2976
+ } else {
2977
+ attribute = iio_device_find_attr (dev , attr );
2978
+ ret = iio_attr_write (attribute ,value );
2977
2979
}
2978
2980
if (ret < 0 ) {
2979
2981
fprintf (stderr , "Unable to write '%s' to %s:%s\n" , value ,
0 commit comments