Ejemplo n.º 1
0
static void send_update(size_t pos, char *buf)
{
	uint32_t pressure;
    uint16_t rawtemp, rawhum;
    int temp, hum, temp_abs, hum_abs, pressure_abs;
	uint8_t status;
	tcs37727_data_t light_data;

	hdc1000_read(&th_dev, &rawtemp, &rawhum);
	hdc1000_convert(rawtemp, rawhum,  &temp, &hum);
    temp_abs = temp / 100;
    hum_abs = hum / 100;
    temp -= temp_abs * 100;
    hum -= hum_abs * 100;

	mpl3115a2_read_pressure(&p_dev, &pressure, &status);
    pressure_abs = pressure / 100000;
    pressure -= pressure_abs * 100000;
	//mpl3115a2_read_temp(&p_dev, &temp);

	tcs37727_read(&light_dev, &light_data);

    pos += sprintf(&buf[pos], "{\"n\":\"s:temp\", \"u\":\"°C\", \"v\":\"%2i.%03i\"},",
                   temp_abs, temp);
    pos += sprintf(&buf[pos], "{\"n\":\"s:hum\", \"u\":\"%%RH\", \"v\":\"%2i.%03i\"},",
                   hum_abs, hum);
    pos += sprintf(&buf[pos], "{\"n\":\"s:pres\", \"u\":\"bar\", \"v\":\"%2i.%03i\"},",
                   pressure_abs, (unsigned int) pressure);
    pos += sprintf(&buf[pos], "{\"n\":\"s:rgb\", \"u\":\"RGB\", \"v\":\"[%"PRIu32", %"PRIu32", %"PRIu32"]\"}]",
                   light_data.red, light_data.green, light_data.blue);

    hdc1000_startmeasure(&th_dev);

    send_coap_post((uint8_t *)buf, pos);
}
Ejemplo n.º 2
0
/**
 * @brief Measure the illuminance with a TCS37727.
 * 
 * @ return illuminance in lux
 */
long get_illuminance(void) {
    tcs37727_data_t data;
    // enable TCS37727 and start the measurment
    if (tcs37727_set_rgbc_active(&tcsDev) != 0) {
        puts("[sensors] ERROR: TCS37727 activation failed");
        return -1;
    }
    // wait for the measurment to finish
    xtimer_usleep(2400 + tcsDev.atime_us);
    if (tcs37727_read(&tcsDev, &data) != 0) {
        puts("[sensors] ERROR: TCS37727 reading data failed");
        return -1;
    }
    printf("[sensors] INFO: TCS37727 Data R: %5"PRIu32" G: %5"PRIu32
           " B: %5"PRIu32" C: %5"PRIu32"\n", data.red, data.green, data.blue,
           data.clear);
    printf("[sensors] INFO: TCS37727 Data CT : %5"PRIu32" Lux: %6"PRIu32
           " AGAIN: %2d ATIME %d\n", data.ct, data.lux, tcsDev.again,
           tcsDev.atime_us);
    // disable the TCS37727
    if (tcs37727_set_rgbc_standby(&tcsDev) != 0) {
        puts("[sensors] ERROR: TCS37727 deactivation failed");
    }
    return data.lux;
}
Ejemplo n.º 3
0
int main(void)
{
    tcs37727_t dev;
    tcs37727_data_t data;

    puts("TCS37727 RGBC Data; Sensor driver test application\n");
    printf("Initializing TCS37727 sensor at I2C_%i... ", TEST_TCS37727_I2C);

    if (tcs37727_init(&dev, TEST_TCS37727_I2C, TEST_TCS37727_ADDR,
                      TCS37727_ATIME_DEFAULT) == 0) {
        puts("[OK]\n");
    }
    else {
        puts("[Failed]");
        return -1;
    }

    if (tcs37727_set_rgbc_active(&dev)) {
        puts("Measurement start failed.");
        return -1;
    }

    while (1) {
        tcs37727_read(&dev, &data);
        printf("R: %5"PRIu32" G: %5"PRIu32" B: %5"PRIu32" C: %5"PRIu32"\n",
               data.red, data.green, data.blue, data.clear);
        printf("CT : %5"PRIu32" Lux: %6"PRIu32" AGAIN: %2d ATIME %d\n",
               data.ct, data.lux, dev.again, dev.atime_us);

        xtimer_usleep(SLEEP);
    }

    return 0;
}