View Single Post
jaeezzy's Avatar
Posts: 664 | Thanked: 160 times | Joined on Jul 2008 @ Australia
#34
Originally Posted by qwerty12 View Post
That would be due to those being the values for the light sensor... You want the file "/sys/bus/platform/devices/proximity/state" which can have a state of "open" or "closed".

P.S. GIOChannels provide a nicer alternative to watching files.
Thanks for the info but I just couldn't make use of GIOChannel. Here's how I did:

Code:
int fd = open("/sys/bus/platform/devices/proximity/state", O_RDONLY, O_NONBLOCK, O_NOCTTY);
GIOChannel *channel = g_io_channel_unix_new(fd);
g_io_add_watch(channel, G_IO_IN | G_IO_PRI, (GIOFunc)readState, NULL);
..........

gboolean readState(GIOChannel *channel, GIOCondition cond, gpointer data){
 gchar *state;
 gsize size;
 GIOStatus ret = g_io_channel_read_line(channel, &state, &size, NULL, NULL);
 if (ret != G_IO_STATUS_ERROR){
   printf("STATE: %s", state);
   if (strcmp(state, "open") == 0){
        ...........
    }
   else if (strcmp(state, "closed") == 0){
        ...........
   }
   g_free(state);
 }else
   return FALSE;

 return TRUE;
}
Any help would be great. Thanks