aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lm75.c55
1 files changed, 44 insertions, 11 deletions
diff --git a/src/lm75.c b/src/lm75.c
index 9207860..9510a46 100644
--- a/src/lm75.c
+++ b/src/lm75.c
@@ -4,6 +4,7 @@
#include <string.h>
#include <unistd.h>
#include <errno.h>
+#include <ctype.h> //# isdigit
#include "lm75.h"
@@ -35,7 +36,7 @@ uchar *xchg_data (uchar *buf, uint8 wrlen, uint8 waitlen, uint8 rdlen){
bus_err(errno);
}
usleep(waitlen*1000); //# Wait 10ms for reading
-
+
if(read(devicef, buf, rdlen) != rdlen) { //# read the result
bus_err(errno);
}
@@ -121,24 +122,30 @@ void lm75_read_one(const uchar *opts){ // Prints the selected r
uint16 id,i;
uchar temp[256];
- if(opts != NULL){
+ if(opts != NULL){ //# Search the comma: ...<01,-11.24>
for(i = 0; i < strlen((char*)opts); i++){
- if (*(opts+i) == ','){
+
+ if (*(opts+i) == ','){
break;
+
+ } else {
+ if( !isdigit(*(opts+i)) ){ //# Check the register string
+ printf("The Register address must be an integer!\n");
+ print_help();
+ exit (EXIT_FAILURE);
+ }
+ temp[i] = *(opts+i); //# copy register string
+ temp[i+1] = '\0';
}
- temp[i] = *(opts+i);
- temp[i+1] = '\0';
}
- id = atoi((char*)temp);
- strncpy((char*)temp, (char*)opts+i+1, 255);
- // id = strtol (opts,&ptr,0); //all format allowed
- // ptr++; //one separator allowed
+ id = atoi((char*)temp); //# Convert register to number
+ strncpy((char*)temp, (char*)opts+i+1, 255); //# Copy remain to temp
- switch (id)
+ switch (id) //# Which register is selected?
{
case 0x00:
- printf("%f\n", calculate_temp(atof((char*)temp)));
+ printf("%f\n", calculate_temp(atof((char*)temp))); //# with the offset
break;
case 0x01:
printf("0x%x\n", read_conf());
@@ -170,6 +177,32 @@ void lm75_conf_set(const uchar *opts){ // Prints the selected r
temp[i+1] = '\0';
}
+ if(!strcmp("tos", (char*)temp)){ //# Set the Tos register value
+
+ }else if(!strcmp("thys", (char*)temp)){ //# Set the Thys reg
+
+ }else if(!strcmp("conf", (char*)temp)){ //# Set whole conf register
+
+ }else if(!strcmp("sleep", (char*)temp)){ //# Send the sleep command
+
+ }else if(!strcmp("mode", (char*)temp)){ //# Comparator/Interrupt mode
+
+ }else if(!strcmp("tos_pol", (char*)temp)){ //# Tos polarity
+
+ }else if(!strcmp("fault_q", (char*)temp)){ //# Tos Fault Queue
+
+ } else {
+ for(i = 0; i < strlen((char*)opts); i++ ){
+ if( !isxdigit(*(opts+i)) || *(opts+i) !='x' || opts[i] != ','){ //# Check the register string
+ printf("The Register address, and value must be a hex, or an integer!\n");
+ print_help();
+ exit (EXIT_FAILURE);
+ }
+ }
+ }
+
+
+
id = atoi((char*)temp);
strncpy((char*)temp, (char*)opts+i+1, 255);
// id = strtol (opts,&ptr,0); //all format allowed