Minor fixes

This commit is contained in:
Antonio Lignan 2016-01-25 22:58:06 +01:00
parent 31e6cc48ca
commit 8337843d69
3 changed files with 48 additions and 36 deletions

View File

@ -64,13 +64,11 @@ static struct etimer et;
PROCESS_THREAD(test_pm10_sensor_process, ev, data)
{
PROCESS_BEGIN();
SENSORS_ACTIVATE(pm10);
static uint16_t pm10_value;
/* Configure the ADC ports */
/* 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 */
@ -79,8 +77,8 @@ PROCESS_THREAD(test_pm10_sensor_process, ev, data)
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
leds_toggle(LEDS_GREEN);
printf("PM10 value\n");
pm10_value = pm10.value(1);
if(pm10_value != ADC_WRAPPER_ERROR) {
printf("PM10 value = %u ppm\n", pm10_value);
} else {

View File

@ -49,52 +49,54 @@
#include "dev/gpio.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;
/*---------------------------------------------------------------------------*/
#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
configure(int type, int value)
{
int error;
if(type != SENSORS_ACTIVE) {
return PM10_ERROR;
}
/*Set PA7 as output, used as pulse-driven wave*/
ioc_set_over(PM10_SENSOR_PORT, PM10_SENSOR_CTRL_PIN, IOC_OVERRIDE_DIS);
GPIO_SOFTWARE_CONTROL(PM10_SENSOR_PORT, GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN));
GPIO_SET_OUTPUT(PM10_SENSOR_PORT, GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN));
if(value) {
/* Set as output, used as pulse-driven wave */
GPIO_SOFTWARE_CONTROL(PM10_SENSOR_PORT_BASE, PM10_SENSOR_PIN_MASK);
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 */
error = adc_sensors.configure(ANALOG_PM10_SENSOR, value);
return error;
enabled = 0;
return PM10_SUCCESS;
}
/*---------------------------------------------------------------------------*/
static int
value(int type)
{
uint16_t val;
/*Set Pulse Wave pin before measure*/
GPIO_SET_PIN(PM10_SENSOR_PORT, GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN));
/*Pulse wave delay*/
clock_delay_usec(280);
/*Data acquisition*/
if(!enabled) {
return PM10_ERROR;
}
/* 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);
/*Clear pulse wave pin*/
GPIO_CLR_PIN(PM10_SENSOR_PORT, GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN));
/* Clear pulse wave pin */
GPIO_CLR_PIN(PM10_SENSOR_PORT_BASE, PM10_SENSOR_PIN_MASK);
/*Applied constant conversion from UAir project*/
/*to obtain value in ppm (value in mV * 0.28)*/
/* Applied constant conversion from UAir project
* to obtain value in ppm (value in mV * 0.28)
*/
val *= 28;
val /= 1000;

View File

@ -43,17 +43,29 @@
*/
/*---------------------------------------------------------------------------*/
#include "lib/sensors.h"
/*---------------------------------------------------------------------------*/
#ifndef PM10_SENSOR_H_
#define PM10_SENSOR_H_
/* -------------------------------------------------------------------------- */
#define PM10_ERROR -1
#define PM10_SENSOR "PM10 Sensor"
#define PM10_ERROR (-1)
#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;
/* -------------------------------------------------------------------------- */
#endif /* ifndef VAC_SENSOR_H_ */
#endif /* ifndef PM10_SENSOR_H_ */
/**
* @}
* @}