aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c94
1 files changed, 53 insertions, 41 deletions
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();
}