diff --git a/binding.gyp b/binding.gyp index c24c497..dcb2e38 100644 --- a/binding.gyp +++ b/binding.gyp @@ -3,7 +3,7 @@ { 'target_name': 'node-dht-sensor', 'sources': [ 'node-dht-sensor.cpp' ], - 'libraries': [ '-lbcm2835' ], + 'libraries': [ '-lwiringPi' ], 'conditions': [ ['OS=="linux"', { 'include_dirs+': '/usr/local/lib/libbcm2835.a', diff --git a/node-dht-sensor.cpp b/node-dht-sensor.cpp index 009b0ef..c4d80b3 100644 --- a/node-dht-sensor.cpp +++ b/node-dht-sensor.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include @@ -69,38 +69,39 @@ long readDHT(int type, int pin, float &temperature, float &humidity) } // Set GPIO pin to output - bcm2835_gpio_fsel(pin, BCM2835_GPIO_FSEL_OUTP); - - bcm2835_gpio_write(pin, HIGH); - bcm2835_delay(400); - bcm2835_gpio_write(pin, LOW); - bcm2835_delay(20); - - bcm2835_gpio_fsel(pin, BCM2835_GPIO_FSEL_INPT); + pinMode (pin, OUTPUT); + + digitalWrite (pin, HIGH); + delay(500); + + digitalWrite (pin, LOW); + delay(20); + pinMode (pin, INPUT) ; + data[0] = data[1] = data[2] = data[3] = data[4] = 0; // wait for pin to drop? int timeout = 100000; - while (bcm2835_gpio_lev(pin) == 1) { + while (digitalRead (pin) == 1) { if (--timeout < 0) { #ifdef VERBOSE printf("Sensor timeout.\n"); #endif return -3; } - bcm2835_delayMicroseconds(1); //usleep(1); + usleep(1); } // read data! for (int i = 0; i < MAXTIMINGS; i++) { counter = 0; - while (bcm2835_gpio_lev(pin) == laststate) { + while (digitalRead (pin) == laststate) { counter++; if (counter == 1000) break; } - laststate = bcm2835_gpio_lev(pin); + laststate = digitalRead (pin); if (counter == 1000) break; #ifdef VERBOSE if (bitidx < 1000) { @@ -178,23 +179,12 @@ int initialize() struct sched_param schedp; schedp.sched_priority = 1; sched_setscheduler(0, SCHED_FIFO, &schedp); + + wiringPiSetup (); - if (!bcm2835_init()) - { -#ifdef VERBOSE - printf("BCM2835 initialization failed.\n"); -#endif - return 1; - } - else - { -#ifdef VERBOSE - printf("BCM2835 initialized.\n"); -#endif - initialized = 1; - memset(last_read, 0, sizeof(unsigned long long)*32); - return 0; - } + initialized = 1; + memset(last_read, 0, sizeof(unsigned long long)*32); + return 0; } using namespace v8;