aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/main.c b/src/main.c
index c71c872..ee3ec67 100644
--- a/src/main.c
+++ b/src/main.c
@@ -24,16 +24,17 @@ extern void hih61xx_read_all(const char *opts);
extern void hih61xx_read_one(const char *opts);
-int file;
+int file;
+char temp[256];
void (*list_all)(void) = NULL;
void (*read_all)(const char *opts) = NULL;
void (*read_one)(const char *opts) = NULL;
void print_help(void)
-{
+{
printf ("Usage:\n"
- " i2sensor <op> <bus> <dev_type> <dev_addr> (<options>)\n"
+ " i2sensor <op> <bus> <dev_type> <dev_addr> (<options>)\n"
"Aviable options: <op>\n"
" list_all -- list all measured parameters off device\n"
" read_all -- read all measured parameters from device\n"
@@ -41,9 +42,11 @@ void print_help(void)
"Exmples:\n"
" i2sensor read_all <bus> <device> <address> <offset_for_param-01,offset_for_param-02,...>\n"
" i2sensor read_one <bus> <device> <address> <param-id,offset_for_param-id>\n"
- " i2sensor read_all 1 lm75 0x4f -1.35,\n"
- " i2sensor read_one 1 lm75 0x4f 01,-1.35\n"
- "" "\n");
+ " i2sensor read_all 1 lm75 0x4f ---,\n"
+ " i2sensor read_one 1 lm75 0x4f 00,-1.35\n"
+ "" "");
+ printf ("Build: %s %s\n\n",__DATE__,__TIME__);
+
}
void bus_err(int ern)
@@ -84,7 +87,7 @@ int main(int argc, char *argv[])
// ...set_reg... <dev_addr>, <reg_addr,value_hex>
- if(4 < argc && 7 > argc) //Minimal 5 argument passed
+ if(4 < argc && argc < 10) //Minimal 5 argument passed
{
char filename[32];
@@ -100,22 +103,20 @@ int main(int argc, char *argv[])
exit (EXIT_FAILURE);
}
}
-
snprintf(filename, 31, "/dev/i2c-%s", argv[2]); //Open i2c bus
file = open(filename, O_RDWR);
if (file < 0)
{
- printf("\n\tCan't open i2c BUS, are you root?\n\n");
+ printf("\n\tCan't open i2c BUS. Have you any permission?\n\n");
print_help();
exit (EXIT_FAILURE);
}
- if(argv[4][0]=='0' && argv[4][1]=='x') //?
- {
-
- int addr = (int)strtol(argv[4], NULL, 0); //Open i2c device
+ if(argv[4][0]=='0' && argv[4][1]=='x'){ // Hexadecimal device address
+
+ long addr = (int)strtol(argv[4], NULL, 0); //# strtol() is working with hex string
if (ioctl(file, I2C_SLAVE, addr) < 0)
{
@@ -139,15 +140,16 @@ int main(int argc, char *argv[])
}
else if(!strcmp("read_all",argv[1]) && read_all != NULL)
{
- read_all(argv[5]);
+ // read_all(argv[5]);
+ read_all(NULL);
}
- else if(!strcmp("read_one",argv[1]) && read_one != NULL && argc == 5)
+ else if(!strcmp("read_one",argv[1]) && read_one != NULL && argc > 5)
{
read_one(argv[5]);
}
else
{
- // print_help();
+ print_help();
}
close(file);