Microchip® Advanced Software Framework

common/applications/sensors/lightprox_visualizer/main.c File Reference

Common Sensor Service Light and Proximity Sensor Example.

Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.

#include <asf.h>
#include <led.h>
#include "data_visualizer.h"

Macros

#define ALL_LEDS   (LED1 | LED2 | LED3 | LED4)
 
#define LIGHT_SAMPLE_RATE   (10) /* Light sensor sample rate (Hz) */
 
#define LIGHT_STREAM_NUM   1 /* Light Sensor data stream number */
 
#define NUM_BLINK_LEDS   (LED_COUNT - 1) /* Don't blink LED0 (shared gpio) */
 
#define NUM_LIGHT_FIELDS   1 /* Light Sensor data fields in data pkt */
 
#define NUM_PROX_FIELDS   3 /* Prox Sensor data fields in data pkt */
 
#define NUM_PROX_THRESHOLD_FIELDS   3 /* Prox threshold data fields in data pkt */
 
#define PROMPT_LED   LED4 /* Blink while waiting for user input */
 
#define PROX_CURRENT_mA   (50) /* Prox sensor LED current value (mA) */
 
#define PROX_SAMPLE_RATE   (100) /* Proximity sensor sample rate (Hz) */
 
#define PROX_STREAM_NUM   2 /* Prox Sensor data stream number */
 
#define PROX_THRESHOLD   (100) /* Manual prox sensor threshold for"near" */
 
#define PROX_THRESHOLD_STREAM_NUM   3 /* Prox threshold data stream number */
 
#define SCALED_DATA
 
#define SET_PROX_CURRENT   (true) /* If true, manually set proximity current */
 
#define SET_PROX_THRESHOLD
 
#define SWITCH_PRESSED   gpio_pin_is_low(GPIO_PUSH_BUTTON_0)
 
#define TIMESTAMP_RES   1000000 /* Timestamp resolution (1 per usec) */
 

Functions

int main (void)
 Inertial sensor demo application entry. More...
 
static void visual_stream_init (void)
 Initialize sensor data output streams for Atmel Data Visualizer. More...
 

Variables

static const uint32_t led_array [LED_COUNT-1] = {LED1, LED2, LED3, LED4}
 
static const char *const prox_labels [4]
 Strings to display based on proximity values. More...
 

#define ALL_LEDS   (LED1 | LED2 | LED3 | LED4)

Referenced by main().

#define LIGHT_SAMPLE_RATE   (10) /* Light sensor sample rate (Hz) */

Referenced by main().

#define LIGHT_STREAM_NUM   1 /* Light Sensor data stream number */

Referenced by main(), and visual_stream_init().

#define NUM_BLINK_LEDS   (LED_COUNT - 1) /* Don't blink LED0 (shared gpio) */
#define NUM_LIGHT_FIELDS   1 /* Light Sensor data fields in data pkt */

Referenced by visual_stream_init().

#define NUM_PROX_FIELDS   3 /* Prox Sensor data fields in data pkt */

Referenced by visual_stream_init().

#define NUM_PROX_THRESHOLD_FIELDS   3 /* Prox threshold data fields in data pkt */

Referenced by visual_stream_init().

#define PROMPT_LED   LED4 /* Blink while waiting for user input */

Referenced by main().

#define PROX_CURRENT_mA   (50) /* Prox sensor LED current value (mA) */

Referenced by main().

#define PROX_SAMPLE_RATE   (100) /* Proximity sensor sample rate (Hz) */

Referenced by main().

#define PROX_STREAM_NUM   2 /* Prox Sensor data stream number */

Referenced by main(), and visual_stream_init().

#define PROX_THRESHOLD   (100) /* Manual prox sensor threshold for"near" */

Referenced by main().

#define PROX_THRESHOLD_STREAM_NUM   3 /* Prox threshold data stream number */

Referenced by main(), and visual_stream_init().

#define SCALED_DATA
Value:
(true) /* If true, convert sensor data to std.
* units */

Referenced by main().

