From 3ef6cf39749c00366b12aef9f023aac3bda16f2d Mon Sep 17 00:00:00 2001
From: guowenxue <guowenxue@gmail.com>
Date: Mon, 17 Nov 2025 23:39:25 +0800
Subject: [PATCH] update modules for tsl2561 and ds18b20

---
 project/modules/ds18b20.c |    1 -
 project/modules/tsl2561.c |   11 +++++++----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/project/modules/ds18b20.c b/project/modules/ds18b20.c
index 5f279fe..aa1e01b 100644
--- a/project/modules/ds18b20.c
+++ b/project/modules/ds18b20.c
@@ -49,7 +49,6 @@
     struct dirent  *direntp;
     int             fd =-1;
     char           *ptr;
-    float           value;
     int             found = 0;
 
     if( !temp )
diff --git a/project/modules/tsl2561.c b/project/modules/tsl2561.c
index c23f61c..b912433 100644
--- a/project/modules/tsl2561.c
+++ b/project/modules/tsl2561.c
@@ -150,7 +150,6 @@
     float               div = 0.0;
 
     unsigned char       reg_data[REG_COUNT];
-    unsigned char       buf;
     int                 chn0_data = 0;
     int                 chn1_data = 0;
 
@@ -173,7 +172,9 @@
     /* Read register Channel0 and channel1 data from register */
     for(i=0; i<REG_COUNT; i++)
     {
-        tsl2561_readreg(fd, regs_addr[i], &reg_data[i]);
+        rv = tsl2561_readreg(fd, regs_addr[i], &reg_data[i]);
+        if( rv < 0)
+            goto failed;
     }
 
     chn0_data = reg_data[1]*256 + reg_data[0]; /* Channel0 = DATA0HIGH<<8 + DATA0LOW  */
@@ -182,7 +183,7 @@
     if( chn0_data<=0 || chn1_data<0 )
     {
         rv = -2;
-        goto OUT;
+        goto cleanup;
     }
 
     div = (float)chn1_data / (float)chn0_data;
@@ -202,8 +203,10 @@
     else if( div>1.3 )
         *lux = 0.0;
 
-OUT:
+cleanup:
     tsl2561_power(fd, OFF);
+
+failed:
     close(fd);
     return rv;
 }

--
Gitblit v1.9.1