aboutsummaryrefslogtreecommitdiffstats
path: root/src/lm75.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lm75.c')
-rw-r--r--src/lm75.c85
1 files changed, 48 insertions, 37 deletions
diff --git a/src/lm75.c b/src/lm75.c
index fac61c2..b2155ad 100644
--- a/src/lm75.c
+++ b/src/lm75.c
@@ -12,7 +12,7 @@ extern int file;
extern void bus_err(int ern);
extern void print_help(void);
unsigned char buf[5];
-
+
void lm75_list_all(void)
{
@@ -26,15 +26,13 @@ void lm75_list_all(void)
-void lm75_get_data(void)
-{
- if(write(file, buf, 1) != 1)
- {
+void lm75_get_data(void){
+
+ if(write(file, buf, 1) != 1){
bus_err(errno);
}
- if(read(file, buf, 2) != 2)
- {
+ if(read(file, buf, 2) != 2) {
bus_err(errno);
}
}
@@ -118,14 +116,14 @@ char lm75_read_conf(void)
void lm75_read_all(const char *opts)
{
- if(opts != NULL)
- {
- printf("00:%f\n", lm75_read_temp(strtof(opts, NULL)));
- }
- else
- {
+ // if(opts != NULL)
+ // {
+ // printf("00:%f\n", lm75_read_temp(strtof(opts, NULL)));
+ // }
+ // else
+ // {
printf("00:%f\n", lm75_read_temp(0.0));
- }
+ // }
printf("01:0x%x\n", lm75_read_conf());
printf("02:%f\n", lm75_read_tos());
@@ -136,28 +134,41 @@ void lm75_read_all(const char *opts)
void lm75_read_one(const char *opts)
{
- int id;
- char *ptr;
-
- id = strtol (opts,&ptr,0); //all format allowed
- ptr++; //one separator allowed
-
- switch (id)
- {
- case 0x00:
- printf("00:%f\n", lm75_read_temp(strtof(ptr, NULL)));
- break;
- case 0x01:
- printf("01:0x%x\n", lm75_read_conf());
- break;
- case 0x02:
- printf("02:%f\n", lm75_read_tos());
- break;
- case 0x03:
- printf("03:%f\n", lm75_read_thys());
- break;
- default:
- print_help();
- }
+ int id,i;
+ //char *ptr;
+ char temp[256];
+
+ if(opts != NULL){
+ for(i = 0; i < strlen(opts); i++){
+ if (*(opts+i) == ','){
+ break;
+ }
+ temp[i] = *(opts+i);
+ temp[i+1] = '\0';
+ }
+
+ id = atoi(temp);
+ strncpy(temp, opts+i+1, 255);
+ // id = strtol (opts,&ptr,0); //all format allowed
+ // ptr++; //one separator allowed
+
+ switch (id)
+ {
+ case 0x00:
+ printf("00:%f\n", lm75_read_temp(atof(temp)));
+ break;
+ case 0x01:
+ printf("01:0x%x\n", lm75_read_conf());
+ break;
+ case 0x02:
+ printf("02:%f\n", lm75_read_tos());
+ break;
+ case 0x03:
+ printf("03:%f\n", lm75_read_thys());
+ break;
+ default:
+ print_help();
+ }
+ }
}