#define SET_PROX_CURRENT   (true) /* If true, manually set proximity current */
#define SET_PROX_THRESHOLD
Value:
(true) /* If true, manually set proximity
* threshold */
#define SWITCH_PRESSED   gpio_pin_is_low(GPIO_PUSH_BUTTON_0)

Referenced by main().

#define TIMESTAMP_RES   1000000 /* Timestamp resolution (1 per usec) */

Referenced by visual_stream_init().

int main ( void  )

Inertial sensor demo application entry.

After initializing the Xplained platform and sensor boards, this application attaches descriptors to the accelerometer, gyroscope, and compass devices on an Xplained inertial sensor board. The sensor data, which is formatted and printed via printf() after being read, can be viewed with a serial terminal application on a machine attached to the USB interface on the Xplained board.

References adv_data_send_1(), adv_data_send_3(), ALL_LEDS, delay_ms, sensor_desc::err, sensor_data_t::light, light_data, light_dev, LIGHT_SAMPLE_RATE, LIGHT_STREAM_NUM, PROMPT_LED, PROX_CURRENT_mA, prox_data, prox_dev, PROX_SAMPLE_RATE, PROX_STREAM_NUM, PROX_THRESHOLD, PROX_THRESHOLD_STREAM_NUM, sensor_data_t::proximity, sensor_data_t::scaled, SCALED_DATA, sensor_attach(), SENSOR_CHANNEL_ALL, sensor_get_light(), sensor_get_proximity(), sensor_platform_init(), sensor_set_channel(), sensor_set_current(), sensor_set_sample_rate(), sensor_set_threshold(), SENSOR_THRESHOLD_NEAR_PROXIMITY, SENSOR_TYPE_LIGHT, SENSOR_TYPE_PROXIMITY, SWITCH_PRESSED, sensor_data_t::timestamp, and visual_stream_init().

static void visual_stream_init ( void  )
static

Initialize sensor data output streams for Atmel Data Visualizer.

This routine initializes the data streams used in this application for the Atmel Data Visualizer (ADV) tool. First, a start-of-configuration packet is constructed and sent. Next, each data stream is described with a stream descriptor packet and either one or three field descriptor packets (depending on how many data fields are used to report a single set of data from that device). After all streams and data fields have been described, an end-of-configuration packet is sent.

References adv_config_start_t, ADV_PKT_CONFIG_END, ADV_PKT_CONFIG_FIELD, ADV_PKT_CONFIG_START, ADV_PKT_CONFIG_STREAM, ADV_PKT_END, ADV_PKT_HEADER_1, ADV_PKT_HEADER_2, cpu_to_le16, cpu_to_le32, adv_config_stream_t::crc, adv_config_field_t::crc, adv_config_end_t::crc, FIELD_FORMAT_SIGNED, adv_config_field_t::field_length, adv_config_field_t::field_num, adv_config_field_t::format, adv_config_stream_t::header1, adv_config_field_t::header1, adv_config_end_t::header1, adv_config_stream_t::header2, adv_config_field_t::header2, adv_config_end_t::header2, adv_config_stream_t::length, adv_config_field_t::length, adv_config_end_t::length, LIGHT_STREAM_NUM, adv_config_stream_t::mark, adv_config_field_t::mark, adv_config_end_t::mark, adv_config_field_t::max, adv_config_field_t::min, adv_config_field_t::name, adv_config_stream_t::num_fields, NUM_LIGHT_FIELDS, NUM_PROX_FIELDS, NUM_PROX_THRESHOLD_FIELDS, adv_config_end_t::num_streams, PROX_STREAM_NUM, PROX_THRESHOLD_STREAM_NUM, adv_config_stream_t::stream_name, adv_config_stream_t::stream_num, adv_config_field_t::stream_num, adv_config_stream_t::tick_res, TIMESTAMP_RES, adv_config_stream_t::type, adv_config_field_t::type, adv_config_end_t::type, and adv_config_field_t::units.

Referenced by main().

const uint32_t led_array[LED_COUNT-1] = {LED1, LED2, LED3, LED4}
static
const char* const prox_labels[4]
static
Initial value:
= {
"none ",
"far ",
"medium",
"close "
}

Strings to display based on proximity values.