forked from Ivasoft/DSView
Code refactoring 4
This commit is contained in:
@@ -35,6 +35,14 @@
|
||||
|
||||
#include "../config/appconfig.h"
|
||||
#include "../ui/msgbox.h"
|
||||
|
||||
|
||||
static const struct dev_mode_name dev_mode_name_list[] =
|
||||
{
|
||||
{LOGIC, "Logic Analyzer", "逻辑分析仪", "la.svg"},
|
||||
{ANALOG, "Data Acquisition", "数据记录仪", "daq.svg"},
|
||||
{DSO, "Oscilloscope", "示波器", "osc.svg"},
|
||||
};
|
||||
|
||||
namespace pv {
|
||||
namespace view {
|
||||
@@ -115,17 +123,20 @@ void DevMode::set_device()
|
||||
|
||||
QString iconPath = GetIconPath() + "/";
|
||||
|
||||
for (const GSList *l = dev_inst->get_dev_mode_list(); l; l = l->next)
|
||||
auto dev_mode_list = dev_inst->get_dev_mode_list();
|
||||
|
||||
for (const GSList *l = dev_mode_list; l; l = l->next)
|
||||
{
|
||||
const sr_dev_mode *mode = (const sr_dev_mode *)l->data;
|
||||
QString icon_name = QString::fromLocal8Bit(mode->icon);
|
||||
auto *mode_name = get_mode_name(mode->mode);
|
||||
QString icon_name = QString::fromLocal8Bit(mode_name->_logo);
|
||||
|
||||
QAction *action = new QAction(this);
|
||||
action->setIcon(QIcon(iconPath + "square-" + icon_name));
|
||||
if (lan == LAN_CN)
|
||||
action->setText(mode->name_cn);
|
||||
action->setText(mode_name->_name_cn);
|
||||
else
|
||||
action->setText(mode->name);
|
||||
action->setText(mode_name->_name_en);
|
||||
|
||||
connect(action, SIGNAL(triggered()), this, SLOT(on_mode_change()));
|
||||
|
||||
@@ -135,9 +146,9 @@ void DevMode::set_device()
|
||||
QString icon_fname = iconPath + icon_name;
|
||||
_mode_btn->setIcon(QIcon(icon_fname));
|
||||
if (lan == LAN_CN)
|
||||
_mode_btn->setText(mode->name_cn);
|
||||
_mode_btn->setText(mode_name->_name_cn);
|
||||
else
|
||||
_mode_btn->setText(mode->name);
|
||||
_mode_btn->setText(mode_name->_name_en);
|
||||
}
|
||||
_pop_menu->addAction(action);
|
||||
}
|
||||
@@ -187,13 +198,14 @@ void DevMode::on_mode_change()
|
||||
SR_CONF_DEVICE_MODE,
|
||||
g_variant_new_int16((*i).second->mode));
|
||||
|
||||
QString icon_fname = iconPath + "/" + QString::fromLocal8Bit((*i).second->icon);
|
||||
auto *mode_name = get_mode_name((*i).second->mode);
|
||||
QString icon_fname = iconPath + "/" + QString::fromLocal8Bit(mode_name->_logo);
|
||||
|
||||
_mode_btn->setIcon(QIcon(icon_fname));
|
||||
if (lan == LAN_CN)
|
||||
_mode_btn->setText((*i).second->name_cn);
|
||||
_mode_btn->setText(mode_name->_name_cn);
|
||||
else
|
||||
_mode_btn->setText((*i).second->name);
|
||||
_mode_btn->setText(mode_name->_name_en);
|
||||
dev_changed(false);
|
||||
}
|
||||
|
||||
@@ -238,5 +250,14 @@ void DevMode::leaveEvent(QEvent*)
|
||||
update();
|
||||
}
|
||||
|
||||
const struct dev_mode_name* DevMode::get_mode_name(int mode)
|
||||
{
|
||||
for(auto &o : dev_mode_name_list)
|
||||
if (mode == o._mode){
|
||||
return &o;
|
||||
}
|
||||
assert(false);
|
||||
}
|
||||
|
||||
} // namespace view
|
||||
} // namespace pv
|
||||
|
||||
@@ -35,6 +35,13 @@
|
||||
#include <QLabel>
|
||||
|
||||
#include <libsigrok.h>
|
||||
|
||||
struct dev_mode_name{
|
||||
int _mode;
|
||||
const char *_name_en;
|
||||
const char *_name_cn;
|
||||
const char *_logo;
|
||||
};
|
||||
|
||||
namespace pv {
|
||||
|
||||
@@ -65,8 +72,8 @@ private:
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
void leaveEvent(QEvent *event);
|
||||
|
||||
void changeEvent(QEvent *event);
|
||||
const dev_mode_name* get_mode_name(int mode);
|
||||
|
||||
public slots:
|
||||
void set_device();
|
||||
|
||||
@@ -72,13 +72,7 @@ static const char *probe_names[] = {
|
||||
"24", "25", "26", "27", "28", "29", "30", "31",
|
||||
NULL,
|
||||
};
|
||||
|
||||
static struct sr_dev_mode mode_list[] = {
|
||||
{LOGIC, "Logic Analyzer", "逻辑分析仪", "la", "la.svg"},
|
||||
{ANALOG, "Data Acquisition", "数据记录仪", "daq", "daq.svg"},
|
||||
{DSO, "Oscilloscope", "示波器", "osc", "osc.svg"},
|
||||
};
|
||||
|
||||
|
||||
static const gboolean default_ms_en[] = {
|
||||
FALSE, /* DSO_MS_BEGIN */
|
||||
TRUE, /* DSO_MS_FREQ */
|
||||
@@ -90,7 +84,6 @@ static const gboolean default_ms_en[] = {
|
||||
FALSE, /* DSO_MS_VP2P */
|
||||
};
|
||||
|
||||
|
||||
SR_PRIV void dsl_probe_init(struct sr_dev_inst *sdi)
|
||||
{
|
||||
unsigned int i, j;
|
||||
@@ -202,9 +195,9 @@ SR_PRIV const GSList *dsl_mode_list(const struct sr_dev_inst *sdi)
|
||||
unsigned int i;
|
||||
|
||||
devc = sdi->priv;
|
||||
for (i = 0; i < ARRAY_SIZE(mode_list); i++) {
|
||||
for (i = 0; i < ARRAY_SIZE(sr_mode_list); i++) {
|
||||
if (devc->profile->dev_caps.mode_caps & (1 << i))
|
||||
l = g_slist_append(l, &mode_list[i]);
|
||||
l = g_slist_append(l, &sr_mode_list[i]);
|
||||
}
|
||||
|
||||
return l;
|
||||
|
||||
@@ -46,11 +46,6 @@
|
||||
#define DSL_REQUIRED_VERSION_MINOR 0
|
||||
#define DSL_HDL_VERSION 0x0D
|
||||
|
||||
/* hardware Capabilities */
|
||||
#define CAPS_MODE_LOGIC (1 << 0)
|
||||
#define CAPS_MODE_ANALOG (1 << 1)
|
||||
#define CAPS_MODE_DSO (1 << 2)
|
||||
|
||||
#define CAPS_FEATURE_NONE 0
|
||||
// voltage threshold
|
||||
#define CAPS_FEATURE_VTH (1 << 0)
|
||||
@@ -486,6 +481,11 @@ static const struct DSL_channels channel_modes[] = {
|
||||
SR_KHZ(10), SR_MHZ(500), 1, "Use Channels 0~1 (Max 1GHz)", "使用通道 0~1 (最大采样率 1GHz)"}
|
||||
};
|
||||
|
||||
/* hardware Capabilities */
|
||||
#define CAPS_MODE_LOGIC (1 << 0)
|
||||
#define CAPS_MODE_ANALOG (1 << 1)
|
||||
#define CAPS_MODE_DSO (1 << 2)
|
||||
|
||||
static const struct DSL_profile supported_DSLogic[] = {
|
||||
/*
|
||||
* DSLogic
|
||||
|
||||
@@ -49,132 +49,6 @@
|
||||
#define BUFSIZE 512*1024
|
||||
#define DSO_BUFSIZE 10*1024
|
||||
|
||||
static const int hwoptions[] = {
|
||||
SR_CONF_PATTERN_MODE,
|
||||
SR_CONF_MAX_HEIGHT,
|
||||
};
|
||||
|
||||
static const int32_t sessions[] = {
|
||||
SR_CONF_SAMPLERATE,
|
||||
SR_CONF_LIMIT_SAMPLES,
|
||||
SR_CONF_PATTERN_MODE,
|
||||
SR_CONF_MAX_HEIGHT,
|
||||
};
|
||||
|
||||
static const int32_t probeOptions[] = {
|
||||
SR_CONF_PROBE_COUPLING,
|
||||
SR_CONF_PROBE_VDIV,
|
||||
SR_CONF_PROBE_MAP_DEFAULT,
|
||||
SR_CONF_PROBE_MAP_UNIT,
|
||||
SR_CONF_PROBE_MAP_MIN,
|
||||
SR_CONF_PROBE_MAP_MAX,
|
||||
};
|
||||
|
||||
static const int32_t probeSessions[] = {
|
||||
SR_CONF_PROBE_COUPLING,
|
||||
SR_CONF_PROBE_VDIV,
|
||||
SR_CONF_PROBE_MAP_DEFAULT,
|
||||
SR_CONF_PROBE_MAP_UNIT,
|
||||
SR_CONF_PROBE_MAP_MIN,
|
||||
SR_CONF_PROBE_MAP_MAX,
|
||||
};
|
||||
|
||||
static const uint8_t probeCoupling[] = {
|
||||
SR_DC_COUPLING,
|
||||
SR_AC_COUPLING,
|
||||
};
|
||||
|
||||
static const char *maxHeights[] = {
|
||||
"1X",
|
||||
"2X",
|
||||
"3X",
|
||||
"4X",
|
||||
"5X",
|
||||
};
|
||||
|
||||
/* We name the probes 0-7 on our demo driver. */
|
||||
static const char *probe_names[] = {
|
||||
"0", "1", "2", "3",
|
||||
"4", "5", "6", "7",
|
||||
"8", "9", "10", "11",
|
||||
"12", "13", "14", "15",
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const char *probeMapUnits[] = {
|
||||
"V",
|
||||
"A",
|
||||
"°C",
|
||||
"°F",
|
||||
"g",
|
||||
"m",
|
||||
"m/s",
|
||||
};
|
||||
|
||||
static const gboolean default_ms_en[] = {
|
||||
FALSE, /* DSO_MS_BEGIN */
|
||||
TRUE, /* DSO_MS_FREQ */
|
||||
FALSE, /* DSO_MS_PERD */
|
||||
TRUE, /* DSO_MS_VMAX */
|
||||
TRUE, /* DSO_MS_VMIN */
|
||||
FALSE, /* DSO_MS_VRMS */
|
||||
FALSE, /* DSO_MS_VMEA */
|
||||
FALSE, /* DSO_MS_VP2P */
|
||||
};
|
||||
|
||||
static struct sr_dev_mode mode_list[] = {
|
||||
{LOGIC, "Logic Analyzer", "逻辑分析仪", "la", "la.svg"},
|
||||
{ANALOG, "Data Acquisition", "数据记录仪", "daq", "daq.svg"},
|
||||
{DSO, "Oscilloscope", "示波器", "osc", "osc.svg"},
|
||||
};
|
||||
|
||||
/* hardware Capabilities */
|
||||
#define CAPS_MODE_LOGIC (1 << 0)
|
||||
#define CAPS_MODE_ANALOG (1 << 1)
|
||||
#define CAPS_MODE_DSO (1 << 2)
|
||||
|
||||
#define CAPS_FEATURE_NONE 0
|
||||
// zero calibration ability
|
||||
#define CAPS_FEATURE_ZERO (1 << 4)
|
||||
/* end */
|
||||
|
||||
static const struct DEMO_profile supported_Demo[] = {
|
||||
/*
|
||||
* Demo
|
||||
*/
|
||||
{"DreamSourceLab", "Demo Device", NULL,
|
||||
{CAPS_MODE_LOGIC | CAPS_MODE_ANALOG | CAPS_MODE_DSO,
|
||||
CAPS_FEATURE_NONE,
|
||||
(1 << DEMO_LOGIC100x16) |
|
||||
(1 << DEMO_ANALOG10x2) |
|
||||
(1 << DEMO_DSO200x2),
|
||||
SR_Mn(100),
|
||||
SR_Kn(20),
|
||||
0,
|
||||
vdivs10to2000,
|
||||
0,
|
||||
DEMO_LOGIC100x16,
|
||||
PATTERN_SINE,
|
||||
SR_NS(500)}
|
||||
},
|
||||
|
||||
{ 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}
|
||||
};
|
||||
|
||||
static const struct DEMO_channels channel_modes[] = {
|
||||
// LA Stream
|
||||
{DEMO_LOGIC100x16, LOGIC, SR_CHANNEL_LOGIC, 16, 1, SR_MHZ(1), SR_Mn(1),
|
||||
SR_KHZ(10), SR_MHZ(100), "Use 16 Channels (Max 20MHz)"},
|
||||
|
||||
// DAQ
|
||||
{DEMO_ANALOG10x2, ANALOG, SR_CHANNEL_ANALOG, 2, 8, SR_MHZ(1), SR_Mn(1),
|
||||
SR_HZ(10), SR_MHZ(10), "Use Channels 0~1 (Max 10MHz)"},
|
||||
|
||||
// OSC
|
||||
{DEMO_DSO200x2, DSO, SR_CHANNEL_DSO, 2, 8, SR_MHZ(100), SR_Kn(10),
|
||||
SR_HZ(100), SR_MHZ(200), "Use Channels 0~1 (Max 200MHz)"}
|
||||
};
|
||||
|
||||
|
||||
/* Private, per-device-instance driver context. */
|
||||
/* TODO: struct context as with the other drivers. */
|
||||
@@ -317,9 +191,9 @@ static const GSList *hw_dev_mode_list(const struct sr_dev_inst *sdi)
|
||||
unsigned int i;
|
||||
|
||||
devc = sdi->priv;
|
||||
for (i = 0; i < ARRAY_SIZE(mode_list); i++) {
|
||||
for (i = 0; i < ARRAY_SIZE(sr_mode_list); i++) {
|
||||
if (devc->profile->dev_caps.mode_caps & (1 << i))
|
||||
l = g_slist_append(l, &mode_list[i]);
|
||||
l = g_slist_append(l, &sr_mode_list[i]);
|
||||
}
|
||||
|
||||
return l;
|
||||
@@ -544,7 +418,8 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi,
|
||||
sr_dbg("%s: setting samplerate to %llu", __func__,
|
||||
devc->cur_samplerate);
|
||||
ret = SR_OK;
|
||||
} else if (id == SR_CONF_LIMIT_SAMPLES) {
|
||||
}
|
||||
else if (id == SR_CONF_LIMIT_SAMPLES) {
|
||||
devc->limit_msec = 0;
|
||||
devc->limit_samples = g_variant_get_uint64(data);
|
||||
devc->limit_samples = (devc->limit_samples + 63) & ~63;
|
||||
@@ -555,14 +430,16 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi,
|
||||
sr_dbg("%s: setting limit_samples to %llu", __func__,
|
||||
devc->limit_samples);
|
||||
ret = SR_OK;
|
||||
} else if (id == SR_CONF_LIMIT_MSEC) {
|
||||
}
|
||||
else if (id == SR_CONF_LIMIT_MSEC) {
|
||||
devc->limit_msec = g_variant_get_uint64(data);
|
||||
devc->limit_samples = 0;
|
||||
devc->limit_samples_show = devc->limit_samples;
|
||||
sr_dbg("%s: setting limit_msec to %llu", __func__,
|
||||
devc->limit_msec);
|
||||
ret = SR_OK;
|
||||
} else if (id == SR_CONF_DEVICE_MODE) {
|
||||
}
|
||||
else if (id == SR_CONF_DEVICE_MODE) {
|
||||
sdi->mode = g_variant_get_int16(data);
|
||||
ret = SR_OK;
|
||||
for (i = 0; i < ARRAY_SIZE(channel_modes); i++) {
|
||||
@@ -581,7 +458,8 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi,
|
||||
setup_probes(sdi, num_probes);
|
||||
adjust_samplerate(devc);
|
||||
sr_dbg("%s: setting mode to %d", __func__, sdi->mode);
|
||||
}else if (id == SR_CONF_PATTERN_MODE) {
|
||||
}
|
||||
else if (id == SR_CONF_PATTERN_MODE) {
|
||||
stropt = g_variant_get_string(data, NULL);
|
||||
ret = SR_OK;
|
||||
if (!strcmp(stropt, pattern_strings[PATTERN_SINE])) {
|
||||
@@ -599,7 +477,8 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi,
|
||||
}
|
||||
sr_dbg("%s: setting pattern to %d",
|
||||
__func__, devc->sample_generator);
|
||||
} else if (id == SR_CONF_MAX_HEIGHT) {
|
||||
}
|
||||
else if (id == SR_CONF_MAX_HEIGHT) {
|
||||
stropt = g_variant_get_string(data, NULL);
|
||||
ret = SR_OK;
|
||||
for (i = 0; i < ARRAY_SIZE(maxHeights); i++) {
|
||||
@@ -610,18 +489,23 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi,
|
||||
}
|
||||
sr_dbg("%s: setting Signal Max Height to %d",
|
||||
__func__, devc->max_height);
|
||||
} else if (id == SR_CONF_INSTANT) {
|
||||
}
|
||||
else if (id == SR_CONF_INSTANT) {
|
||||
devc->instant = g_variant_get_boolean(data);
|
||||
sr_dbg("%s: setting INSTANT mode to %d", __func__,
|
||||
devc->instant);
|
||||
ret = SR_OK;
|
||||
} else if (id == SR_CONF_HORIZ_TRIGGERPOS) {
|
||||
}
|
||||
else if (id == SR_CONF_HORIZ_TRIGGERPOS) {
|
||||
ret = SR_OK;
|
||||
} else if (id == SR_CONF_TRIGGER_HOLDOFF) {
|
||||
}
|
||||
else if (id == SR_CONF_TRIGGER_HOLDOFF) {
|
||||
ret = SR_OK;
|
||||
} else if (id == SR_CONF_TRIGGER_MARGIN) {
|
||||
}
|
||||
else if (id == SR_CONF_TRIGGER_MARGIN) {
|
||||
ret = SR_OK;
|
||||
} else if (id == SR_CONF_PROBE_EN) {
|
||||
}
|
||||
else if (id == SR_CONF_PROBE_EN) {
|
||||
ch->enabled = g_variant_get_boolean(data);
|
||||
if (en_ch_num(sdi) != 0) {
|
||||
devc->limit_samples_show = devc->profile->dev_caps.dso_depth / en_ch_num(sdi);
|
||||
@@ -629,48 +513,57 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi,
|
||||
sr_dbg("%s: setting ENABLE of channel %d to %d", __func__,
|
||||
ch->index, ch->enabled);
|
||||
ret = SR_OK;
|
||||
} else if (id == SR_CONF_PROBE_VDIV) {
|
||||
}
|
||||
else if (id == SR_CONF_PROBE_VDIV) {
|
||||
tmp_u64 = g_variant_get_uint64(data);
|
||||
ch->vdiv = tmp_u64;
|
||||
sr_dbg("%s: setting VDIV of channel %d to %llu", __func__,
|
||||
ch->index, ch->vdiv);
|
||||
ret = SR_OK;
|
||||
} else if (id == SR_CONF_PROBE_FACTOR) {
|
||||
}
|
||||
else if (id == SR_CONF_PROBE_FACTOR) {
|
||||
ch->vfactor = g_variant_get_uint64(data);
|
||||
sr_dbg("%s: setting FACTOR of channel %d to %llu", __func__,
|
||||
ch->index, ch->vfactor);
|
||||
ret = SR_OK;
|
||||
} else if (id == SR_CONF_PROBE_OFFSET) {
|
||||
}
|
||||
else if (id == SR_CONF_PROBE_OFFSET) {
|
||||
ch->offset = g_variant_get_uint16(data);
|
||||
sr_dbg("%s: setting OFFSET of channel %d to %d", __func__,
|
||||
ch->index, ch->offset);
|
||||
ret = SR_OK;
|
||||
} else if (id == SR_CONF_TIMEBASE) {
|
||||
}
|
||||
else if (id == SR_CONF_TIMEBASE) {
|
||||
devc->timebase = g_variant_get_uint64(data);
|
||||
sr_dbg("%s: setting TIMEBASE to %llu", __func__,
|
||||
devc->timebase);
|
||||
ret = SR_OK;
|
||||
} else if (id == SR_CONF_PROBE_COUPLING) {
|
||||
}
|
||||
else if (id == SR_CONF_PROBE_COUPLING) {
|
||||
ch->coupling = g_variant_get_byte(data);
|
||||
sr_dbg("%s: setting AC COUPLING of channel %d to %d", __func__,
|
||||
ch->index, ch->coupling);
|
||||
ret = SR_OK;
|
||||
} else if (id == SR_CONF_TRIGGER_SOURCE) {
|
||||
}
|
||||
else if (id == SR_CONF_TRIGGER_SOURCE) {
|
||||
devc->trigger_source = g_variant_get_byte(data);
|
||||
sr_dbg("%s: setting Trigger Source to %d",
|
||||
__func__, devc->trigger_source);
|
||||
ret = SR_OK;
|
||||
} else if (id == SR_CONF_TRIGGER_SLOPE) {
|
||||
}
|
||||
else if (id == SR_CONF_TRIGGER_SLOPE) {
|
||||
devc->trigger_slope = g_variant_get_byte(data);
|
||||
sr_dbg("%s: setting Trigger Slope to %d",
|
||||
__func__, devc->trigger_slope);
|
||||
ret = SR_OK;
|
||||
} else if (id == SR_CONF_TRIGGER_VALUE) {
|
||||
}
|
||||
else if (id == SR_CONF_TRIGGER_VALUE) {
|
||||
ch->trig_value = g_variant_get_byte(data);
|
||||
sr_dbg("%s: setting channel %d Trigger Value to %d",
|
||||
__func__, ch->index, ch->trig_value);
|
||||
ret = SR_OK;
|
||||
} else if (id == SR_CONF_PROBE_MAP_DEFAULT) {
|
||||
}
|
||||
else if (id == SR_CONF_PROBE_MAP_DEFAULT) {
|
||||
ch->map_default = g_variant_get_boolean(data);
|
||||
if (ch->map_default) {
|
||||
ch->map_unit = probeMapUnits[0];
|
||||
@@ -678,28 +571,33 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi,
|
||||
ch->map_max = ch->vdiv * ch->vfactor * DS_CONF_DSO_VDIVS / 2000.0;
|
||||
}
|
||||
ret = SR_OK;
|
||||
} else if (id == SR_CONF_PROBE_MAP_UNIT) {
|
||||
}
|
||||
else if (id == SR_CONF_PROBE_MAP_UNIT) {
|
||||
if (ch->map_default)
|
||||
ch->map_unit = probeMapUnits[0];
|
||||
else
|
||||
ch->map_unit = g_variant_get_string(data, NULL);
|
||||
ret = SR_OK;
|
||||
} else if (id == SR_CONF_PROBE_MAP_MIN) {
|
||||
}
|
||||
else if (id == SR_CONF_PROBE_MAP_MIN) {
|
||||
if (ch->map_default)
|
||||
ch->map_min = -(ch->vdiv * ch->vfactor * DS_CONF_DSO_VDIVS / 2000.0);
|
||||
else
|
||||
ch->map_min = g_variant_get_double(data);
|
||||
ret = SR_OK;
|
||||
} else if (id == SR_CONF_PROBE_MAP_MAX) {
|
||||
}
|
||||
else if (id == SR_CONF_PROBE_MAP_MAX) {
|
||||
if (ch->map_default)
|
||||
ch->map_max = ch->vdiv * ch->vfactor * DS_CONF_DSO_VDIVS / 2000.0;
|
||||
else
|
||||
ch->map_max = g_variant_get_double(data);
|
||||
ret = SR_OK;
|
||||
} else if (id == SR_CONF_LANGUAGE) {
|
||||
}
|
||||
else if (id == SR_CONF_LANGUAGE) {
|
||||
devc->language = g_variant_get_int16(data);
|
||||
ret = SR_OK;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
ret = SR_ERR_NA;
|
||||
}
|
||||
|
||||
|
||||
@@ -170,7 +170,126 @@ static const uint64_t samplerates[] = {
|
||||
SR_GHZ(10),
|
||||
};
|
||||
|
||||
/* hardware Capabilities */
|
||||
#define CAPS_MODE_LOGIC (1 << 0)
|
||||
#define CAPS_MODE_ANALOG (1 << 1)
|
||||
#define CAPS_MODE_DSO (1 << 2)
|
||||
|
||||
#define CAPS_FEATURE_NONE 0
|
||||
// zero calibration ability
|
||||
#define CAPS_FEATURE_ZERO (1 << 4)
|
||||
/* end */
|
||||
|
||||
|
||||
static const char *maxHeights[] = {
|
||||
"1X",
|
||||
"2X",
|
||||
"3X",
|
||||
"4X",
|
||||
"5X",
|
||||
};
|
||||
|
||||
/* We name the probes 0-7 on our demo driver. */
|
||||
static const char *probe_names[] = {
|
||||
"0", "1", "2", "3",
|
||||
"4", "5", "6", "7",
|
||||
"8", "9", "10", "11",
|
||||
"12", "13", "14", "15",
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const char *probeMapUnits[] = {
|
||||
"V",
|
||||
"A",
|
||||
"°C",
|
||||
"°F",
|
||||
"g",
|
||||
"m",
|
||||
"m/s",
|
||||
};
|
||||
|
||||
static const int hwoptions[] = {
|
||||
SR_CONF_PATTERN_MODE,
|
||||
SR_CONF_MAX_HEIGHT,
|
||||
};
|
||||
|
||||
static const int32_t sessions[] = {
|
||||
SR_CONF_SAMPLERATE,
|
||||
SR_CONF_LIMIT_SAMPLES,
|
||||
SR_CONF_PATTERN_MODE,
|
||||
SR_CONF_MAX_HEIGHT,
|
||||
};
|
||||
|
||||
static const int32_t probeOptions[] = {
|
||||
SR_CONF_PROBE_COUPLING,
|
||||
SR_CONF_PROBE_VDIV,
|
||||
SR_CONF_PROBE_MAP_DEFAULT,
|
||||
SR_CONF_PROBE_MAP_UNIT,
|
||||
SR_CONF_PROBE_MAP_MIN,
|
||||
SR_CONF_PROBE_MAP_MAX,
|
||||
};
|
||||
|
||||
static const int32_t probeSessions[] = {
|
||||
SR_CONF_PROBE_COUPLING,
|
||||
SR_CONF_PROBE_VDIV,
|
||||
SR_CONF_PROBE_MAP_DEFAULT,
|
||||
SR_CONF_PROBE_MAP_UNIT,
|
||||
SR_CONF_PROBE_MAP_MIN,
|
||||
SR_CONF_PROBE_MAP_MAX,
|
||||
};
|
||||
|
||||
static const uint8_t probeCoupling[] = {
|
||||
SR_DC_COUPLING,
|
||||
SR_AC_COUPLING,
|
||||
};
|
||||
|
||||
static const gboolean default_ms_en[] = {
|
||||
FALSE, /* DSO_MS_BEGIN */
|
||||
TRUE, /* DSO_MS_FREQ */
|
||||
FALSE, /* DSO_MS_PERD */
|
||||
TRUE, /* DSO_MS_VMAX */
|
||||
TRUE, /* DSO_MS_VMIN */
|
||||
FALSE, /* DSO_MS_VRMS */
|
||||
FALSE, /* DSO_MS_VMEA */
|
||||
FALSE, /* DSO_MS_VP2P */
|
||||
};
|
||||
|
||||
static const struct DEMO_channels channel_modes[] = {
|
||||
// LA Stream
|
||||
{DEMO_LOGIC100x16, LOGIC, SR_CHANNEL_LOGIC, 16, 1, SR_MHZ(1), SR_Mn(1),
|
||||
SR_KHZ(10), SR_MHZ(100), "Use 16 Channels (Max 20MHz)"},
|
||||
|
||||
// DAQ
|
||||
{DEMO_ANALOG10x2, ANALOG, SR_CHANNEL_ANALOG, 2, 8, SR_MHZ(1), SR_Mn(1),
|
||||
SR_HZ(10), SR_MHZ(10), "Use Channels 0~1 (Max 10MHz)"},
|
||||
|
||||
// OSC
|
||||
{DEMO_DSO200x2, DSO, SR_CHANNEL_DSO, 2, 8, SR_MHZ(100), SR_Kn(10),
|
||||
SR_HZ(100), SR_MHZ(200), "Use Channels 0~1 (Max 200MHz)"}
|
||||
};
|
||||
|
||||
static const struct DEMO_profile supported_Demo[] = {
|
||||
/*
|
||||
* Demo
|
||||
*/
|
||||
{"DreamSourceLab", "Demo Device", NULL,
|
||||
{CAPS_MODE_LOGIC | CAPS_MODE_ANALOG | CAPS_MODE_DSO,
|
||||
CAPS_FEATURE_NONE,
|
||||
(1 << DEMO_LOGIC100x16) |
|
||||
(1 << DEMO_ANALOG10x2) |
|
||||
(1 << DEMO_DSO200x2),
|
||||
SR_Mn(100),
|
||||
SR_Kn(20),
|
||||
0,
|
||||
vdivs10to2000,
|
||||
0,
|
||||
DEMO_LOGIC100x16,
|
||||
PATTERN_SINE,
|
||||
SR_NS(500)}
|
||||
},
|
||||
|
||||
{ 0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}
|
||||
};
|
||||
|
||||
static const int const_dc = 1.95 / 10 * 255;
|
||||
static const int sinx[] = {
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
|
||||
/*
|
||||
How to use libsigrok4DSL
|
||||
*/
|
||||
|
||||
1.Complie
|
||||
cd libsigrok4DSL
|
||||
cmake .
|
||||
make
|
||||
make install
|
||||
|
||||
2.Example
|
||||
|
||||
#include <libsigrok.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void event_cb(int ev)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void data_cb(pack p){
|
||||
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
sr_init();
|
||||
|
||||
const char *res_path = "c:\DSView\res"
|
||||
sr_set_firmware_resource_dir(res_path);
|
||||
|
||||
sr_disable_data_cache(flag); // don't manager data
|
||||
sr_set_datafeed_callback(data_cb); //only transfers data
|
||||
sr_set_event_callback(event_cb);
|
||||
|
||||
while(true){
|
||||
if (getche() == 'x'){
|
||||
//exit app
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sr_exit();
|
||||
}
|
||||
|
||||
|
||||
/* api
|
||||
|
||||
sr_lib_init();
|
||||
|
||||
sr_lib_exit();
|
||||
|
||||
sr_set_firmware_resource_dir();
|
||||
|
||||
sr_set_datafeed_callback(data_cb);
|
||||
|
||||
sr_set_event_callback(event_cb);
|
||||
|
||||
sr_update_device_list();
|
||||
sr_get_device_list();
|
||||
|
||||
sr_get_device_channels();
|
||||
|
||||
//当断开设备时,如果属当前设备且存在数据,不能自动切换到其它设备,须提示用户保存数据,再自动切换当前设备
|
||||
//当接入新设备时,如果当前设备有数据,须提示用户保存数据,再扫描设备列表
|
||||
//加载文件时,由外部判断当前硬件是否存在数据,以便提示用户保存,再执行加载文件,并通知用户更新列表
|
||||
//扫描设备列表会自动切换到最新设备,并通知用户更新列表
|
||||
|
||||
*/
|
||||
@@ -735,7 +735,7 @@ struct sr_status {
|
||||
uint32_t ch1_acc_mean_p3;
|
||||
};
|
||||
|
||||
enum {
|
||||
enum sr_config_option_id{
|
||||
/*--- Device classes ------------------------------------------------*/
|
||||
|
||||
/** The device can act as logic analyzer. */
|
||||
@@ -1163,10 +1163,15 @@ enum {
|
||||
|
||||
struct sr_dev_mode {
|
||||
int mode;
|
||||
char *name;
|
||||
char *name_cn;
|
||||
char *acronym;
|
||||
char *icon;
|
||||
const char *name;
|
||||
const char *acronym;
|
||||
};
|
||||
|
||||
static const struct sr_dev_mode sr_mode_list[] =
|
||||
{
|
||||
{LOGIC,"Logic Analyzer","la"},
|
||||
{ANALOG, "Data Acquisition", "daq"},
|
||||
{DSO, "Oscilloscope", "osc"},
|
||||
};
|
||||
|
||||
struct sr_dev_driver {
|
||||
@@ -1276,8 +1281,8 @@ SR_API int sr_listen_hotplug(struct sr_context *ctx, hotplug_event_callback call
|
||||
SR_API int sr_close_hotplug(struct sr_context *ctx);
|
||||
SR_API void sr_hotplug_wait_timout(struct sr_context *ctx);
|
||||
|
||||
SR_API int sr_init(struct sr_context **ctx);
|
||||
SR_API int sr_exit(struct sr_context *ctx);
|
||||
SR_PRIV int sr_init(struct sr_context **ctx);
|
||||
SR_PRIV int sr_exit(struct sr_context *ctx);
|
||||
|
||||
/*--- device.c --------------------------------------------------------------*/
|
||||
|
||||
@@ -1531,7 +1536,7 @@ SR_API int sr_device_start_collect();
|
||||
/**
|
||||
* Stop collect data
|
||||
*/
|
||||
SR_API int sr_device_start_collect();
|
||||
SR_API int sr_device_top_collect();
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -117,12 +117,6 @@ static const char *probeMapUnits[] = {
|
||||
"m/s",
|
||||
};
|
||||
|
||||
static struct sr_dev_mode mode_list[] = {
|
||||
{LOGIC, "Logic Analyzer", "逻辑分析仪", "la", "la.svg"},
|
||||
{ANALOG, "Data Acquisition", "数据记录仪", "daq", "daq.svg"},
|
||||
{DSO, "Oscilloscope", "示波器", "osc", "osc.svg"},
|
||||
};
|
||||
|
||||
static int trans_data(struct sr_dev_inst *sdi)
|
||||
{
|
||||
// translate for old format
|
||||
@@ -369,9 +363,9 @@ static const GSList *dev_mode_list(const struct sr_dev_inst *sdi)
|
||||
GSList *l = NULL;
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(mode_list); i++) {
|
||||
if (sdi->mode == mode_list[i].mode)
|
||||
l = g_slist_append(l, &mode_list[i]);
|
||||
for (i = 0; i < ARRAY_SIZE(sr_mode_list); i++) {
|
||||
if (sdi->mode == sr_mode_list[i].mode)
|
||||
l = g_slist_append(l, &sr_mode_list[i]);
|
||||
}
|
||||
|
||||
return l;
|
||||
@@ -935,7 +929,7 @@ static int dev_acquisition_start(struct sr_dev_inst *sdi,
|
||||
|
||||
struct session_vdev *vdev;
|
||||
struct sr_datafeed_packet packet;
|
||||
int ret;
|
||||
int ret;
|
||||
GSList *l;
|
||||
struct sr_channel *probe;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
#include <libsigrok.h>
|
||||
|
||||
int main()
|
||||
int main2()
|
||||
{
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user