void irq_handler(int n, siginfo_t *info, void *unused)
{
//every minute
counter++;
dht_request_data();
}
void dht_request_data()
{
int fd=open("/sys/kernel/debug/irq-dht", O_WRONLY);
sprintf(buf, "%d %u", DHT_GPIO, getpid()); // gpio-dht-handler kernel module
write(fd, buf, strlen(buf) + 1);
close(fd);
}
void dht_handler(int n, siginfo_t *info, void *unused)
{
if (info->si_int == 0) // DHT protocol CRC error
{
if (++failcounter > 10)
{
printf("Error retrieving data from DHT sensor\n");
failcounter = 0;
return;
}
usleep(3000000); // wait 3 seconds between attempts
dht_request_data();
return;
}
float humidity = (float)((info->si_int) >> 16)/10.0; // 2xMSB
float temperature = (float)((info->si_int) & 0xFFFF)/10.0; //2xLSB
// ...
}
int main(int argc, char* argv[])
{
int timer = TIMER_TIMER;
int tick = 1000*1000; // 1 sec
unsigned int timeout = 1000*1000*60; // 60 sec
if (!init_handler(timer, tick, timeout))
{
printf("Error initializing timer %d\n", timer);
return -1;
}
struct sigaction sig;
sig.sa_sigaction = dht_handler;
sig.sa_flags = SA_SIGINFO | SA_NODEFER;
sigaction(SIG_DHT_IRQ, &sig, NULL);
// ...
}