forked from analogdevicesinc/iio-oscilloscope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iio_widget.c
722 lines (614 loc) · 20.4 KB
/
iio_widget.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
/**
* Copyright 2012-2013(c) Analog Devices, Inc.
*
* Licensed under the GPL-2.
*
**/
#include <gtk/gtk.h>
#include <stdint.h>
#include <stdbool.h>
#include <errno.h>
#include <string.h>
#include <math.h>
#include "iio_widget.h"
struct update_widgets_params {
struct iio_widget *widgets;
unsigned int nb;
};
void g_builder_connect_signal(GtkBuilder *builder, const gchar *name,
const gchar *signal, GCallback callback, gpointer data)
{
GObject *tmp;
tmp = gtk_builder_get_object(builder, name);
if (tmp == NULL)
fprintf(stderr, "Couldn't find object \"%s\".\n", name);
else
g_signal_connect(tmp, signal, callback, data);
}
void g_builder_connect_signal_data(GtkBuilder *builder, const gchar *name,
const gchar *signal, GCallback callback, gpointer data,
GClosureNotify destroy_data, GConnectFlags connect_flags)
{
GObject *tmp;
tmp = gtk_builder_get_object(builder, name);
if (tmp == NULL)
fprintf(stderr, "Couldn't find object \"%s\".\n", name);
else
g_signal_connect_data(tmp, signal, callback, data, destroy_data, connect_flags);
}
void g_builder_bind_property(GtkBuilder *builder,
const gchar *source_name, const gchar *source_property,
const gchar *target_name, const gchar *target_property,
GBindingFlags flags)
{
GObject *source_object, *target_object;
source_object = gtk_builder_get_object(builder, source_name);
if (!source_object) {
fprintf(stderr, "Couldn't find object \"%s\"\n", source_name);
return;
}
target_object = gtk_builder_get_object(builder, target_name);
if (!target_object) {
fprintf(stderr, "Couldn't find object \"%s\"\n", target_name);
g_object_unref(source_object);
return;
}
g_object_bind_property(source_object, source_property, target_object,
target_property, flags);
}
static void iio_widget_init(struct iio_widget *widget,
struct iio_device *dev, struct iio_channel *chn, const char *attr_name,
const char *attr_name_avail, GtkWidget *gtk_widget, void *priv,
void (*update)(struct iio_widget *),
void (*update_value)(struct iio_widget *, const char *, size_t),
void (*save)(struct iio_widget *))
{
if (!gtk_widget) {
const char *name = iio_device_get_name(dev) ?:
iio_device_get_id(dev);
printf("Missing widget for %s/%s\n", name, attr_name);
}
memset(widget, 0, sizeof(*widget));
widget->dev = dev;
widget->chn = chn;
widget->attr_name = attr_name;
widget->attr_name_avail = attr_name_avail;
widget->widget = gtk_widget;
widget->update = update;
widget->update_value = update_value;
widget->save = save;
widget->priv = priv;
}
static void iio_spin_button_update_value(struct iio_widget *widget,
const char *src, size_t len)
{
gdouble freq, mag, min, max;
gdouble scale = widget->priv ? *(gdouble *)widget->priv : 1.0;
char *end;
mag = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget->widget));
gtk_spin_button_get_range(GTK_SPIN_BUTTON(widget->widget), &min, &max);
freq = g_ascii_strtod(src, &end);
if (end == src)
return;
if (widget->priv_convert_function)
freq = ((double (*)(double, bool))widget->priv_convert_function)(freq, true);
freq /= fabs(scale);
/* if scale is negative, we treat things a little differently */
if (scale < 0) {
/* if the setting is negative, and it can be set negative */
if (mag < 0 && min < 0)
freq *= -1;
else if (min >= 0)
freq *= -1;
}
gtk_spin_button_set_value(GTK_SPIN_BUTTON (widget->widget), freq);
}
static void iio_spin_button_update(struct iio_widget *widget)
{
ssize_t ret;
char buf[0x100];
if (widget->chn)
ret = iio_channel_attr_read(widget->chn,
widget->attr_name, buf, sizeof(buf));
else
ret = iio_device_attr_read(widget->dev,
widget->attr_name, buf, sizeof(buf));
if (ret > 0)
iio_spin_button_update_value(widget, buf, ret);
else if (ret == -ENODEV)
gtk_widget_hide(widget->widget);
}
static void spin_button_save(struct iio_widget *widget, bool is_double)
{
gdouble freq, min;
gdouble scale = widget->priv ? *(gdouble *)widget->priv : 1.0;
freq = gtk_spin_button_get_value(GTK_SPIN_BUTTON (widget->widget));
min = gtk_adjustment_get_lower(gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(widget->widget)));
if (scale < 0 && min < 0)
freq = fabs(freq * scale);
else
freq *= scale;
if (widget->priv_convert_function)
freq = ((double (*)(double, bool))widget->priv_convert_function)(freq, false);
if (widget->chn) {
if (is_double)
iio_channel_attr_write_double(widget->chn,
widget->attr_name, freq);
else
iio_channel_attr_write_longlong(widget->chn,
widget->attr_name, (long long) freq);
} else {
if (is_double)
iio_device_attr_write_double(widget->dev,
widget->attr_name, freq);
else
iio_device_attr_write_longlong(widget->dev,
widget->attr_name, (long long) freq);
}
}
static void iio_spin_button_savedbl(struct iio_widget *widget)
{
return spin_button_save(widget, true);
}
void iio_spin_button_save(struct iio_widget *widget)
{
return spin_button_save(widget, false);
}
void iio_spin_button_init(struct iio_widget *widget, struct iio_device *dev,
struct iio_channel *chn, const char *attr_name,
GtkWidget *spin_button, const gdouble *scale)
{
iio_widget_init(widget, dev, chn, attr_name, NULL, spin_button,
(void *)scale, iio_spin_button_update,
iio_spin_button_update_value, iio_spin_button_savedbl);
}
void iio_spin_button_int_init(struct iio_widget *widget, struct iio_device *dev,
struct iio_channel *chn, const char *attr_name,
GtkWidget *spin_button, const gdouble *scale)
{
iio_widget_init(widget, dev, chn, attr_name, NULL, spin_button,
(void *)scale, iio_spin_button_update,
iio_spin_button_update_value, iio_spin_button_save);
}
void iio_spin_button_s64_init(struct iio_widget *widget, struct iio_device *dev,
struct iio_channel *chn, const char *attr_name,
GtkWidget *spin_button, const gdouble *scale)
{
iio_widget_init(widget, dev, chn, attr_name, NULL, spin_button,
(void *)scale, iio_spin_button_update,
iio_spin_button_update_value, iio_spin_button_save);
}
static void iio_toggle_button_save(struct iio_widget *widget)
{
bool active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (widget->widget));
active = widget->priv ? !active : active;
if (widget->chn)
iio_channel_attr_write_bool(widget->chn,
widget->attr_name, active);
else
iio_device_attr_write_bool(widget->dev,
widget->attr_name, active);
}
static void iio_toggle_button_update_value(struct iio_widget *widget,
const char *src, size_t len)
{
bool active;
if (len != 2)
return;
active = src[0] == '1' || src[0] == 'Y';
active = widget->priv ? !active : active;
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (widget->widget), active);
}
static void iio_toggle_button_update(struct iio_widget *widget)
{
char buf[0x100];
ssize_t ret;
if (widget->chn)
ret = iio_channel_attr_read(widget->chn,
widget->attr_name, buf, sizeof(buf));
else
ret = iio_device_attr_read(widget->dev,
widget->attr_name, buf, sizeof(buf));
if (ret > 0)
iio_toggle_button_update_value(widget, buf, ret);
else if (ret == -ENODEV)
gtk_widget_hide(widget->widget);
}
static void iio_toggle_button_init(struct iio_widget *widget,
struct iio_device *dev, struct iio_channel *chn, const char *attr_name,
GtkWidget *toggle_button, const bool invert)
{
iio_widget_init(widget, dev, chn, attr_name, NULL, toggle_button,
(void *)invert, iio_toggle_button_update,
iio_toggle_button_update_value, iio_toggle_button_save);
}
static void iio_button_save(struct iio_widget *widget)
{
if (widget->chn)
iio_channel_attr_write_bool(widget->chn,
widget->attr_name, 1);
else
iio_device_attr_write_bool(widget->dev,
widget->attr_name, 1);
}
static void iio_button_update_value(struct iio_widget *widget,
const char *src, size_t len)
{
}
static void iio_button_update(struct iio_widget *widget)
{
}
static void iio_button_init(struct iio_widget *widget,
struct iio_device *dev, struct iio_channel *chn, const char *attr_name,
GtkWidget *button)
{
iio_widget_init(widget, dev, chn, attr_name, NULL, button,
NULL, iio_button_update,
iio_button_update_value, iio_button_save);
}
static void iio_combo_box_save(struct iio_widget *widget)
{
const char *text;
text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widget->widget));
if (text == NULL)
return;
if (widget->chn)
iio_channel_attr_write(widget->chn, widget->attr_name, text);
else
iio_device_attr_write(widget->dev, widget->attr_name, text);
}
static void iio_combo_box_update_value(struct iio_widget *widget,
const char *src, size_t len)
{
int (*compare)(const char *, const char *);
GtkComboBox *combo_box;
GtkTreeIter iter;
GtkTreeModel *model;
char text2[1024], *item;
gchar **items_avail = NULL, **saveditems_avail;
gboolean has_iter;
ssize_t ret;
combo_box = GTK_COMBO_BOX(widget->widget);
model = gtk_combo_box_get_model(combo_box);
if (widget->attr_name_avail) {
if (widget->chn)
ret = iio_channel_attr_read(widget->chn,
widget->attr_name_avail, text2, sizeof(text2));
else
ret = iio_device_attr_read(widget->dev,
widget->attr_name_avail, text2, sizeof(text2));
if (ret < 0)
return;
/* may use gtk_combo_box_text_remove_all gtk3 only */
gtk_list_store_clear (GTK_LIST_STORE (model));
saveditems_avail = items_avail = g_strsplit (text2, " ", 0);
for (; NULL != *items_avail; items_avail++) {
if (*items_avail[0] == '\0')
continue;
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(widget->widget),
*items_avail);
}
if (saveditems_avail)
g_strfreev(saveditems_avail);
}
if (widget->priv)
compare = widget->priv;
else
compare = strcmp;
has_iter = gtk_tree_model_get_iter_first(model, &iter);
while (has_iter) {
gtk_tree_model_get(model, &iter, 0, &item, -1);
if (compare (src, item) == 0) {
gtk_combo_box_set_active_iter(combo_box, &iter);
g_free(item);
break;
}
g_free(item);
has_iter = gtk_tree_model_iter_next(model, &iter);
}
}
static void iio_combo_box_update(struct iio_widget *widget)
{
ssize_t len;
char text[1024];
if (widget->chn)
len = iio_channel_attr_read(widget->chn,
widget->attr_name, text, sizeof(text));
else
len = iio_device_attr_read(widget->dev,
widget->attr_name, text, sizeof(text));
if (len > 0)
iio_combo_box_update_value(widget, text, len);
}
void iio_combo_box_init(struct iio_widget *widget, struct iio_device *dev,
struct iio_channel *chn, const char *attr_name, const char *attr_name_avail,
GtkWidget *combo_box, int (*compare)(const char *a, const char *b))
{
iio_widget_init(widget, dev, chn, attr_name, attr_name_avail, combo_box,
(void *)compare, iio_combo_box_update,
iio_combo_box_update_value, iio_combo_box_save);
gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(widget->widget), 0);
}
void iio_widget_update(struct iio_widget *widget)
{
widget->update(widget);
}
void iio_widget_save(struct iio_widget *widget)
{
widget->save(widget);
widget->update(widget);
}
void iio_update_widgets(struct iio_widget *widgets, unsigned int num_widgets)
{
unsigned int i;
for (i = 0; i < num_widgets; i++)
iio_widget_update(&widgets[i]);
}
static int __cb_dev_update(struct iio_device *dev, const char *attr,
const char *value, size_t len, void *d)
{
unsigned int i;
struct update_widgets_params *params = d;
for (i = 0; i < params->nb; i++) {
struct iio_widget *widget = ¶ms->widgets[i];
if (widget->update_value && !widget->chn &&
widget->dev == dev &&
!strcmp(widget->attr_name, attr)) {
widget->update_value(widget, value, len);
return 0;
}
}
return 0;
}
static int __cb_chn_update(struct iio_channel *chn, const char *attr,
const char *value, size_t len, void *d)
{
unsigned int i;
struct update_widgets_params *params = d;
for (i = 0; i < params->nb; i++) {
struct iio_widget *widget = ¶ms->widgets[i];
if (widget->update_value && widget->chn == chn &&
!strcmp(widget->attr_name, attr)) {
widget->update_value(widget, value, len);
return 0;
}
}
return 0;
}
void iio_update_widgets_of_device(struct iio_widget *widgets,
unsigned int num_widgets, struct iio_device *dev)
{
unsigned int i;
struct update_widgets_params params = {
.widgets = widgets,
.nb = num_widgets,
};
iio_device_attr_read_all(dev, __cb_dev_update, ¶ms);
for (i = 0; i < iio_device_get_channels_count(dev); i++)
iio_channel_attr_read_all(iio_device_get_channel(dev, i),
__cb_chn_update, ¶ms);
}
void iio_save_widgets(struct iio_widget *widgets, unsigned int num_widgets)
{
unsigned int i;
for (i = 0; i < num_widgets; i++)
iio_widget_save(&widgets[i]);
}
void iio_spin_button_init_from_builder(struct iio_widget *widget,
struct iio_device *dev, struct iio_channel *chn, const char *attr_name,
GtkBuilder *builder, const char *widget_name, const gdouble *scale)
{
iio_spin_button_init(widget, dev, chn, attr_name,
GTK_WIDGET(gtk_builder_get_object(builder, widget_name)),
scale);
}
void iio_spin_button_int_init_from_builder(struct iio_widget *widget,
struct iio_device *dev, struct iio_channel *chn, const char *attr_name,
GtkBuilder *builder, const char *widget_name, const gdouble *scale)
{
iio_spin_button_int_init(widget, dev, chn, attr_name,
GTK_WIDGET(gtk_builder_get_object(builder, widget_name)),
scale);
}
void iio_spin_button_s64_init_from_builder(struct iio_widget *widget,
struct iio_device *dev, struct iio_channel *chn, const char *attr_name,
GtkBuilder *builder, const char *widget_name, const gdouble *scale)
{
iio_spin_button_s64_init(widget, dev, chn, attr_name,
GTK_WIDGET(gtk_builder_get_object(builder, widget_name)),
scale);
}
void iio_combo_box_init_from_builder(struct iio_widget *widget,
struct iio_device *dev, struct iio_channel *chn, const char *attr_name,
const char *attr_name_avail,
GtkBuilder *builder, const char *widget_name,
int (*compare)(const char *a, const char *b))
{
iio_combo_box_init(widget, dev, chn, attr_name, attr_name_avail,
GTK_WIDGET(gtk_builder_get_object(builder, widget_name)),
compare);
}
void iio_toggle_button_init_from_builder(struct iio_widget *widget,
struct iio_device *dev, struct iio_channel *chn, const char *attr_name,
GtkBuilder *builder, const char *widget_name, const bool invert)
{
iio_toggle_button_init(widget, dev, chn, attr_name,
GTK_WIDGET(gtk_builder_get_object(builder, widget_name)), invert);
}
void iio_button_init_from_builder(struct iio_widget *widget,
struct iio_device *dev, struct iio_channel *chn, const char *attr_name,
GtkBuilder *builder, const char *widget_name)
{
iio_button_init(widget, dev, chn, attr_name,
GTK_WIDGET(gtk_builder_get_object(builder, widget_name)));
}
/*
* struct progress_data - Information about the progress spinbutton
*
* @is_progress_spin_button: Used for progress spinbutton identification
* @progress: Progress status. Range between 0.0 and 1.0
* @timeoutID: Handler ID of callback that increases progress step by step
* @value_changed_hid: Handler ID of callback for a "value-changed" event of the
* progress spinbutton
* @skip_widget_save: Allows widget to skip writing its value to the
* driver attrbiute when the progress bar completes
* @on_complete_data: Data to be passed to the on_complete() function
* @on_complete: Function to be called when progress reaches 1.0.
*/
struct progress_data {
gboolean is_progress_spin_button;
gfloat progress;
gint timeoutID;
gint value_changed_hid;
gboolean skip_widget_save;
void *on_complete_data;
void (*on_complete)(void *data);
};
/*
* Gets called periodically to increase the progress with one step.
* When progress is complete saves the spinbutton value to file, clears the
* progress and stops the function to be called periodically.
*/
static gboolean spin_button_progress_step(struct iio_widget *iio_w)
{
struct progress_data *pdata = iio_w->priv_progress;
void (*on_complete_cb)(void *) = pdata->on_complete;
if (pdata->progress < 1.0) {
pdata->progress += 0.095;
gtk_entry_set_progress_fraction(GTK_ENTRY(iio_w->widget), pdata->progress);
return TRUE;
} else {
pdata->progress = 0.0;
gtk_entry_set_progress_fraction(GTK_ENTRY(iio_w->widget), pdata->progress);
if (!pdata->skip_widget_save)
iio_widget_save(iio_w);
if (pdata->on_complete != NULL)
on_complete_cb(pdata->on_complete_data);
pdata->timeoutID = -1;
return FALSE;
}
}
/*
* When a "value-changed" event of the spinbutton occurs the progress bar of the
* spinbutton starts to increase until reaches the complete state. If another
* event occurs while the progress is not finished, the progress will be reset.
*/
static void delayed_spin_button_update_cb(GtkSpinButton *spinbutton,
struct iio_widget *iio_w)
{
struct progress_data *pdata = iio_w->priv_progress;
if (pdata->timeoutID != - 1)
pdata->progress = 0.0;
else
pdata->timeoutID = g_timeout_add_full(G_PRIORITY_DEFAULT_IDLE, 90,
(GSourceFunc)spin_button_progress_step, iio_w, NULL);
}
/*
* Customises a iio_widget that contains a GtkSpinButton widget to be able to
* work as a progress spinbutton.
*/
void iio_spin_button_add_progress(struct iio_widget *iio_w)
{
struct progress_data *pdata;
if (GTK_IS_SPIN_BUTTON(iio_w->widget) == FALSE) {
const char *name = iio_device_get_name(iio_w->dev) ?:
iio_device_get_id(iio_w->dev);
printf("The widget connected to the attribute: %s of device: %s is not a GtkSpinButton\n",
iio_w->attr_name, name);
return;
}
pdata = malloc(sizeof(struct progress_data));
pdata->is_progress_spin_button = TRUE;
pdata->progress = 0.0;
pdata->timeoutID = -1;
pdata->value_changed_hid = -1;
pdata->skip_widget_save = FALSE;
pdata->on_complete_data = NULL;
pdata->on_complete = NULL;
iio_w->priv_progress = pdata;
}
/*
* In order for the progress spinbutton to work, this function must be called
* to connect the required callback to the widget.
*/
void iio_spin_button_progress_activate(struct iio_widget *iio_w)
{
struct progress_data *pdata = iio_w->priv_progress;
if (GTK_IS_SPIN_BUTTON(iio_w->widget) == FALSE) {
const char *name = iio_device_get_name(iio_w->dev) ?:
iio_device_get_id(iio_w->dev);
printf("The widget connected to the attribute: %s of device: %s is not a GtkSpinButton\n",
iio_w->attr_name, name);
return;
}
pdata->value_changed_hid = g_signal_connect(G_OBJECT(iio_w->widget),
"value-changed", G_CALLBACK(delayed_spin_button_update_cb), iio_w);
}
/*
* Set a user function to be called when the progress is completed. The function
* can take one generic pointer as parameter.
*/
void iio_spin_button_set_on_complete_function(struct iio_widget *iio_w,
void(*on_complete)(void *), void *data)
{
struct progress_data *pdata = iio_w->priv_progress;
if (GTK_IS_SPIN_BUTTON(iio_w->widget) == FALSE) {
const char *name = iio_device_get_name(iio_w->dev) ?:
iio_device_get_id(iio_w->dev);
printf("The widget connected to the attribute: %s of device: %s is not a GtkSpinButton\n",
iio_w->attr_name, name);
return;
}
pdata->on_complete = on_complete;
pdata->on_complete_data = data;
}
/*
* Allow user to disable the function that saves the value of the widget
* to the driver when progress bar reaches 100%. User may use
* iio_spin_button_set_on_complete_function() in order to provide a
* more complex logic before saving the value of the widget.
*/
void iio_spin_button_skip_save_on_complete(struct iio_widget *iio_w,
gboolean skip)
{
struct progress_data *pdata = iio_w->priv_progress;
pdata->skip_widget_save = skip;
}
/*
* Disconnect the callback of the "value-changed" event from the progress
* spinbutton.
*/
void iio_spin_button_progress_deactivate(struct iio_widget *iio_w)
{
struct progress_data *pdata = iio_w->priv_progress;
if (GTK_IS_SPIN_BUTTON(iio_w->widget) == FALSE) {
const char *name = iio_device_get_name(iio_w->dev) ?:
iio_device_get_id(iio_w->dev);
printf("The widget connected to the attribute: %s of device: %s is not a GtkSpinButton\n",
iio_w->attr_name, name);
return;
}
g_signal_handler_disconnect(iio_w->widget, pdata->value_changed_hid);
}
/*
* Remove all implementation made to convert a iio_widget to a progress
* spinbutton.
*/
void iio_spin_button_remove_progress(struct iio_widget *iio_w)
{
if (GTK_IS_SPIN_BUTTON(iio_w->widget) == FALSE) {
const char *name = iio_device_get_name(iio_w->dev) ?:
iio_device_get_id(iio_w->dev);
printf("The widget connected to the attribute: %s of device: %s is not a GtkSpinButton\n",
iio_w->attr_name, name);
return;
}
iio_spin_button_progress_deactivate(iio_w);
if (iio_w->priv_progress)
free(iio_w->priv_progress);
}
void iio_spin_button_set_convert_function(struct iio_widget *iio_w,
double (*convert)(double, bool))
{
iio_w->priv_convert_function = convert;
}