From: Uwe Hermann Date: Thu, 3 Aug 2017 19:08:44 +0000 (+0200) Subject: drivers: Use NUM_CHANNELS in favor of hardcoded values. X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=b3fd09937ce099d5a7086ff6bbdfa1b4f371cabd drivers: Use NUM_CHANNELS in favor of hardcoded values. --- diff --git a/src/hardware/dreamsourcelab-dslogic/api.c b/src/hardware/dreamsourcelab-dslogic/api.c index 25fa6fe4..f7dd7256 100644 --- a/src/hardware/dreamsourcelab-dslogic/api.c +++ b/src/hardware/dreamsourcelab-dslogic/api.c @@ -233,7 +233,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) /* Logic channels, all in one channel group. */ cg = g_malloc0(sizeof(struct sr_channel_group)); cg->name = g_strdup("Logic"); - for (j = 0; j < 16; j++) { + for (j = 0; j < NUM_CHANNELS; j++) { sprintf(channel_name, "%d", j); ch = sr_channel_new(sdi, j, SR_CHANNEL_LOGIC, TRUE, channel_name); diff --git a/src/hardware/hantek-6xxx/api.c b/src/hardware/hantek-6xxx/api.c index 8d0d280d..4e648089 100644 --- a/src/hardware/hantek-6xxx/api.c +++ b/src/hardware/hantek-6xxx/api.c @@ -530,7 +530,7 @@ static void send_chunk(struct sr_dev_inst *sdi, unsigned char *buf, return; } - for (int ch = 0; ch < 2; ch++) { + for (int ch = 0; ch < NUM_CHANNELS; ch++) { if (!devc->ch_enabled[ch]) continue; diff --git a/src/hardware/hantek-dso/api.c b/src/hardware/hantek-dso/api.c index cdc4360e..bc10f39e 100644 --- a/src/hardware/hantek-dso/api.c +++ b/src/hardware/hantek-dso/api.c @@ -613,7 +613,7 @@ static void send_chunk(struct sr_dev_inst *sdi, unsigned char *buf, /* TODO: Check malloc return value. */ analog.data = g_try_malloc(num_samples * sizeof(float)); - for (int ch = 0; ch < 2; ch++) { + for (int ch = 0; ch < NUM_CHANNELS; ch++) { if (!devc->ch_enabled[ch]) continue; diff --git a/src/hardware/hantek-dso/protocol.c b/src/hardware/hantek-dso/protocol.c index b1a56ebd..644ac0d2 100644 --- a/src/hardware/hantek-dso/protocol.c +++ b/src/hardware/hantek-dso/protocol.c @@ -27,8 +27,6 @@ #include "libsigrok-internal.h" #include "protocol.h" -#define NUM_CHANNELS 2 - static int send_begin(const struct sr_dev_inst *sdi) { struct sr_usb_dev_inst *usb; diff --git a/src/hardware/hantek-dso/protocol.h b/src/hardware/hantek-dso/protocol.h index 9cab61b3..20aaebdc 100644 --- a/src/hardware/hantek-dso/protocol.h +++ b/src/hardware/hantek-dso/protocol.h @@ -51,6 +51,8 @@ /* All models have this for their "fast" mode. */ #define FRAMESIZE_SMALL (10 * 1024) +#define NUM_CHANNELS 2 + enum control_requests { CTRL_READ_EEPROM = 0xa2, CTRL_GETSPEED = 0xb2, diff --git a/src/hardware/lecroy-logicstudio/api.c b/src/hardware/lecroy-logicstudio/api.c index 3d16f3a2..6dd0bd01 100644 --- a/src/hardware/lecroy-logicstudio/api.c +++ b/src/hardware/lecroy-logicstudio/api.c @@ -35,6 +35,8 @@ #define UNKNOWN_ADDRESS 0xff #define MAX_RENUM_DELAY_MS 3000 +#define NUM_CHANNELS 16 + static const uint32_t drvopts[] = { SR_CONF_LOGIC_ANALYZER, }; @@ -89,7 +91,7 @@ static struct sr_dev_inst *create_device(struct sr_usb_dev_inst *usb, sdi->inst_type = SR_INST_USB; sdi->conn = usb; - for (i = 0; i < 16; i++) { + for (i = 0; i < NUM_CHANNELS; i++) { snprintf(channel_name, sizeof(channel_name), "D%i", i); sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_name); }