Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to build with DHT from PlatformIO #210

Open
golyalpha opened this issue Jan 1, 2020 · 2 comments
Open

Unable to build with DHT from PlatformIO #210

golyalpha opened this issue Jan 1, 2020 · 2 comments

Comments

@golyalpha
Copy link

When compiling a project with PlatformIO, targeting Arduino Mega and Arduino Due, it seems that it is unable to find the DHT sensor driver.

Here's the code:

#include "simba.h"
#include "pins.h"
#include "config.h"
#include "events.h"
#include "sensor_threads.h"

#ifndef DHT_SENSOR
// Omitted
#else

static THRD_STACK(dht_sensor_stack, 256);

void *dht_sensor_thread(void *arg_p){
    dht_module_init(); // Mega - W;Due - E:Implicit function declaration

    struct pin_device_t pin_targets[] = DHT;
    int pincount = sizeof(pin_targets)/sizeof(struct pin_device_t);
    struct dht_driver_t sensors[pincount]; // E:Incomplete element type

    for (int i=0;i<pincount;i++){
        dht_init(&sensors[i], &pin_targets[i]); // Mega - W;Due - E:Implicit function declaration
    }

    while (1) {
        int sensor_count=pincount;
        float temperature_acc=0;
        float humidity_acc=0;
        for (int i=0;i<pincount;i++){
            float temp, humidity;
            int res = dht_read(&sensors[i], &temp, &humidity); // Mega - W;Due - E:Implicit function declaration
            if (res != 0){
                std_printf(
                    FSTR("Read failed from DHT sensor %d with %d: %S\n"),
                    i,
                    res,
                    errno_as_string(res) // Mega - W;Due - E:Implicit function declaration
                );
                sensor_count--;
                continue;
            }
            temperature_acc+=temp;
            humidity_acc+=humidity;
        }
        
        float temp = temperature_acc/sensor_count;
        float hmid = humidity_acc/sensor_count;
        if (temp > 30){
            int mask = MAXTEMP_EVENT;
            event_write(&temp_event, &mask, sizeof(mask));
        }
        if (temp < 10){
            int mask = MINTEMP_EVENT;
            event_write(&temp_event, &mask, sizeof(mask));
        }
        if (hmid > 50){
            int mask = MAXHMID_EVENT;
            event_write(&hmid_event, &mask, sizeof(mask));
        }
        if (hmid < 10){
            int mask = MINHMID_EVENT;
            event_write(&hmid_event, &mask, sizeof(mask));
        }
    }
}

#endif

void register_threads(){
#ifndef DHT_SENSOR
    thrd_spawn(temp_sensor_thread, NULL, 2, temp_sensor_stack, sizeof(temp_sensor_stack));
    thrd_spawn(hmid_sensor_thread, NULL, 2, hmid_sensor_stack, sizeof(hmid_sensor_stack));
#else
    thrd_spawn(dht_sensor_thread, NULL, 2, dht_sensor_stack, sizeof(dht_sensor_stack));
#endif
}
@eerimoq
Copy link
Owner

eerimoq commented Jan 1, 2020

I'm sorry, but I don't have time to give any support. I hope you can figure it out somehow.

@golyalpha
Copy link
Author

golyalpha commented Jan 1, 2020

Alright, I managed to move ahead. Everyone (Arduino IDE and PlatformIO) is on the latest release... Which does not contain the DHT sensor drivers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants