⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 accelerometer.h

📁 基于MMA7260QR2的跌落检查程序
💻 H
字号:
/************************************************************************************
* Accelerometer Header File 
*
* Author(s):  $B03847
*
* (c) Copyright 2008, Freescale, Inc.  All rights reserved.
*
* No part of this document must be reproduced in any form - including copied,
* transcribed, printed or by any electronic means - without specific written
* permission from Freescale.
*
* Last Inspected: 05/16/2008
* Last Tested: 
************************************************************************************/
 
 
/* This file contain the features to be included within SMAC platform*/
 
#ifndef __SMAC_ACCELEROMETER_H__
#define __SMAC_ACCELEROMETER_H__
 
/* includes */
#include "PC_Radio.h"

 typedef struct {
   uint8_t NxOff;
   uint8_t NxMax;
   uint8_t NyOff;
   uint8_t NyMax;
   uint8_t NzOff;
   uint8_t NzMax;
   uint8_t FlashCounter;
} tAccelCal;

/* Accelometer Externs Functions Prototypes */
extern void ResetMaca(void);

/* Accelerometer Aplications Prototypes */

/*******************************************************************************
* This is the callback function when a valid packet has been received
* by the radio.
*
* Interface assumptions: None 
*
* Routine limitations. It is not recommended to call other radio functions here.
*
* Return value: void.
*
* Effects on global data: set gbDataIndicationFlag to TRUE
*
* Source of algorithm used:
*
* Revison history:
*   date      Author    Comments
*   ------    ------    --------
*   
*******************************************************************************/
void accelerometer_rx_cb (void);

/*******************************************************************************
* This function init the Accelerometer demo interface.
*
* Interface assumptions: None 
*
* Routine limitations. 
*
* Return value: void.
*
* Effects on global data: Initialize app states and set calibration values.
*
* Source of algorithm used:
*
* Revison history:
*   date      Author    Comments
*   ------    ------    --------
*   
*******************************************************************************/
void AppInit(void);

/*******************************************************************************
* This function sends an App Packet to the PC_Radio to tell the PC Radio 
* that an event has occured.
*
* Interface assumptions: None
*
* Routine limitations. 
*
* Return value: void.
*
* Effects on global data: Modify the transmission message to send
*
* Source of algorithm used:
*
* Revison history:
*   date      Author    Comments
*   ------    ------    --------
*   
*******************************************************************************/
void appEventPacket(uint8_t options, uint8_t retries);

/*******************************************************************************
* This function sends a ping packet to the PC_Radio.
*
* Interface assumptions: None
*
* Routine limitations. 
*
* Return value: void.
*
* Effects on global data: Modify the transmission message to send it every 
* ~2 seconds
*
* Source of algorithm used:
*
* Revison history:
*   date      Author    Comments
*   ------    ------    --------
*   
*******************************************************************************/
void pingPacket(uint16_t, uint8_t);

/*******************************************************************************
* This function Performs x,y,z measurements compensated.
*
* Interface assumptions: None
*
* Routine limitations. 
*
* Return value: void.
*
* Effects on global data: Save the new compensated measurement 
*
* Source of algorithm used:
*
* Revison history:
*   date      Author    Comments
*   ------    ------    --------
*   
*******************************************************************************/
void doAccelMeasurement(uint8_t axis);

/*******************************************************************************
* This function Performs x,y,z measurements without compensation.
*
* Interface assumptions: None
*
* Routine limitations. 
*
* Return value: void.
*
* Effects on global data: Save the new measurement with no compensation 
*
* Source of algorithm used:
*
* Revison history:
*   date      Author    Comments
*   ------    ------    --------
*   
*******************************************************************************/
void doAccelMeasurementNoCompensation(uint8_t axis);

/*******************************************************************************
* This function Performs a comparation between the last measurement value and 
* the current measurement value
*
* Interface assumptions: None
*
* Routine limitations. 
*
* Return value: uint8_t.
*
* Effects on global data:  
*
* Source of algorithm used:
*
* Revison history:
*   date      Author    Comments
*   ------    ------    --------
*   
*******************************************************************************/
uint8_t	compareADCReading (uint8_t, uint8_t, uint8_t);

/*******************************************************************************
* This application detects the changes in X, Y and Z Axis from the 
* accelerometer, an update the App package that will be send to the PC_Radio.
*
* Interface assumptions: None
*
* Routine limitations. 
*
* Return value: void.
*
* Effects on global data: Modify the trassmision data buffer. 
*
* Source of algorithm used:
*
* Revison history:
*   date      Author    Comments
*   ------    ------    --------
*   
*******************************************************************************/
void TxAccel(void);

/*******************************************************************************
* This application detects a freefall condition.
*
* Interface assumptions: None
*
* Routine limitations. 
*
* Return value: void.
*
* Effects on global data: Modify the trassmision data buffer. 
*
* Source of algorithm used:
*
* Revison history:
*   date      Author    Comments
*   ------    ------    --------
*   
*******************************************************************************/
void freefall_app(void);

/*******************************************************************************
*  This application chirps LED3:
*     - once for x movement.
*     - twice for y movement.
*     - thrice for z movement.
*
* Interface assumptions: None
*
* Routine limitations. 
*
* Return value: void.
*
* Effects on global data: Modify the trassmision data buffer. 
*
* Source of algorithm used:
*
* Revison history:
*   date      Author    Comments
*   ------    ------    --------
*   
*******************************************************************************/
void shockDetect_app(void);

