Hi,
I try to read from system fs, but it don't work?
Please see the attachment and help me fix it.
Thanks in advance!

-- 
Trần Ngọc Quân.
component cpu_thermalusr "Read cpu thermal from sysfs";
pin out float value "Return value";
option userspace;
option singleton yes;
option extra_setup;
option extra_cleanup;
license "GPL";
;;

#define THERMALFILE "/sys/class/thermal/thermal_zone0/temp"
#define MAX_BUFFER 10
#define BASE 10
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>

static int fd;

EXTRA_SETUP(){
        fd = open(THERMALFILE, O_RDONLY);
}

void user_mainloop(void) {
        char buff[MAX_BUFFER];
        ssize_t sz;
    while(1) {
      usleep(1000);
        sz = read(fd, buff, sizeof(char) * MAX_BUFFER);
            buff[sz]= 0;
            value = strtol(buff, NULL, BASE) / 1000.0;
    }
}

EXTRA_CLEANUP(){
        close(fd);
}

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Emc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-users

Reply via email to