/*
Copyright 2003/2004, Freie Universitaet Berlin. All rights reserved.

These sources were developed at the Freie Universität Berlin, Computer
Systems and Telematics group.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
 
- Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

This software is provided by FUB and the contributors on an "as is"
basis, without any representations or warranties of any kind, express
or implied including, but not limited to, representations or
warranties of non-infringement, merchantability or fitness for a
particular purpose. In no event shall FUB or contributors be liable
for any direct, indirect, incidental, special, exemplary, or
consequential damages (including, but not limited to, procurement of
substitute goods or services; loss of use, data, or profits; or
business interruption) however caused and on any theory of liability,
whether in contract, strict liability, or tort (including negligence
or otherwise) arising in any way out of the use of this software, even
if advised of the possibility of such damage.

This implementation was developed by the CST group at the FUB.
Contributors: Marco Hutta

For documentation and questions please use the web site
http://scatterweb.mi.fu-berlin.de and the mailinglist
scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
Berlin, 2003/2004/2005
*/

#ifndef ScatterWeb_Data
#define ScatterWeb_Data

#include "ScatterWeb.Time.h"

// States of Sensors
#define REDSTATE            (Data_redLed())
#define YELLOWSTATE         (Data_yellowLed())
#define GREENSTATE          (Data_greenLed())

// Bitmasks for the different sensor flags (::sensorFlags)
// movement sensor (on P13) 
#define SENSOR_MOVEMENT     (0x08)
// vibration sensor (on P14)
#define SENSOR_VIBRATION    (0x10)
// button (on P27)
#define SENSOR_BUTTON       (0x80)
// microphone (on P60, see ScatterWeb.HAL.h).
#define SENSOR_MICROPHONE   (0x01)
// temperature sensor (DS1629 or LM71)
#define SENSOR_TEMPERATURE  (0x02)
// RC5 receiving via IR diode
#define SENSOR_RC5          (0x04)
// supply voltage (not implemented, access direct via ScatterWeb.HAL.h)
#define SENSOR_VOLTAGE      (0x40)

typedef struct {
  UINT16 id;        ///< Id of node these readings belong to.
  UINT8 sensor;     ///< Must be one of ::SENSOR_PIR, ::SENSOR_VIB, ::SENSOR_BUTTON, ::SENSOR_MIC, ::SENSOR_TMP, ::SENSOR_RC5, ::SENSOR_VOLTAGE.
  time_t timeStamp; ///< Timestamp of sensor reading.
  UINT16 value;     ///< Value of the reading. 
} sdata_t;          ///< Holds sensor data record.

// Value of SensorFlags
extern UINT8 sensorFlags;

/*
 * Initializes the sensors
 *
 * @return bool     True if sensors available, otherwise False  
 *  
 */  
bool Data_init();

/*
 * Enables the sensor power
 * 
 * @return bool     True if sensors available, otherwise False    
 *
 */  
bool Data_on();

/*
 * Disables the sensor power
 * 
 * @return bool     True if sensors available, otherwise False    
 *
 */  
bool Data_off();

/*
 * Enables the battery sensor
 * 
 * @return bool     True if battery sensor available, otherwise False  
 *
 */
bool Data_batteryOn(UINT16 interval, UINT16 thresh);

/*
 * Disables the battery sensor
 * 
 * @return bool     True if battery sensor available, otherwise False    
 *
 */
bool Data_batteryOff();

/*
 * Enables the beeper
 *
 * @return bool     True if beeper sensor available, otherwise False  
 *  
 */
bool Data_beeperOn();

/*
 * Disables the beeper
 * 
 * @return bool     True if beeper available, otherwise False    
 *
 */
bool Data_beeperOff();

/*
 * Toggles the beeper
 * 
 * @return bool     True if beeper available, otherwise False    
 *
 */
bool Data_beeperToggle();

/*
 * Enables the button
 * 
 * @return bool     True if button sensor available, otherwise False      
 *
 */
bool Data_buttonOn(UINT16 delay);

/*
 * Disables the button
 * 
 * @return bool     True if button sensor available, otherwise False    
 *
 */
