aboutsummaryrefslogtreecommitdiffstats
path: root/src/lm75.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lm75.c')
-rw-r--r--src/lm75.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/src/lm75.c b/src/lm75.c
index c1b67f0..2e14738 100644
--- a/src/lm75.c
+++ b/src/lm75.c
@@ -15,6 +15,7 @@
extern uint16 devicef;
extern void bus_err(int ern);
extern void print_help(void);
+extern uchar *xchg_data (uchar *buf, uint8 wrlen, uint8 waitlen, uint8 rdlen);
uchar buf[32];
@@ -40,21 +41,21 @@ void lm75_print_all(void)
}
-uchar *xchg_data (uchar *buf, uint8 wrlen, uint8 waitlen, uint8 rdlen){ //# [buf] = 32 byte
+// uchar *xchg_data (uchar *buf, uint8 wrlen, uint8 waitlen, uint8 rdlen){ //# [buf] = 32 byte
- if(write(devicef, buf, wrlen) != wrlen){ //# write one byte to device
- bus_err(errno);
- }
- usleep(waitlen*1000); //# Wait 10ms for reading
+// if(write(devicef, buf, wrlen) != wrlen){ //# write one byte to device
+// bus_err(errno);
+// }
+// usleep(waitlen*1000); //# Wait 10ms for reading
- if(read(devicef, buf, rdlen) != rdlen) { //# read the result
- bus_err(errno);
- }
- return buf;
-}
+// if(read(devicef, buf, rdlen) != rdlen) { //# read the result
+// bus_err(errno);
+// }
+// return buf;
+// }
-float calculate_temp(float offset){ // Calculate temperature
+static float calc_temp(float offset){ // Calculate temperature
uint16 rawtemp = 0; //# Signed by default
float temp;
@@ -73,7 +74,7 @@ float calculate_temp(float offset){ // Calculate temperature
}
-float read_tos(void){ // Over-Temperature Shutdown register
+static float read_tos(void){ // Over-Temperature Shutdown register
uint16 rawtemp = 0; //# Int16 default signed
buf[0] = 0x03; //# Tos = REG[2]
xchg_data(buf,1,0,2);
@@ -91,7 +92,7 @@ float read_tos(void){ // Over-Temperature Shutdown reg
}
-float read_thys(void){ // Over-Temp Hysteresis Register
+static float read_thys(void){ // Over-Temp Hysteresis Register
uint16 rawtemp = 0; //# signed
buf[0] = 0x02;
xchg_data(buf,1,0,2); //# read from REG[3]
@@ -108,7 +109,7 @@ float read_thys(void){ // Over-Temp Hysteresis Register
}
-uchar read_conf(void){ //Configuration register
+static uchar read_conf(void){ //Configuration register
buf[0] = 0x01;
xchg_data(buf,1,0,1);
return buf[0];
@@ -118,9 +119,9 @@ uchar read_conf(void){ //Configuration register
void lm75_read_all(const uchar *opts){ // Print out whole device's data
// if(opts != NULL)
// {
- // printf("00:%f\n", calculate_temp(strtof(opts, NULL)));
+ // printf("00:%f\n", calc_temp(strtof(opts, NULL)));
// } else {
- printf("00:%f\n", calculate_temp(0.0));
+ printf("00:%f\n", calc_temp(0.0));
// }
printf("01:0x%x\n", read_conf());
printf("02:%f\n", read_thys());
@@ -143,6 +144,7 @@ void lm75_read_one(const uchar *opts){ // Prints the selected r
if( !isdigit(*(opts+i)) ){ //# Check the register string
printf("The Register address must be an integer!\n");
print_help();
+ lm75_print_all();
exit (EXIT_FAILURE);
}
temp[i] = *(opts+i); //# copy register string
@@ -156,7 +158,7 @@ void lm75_read_one(const uchar *opts){ // Prints the selected r
switch (id) //# Which register is selected?
{
case 0x00:
- printf("%f\n", calculate_temp(atof((char*)temp))); //# with the offset
+ printf("%f\n", calc_temp(atof((char*)temp))); //# with the offset
break;
case 0x01:
printf("0x%x\n", read_conf());
@@ -176,11 +178,11 @@ void lm75_read_one(const uchar *opts){ // Prints the selected r
void lm75_conf_set(const uchar *opts){ // Prints the selected register's data
- uint16 i,j;
+ uint16 i;
uchar temp[256];
if(opts != NULL){
- for(i = 0; i < strlen((char*)opts); i++, j++){
+ for(i = 0; i < strlen((char*)opts); i++){
if (*(opts+i) == ','){ //# .... conf_set 0x49 thys,-10.5
break;
}