예제 #1
0
파일: main.c 프로젝트: 4dahalibut/RIOT
int main(void)
{
    hdc1000_t dev;
    uint16_t rawtemp, rawhum;
    int temp, hum;

    puts("HDC1000 Temperature and Humidity Sensor driver test application\n");
    printf("Initializing HDC1000 sensor at I2C_%i... ", TEST_HDC1000_I2C);
    if (hdc1000_init(&dev, TEST_HDC1000_I2C, TEST_HDC1000_ADDR) == 0) {
        puts("[OK]\n");
    }
    else {
        puts("[Failed]");
        return -1;
    }

    while (1) {
        if (hdc1000_startmeasure(&dev)) {
            puts("Start measure failed.");
            return -1;
        }
        vtimer_usleep(HDC1000_CONVERSION_TIME);

        hdc1000_read(&dev, &rawtemp, &rawhum);
        printf("Raw data T: %5i   RH: %5i\n", rawtemp, rawhum);

        hdc1000_convert(rawtemp, rawhum,  &temp, &hum);
        printf("Data T: %d   RH: %d\n", temp, hum);

        vtimer_usleep(SLEEP);

    }

    return 0;
}
예제 #2
0
파일: main.c 프로젝트: ant9000/RIOT
int main(void)
{
    hdc1000_t dev;
    int16_t temp, hum;
    size_t len;
    char tstr[8];
    char hstr[8];

    puts("HDC1000 Temperature and Humidity Sensor driver test application\n");
    printf("Initializing HDC1000 sensor at I2C_DEV(%i)... ",
            (int)hdc1000_params[0].i2c);
    if (hdc1000_init(&dev, &hdc1000_params[0]) == HDC1000_OK) {
        puts("[OK]\n");
    }
    else {
        puts("[Failed]");
        return 1;
    }

    while (1) {
        hdc1000_read(&dev, &temp, &hum);

        len = fmt_s16_dfp(tstr, temp, 2);
        tstr[len] = '\0';
        len = fmt_s16_dfp(hstr, hum, 2);
        hstr[len] = '\0';
        printf("Reading: T: %s °C  RH: %s %%\n", tstr, hstr);

        xtimer_usleep(SLEEP);
    }

    return 0;
}
예제 #3
0
파일: main.c 프로젝트: PeterKietzmann/Demos
int main(void)
{
#ifdef WITH_SHELL
    /* initialize message queue */
    msg_init_queue(_main_msg_q, Q_SZ);
#endif

    eui64_t iid;
    // uint16_t chan = 15;
    netopt_enable_t acks = NETOPT_DISABLE;
    kernel_pid_t ifs[GNRC_NETIF_NUMOF];

    gnrc_netif_get(ifs);
    gnrc_netapi_set(ifs[0], NETOPT_AUTOACK, 0, &acks, sizeof(acks));
    // gnrc_netapi_set(ifs[0], NETOPT_CHANNEL, 0, &chan, sizeof(chan));
    ipv6_addr_from_str(&dst_addr, "2001:affe:1234::1");
    // ipv6_addr_from_str(&dst_addr, "fd38:3734:ad48:0:211d:50ce:a189:7cc4");

    /* initialize senml payload */
    gnrc_netapi_get(ifs[0], NETOPT_IPV6_IID, 0, &iid, sizeof(eui64_t));

    initial_pos  = sprintf(&p_buf[initial_pos], "[{\"bn\":\"urn:dev:mac:");
    initial_pos += sprintf(&p_buf[initial_pos], "%02x%02x%02x%02x%02x%02x%02x%02x",
                           iid.uint8[0], iid.uint8[1], iid.uint8[2], iid.uint8[3],
                           iid.uint8[4], iid.uint8[5], iid.uint8[6], iid.uint8[7]);
    initial_pos += sprintf(&p_buf[initial_pos], "\"},");

    /* initialize sensors */
    hdc1000_init(&th_dev, HDC1000_I2C, HDC1000_ADDR);
    hdc1000_startmeasure(&th_dev);
    mpl3115a2_init(&p_dev, MPL3115A2_I2C, MPL3115A2_ADDR, MPL3115A2_OS_RATIO_DEFAULT);
    mpl3115a2_set_active(&p_dev);
    tcs37727_init(&light_dev, TCS37727_I2C, TCS37727_ADDR, TCS37727_ATIME_DEFAULT);
    tcs37727_set_rgbc_active(&light_dev);

#ifdef WITH_SHELL
    thread_create(beac_stack, sizeof(beac_stack), PRIO, THREAD_CREATE_STACKTEST, beaconing,
                  NULL, "beaconing");
    char line_buf[SHELL_DEFAULT_BUFSIZE];
    shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
#else
    beaconing(NULL);
#endif

    return 0;
}
예제 #4
0
/**
 * @brief Intialise all sensores.
 * 
 * @return 0 on error
 */
int init_sensors(void) {
    // initialise temperature/humidity sensor
    if (hdc1000_init(&hdcDev, 0, HDC1000_I2C_ADDRESS) == 0) {
        puts("[sensors] INFO: HDC1000 initialisation success");
    } else {
        puts("[sensors] ERROR: HDC1000 initialisation failed");
        return 0;
    }
    // intialise illuminance sensor
    if (tcs37727_init(&tcsDev, 0, TCS37727_I2C_ADDRESS, TCS37727_ATIME_DEFAULT)
            == 0) {
        puts("[sensors] INFO: TCS37727 initialisation success");
    } else {
        puts("[sensors] ERROR: TCS37727 initialisation failed");
        return 0;
    }
    return 1;
}
예제 #5
0
void auto_init_hdc1000(void)
{
    for (unsigned i = 0; i < HDC1000_NUM; i++) {
        LOG_DEBUG("[auto_init_saul] initializing hdc1000 #%u\n", i);

        int res = hdc1000_init(&hdc1000_devs[i], &hdc1000_params[i]);
        if (res < 0) {
            LOG_ERROR("[auto_init_saul] error initializing hdc1000 #%u\n", i);
            continue;
        }

        saul_entries[(i * 2)].dev = &(hdc1000_devs[i]);
        saul_entries[(i * 2)].name = hdc1000_saul_info[i].name;
        saul_entries[(i * 2)].driver = &hdc1000_saul_temp_driver;
        saul_entries[(i * 2) + 1].dev = &(hdc1000_devs[i]);
        saul_entries[(i * 2) + 1].name = hdc1000_saul_info[i].name;
        saul_entries[(i * 2) + 1].driver = &hdc1000_saul_hum_driver;
        saul_reg_add(&(saul_entries[(i * 2)]));
        saul_reg_add(&(saul_entries[(i * 2) + 1]));
    }
}