bool Data_buttonOff();

/*
 * Enables the green LED
 * 
 * @return bool     True if green led available, otherwise False    
 *
 */
bool Data_greenOn();

/*
 * Disables the green LED
 * 
 * @return bool     True if green led available, otherwise False      
 *
 */
bool Data_greenOff();

/*
 * Toggles the green LED
 * 
 * @return bool     True if green led available, otherwise False      
 *
 */
bool Data_greenToggle();

/*
 * Enables the red LED
 * 
 * @return bool     True if red led available, otherwise False      
 *
 */
bool Data_redOn();

/*
 * Disables the red LED
 * 
 * @return bool     True if red led available, otherwise False        
 *
 */
bool Data_redOff();

/*
 * Toggles the red LED
 * 
 * @return bool     True if red led available, otherwise False        
 *
 */
bool Data_redToggle();

/*
 * Enables the yellow LED
 * 
 * @return bool     True if yellow led available, otherwise False        
 *
 */
bool Data_yellowOn();

/*
 * Disables the yellow LED
 * 
 * @return bool     True if yellow led available, otherwise False          
 *
 */
bool Data_yellowOff();

/*
 * Toggles the yellow LED
 * 
 * @return bool     True if yellow led available, otherwise False          
 *
 */
bool Data_yellowToggle();

/*
 * Enables the microphone sensor
 * 
 * @return bool     True if microphone sensor available, otherwise False      
 *
 */
bool Data_microphoneOn(UINT16 delay, UINT16 diff);

/*
 * Disables the microphone sensor
 * 
 * @return bool     True if microphone sensor available, otherwise False        
 *
 */
bool Data_microphoneOff();

/*
 * Enables the movement sensor
 * 
 * @return bool     True if movement sensor available, otherwise False        
 *
 */
bool Data_movementOn(UINT16 delay);

/*
 * Disables the movement sensor
 * 
 * @return bool     True if movement sensor available, otherwise False        
 *
 */
bool Data_movementOff();

/*
 * Enables the temperature sensor
 * 
 * @return bool     True if temperature sensor available, otherwise False        
 *
 */  
bool Data_temperatureOn(UINT16 interval, UINT16 range, UINT16 diff, UINT16 spd);

/*
 * Disables the temperature sensor
 * 
 * @return bool     True if temperature sensor available, otherwise False        
 *
 */  
bool Data_temperatureOff();

/*
 * Enables the vibration sensor
 * 
 * @return bool     True if vibration sensor available, otherwise False        
 *
 */  
bool Data_vibrationOn(UINT16 delay);

/*
 * Disables the vibration sensor
 * 
 * @return bool     True if vibration sensor available, otherwise False        
 *
 */  
bool Data_vibrationOff();

/*
 * Returns the state of the green LED
 *  
 * @return UINT8  state of green Led
 *  
 */
UINT8 Data_greenLed();

/*
 * Returns the state of the red LED
 *  
 * @return UINT8  state of red Led
 *  
 */
UINT8 Data_redLed();

/*
 * Returns the state of the yellow LED
 *  
 * @return UINT8  state of yellow Led
 *  
 */
UINT8 Data_yellowLed();

/*
 * Sends a RC5 command
 *  
 * @return bool    True if ir sensor available, otherwise False
 *  
 */
bool Data_RC5Send(int data);

/*
 * Enables the RC5
 * 
 * @return bool    True if ir sensor available, otherwise False  
 *  
 */
bool Data_RC5Enable();

/*
 * Disables the RC5
 * 
 * @return bool    True if ir sensor available, otherwise False  
 *  
 */
bool Data_RC5Disable();

/*
 * Sends a RC5 NEC command
 *  
 * @return bool    True if ir sensor available, otherwise False
 *  
 */
bool Data_RC5SendNEC(UINT16 data1, UINT16 data2);

/* 
 * This members support the ScatterWeb infrastructure
 * and are not intended to be used directly from your code.
 */
bool Data_sensorHandler();
void Data_RC5ReceiveHandler();
void Data_RC5EventHandler();  

#endif