/*******************************************************************************
*  This application detects a tilt condition and 
*  Turn on LED3 while the tilt condition exists.
*
* Interface assumptions: None
*
* Routine limitations. 
*
* Return value: void.
*
* Effects on global data: Modify the trassmision data buffer. 
*
* Source of algorithm used:
*
* Revison history:
*   date      Author    Comments
*   ------    ------    --------
*   
*******************************************************************************/
void antiTheft_app(void);

/*******************************************************************************
*  If the remote accel board is still for more than 5 seconds
*  without movement the PC_radio board will turn off LED3 and 
*  blink the accel LEDs.
*
* Interface assumptions: None
*
* Routine limitations. 
*
* Return value: void.
*
* Effects on global data: Modify the trassmision data buffer. 
*
* Source of algorithm used:
*
* Revison history:
*   date      Author    Comments
*   ------    ------    --------
*   
*******************************************************************************/
void batterySave_app(void);

/*******************************************************************************
*  This is the callback function for when a valid packet has been
*  decoded by the radio.  The valid packet is passed to the app
*  via this MCPS_data_indication callback function.  All the data
*  resides in the RX_msg.
*
* Interface assumptions: None
*
* Routine limitations. It is not recommended to call other radio functions here.
*
* Return value: void.
*
* Effects on global data:
*
* Source of algorithm used:
*
* Revison history:
*   date      Author    Comments
*   ------    ------    --------
*   
*******************************************************************************/
void data_indication_execute(void);

/*******************************************************************************
*  This function calculate the new calibration values
*  of the accelerometer demo application.
*
* Interface assumptions: None
*
* Routine limitations. 
*
* Return value: void.
*
* Effects on global data: set in RAM the new calibration values
*                         of the accelerometer demo application.
*
* Source of algorithm used:
*
* Revison history:
*   date      Author    Comments
*   ------    ------    --------
*   
*******************************************************************************/
void calibration_app(void);

/*******************************************************************************
* This is the SW4 interrupt.
*
* Interface assumptions: None
*
* Routine limitations. 
*
* Return value: void.
*
* Effects on global data: SW4 Interrupt Event is set
*
* Source of algorithm used:
*
* Revison history:
*   date      Author    Comments
*   ------    ------    --------
*   
*******************************************************************************/
void calibration_app_isr(void);

/* Accelerometer Setup Functions Prototypes */

/*******************************************************************************
* This function setup the Accelerometer
*
* Interface assumptions: None
*
* Routine limitations. 
*
* Return value: void.
*
* Effects on global data: 
*
* Source of algorithm used:
*
* Revison history:
*   date      Author    Comments
*   ------    ------    --------
*   
*******************************************************************************/
void SetupAccelerometer(void);

/*******************************************************************************
* This function change the application state to set in the 
* next application.
*
* Interface assumptions: None
*
* Routine limitations. 
*
* Return value: void.
*
* Effects on global data: 
*
* Source of algorithm used:
*
* Revison history:
*   date      Author    Comments
*   ------    ------    --------
*   
*******************************************************************************/
void increase_App(void);

/*******************************************************************************
* This is the SW1 interrupt.
*
* Interface assumptions: None
*
* Routine limitations. 
*
* Return value: void.
*
* Effects on global data: SW1 Interrupt Event is set
*
* Source of algorithm used:
*
* Revison history:
*   date      Author    Comments
*   ------    ------    --------
*   
*******************************************************************************/
void increase_AppState_isr(void);

/*******************************************************************************
* This function is using for change the operating channel.
*
* Interface assumptions: None
*
* Routine limitations. 
*
* Return value: void.
*
* Effects on global data: 
*
* Source of algorithm used:
*
* Revison history:
*   date      Author    Comments
*   ------    ------    --------
*   
*******************************************************************************/
void increase_channel(void);

/*******************************************************************************
* This is the SW2 interrupt.
*
* Interface assumptions: None
*
* Routine limitations. 
*
* Return value: void.
*
* Effects on global data: SW2 Interrupt Event is set
*
* Source of algorithm used:
*
* Revison history:
*   date      Author    Comments
*   ------    ------    --------
*   
*******************************************************************************/
void increase_channel_isr(void);

/*******************************************************************************
* This is the Timer0 interrupt.
*
* Interface assumptions: None
*
* Routine limitations. 
*
* Return value: void.
*
* Effects on global data: Timer Interrupt Event is set
*
* Source of algorithm used:
*
* Revison history:
*   date      Author    Comments
*   ------    ------    --------
*   
*******************************************************************************/
void Tmr_Isr(TmrNumber_t tmrNumber);

/*******************************************************************************
* This is the Timer1 interrupt.
*
* Interface assumptions: None
*
* Routine limitations. 
*
* Return value: void.
*
* Effects on global data: Timer Interrupt Event is set to sound the buzzer
*
* Source of algorithm used:
*
* Revison history:
*   date      Author    Comments
*   ------    ------    --------
*   
*******************************************************************************/
void Tmr1_Isr(TmrNumber_t tmrNumber);

/* Defines 
*/

#define MAX_ADC_VALUE     (220)
#define MIN_ADC_VALUE      (33)
#define COMPENSATED_VALUE (128)

#define SW1_EVENT     (0x10)
#define SW2_EVENT     (0x20)
#define SW4_EVENT     (0x40)
#define TIMER_EVENT   (0x80)

/* Ping Packet Options */
#define PING_NO_OPTIONS             (0x00)
#define PING_FREEFALL               (0x02)
#define PING_BATTERYSAVE_BUZZER_OFF (0x03)
#define PING_BATTERYSAVE_BUZZER_ON  (0x04)
#define PING_ANTITHEFT              (0x05)
#define PING_SHOCKDETECT            (0x06)

#endif /* __SMAC_APP_CONFIG_H__ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -