Exemple #1
0
static int
scd_isa_attach (device_t dev)
{
	struct scd_softc *	sc;
	int			error;

	sc = device_get_softc(dev);
	error = 0;

	sc->dev = dev;
	sc->port_rid = 0;
	sc->port_type = SYS_RES_IOPORT;
	error = scd_alloc_resources(dev);
	if (error)
		goto fail;

	error = scd_probe(sc);
	if (error) {
		device_printf(dev, "Re-Probe failed.\n");
		goto fail;
	}

	error = scd_attach(sc);
	if (error) {
		device_printf(dev, "Attach failed.\n");
		goto fail;
	}

	return (0);
fail:
	scd_release_resources(dev);
	return (error);
}
Exemple #2
0
static int
scd_isa_probe (device_t dev)
{
	struct scd_softc *	sc;
	int			error;

	/* No pnp support */
	if (isa_get_vendorid(dev))
		return (ENXIO);

	/* IO port must be configured. */
	if (bus_get_resource_start(dev, SYS_RES_IOPORT, 0) == 0)
		return (ENXIO);

	sc = device_get_softc(dev);
	sc->dev = dev;
	sc->port_rid = 0;
	sc->port_type = SYS_RES_IOPORT;
	error = scd_alloc_resources(dev);
	if (error)
		goto fail;

	error = scd_probe(sc);
	if (error) {
		device_printf(dev, "Probe failed.\n");
		goto fail;
	}

	device_set_desc(dev, sc->data.name);

fail:
	scd_release_resources(dev);
	return (error);
}
int main(void) {
    float32_t co2_ppm, temperature, relative_humidity;
    uint16_t data_ready;
    int16_t ret;
    int16_t interval_in_seconds = 2;

    /* Busy loop for initialization, because the main loop does not work without
     * a sensor.
     */
    while (scd_probe() != STATUS_OK) {
        printf("SCD30 sensor probing failed\n");
        sleep(1);
    }
    printf("SCD30 sensor probing successful\n");

    scd_set_measurement_interval(interval_in_seconds);
    usleep(20000);
    scd_start_periodic_measurement(0);
    sleep(interval_in_seconds);

    while (1) {
        /* Measure co2, temperature and relative humidity and store into
         * variables.
         */
        ret = scd_get_data_ready(&data_ready);
        if (ret == STATUS_OK) {
            if (data_ready) {
                ret = scd_read_measurement(&co2_ppm, &temperature,
                                           &relative_humidity);
                if (ret != STATUS_OK) {
                    printf("error reading measurement\n");

                } else {
                    printf("measured co2 concentration: %0.2f ppm, "
                           "measured temperature: %0.2f degreeCelsius, "
                           "measured humidity: %0.2f %%RH\n",
                           co2_ppm, temperature, relative_humidity);
                }
            } else {
                printf("measurement not ready\n");
                usleep(20000);
                continue;
            }

        } else {
            printf("error reading data ready flag\n");
        }

        sleep(interval_in_seconds);
    }

    scd_stop_periodic_measurement();
    return 0;
}