static void rx_phase_rotation_set(GtkSpinButton *spinbutton, gpointer user_data) { glong offset = (glong) user_data; struct iio_channel *out0, *out1; gdouble val, phase; val = gtk_spin_button_get_value(spinbutton); phase = val * 2 * M_PI / 360.0; if (offset == 2) { out0 = iio_device_find_channel(cap, "voltage2", false); out1 = iio_device_find_channel(cap, "voltage3", false); } else { out0 = iio_device_find_channel(cap, "voltage0", false); out1 = iio_device_find_channel(cap, "voltage1", false); } if (out1 && out0) { iio_channel_attr_write_double(out0, "calibscale", (double) cos(phase)); iio_channel_attr_write_double(out0, "calibphase", (double) (-1 * sin(phase))); iio_channel_attr_write_double(out1, "calibscale", (double) cos(phase)); iio_channel_attr_write_double(out1, "calibphase", (double) sin(phase)); } }
static void rx_phase_rotation(struct iio_device *dev, gdouble val) { struct iio_channel *out0, *out1; gdouble phase; unsigned offset; DBG("%s %f\n", iio_device_get_name(dev), val); phase = val * 2 * M_PI / 360.0; /* Set both RX1 and RX2 */ for (offset = 0; offset <= 2; offset += 2) { if (offset == 2) { out0 = iio_device_find_channel(dev, "voltage2", false); out1 = iio_device_find_channel(dev, "voltage3", false); } else { out0 = iio_device_find_channel(dev, "voltage0", false); out1 = iio_device_find_channel(dev, "voltage1", false); } if (out1 && out0) { iio_channel_attr_write_double(out0, "calibscale", (double) cos(phase)); iio_channel_attr_write_double(out0, "calibphase", (double) (-1 * sin(phase))); iio_channel_attr_write_double(out1, "calibscale", (double) cos(phase)); iio_channel_attr_write_double(out1, "calibphase", (double) sin(phase)); } } }
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 trx_phase_rotation(struct iio_device *dev, gdouble val) { struct iio_channel *out0, *out1; gdouble phase, vcos, vsin; unsigned offset; bool output = (dev == dev_dds_slave) || (dev == dev_dds_master); DBG("%s %f\n", iio_device_get_name(dev), val); phase = val * 2 * M_PI / 360.0; vcos = cos(phase); vsin = sin(phase); if (output) { gdouble corr; corr = 1.0 / fmax(fabs(sin(phase) + cos(phase)), fabs(cos(phase) - sin(phase))); vcos *= corr; vsin *= corr; } /* Set both RX1 and RX2 */ for (offset = 0; offset <= 2; offset += 2) { if (offset == 2) { out0 = iio_device_find_channel(dev, "voltage2", output); out1 = iio_device_find_channel(dev, "voltage3", output); } else { out0 = iio_device_find_channel(dev, "voltage0", output); out1 = iio_device_find_channel(dev, "voltage1", output); } if (out1 && out0) { iio_channel_attr_write_double(out0, "calibscale", (double) vcos); iio_channel_attr_write_double(out0, "calibphase", (double) (-1.0 * vsin)); iio_channel_attr_write_double(out1, "calibscale", (double) vcos); iio_channel_attr_write_double(out1, "calibphase", (double) vsin); } } }
static int default_dds(long long freq, double scale) { int i, j, ret = 0; for (i = 0; i < 2; i++) { for (j = 0; j < 8; j++) { ret |= iio_channel_attr_write_longlong(dds_out[i][j], "frequency", freq); ret |= iio_channel_attr_write_double(dds_out[i][j], "scale", scale); } tx_phase_rotation(i ? dev_dds_slave : dev_dds_master, 0.0); } return ret; }