aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--run.sh21
-rw-r--r--src/hih61xx.c10
-rw-r--r--src/hih61xx.h7
-rw-r--r--src/hmc5883.c29
-rw-r--r--src/hmc5883.h21
-rw-r--r--src/lm75.c11
-rw-r--r--src/lm75.h5
-rw-r--r--src/main.c94
9 files changed, 136 insertions, 66 deletions
diff --git a/Makefile b/Makefile
index d3f01f7..78634ae 100644
--- a/Makefile
+++ b/Makefile
@@ -6,8 +6,8 @@ all: main copy
main:
- $(CC) $(CFLAGS) src/main.c src/hih61xx.c src/lm75.c -o build/i2sensors
- $(ACC) $(CFLAGS) src/main.c src/hih61xx.c src/lm75.c -o build/i2sensors-armhf
+ $(CC) $(CFLAGS) src/hmc5883.c src/hih61xx.c src/lm75.c src/main.c -o build/i2sensors
+ $(ACC) $(CFLAGS) src/hmc5883.c src/hih61xx.c src/lm75.c src/main.c -o build/i2sensors-armhf
clean:
diff --git a/run.sh b/run.sh
index c78d362..013205c 100644
--- a/run.sh
+++ b/run.sh
@@ -1,17 +1,20 @@
#!/bin/bash
+make
+if [ "$?" == "0" ]; then
+ #rsync -aHv -q -e "ssh" build/i2sensors-arm root@cb2:/tmp/i2sensors
+ scp build/i2sensors-armhf root@cb2:/tmp/i2sensors
-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'
-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
-exit 0 \ No newline at end of file
+else
+ exit 1
+fi \ No newline at end of file
diff --git a/src/hih61xx.c b/src/hih61xx.c
index 221f2b2..2a61d3b 100644
--- a/src/hih61xx.c
+++ b/src/hih61xx.c
@@ -8,15 +8,14 @@
#include "hih61xx.h"
-extern int file;
+extern int file;
extern void bus_err(int ern);
-extern void print_help(void);
+extern void print_help(void);
unsigned char buf[5];
-
-
+
-void hih61xx_list_all(void)
+void hih61xx_print_all(void)
{
printf(
"00: Relative Humidity [%%] (reg: 0x00)\n"
@@ -25,6 +24,7 @@ void hih61xx_list_all(void)
"\n");
}
+void hih61xx_conf_set(const char *opts) {}
void hih61xx_get_data(void)
diff --git a/src/hih61xx.h b/src/hih61xx.h
index 25842a6..23546d2 100644
--- a/src/hih61xx.h
+++ b/src/hih61xx.h
@@ -3,17 +3,18 @@
#define _HIH61xx_INCLUDED
/*
-extern int file;
+extern int file;
void hih61xx_list_all(void);
void hih61xx_read_all(const char *opts);
*/
-void hih61xx_list_all(void);
+void hih61xx_print_all(void);
void hih61xx_get_data(void);
+void hih61xx_conf_set(const char *opts);
unsigned char hih61xx_read_status(void);
float hih61xx_read_humidity(float offset);
float hih61xx_read_temp(float offset);
void hih61xx_read_all(const char *opts);
void hih61xx_read_one(const char *opts);
-#endif \ No newline at end of file
+#endif \ No newline at end of file
diff --git a/src/hmc5883.c b/src/hmc5883.c
new file mode 100644
index 0000000..6167f73
--- /dev/null
+++ b/src/hmc5883.c
@@ -0,0 +1,29 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+
+#include "hmc5883.h"
+
+extern int file;
+extern void bus_err(int ern);
+extern void print_help(void);
+unsigned char buf[5];
+
+
+void hmc5883_print_all(void)
+{
+ printf(
+ "00: Temperature data [°C] (reg: 0x00)\n"
+ "01: Configuration [hex] (reg: 0x01)\n"
+ "02: Tos (Overtemp) [°C] (reg: 0x03)\n"
+ "03: Thys (Hysteresis) [°C] (reg: 0x04)\n"
+ "\n");
+}
+
+void hmc5883_read_all(const char *opts) {}
+void hmc5883_read_one(const char *opts) {}
+void hmc5883_conf_set(const char *opts){} \ No newline at end of file
diff --git a/src/hmc5883.h b/src/hmc5883.h
new file mode 100644
index 0000000..b4c6a58
--- /dev/null
+++ b/src/hmc5883.h
@@ -0,0 +1,21 @@
+
+#ifndef _HMC5883_INCLUDED
+#define _HMC5883_INCLUDED
+
+// extern int file;
+//
+// void lm75_list_all(void);
+// void lm75_read_all(const char *opts);
+//
+void hmc5883_print_all(void);
+void hmc5883_get_data(void);
+void hmc5883_conf_set(const char *opts);
+// float lm75_read_temp(float offset);
+// float lm75_read_tos(void);
+// float lm75_read_thys(void);
+// char lm75_read_conf(void);
+void hmc5883_read_all(const char *opts);
+void hmc5883_read_one(const char *opts);
+
+
+#endif \ No newline at end of file
diff --git a/src/lm75.c b/src/lm75.c
index b2155ad..fd6f374 100644
--- a/src/lm75.c
+++ b/src/lm75.c
@@ -12,9 +12,9 @@ extern int file;
extern void bus_err(int ern);
extern void print_help(void);
unsigned char buf[5];
-
+
-void lm75_list_all(void)
+void lm75_print_all(void)
{
printf(
"00: Temperature data [°C] (reg: 0x00)\n"
@@ -22,9 +22,9 @@ void lm75_list_all(void)
"02: Tos (Overtemp) [°C] (reg: 0x03)\n"
"03: Thys (Hysteresis) [°C] (reg: 0x04)\n"
"\n");
-}
-
+}
+
void lm75_get_data(void){
@@ -37,6 +37,9 @@ void lm75_get_data(void){
}
}
+void lm75_conf_set(const char *opts){
+ // printf("");
+}
float lm75_read_temp(float offset)
diff --git a/src/lm75.h b/src/lm75.h
index 3f21ff5..30edee4 100644
--- a/src/lm75.h
+++ b/src/lm75.h
@@ -5,10 +5,11 @@
// extern int file;
//
// void lm75_list_all(void);
-// void lm75_read_all(const char *opts);
+// void lm75_read_all(const char *opts);
//
-void lm75_list_all(void);
+void lm75_print_all(void);
void lm75_get_data(void);
+void lm75_conf_set(const char *opts);
float lm75_read_temp(float offset);
float lm75_read_tos(void);
float lm75_read_thys(void);
diff --git a/src/main.c b/src/main.c
index ee3ec67..7d39441 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,68 +6,82 @@
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
-#include <errno.h>
+#include <errno.h>
#include <unistd.h>
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
-
+
#include "lm75.h"
#include "hih61xx.h"
+#include "hmc5883.h"
+
+#define VERSION 1.22
-extern void lm75_list_all(void);
-extern void lm75_read_all(const char *opts);
-extern void lm75_read_one(const char *opts);
-extern void hih61xx_list_all(void);
-extern void hih61xx_read_all(const char *opts);
-extern void hih61xx_read_one(const char *opts);
+// extern void lm75_print_help(void);
+// extern void lm75_read_all(const char *opts);
+// extern void lm75_read_one(const char *opts);
+// extern void hih61xx_print_help(void);
+// extern void hih61xx_read_all(const char *opts);
+// extern void hih61xx_read_one(const char *opts);
int file;
char temp[256];
-void (*list_all)(void) = NULL;
+void (*print_all)(void) = NULL;
void (*read_all)(const char *opts) = NULL;
void (*read_one)(const char *opts) = NULL;
+void (*conf_set)(const char *opts) = NULL;
-void print_help(void)
-{
- printf ("Usage:\n"
- " i2sensor <op> <bus> <dev_type> <dev_addr> (<options>)\n"
+void print_help(void) {
+ printf ("\n"
+ " i2sensors <op> <bus> <dev_type> <dev_addr> (<options>)\n"
+ "\n"
"Aviable options: <op>\n"
- " list_all -- list all measured parameters off device\n"
- " read_all -- read all measured parameters from device\n"
- " read_one -- read the selected parameters from device\n"
- "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 ---,\n"
- " i2sensor read_one 1 lm75 0x4f 00,-1.35\n"
- "" "");
- printf ("Build: %s %s\n\n",__DATE__,__TIME__);
-
+ " print_all -- list all available measurement parameters of the device\n"
+ " read_all -- read all measured parameters from device\n"
+ " read_one -- read the selected parameters from device\n"
+ " conf_set -- set the configuration register\n"
+ "\n"
+ "Usage:\n"
+ " i2sensors read_all <bus> <device-type> <address> \n"
+ " i2sensors read_one <bus> <device-type> <address> <param-id,offset_for_param>\n"
+ " i2sensors conf_set <bus> <device-type> <address> <reg-id,word-of-bits>\n"
+ "\n"
+ "Examples:\n"
+ " i2sensors read_all 1 lm75 0x4f \n"
+ " i2sensors read_one 1 lm75 0x4f 00,-1.35\n"
+ "\n" );
+ printf ("Version: v%1.2f, build: %s %s\n\n",VERSION,__DATE__,__TIME__);
}
-void bus_err(int ern)
-{
+void bus_err(int ern){
printf("I2C communication(rd) error. errno: %d\n",errno);
}
-void preinit(const char *dev_type)
-{
- if(!strcmp("lm75", dev_type))
- {
- list_all = lm75_list_all;
+void preinit(const char *dev_type){
+
+ if(!strcmp("lm75", dev_type)){
+ print_all = lm75_print_all;
read_all = lm75_read_all;
read_one = lm75_read_one;
+ conf_set = lm75_conf_set;
}
- else if(!strcmp("hih61xx", dev_type))
- {
- list_all = hih61xx_list_all;
+ else if(!strcmp("hih61xx", dev_type)) {
+ print_all = hih61xx_print_all;
read_all = hih61xx_read_all;
read_one = hih61xx_read_one;
+ conf_set = hih61xx_conf_set;
+ }
+
+ else if(!strcmp("hmc5883", dev_type)) {
+ print_all = hmc5883_print_all;
+ read_all = hmc5883_read_all;
+ read_one = hmc5883_read_one;
+ conf_set = hmc5883_conf_set;
}
}
@@ -96,8 +110,7 @@ int main(int argc, char *argv[])
for(i=0;i<strlen(argv[2]);i++) //Some test on bus address, for safety.
{
- if(!isdigit(argv[2][i]))
- {
+ if(!isdigit(argv[2][i])){
printf("\n\tThe BUS Address must be an integer\n\n");
print_help();
exit (EXIT_FAILURE);
@@ -106,8 +119,7 @@ int main(int argc, char *argv[])
snprintf(filename, 31, "/dev/i2c-%s", argv[2]); //Open i2c bus
file = open(filename, O_RDWR);
- if (file < 0)
- {
+ if (file < 0){
printf("\n\tCan't open i2c BUS. Have you any permission?\n\n");
print_help();
exit (EXIT_FAILURE);
@@ -134,9 +146,9 @@ int main(int argc, char *argv[])
- if(!strcmp("list_all",argv[1]) && list_all != NULL) // If list_all is selected.
+ if(!strcmp("print_all",argv[1]) && print_all != NULL) // If list_all is selected.
{
- list_all();
+ print_all();
}
else if(!strcmp("read_all",argv[1]) && read_all != NULL)
{
@@ -148,7 +160,7 @@ int main(int argc, char *argv[])
read_one(argv[5]);
}
else
- {
+ {
print_help();
}