Minor fixes
This commit is contained in:
parent
31e6cc48ca
commit
8337843d69
|
@ -64,13 +64,11 @@ static struct etimer et;
|
||||||
PROCESS_THREAD(test_pm10_sensor_process, ev, data)
|
PROCESS_THREAD(test_pm10_sensor_process, ev, data)
|
||||||
{
|
{
|
||||||
PROCESS_BEGIN();
|
PROCESS_BEGIN();
|
||||||
SENSORS_ACTIVATE(pm10);
|
|
||||||
|
|
||||||
static uint16_t pm10_value;
|
static uint16_t pm10_value;
|
||||||
|
|
||||||
/* Configure the ADC ports */
|
|
||||||
/* Use pin number not mask, for example if using the PA5 pin then use 2 */
|
/* Use pin number not mask, for example if using the PA5 pin then use 2 */
|
||||||
printf("return configure, %d \n", pm10.configure(SENSORS_ACTIVE, ADC_PIN));
|
pm10.configure(SENSORS_ACTIVE, ADC_PIN);
|
||||||
|
|
||||||
/* And periodically poll the sensor */
|
/* And periodically poll the sensor */
|
||||||
|
|
||||||
|
@ -79,8 +77,8 @@ PROCESS_THREAD(test_pm10_sensor_process, ev, data)
|
||||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||||
|
|
||||||
leds_toggle(LEDS_GREEN);
|
leds_toggle(LEDS_GREEN);
|
||||||
printf("PM10 value\n");
|
|
||||||
pm10_value = pm10.value(1);
|
pm10_value = pm10.value(1);
|
||||||
|
|
||||||
if(pm10_value != ADC_WRAPPER_ERROR) {
|
if(pm10_value != ADC_WRAPPER_ERROR) {
|
||||||
printf("PM10 value = %u ppm\n", pm10_value);
|
printf("PM10 value = %u ppm\n", pm10_value);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -49,52 +49,54 @@
|
||||||
#include "dev/gpio.h"
|
#include "dev/gpio.h"
|
||||||
#include "dev/ioc.h"
|
#include "dev/ioc.h"
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
#define PM10_SENSOR_PORT_BASE GPIO_PORT_TO_BASE(PM10_SENSOR_CTRL_PORT)
|
||||||
|
#define PM10_SENSOR_PIN_MASK GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN)
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
static uint8_t enabled;
|
static uint8_t enabled;
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
#ifdef PM10_SENSOR_CONF_CTRL_PIN
|
|
||||||
#define PM10_SENSOR_CTRL_PIN PM10_SENSOR_CONF_CTRL_PIN
|
|
||||||
#else
|
|
||||||
#define PM10_SENSOR_CTRL_PIN 0x07
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define PM10_SENSOR_PORT GPIO_A_BASE
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
configure(int type, int value)
|
configure(int type, int value)
|
||||||
{
|
{
|
||||||
int error;
|
|
||||||
if(type != SENSORS_ACTIVE) {
|
if(type != SENSORS_ACTIVE) {
|
||||||
return PM10_ERROR;
|
return PM10_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Set PA7 as output, used as pulse-driven wave*/
|
if(value) {
|
||||||
ioc_set_over(PM10_SENSOR_PORT, PM10_SENSOR_CTRL_PIN, IOC_OVERRIDE_DIS);
|
/* Set as output, used as pulse-driven wave */
|
||||||
GPIO_SOFTWARE_CONTROL(PM10_SENSOR_PORT, GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN));
|
GPIO_SOFTWARE_CONTROL(PM10_SENSOR_PORT_BASE, PM10_SENSOR_PIN_MASK);
|
||||||
GPIO_SET_OUTPUT(PM10_SENSOR_PORT, GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN));
|
ioc_set_over(PM10_SENSOR_CTRL_PORT, PM10_SENSOR_CTRL_PIN, IOC_OVERRIDE_DIS);
|
||||||
|
GPIO_SET_OUTPUT(PM10_SENSOR_PORT_BASE, PM10_SENSOR_PIN_MASK);
|
||||||
|
GPIO_CLR_PIN(PM10_SENSOR_PORT_BASE, PM10_SENSOR_PIN_MASK);
|
||||||
|
|
||||||
GPIO_CLR_PIN(PM10_SENSOR_PORT, GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN));
|
enabled = 1;
|
||||||
|
return adc_sensors.configure(ANALOG_PM10_SENSOR, value);
|
||||||
|
}
|
||||||
|
|
||||||
/* Use pin number not mask, for example if using the PA5 pin then use 5 */
|
enabled = 0;
|
||||||
error = adc_sensors.configure(ANALOG_PM10_SENSOR, value);
|
return PM10_SUCCESS;
|
||||||
|
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int
|
||||||
value(int type)
|
value(int type)
|
||||||
{
|
{
|
||||||
uint16_t val;
|
uint16_t val;
|
||||||
/*Set Pulse Wave pin before measure*/
|
|
||||||
GPIO_SET_PIN(PM10_SENSOR_PORT, GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN));
|
if(!enabled) {
|
||||||
/*Pulse wave delay*/
|
return PM10_ERROR;
|
||||||
clock_delay_usec(280);
|
}
|
||||||
/*Data acquisition*/
|
|
||||||
|
/* Set Pulse Wave pin before measure */
|
||||||
|
GPIO_SET_PIN(PM10_SENSOR_PORT_BASE, PM10_SENSOR_PIN_MASK);
|
||||||
|
/* Pulse wave delay */
|
||||||
|
clock_delay_usec(PM10_SENSOR_PULSE_DELAY);
|
||||||
|
/* Data acquisition */
|
||||||
val = adc_sensors.value(ANALOG_PM10_SENSOR);
|
val = adc_sensors.value(ANALOG_PM10_SENSOR);
|
||||||
/*Clear pulse wave pin*/
|
/* Clear pulse wave pin */
|
||||||
GPIO_CLR_PIN(PM10_SENSOR_PORT, GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN));
|
GPIO_CLR_PIN(PM10_SENSOR_PORT_BASE, PM10_SENSOR_PIN_MASK);
|
||||||
|
|
||||||
/*Applied constant conversion from UAir project*/
|
/* Applied constant conversion from UAir project
|
||||||
/*to obtain value in ppm (value in mV * 0.28)*/
|
* to obtain value in ppm (value in mV * 0.28)
|
||||||
|
*/
|
||||||
val *= 28;
|
val *= 28;
|
||||||
val /= 1000;
|
val /= 1000;
|
||||||
|
|
||||||
|
|
|
@ -43,17 +43,29 @@
|
||||||
*/
|
*/
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
#include "lib/sensors.h"
|
#include "lib/sensors.h"
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
#ifndef PM10_SENSOR_H_
|
#ifndef PM10_SENSOR_H_
|
||||||
#define PM10_SENSOR_H_
|
#define PM10_SENSOR_H_
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
#define PM10_ERROR -1
|
#define PM10_ERROR (-1)
|
||||||
#define PM10_SENSOR "PM10 Sensor"
|
#define PM10_SUCCESS 0
|
||||||
|
#define PM10_SENSOR "PM10 Sensor"
|
||||||
|
#define PM10_SENSOR_PULSE_DELAY 280
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
#ifdef PM10_SENSOR_CONF_CTRL_PIN
|
||||||
|
#define PM10_SENSOR_CTRL_PIN PM10_SENSOR_CONF_CTRL_PIN
|
||||||
|
#else
|
||||||
|
#define PM10_SENSOR_CTRL_PIN 7
|
||||||
|
#endif
|
||||||
|
#ifdef PM10_SENSOR_CONF_CTRL_PORT
|
||||||
|
#define PM10_SENSOR_CTRL_PORT PM10_SENSOR_CONF_CTRL_PORT
|
||||||
|
#else
|
||||||
|
#define PM10_SENSOR_CTRL_PORT GPIO_A_NUM
|
||||||
|
#endif
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
extern const struct sensors_sensor pm10;
|
extern const struct sensors_sensor pm10;
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
#endif /* ifndef VAC_SENSOR_H_ */
|
#endif /* ifndef PM10_SENSOR_H_ */
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
* @}
|
* @}
|
||||||
|
|
Loading…
Reference in a new issue