Common Sensor Service Proximity Sensor Gesture Recognition Example.
Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.
#include <stdio.h>
#include <asf.h>
#include <led.h>
Macros | |
#define | CHAN_1 0x01 |
#define | CHAN_2 0x02 |
#define | CHAN_3 0x04 |
#define | CHAN_NONE 0x00 |
#define | DOWN_LED LED1 |
#define | ERR_BLINK_COUNT (2) /* Number of times to blink LEDs on error */ |
#define | LEFT_LED LED2 |
#define | PROX_CURRENT_mA (150) /* Current for proximity sensor LEDs (mA) */ |
#define | PROX_SAMPLE_RATE (100) /* Proximity sensor sample rate (Hz) */ |
#define | PROX_THRESHOLD (100) /* Manual prox sensor threshold for "near" */ |
#define | RIGHT_LED LED3 |
#define | SET_PROX_CURRENT (true) /* If true, manually set proximity current */ |
#define | SET_PROX_THRESHOLD |
#define | UP_LED LED0 |
#define | USE_PRINTF |
Enumerations | |
enum | direction_t { UNK = 0, UP = 1, DOWN = 2, LEFT = 3, RIGHT = 4 } |
Direction code values. More... | |
Functions | |
int | main (void) |
Proximity Sensor gesture recognition demo application entry. More... | |
static void | prox_event_handler (volatile sensor_event_data_t *event_data, volatile void *arg) |
Proximity event handler. More... | |
static int8_t | test_channels (sensor_data_t *data) |
Proximity value test. More... | |
Variables | |
static const char *const | channel_labels [8] |
Strings to indicate which channels detected proximity. More... | |
direction_t | dir_tbl [8][8] |
Direction lookup table of start_channels (rows) x end_channels (columns) More... | |
static const char *const | direction_labels [5] |
Strings to display based on gesture direction. More... | |
sensor_data_t | prox_data = { .scaled = true } |
sensor_t | prox_dev |
bool | prox_event_occurred = false |
#define CHAN_1 0x01 |
Referenced by test_channels().
#define CHAN_2 0x02 |
Referenced by test_channels().
#define CHAN_3 0x04 |
Referenced by test_channels().
#define CHAN_NONE 0x00 |
Referenced by main(), and test_channels().
#define DOWN_LED LED1 |
Referenced by main().
#define ERR_BLINK_COUNT (2) /* Number of times to blink LEDs on error */ |
Referenced by main().
#define LEFT_LED LED2 |
Referenced by main().
#define PROX_CURRENT_mA (150) /* Current for proximity sensor LEDs (mA) */ |
Referenced by main().
#define PROX_SAMPLE_RATE (100) /* Proximity sensor sample rate (Hz) */ |
Referenced by main().
#define PROX_THRESHOLD (100) /* Manual prox sensor threshold for "near" */ |
Referenced by main().
#define RIGHT_LED LED3 |
Referenced by main().
#define SET_PROX_THRESHOLD |
#define UP_LED LED0 |
Referenced by main().
#define USE_PRINTF |
enum direction_t |
int main | ( | void | ) |
Proximity Sensor gesture recognition demo application entry.
This application uses a 3-channel proximity sensor to recognize simple gestures. When a proximity event occurs, the routine will wake up from a low-power sleep mode and begin repeatedly sampling the proximity sensor, until the proximity of the object is no longer detected. Then the beginning and ending sensor readings are compared, and the overall direction of the object's movement is determined based on a lookup table.
Once the direction is determined, it is indicate by turning on one of the LEDs on the controller board and (optionally) by serial output to a terminal device. If the direction cannot be determined, all indicator LEDs will be blinked rapidly.
The application then resets by returning to a low-power sleep mode until the next proximity event is detected.
References sensor_device_t::caps, CHAN_NONE, channel_labels, delay_ms, dir_tbl, direction_labels, DOWN, DOWN_LED, sensor_desc::drv, sensor_desc::err, ERR_BLINK_COUNT, LEFT, LEFT_LED, sensor_caps_t::name, PROX_CURRENT_mA, prox_event_handler(), prox_event_occurred, PROX_SAMPLE_RATE, PROX_THRESHOLD, RIGHT, RIGHT_LED, sensor_add_event(), sensor_attach(), SENSOR_CHANNEL_ALL, sensor_device_id(), sensor_disable_event(), sensor_enable_event(), SENSOR_EVENT_NEAR_PROXIMITY, 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_PROXIMITY, sleepmgr_enter_sleep(), sleepmgr_init(), sleepmgr_lock_mode(), test_channels(), UP, and UP_LED.
|
static |
Proximity event handler.
This routine will be called when a near-proximity event occurs. It simply copies the proximity data to the sensor_data_t structure specified during the sensor_add_event function call.
This routine executes as part of the interrupt service routine for the sensor interrupt.
References sensor_event_data_t::data, and prox_event_occurred.
Referenced by main().
|
static |
Proximity value test.
This routine examines the data fields in the sensor_data_t structure and returns a single value summarizing which channels have a reported proximity value (i.e. the value is not PROXIMITY_NONE).
data | Address of sensor_data_t struct containing prox data |
References CHAN_1, CHAN_2, CHAN_3, CHAN_NONE, sensor_data_t::proximity, and PROXIMITY_NONE.
Referenced by main().
|
static |
Strings to indicate which channels detected proximity.
Referenced by main().
direction_t dir_tbl[8][8] |
Direction lookup table of start_channels (rows) x end_channels (columns)
Referenced by main().
|
static |
Strings to display based on gesture direction.
Referenced by main().
sensor_data_t prox_data = { .scaled = true } |
Referenced by main(), and sfh7770_calibrate().
Referenced by main(), prox_event(), and prox_event_handler().