8 Handling sensor events
In addition to reporting measurements on demand, most sensor devices provide
some mechanism to continuously monitor their physical surroundings and generate
an externally visible event when certain criteria are met or internal conditions occur.
The Atmel Sensors Xplained software provides support for handling these
asynchronous events in a consistent manner across different sensor devices.
A sensor device announces an event by changing the level of a specific output pin.
Each sensor device output pin is connected to an input pin on the Atmel AVR
microcontroller. These connections are part of the hardware configuration information
that the Sensors Xplained configuration automatically establishes for the specific
sensor board and processor board combination. The AVR microcontroller input pin is
then used to generate an interrupt when the level changes. The event support in the
Sensors Xplained software allows your application to set up and enable an
appropriate handler generically, without requiring specific references to the actual pin
or interrupt source that is being used.
Once it has been set up and enabled, the event handler routine in your application will
be called whenever the specified sensor event occurs. Your handler routine can then
perform any appropriate action, such as changing the overall state of the application,
processing new sensor data, providing an indication to the user, etc.
8.1 Adding an event handler
A sensor event handler is added by using the sensor_add_event() function. This
function takes a single input parameter, the address of a sensor_event_desc_t
event descriptor structure.
The sensor_event_desc_t structure contains various fields that specify the event
handling behavior, including:
? the sensor_t descriptor of the sensor which will generate the event
? the type(s) of event to detect – to use a common handler for multiple events,
specify the logical OR of multiple event types
? the address of the handler routine
? an argument to the handler routine (typically, the address of the sensor_data_t
structure)
? whether sensor data from the event should be in scaled units or raw values
? whether the event is initially enabled or disabled
8.2 The event handler routine
The event handler routine is created as part of your application. This handler will be
called when the corresponding sensor event occurs, after the sensor device driver
has performed any necessary internal event servicing.
An event handler takes the following form:
void handler_name (volatile void * in);
The handler routine takes a single input parameter, a void * . This parameter is
actually the address of the sensor_event_desc_t structure that was used when
adding the event to the system. Within the sensor_event_desc_t structure, the data
22
Atmel AVR4016
8367B-AVR-06/11
相关PDF资料
ATAVRSBIN2 INERTIAL TWO SENSOR BOARD
ATAVRSBLP1 LIGHT AND PROXIMITY SENSOR BOARD
ATAVRSBPR1 BAROMETRIC PRESSURE ONE SNSR BRD
ATQT600 KIT EVAL TOUCH FOR QT600
ATU6-P305T-R CABLE CAT6 FULL-BOX 305M GRAY
ATUP-P305T-R CABLE CAT5E PULL-BOX 305M GRAY
ATUP-V305T-R CABLE CAT5E REEL 305M GRAY
AWG28-05/F-1/300-R CABLE 5 COND MULTI 300' RIBBON
相关代理商/技术参数
ATAVRSBIN2 功能描述:多功能传感器开发工具 9DOF Inertial Sensor Board 2 RoHS:否 制造商:Texas Instruments 工具用于评估:LMP91200 接口类型:SPI 工作电压:1.8 V to 5.5 V 最大工作温度:
ATAVRSBLP1 功能描述:光学传感器开发工具 Ambient Light and Proximity Snsr Brd RoHS:否 制造商:ams 工具用于评估: 接口类型: 最大工作温度:
ATAVRSBPR1 功能描述:压力传感器开发工具 Barometric Pressure Sensor Board 1 RoHS:否 制造商:Freescale Semiconductor 工具用于评估:MPL3115A2 接口类型:USB 最大工作温度:
ATAVRSECURITYX 功能描述:安全/ 验证开发工具 Security Module Kit for Xplain Series RoHS:否 制造商:Digi International 产品:Development Kits 工具用于评估:XEB-AW140 接口类型:SPI, USB 工作电源电压:3.1 V to 3.6 V
ATAVRSMD 功能描述:ADAPTER KIT SMD ICE200 RoHS:否 类别:编程器,开发系统 >> 过时/停产零件编号 系列:- 标准包装:1 系列:- 类型:MCU 适用于相关产品:Freescale MC68HC908LJ/LK(80-QFP ZIF 插口) 所含物品:面板、缆线、软件、数据表和用户手册 其它名称:520-1035
ATAVR-SOAKIT 功能描述:插座和适配器 Standoff Adapter Kit for JTAG debuggers RoHS:否 制造商:Silicon Labs 产品:Adapter 用于:EM35x
ATAVRTEMPSENSORX 功能描述:温度传感器开发工具 Temp Sensor kit for Xplain Series RoHS:否 制造商:Texas Instruments 产品类型:Temperature Sensors and Control ICs 工具用于评估:MSP430G2553 接口类型:USB 工作电源电压: 工作电源电流:
ATAVRTS2080A 功能描述:开发板和工具包 - AVR ATmega88 QTouch QTch kit w/SW librar RoHS:否 制造商:Arduino 产品:Evaluation Boards 工具用于评估:ATMega32U4 核心:AVR 接口类型:I2C, UART, USB 工作电源电压:6 V to 20 V