From 7893fa123087328d5721fa27e9ee45130ba5da96 Mon Sep 17 00:00:00 2001 From: Gergő J. Miklós Date: Sun, 12 May 2019 12:37:47 +0200 Subject: hmc5883 added + some refactoring --- Makefile | 4 +-- run.sh | 21 +++++++------ src/hih61xx.c | 10 +++---- src/hih61xx.h | 7 +++-- src/hmc5883.c | 29 ++++++++++++++++++ src/hmc5883.h | 21 +++++++++++++ src/lm75.c | 11 ++++--- src/lm75.h | 5 ++-- src/main.c | 94 +++++++++++++++++++++++++++++++++-------------------------- 9 files changed, 136 insertions(+), 66 deletions(-) create mode 100644 src/hmc5883.c create mode 100644 src/hmc5883.h 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 +#include +#include +#include +#include + + +#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 #include #include -#include +#include #include #include #include - + #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 ()\n" +void print_help(void) { + printf ("\n" + " i2sensors ()\n" + "\n" "Aviable options: \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
\n" - " i2sensor read_one
\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
\n" + " i2sensors read_one
\n" + " i2sensors conf_set
\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