/***************************************************************************
 * Copyright (c) 2005, Research Group Embedded Interaction                 *
 * Paul Holleis <paul@hcilab.org>                                          *
 * Matthias Kranz <matthias@hcilab.org>                                    *
 * Albrecht Schmidt <albrecht@hcilab.org>                                  *
 * All rights reserved.                                                    *
 *                                                                         *
 * 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 the <ORGANIZATION> 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS     *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT       *
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR   *
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT    *
 * OWNER 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.                                                                 *
 **************************************************************************/

#ifndef __BT96040_ADDON_C__
#define __BT96040_ADDON_C__         098

#ifndef __BT96040_ADDON_H_

#ifdef __LINUX__
#include "boards\bt96040-addonboard.h"
#else
#include "boards/bt96040-addonboard.h"
#endif

#endif


#ifdef DIST_SCROLL
  #ifndef DISTANCE_SENSOR
    #define DISTANCE_SENSOR
  #endif
  #ifndef BTADDON_BUTTONS
    #define BTADDON_BUTTONS
  #endif
#endif


#ifdef LIGHT_SENSOR
  #ifndef __A905014_C__
    #ifdef __LINUX__
      #include "sensors\ldr_a905014.c"
    #else
      #include "sensors/ldr_a905014.c"
    #endif
  #endif
#endif

#ifdef ACCL_SENSOR
  #ifndef __ADXL311JE_C__
    #ifdef __LINUX__
      #include "sensors\adxl311je.c"
    #else
      #include "sensors/adxl311je.c"
    #endif
  #endif
#endif

#ifdef DISTANCE_SENSOR
  #ifndef __GP2D120_C__
    #ifdef __LINUX__
      #include "sensors\gp2d120.c"
    #else
      #include "sensors/gp2d120.c"
    #endif
  #endif
#endif



/**
* Initializes the SDisplay
*/
void SDisplayInit()
{
  bit_clear(TRIS_DISPLAY_POWER);

  // set analog pins
  // Attention: hardwire 13 and 14!!!! -> Light sensor!
  PCSetAnalogPorts(ANALOG_CONN_11_12_13_14);

  // one scl for all i2c devices
  bit_clear(TRIS_DISPLAY_1_I2C_SCL);

  bit_clear(TRIS_DISPLAY_1_I2C_SDA);
  bit_clear(TRIS_DISPLAY_2_I2C_SDA);

#ifdef BTADDON_BUTTONS
   // some display connectors are used as input for buttons
  bit_set(TRIS_BT_BUTTON_PIN_1);
  bit_set(TRIS_BT_BUTTON_PIN_2);
  bit_set(TRIS_BT_BUTTON_PIN_3);
  bit_set(TRIS_BT_BUTTON_PIN_4);
#else
  bit_clear(TRIS_DISPLAY_3_I2C_SDA);
  bit_clear(TRIS_DISPLAY_4_I2C_SDA);
  bit_clear(TRIS_DISPLAY_5_I2C_SDA);
  bit_clear(TRIS_DISPLAY_6_I2C_SDA);
#endif

  DisplaysOff();
}


/**
* Initializes all sensors on SDisplay
*/
void SDisplaySensorsInit()
{
  #ifdef LIGHT_SENSOR
    LightSensorInit();    //inits the light and sets the tris etc..
  #endif

  #ifdef ACCL_SENSOR
    AcclSensorInit();   //inits the accels and sets the tris etc..
  #endif

  #ifdef DISTANCE_SENSOR
    DistSensorInit();    //inits the distance sensor and sets the tris etc..
  #endif
   
  SDisplaySensorsOff();
}

void DisplaysOn()
{
  output_high(PIN_DISPLAY_POWER);
}

void DisplaysOff()
{
  output_low(PIN_DISPLAY_POWER);
}

/**
* Turn on all sensors on SDisplay
*/
void SDisplaySensorsOn()
{
  // use DisplaysOn for that!
  //DisplaysOn();

  #ifdef LIGHT_SENSOR
    LightSensorOn();
  #endif

  #ifdef ACCL_SENSOR
    AcclSensorOn();
  #endif

  #ifdef DISTANCE_SENSOR
    DistSensorOn();
  #endif
}

/**
* Turn off all sensors on SDisplay
*/
void SDisplaySensorsOff()
{
  // use DisplaysOff for that!
  //DisplaysOff();

  #ifdef LIGHT_SENSOR
    LightSensorOff();
  #endif

  #ifdef ACCL_SENSOR
    AcclSensorOff();
  #endif

  #ifdef DISTANCE_SENSOR
    DistSensorOff();
  #endif
}


#endif // __BT96040_ADDON_C__
