From: Wolfram Sang Date: Wed, 2 Jan 2019 12:15:19 +0000 (+0100) Subject: ols: refactor channel initialization X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=4a34a74d738136906200a76980b00881255f3007;p=libsigrok.git ols: refactor channel initialization We needs this twice so put it into a seperate function, so updates to it will automatically handled for both callers. Signed-off-by: Wolfram Sang --- diff --git a/src/hardware/openbench-logic-sniffer/protocol.c b/src/hardware/openbench-logic-sniffer/protocol.c index 0041b21a..0a9a34a2 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.c +++ b/src/hardware/openbench-logic-sniffer/protocol.c @@ -146,11 +146,20 @@ SR_PRIV struct dev_context *ols_dev_new(void) return devc; } +static void ols_channel_new(struct sr_dev_inst *sdi, int num_chan) +{ + int i; + + for (i = 0; i < num_chan; i++) + sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, + ols_channel_names[i]); +} + SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) { struct sr_dev_inst *sdi; struct dev_context *devc; - uint32_t tmp_int, ui; + uint32_t tmp_int; uint8_t key, type, token; int delay_ms; GString *tmp_str, *devname, *version; @@ -221,9 +230,7 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) switch (token) { case 0x00: /* Number of usable channels */ - for (ui = 0; ui < tmp_int; ui++) - sr_channel_new(sdi, ui, SR_CHANNEL_LOGIC, TRUE, - ols_channel_names[ui]); + ols_channel_new(sdi, tmp_int); break; case 0x01: /* Amount of sample memory available (bytes) */ @@ -257,9 +264,7 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) switch (token) { case 0x00: /* Number of usable channels */ - for (ui = 0; ui < tmp_c; ui++) - sr_channel_new(sdi, ui, SR_CHANNEL_LOGIC, TRUE, - ols_channel_names[ui]); + ols_channel_new(sdi, tmp_c); break; case 0x01: /* protocol version */