Пример #1
0
int main(void)
{
    lps331ap_t dev;
    int temp, pres;
    int temp_abs, pres_abs;

    puts("LPS331AP pressure sensor test application\n");
    printf("Initializing LPS331AP sensor at I2C_%i... ", TEST_LPS331AP_I2C);
    if (lps331ap_init(&dev, TEST_LPS331AP_I2C, TEST_LPS331AP_ADDR, RATE) == 0) {
        puts("[OK]\n");
    }
    else {
        puts("[Failed]");
        return 1;
    }

    while (1) {
        pres = lps331ap_read_pres(&dev);
        temp = lps331ap_read_temp(&dev);

        pres_abs = pres / 1000;
        pres -= pres_abs * 1000;
        temp_abs = temp / 1000;
        temp -= temp_abs * 1000;

        printf("Pressure value: %2i.%03i bar - Temperature: %2i.%03i °C\n",
               pres_abs, pres, temp_abs, temp);

        xtimer_usleep(SLEEP);
    }

    return 0;
}
Пример #2
0
static int read_temp(const void *dev, phydat_t *res)
{
    res->val[0] = (int16_t)(lps331ap_read_temp((const lps331ap_t *)dev) / 10);
    res->unit = UNIT_TEMP_C;
    /* above division by ten leads to °C * 10^-2*/
    res->scale = -2;
    return 1;
}
Пример #3
0
/**
 * Sensors
 */
static void temperature_sensor()
{
    int16_t value;
    lps331ap_read_temp(&value);
    printf("Chip temperature measure: %f\n", 42.5 + value / 480.0);
}