aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGergő J. Miklós2019-05-13 01:27:38 +0200
committerGergő J. Miklós2019-05-13 01:27:38 +0200
commit69663b28552da887dc196a100025e153821dbd57 (patch)
tree171716995a34410d757ec95f1b742609606b0db3
parente0eeeb389302c3050310ac8e618119384ce0fef8 (diff)
downloadi2sensors-69663b28552da887dc196a100025e153821dbd57.tar.gz
i2sensors-69663b28552da887dc196a100025e153821dbd57.zip
LM75 rw
-rw-r--r--src/lm75.c58
-rw-r--r--src/lm75.h10
2 files changed, 52 insertions, 16 deletions
diff --git a/src/lm75.c b/src/lm75.c
index bd1f764..9207860 100644
--- a/src/lm75.c
+++ b/src/lm75.c
@@ -29,14 +29,14 @@ void lm75_print_all(void)
}
-uchar *read_data( uchar *buf ){ //# [buf] = 32 byte
+uchar *xchg_data (uchar *buf, uint8 wrlen, uint8 waitlen, uint8 rdlen){ //# [buf] = 32 byte
- if(write(devicef, buf, 1) != 1){ //# write one byte to device
+ if(write(devicef, buf, wrlen) != wrlen){ //# write one byte to device
bus_err(errno);
}
- usleep(10*1000); //# Wait 10ms for reading
-
- if(read(devicef, buf, 2) != 2) { //# read the result
+ usleep(waitlen*1000); //# Wait 10ms for reading
+
+ if(read(devicef, buf, rdlen) != rdlen) { //# read the result
bus_err(errno);
}
return buf;
@@ -49,7 +49,7 @@ float calculate_temp(float offset){ // Calculate temperature
float temp;
buf[0] = 0x00; //# Measurement in the REG[0]
- read_data(buf); //# [buf] = 32 byte
+ xchg_data(buf,1,0,2); //# Write: 1byte addr, Read: 2byte data, Wait:0, [buf] = 32 byte
rawtemp = (buf[0]*256 + buf[1]) >> 5; // (buf[0] << 8), and (>> 5), Device with 11bit data, is also supported
@@ -66,7 +66,7 @@ float calculate_temp(float offset){ // Calculate temperature
float read_tos(void){ // Over-Temperature Shutdown register
int16 rawtemp = 0; //# Int16 default signed
buf[0] = 0x02; //# Tos = REG[2]
- read_data(buf);
+ xchg_data(buf,1,0,2);
rawtemp = buf[0]*256 + buf[1];
rawtemp = (rawtemp) >> 7; //# 9bit data
@@ -82,7 +82,7 @@ float read_tos(void){ // Over-Temperature Shutdown reg
float read_thys(void){ // Over-Temp Hysteresis Register
int16 rawtemp = 0; //# signed
buf[0] = 0x03;
- read_data(buf); //# read from REG[3]
+ xchg_data(buf,1,0,2); //# read from REG[3]
rawtemp = buf[0]*256 + buf[1];
rawtemp = (rawtemp) >> 7; //# 9bit data
@@ -95,7 +95,7 @@ float read_thys(void){ // Over-Temp Hysteresis Register
uchar read_conf(void){ //Configuration register
buf[0] = 0x01;
- read_data(buf);
+ xchg_data(buf,1,0,2);
return buf[0];
}
@@ -156,6 +156,42 @@ void lm75_read_one(const uchar *opts){ // Prints the selected r
}
-void lm75_conf_set(const uchar *opts){
- // printf("");
+
+void lm75_conf_set(const uchar *opts){ // Prints the selected register's data
+ uint16 id,i,j;
+ uchar temp[256];
+
+ if(opts != NULL){
+ for(i = 0; i < strlen((char*)opts); i++, j++){
+ if (*(opts+i) == ','){
+ break;
+ }
+ 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
+
+ switch (id)
+ {
+ case 0x00:
+ printf("%f\n", calculate_temp(atof((char*)temp)));
+ break;
+ case 0x01:
+ printf("0x%x\n", read_conf());
+ break;
+ case 0x02:
+ printf("%f\n", read_tos());
+ break;
+ case 0x03:
+ printf("%f\n", read_thys());
+ break;
+ default:
+ print_help();
+ }
+
+ }
} \ No newline at end of file
diff --git a/src/lm75.h b/src/lm75.h
index 600934c..0c8b6a8 100644
--- a/src/lm75.h
+++ b/src/lm75.h
@@ -14,11 +14,11 @@ void lm75_read_all(const uchar *opts);
void lm75_read_one(const uchar *opts);
void lm75_conf_set(const uchar *opts);
-//unsigned char *read_data(unsigned char *buf);
-float calculate_temp(float offset);
-float read_tos(void);
-float read_thys(void);
-uchar read_conf(void);
+//unsigned char *xchg_data(unsigned char *buf);
+// float calculate_temp(float offset);
+// float read_tos(void);
+// float read_thys(void);
+// uchar read_conf(void);
//__uint8_t
//__uint16_t