aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGergő J. Miklós2019-05-11 03:27:13 +0200
committerGergő J. Miklós2019-05-11 03:27:13 +0200
commit5cbc1bcd61ccd50b3c37f3f70083afca13c9a175 (patch)
tree83d72b3882b109c93407da8d45da43a43f9434d8
parent7dd3691d171f10a76375796936b0ad215f07efa0 (diff)
downloadi2sensors-5cbc1bcd61ccd50b3c37f3f70083afca13c9a175.tar.gz
i2sensors-5cbc1bcd61ccd50b3c37f3f70083afca13c9a175.zip
some debugging + read
-rw-r--r--Makefile4
-rw-r--r--run.sh17
-rw-r--r--src/hih61xx.c2
-rw-r--r--src/lm75.c85
-rw-r--r--src/lm75.h2
-rw-r--r--src/main.c34
6 files changed, 87 insertions, 57 deletions
diff --git a/Makefile b/Makefile
index a1bfd3a..d3f01f7 100644
--- a/Makefile
+++ b/Makefile
@@ -11,8 +11,8 @@ main:
clean:
- rm -f build/i2sensors*
+ rm -f build/i2sensors*
copy:
- mkdir -p build/bin/
+ echo
\ No newline at end of file
diff --git a/run.sh b/run.sh
new file mode 100644
index 0000000..c78d362
--- /dev/null
+++ b/run.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+
+
+
+
+make
+
+#rsync -aHv -q -e "ssh" build/i2sensors-arm root@cb2:/tmp/i2sensors
+scp build/i2sensors-armhf root@cb2:/tmp/i2sensors
+
+ssh root@cb2 '/tmp/i2sensors read_one 1 lm75 0x49 0,111.1'
+echo
+ssh root@cb2 '/tmp/i2sensors read_all 1 lm75 0x49 '
+#ssh root@cb2 '/tmp/i2sensors list_all 1 lm75 0x49'
+
+exit 0 \ No newline at end of file
diff --git a/src/hih61xx.c b/src/hih61xx.c
index b68b653..221f2b2 100644
--- a/src/hih61xx.c
+++ b/src/hih61xx.c
@@ -14,7 +14,7 @@ extern void print_help(void);
unsigned char buf[5];
-
+
void hih61xx_list_all(void)
{
diff --git a/src/lm75.c b/src/lm75.c
index fac61c2..b2155ad 100644
--- a/src/lm75.c
+++ b/src/lm75.c
@@ -12,7 +12,7 @@ extern int file;
extern void bus_err(int ern);
extern void print_help(void);
unsigned char buf[5];
-
+
void lm75_list_all(void)
{
@@ -26,15 +26,13 @@ void lm75_list_all(void)
-void lm75_get_data(void)
-{
- if(write(file, buf, 1) != 1)
- {
+void lm75_get_data(void){
+
+ if(write(file, buf, 1) != 1){
bus_err(errno);
}
- if(read(file, buf, 2) != 2)
- {
+ if(read(file, buf, 2) != 2) {
bus_err(errno);
}
}
@@ -118,14 +116,14 @@ char lm75_read_conf(void)
void lm75_read_all(const char *opts)
{
- if(opts != NULL)
- {
- printf("00:%f\n", lm75_read_temp(strtof(opts, NULL)));
- }
- else
- {
+ // if(opts != NULL)
+ // {
+ // printf("00:%f\n", lm75_read_temp(strtof(opts, NULL)));
+ // }
+ // else
+ // {
printf("00:%f\n", lm75_read_temp(0.0));
- }
+ // }
printf("01:0x%x\n", lm75_read_conf());
printf("02:%f\n", lm75_read_tos());
@@ -136,28 +134,41 @@ void lm75_read_all(const char *opts)
void lm75_read_one(const char *opts)
{
- int id;
- char *ptr;
-
- id = strtol (opts,&ptr,0); //all format allowed
- ptr++; //one separator allowed
-
- switch (id)
- {
- case 0x00:
- printf("00:%f\n", lm75_read_temp(strtof(ptr, NULL)));
- break;
- case 0x01:
- printf("01:0x%x\n", lm75_read_conf());
- break;
- case 0x02:
- printf("02:%f\n", lm75_read_tos());
- break;
- case 0x03:
- printf("03:%f\n", lm75_read_thys());
- break;
- default:
- print_help();
- }
+ int id,i;
+ //char *ptr;
+ char temp[256];
+
+ if(opts != NULL){
+ for(i = 0; i < strlen(opts); i++){
+ if (*(opts+i) == ','){
+ break;
+ }
+ temp[i] = *(opts+i);
+ temp[i+1] = '\0';
+ }
+
+ id = atoi(temp);
+ strncpy(temp, opts+i+1, 255);
+ // id = strtol (opts,&ptr,0); //all format allowed
+ // ptr++; //one separator allowed
+
+ switch (id)
+ {
+ case 0x00:
+ printf("00:%f\n", lm75_read_temp(atof(temp)));
+ break;
+ case 0x01:
+ printf("01:0x%x\n", lm75_read_conf());
+ break;
+ case 0x02:
+ printf("02:%f\n", lm75_read_tos());
+ break;
+ case 0x03:
+ printf("03:%f\n", lm75_read_thys());
+ break;
+ default:
+ print_help();
+ }
+ }
}
diff --git a/src/lm75.h b/src/lm75.h
index ff31c6a..3f21ff5 100644
--- a/src/lm75.h
+++ b/src/lm75.h
@@ -11,7 +11,7 @@ void lm75_list_all(void);
void lm75_get_data(void);
float lm75_read_temp(float offset);
float lm75_read_tos(void);
-float lm75_read_thys(void);
+float lm75_read_thys(void);
char lm75_read_conf(void);
void lm75_read_all(const char *opts);
void lm75_read_one(const char *opts);
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);