示例#1
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;
}
示例#2
0
文件: main.c 项目: AdamRLukaitis/RIOT
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;
}
示例#3
0
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;
}