From 52da7aebb9bb2929ecdc9838ab54f6bb76e949bb Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 4 Oct 2013 11:38:15 +0200 Subject: i2cget: Allow read commands of arbitrary length --- commandline/i2cget.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'commandline') diff --git a/commandline/i2cget.c b/commandline/i2cget.c index 4138722..a0b2330 100644 --- a/commandline/i2cget.c +++ b/commandline/i2cget.c @@ -6,16 +6,15 @@ int main(int argc, char **argv) { - int address, command, got_ack; + int i, address, cmdbuf, got_ack; unsigned int ret; - char mode = 'c'; char *conv_err; i2c_init(); i2c_start(); if (argc < 3) { - fputs("Usage: vusb-i2cget
[mode]", stderr); + fputs("Usage: vusb-i2cget
", stderr); return 1; } @@ -26,27 +25,21 @@ int main(int argc, char **argv) return 2; } - command = strtol(argv[2], &conv_err, 0); + i2c_tx_byte((address << 1) | 0); - if (conv_err && *conv_err) { - fprintf(stderr, "command: conversion error at '%s'", conv_err); - return 2; + for (i = 2; i < argc; i++) { + cmdbuf = strtol(argv[i], &conv_err, 0); + if (conv_err && *conv_err) { + fprintf(stderr, "read command: Conversion error at '%s'", conv_err); + return 2; + } + i2c_tx_byte(cmdbuf); } - if (argc == 4) - mode = argv[3][0]; - - i2c_tx_byte((address << 1) | 0); - i2c_tx_byte(command); i2c_start(); got_ack = i2c_tx_byte((address << 1) | 1); - if (mode == 'i') { - ret = i2c_rx_byte(1); - ret |= (i2c_rx_byte(0) << 8); - } - else - ret = i2c_rx_byte(0); + ret = i2c_rx_byte(0); i2c_stop(); i2c_deinit(); -- cgit v1.2.3