static u16 read_adc_value(int channel) { u16 data = 0; u32 sum_value = 0; int i = 0; #if 0 down(&channel_mutex); select_channel(channel); mdelay(10); for (i = 0; i < DATA_LEN; i++) { sum_value += amic1608_adc_readdate(); } data = sum_value/DATA_LEN; up(&channel_mutex); #else down(&channel_mutex); select_channel(channel); udelay(100); data = amic1608_adc_readdate(); up(&channel_mutex); #endif return data; }
static void notebook_switch_page(GtkNotebook *w, GtkWidget *page_widget, gint page_num) { GtkWidget *pw; pw = gtk_notebook_get_nth_page(w, page_num); if (pw) { int index = 0; index = get_user_int_data(G_OBJECT(pw)); if ((index < ss->max_sounds) && (snd_ok(ss->sounds[index]))) { snd_info *sp; sp = ss->sounds[index]; if (sp->selected_channel == NO_SELECTION) select_channel(ss->sounds[index], 0); else select_channel(ss->sounds[index], sp->selected_channel); } } }
static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { struct dev_context *devc; struct sr_scpi_dev_inst *scpi; struct sr_channel *ch; struct pps_channel *pch; int cmd, ret; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; devc = sdi->priv; scpi = sdi->conn; devc->cb_data = cb_data; if ((ret = sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 10, scpi_pps_receive_data, (void *)sdi)) != SR_OK) return ret; std_session_send_df_header(sdi, LOG_PREFIX); /* Prime the pipe with the first channel's fetch. */ ch = sr_next_enabled_channel(sdi, NULL); pch = ch->priv; if ((ret = select_channel(sdi, ch)) < 0) return ret; if (pch->mq == SR_MQ_VOLTAGE) cmd = SCPI_CMD_GET_MEAS_VOLTAGE; else if (pch->mq == SR_MQ_FREQUENCY) cmd = SCPI_CMD_GET_MEAS_FREQUENCY; else if (pch->mq == SR_MQ_CURRENT) cmd = SCPI_CMD_GET_MEAS_CURRENT; else if (pch->mq == SR_MQ_POWER) cmd = SCPI_CMD_GET_MEAS_POWER; else return SR_ERR; scpi_cmd(sdi, devc->device->commands, cmd, pch->hwname); return SR_OK; }
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; double d; int ret; if (!sdi) return SR_ERR_ARG; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; if (cg) /* Channel group specified. */ select_channel(sdi, cg->channels->data); devc = sdi->priv; ret = SR_OK; switch (key) { case SR_CONF_ENABLED: if (g_variant_get_boolean(data)) ret = scpi_cmd(sdi, devc->device->commands, SCPI_CMD_SET_OUTPUT_ENABLE); else ret = scpi_cmd(sdi, devc->device->commands, SCPI_CMD_SET_OUTPUT_DISABLE); break; case SR_CONF_VOLTAGE_TARGET: d = g_variant_get_double(data); ret = scpi_cmd(sdi, devc->device->commands, SCPI_CMD_SET_VOLTAGE_TARGET, d); break; case SR_CONF_OUTPUT_FREQUENCY_TARGET: d = g_variant_get_double(data); ret = scpi_cmd(sdi, devc->device->commands, SCPI_CMD_SET_FREQUENCY_TARGET, d); break; case SR_CONF_CURRENT_LIMIT: d = g_variant_get_double(data); ret = scpi_cmd(sdi, devc->device->commands, SCPI_CMD_SET_CURRENT_LIMIT, d); break; case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED: if (g_variant_get_boolean(data)) ret = scpi_cmd(sdi, devc->device->commands, SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_ENABLE); else ret = scpi_cmd(sdi, devc->device->commands, SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_DISABLE); break; case SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD: d = g_variant_get_double(data); ret = scpi_cmd(sdi, devc->device->commands, SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, d); break; case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED: if (g_variant_get_boolean(data)) ret = scpi_cmd(sdi, devc->device->commands, SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE); else ret = scpi_cmd(sdi, devc->device->commands, SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE); break; case SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD: d = g_variant_get_double(data); ret = scpi_cmd(sdi, devc->device->commands, SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD, d); break; case SR_CONF_OVER_TEMPERATURE_PROTECTION: if (g_variant_get_boolean(data)) ret = scpi_cmd(sdi, devc->device->commands, SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_ENABLE); else ret = scpi_cmd(sdi, devc->device->commands, SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_DISABLE); break; default: ret = SR_ERR_NA; } return ret; }
static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; const GVariantType *gvtype; unsigned int i; int cmd, ret; char *s; if (!sdi) return SR_ERR_ARG; devc = sdi->priv; if (cg) { /* * These options only apply to channel groups with a single * channel -- they're per-channel settings for the device. */ /* * Config keys are handled below depending on whether a channel * group was provided by the frontend. However some of these * take a CG on one PPS but not on others. Check the device's * profile for that here, and NULL out the channel group as needed. */ for (i = 0; i < devc->device->num_devopts; i++) { if (devc->device->devopts[i] == key) { cg = NULL; break; } } } gvtype = NULL; cmd = -1; switch (key) { case SR_CONF_ENABLED: gvtype = G_VARIANT_TYPE_BOOLEAN; cmd = SCPI_CMD_GET_OUTPUT_ENABLED; break; case SR_CONF_VOLTAGE: gvtype = G_VARIANT_TYPE_DOUBLE; cmd = SCPI_CMD_GET_MEAS_VOLTAGE; break; case SR_CONF_VOLTAGE_TARGET: gvtype = G_VARIANT_TYPE_DOUBLE; cmd = SCPI_CMD_GET_VOLTAGE_TARGET; break; case SR_CONF_OUTPUT_FREQUENCY: gvtype = G_VARIANT_TYPE_DOUBLE; cmd = SCPI_CMD_GET_MEAS_FREQUENCY; break; case SR_CONF_OUTPUT_FREQUENCY_TARGET: gvtype = G_VARIANT_TYPE_DOUBLE; cmd = SCPI_CMD_GET_FREQUENCY_TARGET; break; case SR_CONF_CURRENT: gvtype = G_VARIANT_TYPE_DOUBLE; cmd = SCPI_CMD_GET_MEAS_CURRENT; break; case SR_CONF_CURRENT_LIMIT: gvtype = G_VARIANT_TYPE_DOUBLE; cmd = SCPI_CMD_GET_CURRENT_LIMIT; break; case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED: gvtype = G_VARIANT_TYPE_BOOLEAN; cmd = SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ENABLED; break; case SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE: gvtype = G_VARIANT_TYPE_BOOLEAN; cmd = SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE; break; case SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD: gvtype = G_VARIANT_TYPE_DOUBLE; cmd = SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD; break; case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED: gvtype = G_VARIANT_TYPE_BOOLEAN; cmd = SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED; break; case SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE: gvtype = G_VARIANT_TYPE_BOOLEAN; cmd = SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE; break; case SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD: gvtype = G_VARIANT_TYPE_DOUBLE; cmd = SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD; break; case SR_CONF_OVER_TEMPERATURE_PROTECTION: gvtype = G_VARIANT_TYPE_BOOLEAN; cmd = SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION; break; case SR_CONF_REGULATION: gvtype = G_VARIANT_TYPE_STRING; cmd = SCPI_CMD_GET_OUTPUT_REGULATION; } if (!gvtype) return SR_ERR_NA; if (cg) select_channel(sdi, cg->channels->data); ret = scpi_cmd_resp(sdi, devc->device->commands, data, gvtype, cmd); if (cmd == SCPI_CMD_GET_OUTPUT_REGULATION) { /* * The Rigol DP800 series return CV/CC/UR, Philips PM2800 * return VOLT/CURR. We always return a GVariant string in * the Rigol notation. */ if ((ret = sr_scpi_get_string(sdi->conn, NULL, &s)) != SR_OK) return ret; if (!strcmp(s, "CV") || !strcmp(s, "VOLT")) { *data = g_variant_new_string("CV"); } else if (!strcmp(s, "CC") || !strcmp(s, "CURR")) { *data = g_variant_new_string("CC"); } else if (!strcmp(s, "UR")) { *data = g_variant_new_string("UR"); } else { sr_dbg("Unknown response to SCPI_CMD_GET_OUTPUT_REGULATION: %s", s); ret = SR_ERR_DATA; } g_free(s); } return ret; }
static void startup_funcs(void) { static int auto_open_ctr = 0; #ifndef SND_AS_WIDGET /* trap outer-level Close for cleanup check */ SG_SIGNAL_CONNECT(MAIN_SHELL(ss), "delete_event", window_close, NULL); /* when iconified, we need to hide any dialogs as well */ SG_SIGNAL_CONNECT(MAIN_SHELL(ss), "window_state_event", window_iconify, NULL); #endif ss->graph_cursor = gdk_cursor_new((GdkCursorType)in_graph_cursor(ss)); ss->wait_cursor = gdk_cursor_new(GDK_WATCH); ss->bounds_cursor = gdk_cursor_new(GDK_SB_H_DOUBLE_ARROW); ss->yaxis_cursor = gdk_cursor_new(GDK_SB_V_DOUBLE_ARROW); ss->play_cursor = gdk_cursor_new(GDK_SB_RIGHT_ARROW); ss->loop_play_cursor = gdk_cursor_new(GDK_SB_LEFT_ARROW); ss->arrow_cursor = gdk_cursor_new(GDK_LEFT_PTR); #if HAVE_EXTENSION_LANGUAGE snd_load_init_file(noglob, noinit); #endif #if HAVE_SIGNAL && HAVE_EXTENSION_LANGUAGE && !__MINGW32__ if (!nostdin) { GIOChannel *channel; signal(SIGTTIN, SIG_IGN); signal(SIGTTOU, SIG_IGN); /* these signals are sent by a shell if we start Snd as a background process, * but try to read stdin (needed to support the emacs subjob connection). If * we don't do this, the background job is suspended when the shell sends SIGTTIN. */ channel = g_io_channel_unix_new(STDIN_FILENO); stdin_id = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, (GIOCondition)(G_IO_IN | G_IO_HUP | G_IO_ERR), io_invoke, NULL, NULL); g_io_channel_unref(channel); } #endif while (auto_open_ctr < auto_open_files) auto_open_ctr = handle_next_startup_arg(auto_open_ctr, auto_open_file_names, true, auto_open_files); #ifndef SND_AS_WIDGET if ((ss->init_window_width > 0) && (ss->init_window_height > 0)) set_widget_size(GTK_WIDGET(MAIN_SHELL(ss)), ss->init_window_width, ss->init_window_height); if ((ss->init_window_x != DEFAULT_INIT_WINDOW_X) && (ss->init_window_y != DEFAULT_INIT_WINDOW_Y)) set_widget_position(GTK_WIDGET(MAIN_SHELL(ss)), ss->init_window_x, ss->init_window_y); #endif #if (!HAVE_FAM) if (auto_update_interval(ss) > 0.0) g_timeout_add_full(0, (guint32)(auto_update_interval(ss) * 1000), auto_update_check, NULL, NULL); #endif #if MUS_TRAP_SEGFAULT if (trap_segfault(ss)) signal(SIGSEGV, segv); #endif if ((ss->sounds) && (ss->selected_sound == NO_SELECTION)) { snd_info *sp; sp = ss->sounds[0]; if ((sp) && (sp->inuse == SOUND_NORMAL) && (sp->selected_channel == NO_SELECTION)) /* don't clobber possible select-channel in loaded startup files */ select_channel(sp, 0); } }
SR_PRIV int scpi_pps_receive_data(int fd, int revents, void *cb_data) { struct dev_context *devc; struct sr_datafeed_packet packet; struct sr_datafeed_analog analog; const struct sr_dev_inst *sdi; struct sr_channel *next_channel; struct sr_scpi_dev_inst *scpi; struct pps_channel *pch; float f; int cmd; (void)fd; (void)revents; if (!(sdi = cb_data)) return TRUE; if (!(devc = sdi->priv)) return TRUE; scpi = sdi->conn; /* Retrieve requested value for this state. */ if (sr_scpi_get_float(scpi, NULL, &f) == SR_OK) { pch = devc->cur_channel->priv; packet.type = SR_DF_ANALOG; packet.payload = &analog; analog.channels = g_slist_append(NULL, devc->cur_channel); analog.num_samples = 1; analog.mq = pch->mq; if (pch->mq == SR_MQ_VOLTAGE) analog.unit = SR_UNIT_VOLT; else if (pch->mq == SR_MQ_CURRENT) analog.unit = SR_UNIT_AMPERE; else if (pch->mq == SR_MQ_POWER) analog.unit = SR_UNIT_WATT; analog.mqflags = SR_MQFLAG_DC; analog.data = &f; sr_session_send(sdi, &packet); g_slist_free(analog.channels); } if (g_slist_length(sdi->channels) > 1) { next_channel = next_enabled_channel(sdi, devc->cur_channel); if (select_channel(sdi, next_channel) != SR_OK) { sr_err("Failed to select channel %s", next_channel->name); return FALSE; } } pch = devc->cur_channel->priv; if (pch->mq == SR_MQ_VOLTAGE) cmd = SCPI_CMD_GET_MEAS_VOLTAGE; else if (pch->mq == SR_MQ_FREQUENCY) cmd = SCPI_CMD_GET_MEAS_FREQUENCY; else if (pch->mq == SR_MQ_CURRENT) cmd = SCPI_CMD_GET_MEAS_CURRENT; else if (pch->mq == SR_MQ_POWER) cmd = SCPI_CMD_GET_MEAS_POWER; else return SR_ERR; scpi_cmd(sdi, cmd); return TRUE; }
SR_PRIV int scpi_pps_receive_data(int fd, int revents, void *cb_data) { struct dev_context *devc; struct sr_datafeed_packet packet; struct sr_datafeed_analog analog; struct sr_analog_encoding encoding; struct sr_analog_meaning meaning; struct sr_analog_spec spec; const struct sr_dev_inst *sdi; struct sr_channel *next_channel; struct sr_scpi_dev_inst *scpi; struct pps_channel *pch; const struct channel_spec *ch_spec; float f; int cmd; (void)fd; (void)revents; if (!(sdi = cb_data)) return TRUE; if (!(devc = sdi->priv)) return TRUE; scpi = sdi->conn; /* Retrieve requested value for this state. */ if (sr_scpi_get_float(scpi, NULL, &f) == SR_OK) { pch = devc->cur_channel->priv; ch_spec = &devc->device->channels[pch->hw_output_idx]; packet.type = SR_DF_ANALOG; packet.payload = &analog; /* Note: digits/spec_digits will be overridden later. */ sr_analog_init(&analog, &encoding, &meaning, &spec, 0); analog.meaning->channels = g_slist_append(NULL, devc->cur_channel); analog.num_samples = 1; analog.meaning->mq = pch->mq; if (pch->mq == SR_MQ_VOLTAGE) { analog.meaning->unit = SR_UNIT_VOLT; analog.encoding->digits = ch_spec->voltage[4]; analog.spec->spec_digits = ch_spec->voltage[3]; } else if (pch->mq == SR_MQ_CURRENT) { analog.meaning->unit = SR_UNIT_AMPERE; analog.encoding->digits = ch_spec->current[4]; analog.spec->spec_digits = ch_spec->current[3]; } else if (pch->mq == SR_MQ_POWER) { analog.meaning->unit = SR_UNIT_WATT; analog.encoding->digits = ch_spec->power[4]; analog.spec->spec_digits = ch_spec->power[3]; } analog.meaning->mqflags = SR_MQFLAG_DC; analog.data = &f; sr_session_send(sdi, &packet); g_slist_free(analog.meaning->channels); } if (g_slist_length(sdi->channels) > 1) { next_channel = sr_next_enabled_channel(sdi, devc->cur_channel); if (select_channel(sdi, next_channel) != SR_OK) { sr_err("Failed to select channel %s", next_channel->name); return FALSE; } } pch = devc->cur_channel->priv; if (pch->mq == SR_MQ_VOLTAGE) cmd = SCPI_CMD_GET_MEAS_VOLTAGE; else if (pch->mq == SR_MQ_FREQUENCY) cmd = SCPI_CMD_GET_MEAS_FREQUENCY; else if (pch->mq == SR_MQ_CURRENT) cmd = SCPI_CMD_GET_MEAS_CURRENT; else if (pch->mq == SR_MQ_POWER) cmd = SCPI_CMD_GET_MEAS_POWER; else return SR_ERR; scpi_cmd(sdi, devc->device->commands, cmd); return TRUE; }
static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; const GVariantType *gvtype; unsigned int i; int cmd, ret; if (!sdi) return SR_ERR_ARG; devc = sdi->priv; if (cg) { /* * These options only apply to channel groups with a single * channel -- they're per-channel settings for the device. */ /* * Config keys are handled below depending on whether a channel * group was provided by the frontend. However some of these * take a CG on one PPS but not on others. Check the device's * profile for that here, and NULL out the channel group as needed. */ for (i = 0; i < devc->device->num_devopts; i++) { if (devc->device->devopts[i] == key) { cg = NULL; break; } } } gvtype = NULL; cmd = -1; switch (key) { case SR_CONF_OUTPUT_ENABLED: gvtype = G_VARIANT_TYPE_BOOLEAN; cmd = SCPI_CMD_GET_OUTPUT_ENABLED; break; case SR_CONF_OUTPUT_VOLTAGE: gvtype = G_VARIANT_TYPE_DOUBLE; cmd = SCPI_CMD_GET_MEAS_VOLTAGE; break; case SR_CONF_OUTPUT_VOLTAGE_TARGET: gvtype = G_VARIANT_TYPE_DOUBLE; cmd = SCPI_CMD_GET_VOLTAGE_TARGET; break; case SR_CONF_OUTPUT_CURRENT: gvtype = G_VARIANT_TYPE_DOUBLE; cmd = SCPI_CMD_GET_MEAS_CURRENT; break; case SR_CONF_OUTPUT_CURRENT_LIMIT: gvtype = G_VARIANT_TYPE_DOUBLE; cmd = SCPI_CMD_GET_CURRENT_LIMIT; break; case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED: gvtype = G_VARIANT_TYPE_BOOLEAN; cmd = SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ENABLED; break; case SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE: gvtype = G_VARIANT_TYPE_BOOLEAN; cmd = SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE; break; case SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD: gvtype = G_VARIANT_TYPE_DOUBLE; cmd = SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD; break; case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED: gvtype = G_VARIANT_TYPE_BOOLEAN; cmd = SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED; break; case SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE: gvtype = G_VARIANT_TYPE_BOOLEAN; cmd = SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE; break; case SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD: gvtype = G_VARIANT_TYPE_DOUBLE; cmd = SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD; break; case SR_CONF_OVER_TEMPERATURE_PROTECTION: gvtype = G_VARIANT_TYPE_BOOLEAN; cmd = SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION; break; case SR_CONF_OUTPUT_REGULATION: gvtype = G_VARIANT_TYPE_STRING; cmd = SCPI_CMD_GET_OUTPUT_REGULATION; } if (gvtype) { if (cg) select_channel(sdi, cg->channels->data); ret = scpi_cmd_resp(sdi, data, gvtype, cmd); } else ret = SR_ERR_NA; return ret; }