aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c50
1 files changed, 23 insertions, 27 deletions
diff --git a/src/main.c b/src/main.c
index 7d39441..18f762a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -13,6 +13,7 @@
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
+#include "deftypes.h"
#include "lm75.h"
#include "hih61xx.h"
#include "hmc5883.h"
@@ -27,8 +28,8 @@
// extern void hih61xx_read_one(const char *opts);
-int file;
-char temp[256];
+uint16 devicef; //# Bus-Device file
+uchar temp[256];
void (*print_all)(void) = NULL;
void (*read_all)(const char *opts) = NULL;
void (*read_one)(const char *opts) = NULL;
@@ -40,10 +41,11 @@ void print_help(void) {
" i2sensors <op> <bus> <dev_type> <dev_addr> (<options>)\n"
"\n"
"Aviable options: <op>\n"
- " 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"
+ " 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"
+ " read_repeat -- read measurements continously\n"
+ " conf_set -- set the configuration register\n"
"\n"
"Usage:\n"
" i2sensors read_all <bus> <device-type> <address> \n"
@@ -101,44 +103,40 @@ int main(int argc, char *argv[])
// ...set_reg... <dev_addr>, <reg_addr,value_hex>
- if(4 < argc && argc < 10) //Minimal 5 argument passed
+ if(4 < argc && argc < 10) //Minimum 5 arguments should be passed.
{
char filename[32];
int i;
preinit(argv[3]);
- for(i=0;i<strlen(argv[2]);i++) //Some test on bus address, for safety.
- {
+ for( i = 0; i < strlen(argv[2]); i++){ //# Test on bus address, for error detection.
if(!isdigit(argv[2][i])){
- printf("\n\tThe BUS Address must be an integer\n\n");
+ printf("\n\tThe BUS Address must be an integer!\n\n");
print_help();
exit (EXIT_FAILURE);
}
}
- snprintf(filename, 31, "/dev/i2c-%s", argv[2]); //Open i2c bus
- file = open(filename, O_RDWR);
+ snprintf(filename, 31, "/dev/i2c-%s", argv[2]);
+ devicef = open(filename, O_RDWR); //# Open the i2c bus
- if (file < 0){
+ if (devicef < 0){
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'){ // Hexadecimal device address
+ if(argv[4][0]=='0' && argv[4][1]=='x'){ //# Hexadecimal representetion of device address
- long addr = (int)strtol(argv[4], NULL, 0); //# strtol() is working with hex string
+ long addr = (int)strtol(argv[4], NULL, 0); //# strtol() is working with hex-string correctly
- if (ioctl(file, I2C_SLAVE, addr) < 0)
- {
+ if (ioctl(devicef, I2C_SLAVE, addr) < 0){ //# Seeking/Opening the device on the Bus
printf("\n\tCan't open i2c DEVICE, errno: %d\n\n",errno);
print_help();
exit (EXIT_FAILURE);
}
- }
- else
- {
+ } else {
printf("\n\tThe DEVICE address must be a hexadecimal number\n\n");
print_help();
exit (EXIT_FAILURE);
@@ -146,25 +144,23 @@ int main(int argc, char *argv[])
- if(!strcmp("print_all",argv[1]) && print_all != NULL) // If list_all is selected.
- {
+ if(!strcmp("print_all",argv[1]) && print_all != NULL){ //# Gets the device's help message.
print_all();
}
- else if(!strcmp("read_all",argv[1]) && read_all != NULL)
- {
+ else if(!strcmp("read_all",argv[1]) && read_all != NULL){ //# Pulls all readable registers data from device
// 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) //# Prints out the selected register
{
read_one(argv[5]);
}
- else
+ else //# No other option
{
print_help();
}
- close(file);
+ close(devicef);
}
else