Mindstorms 3rd Party ROBOTC Drivers RobotC
[Home] [Download] [Submit a bug/suggestion] [ROBOTC Forums] [Blog] [Support this project]

hitechnic-eopd.h

Go to the documentation of this file.
00001 /*!@addtogroup HiTechnic
00002  * @{
00003  * @defgroup hteopd EOPD Sensor
00004  * HiTechnic EOPD Sensor
00005  * @{
00006  */
00007 
00008 /*
00009  * $Id: hitechnic-eopd.h 133 2013-03-10 15:15:38Z xander $
00010  */
00011 
00012 #ifndef __HTEOPD_H__
00013 #define __HTEOPD_H__
00014 /** \file hitechnic-eopd.h
00015  * \brief HiTechnic EOPD Sensor driver
00016  *
00017  * hitechnic-eopd.h provides an API for the HiTechnic EOPD sensor.
00018  *
00019  * Changelog:
00020  * - 0.1: Initial release
00021  * - 0.2: Removed HTEOPDsetRange() and HTEOPDgetRange(), not really necessary
00022  *        Changed the way raw value is calculated due to sensor type change
00023  * - 0.3: Renamed HTEOPDgetRaw to HTEOPDreadRaw
00024  *        Renamed HTEOPDgetProcessed to HTEOPDreadProcessed
00025  *        Added SMUX functions
00026  * - 0.4: Added No Wait versions of HTEOPDsetShortRange and HTEOPDsetLongRange for non-SMUX functions
00027  *        Changed the underlying sensor types for RobotC 1.57A and higher.
00028  * - 0.5: Now only supports ROBOTC 2.00<br>
00029  *        Make use of the new analogue sensor calls for SMUX sensors in common.h
00030  * - 0.6: Replaced array structs with typedefs
00031  *
00032  * Credits:
00033  * - Big thanks to HiTechnic for providing me with the hardware necessary to write and test this.
00034  *
00035  * License: You may use this code as you wish, provided you give credit where its due.
00036  *
00037  * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. 
00038 
00039  * \author Xander Soldaat (xander_at_botbench.com)
00040  * \date 20 February 2011
00041  * \version 0.6
00042  * \example hitechnic-eopd-test1.c
00043  * \example hitechnic-eopd-SMUX-test1.c
00044  */
00045 
00046 #pragma systemFile
00047 
00048 #ifndef __COMMON_H__
00049 #include "common.h"
00050 #endif
00051 
00052 // This ensures the correct sensor types are used.
00053 TSensorTypes HTEOPDLRType = sensorAnalogActive;
00054 TSensorTypes HTEOPDSRType = sensorAnalogInactive;
00055 
00056 int HTEOPDreadRaw(tSensors link);
00057 int HTEOPDreadProcessed(tSensors link);
00058 void HTEOPDsetShortRange(tSensors link);
00059 void HTEOPDsetLongRange(tSensors link);
00060 
00061 #ifdef __HTSMUX_SUPPORT__
00062 int HTEOPDreadRaw(tMUXSensor muxsensor);
00063 int HTEOPDreadProcessed(tMUXSensor muxsensor);
00064 void HTEOPDsetShortRange(tMUXSensor muxsensor);
00065 void HTEOPDsetLongRange(tMUXSensor muxsensor);
00066 #endif
00067 
00068 /**
00069  * Get the raw value from the sensor
00070  * @param link the HTEOPD port number
00071  * @return raw value of the sensor
00072  */
00073 int HTEOPDreadRaw(tSensors link) {
00074   return 1023 - SensorRaw[link];
00075 }
00076 
00077 
00078 /**
00079  * Get the raw value from the sensor
00080  * @param muxsensor the SMUX sensor port number
00081  * @return raw value of the sensor
00082  */
00083 #ifdef __HTSMUX_SUPPORT__
00084 int HTEOPDreadRaw(tMUXSensor muxsensor) {
00085   return 1023 - HTSMUXreadAnalogue(muxsensor);
00086 }
00087 #endif // __HTSMUX_SUPPORT__
00088 
00089 
00090 /**
00091  * Get the processed value from the sensor. This is obtained by using sqrt(raw value * 10)
00092  * @param link the HTEOPD port number
00093  * @return processed value of the sensor
00094  */
00095 int HTEOPDreadProcessed(tSensors link) {
00096   int _val = sqrt(HTEOPDreadRaw(link) * 10);
00097   return _val;
00098 }
00099 
00100 
00101 /**
00102  * Get the processed value from the sensor. This is obtained by using sqrt(raw value * 10)
00103  * @param muxsensor the SMUX sensor port number
00104  * @return processed value of the sensor
00105  */
00106 #ifdef __HTSMUX_SUPPORT__
00107 int HTEOPDreadProcessed(tMUXSensor muxsensor) {
00108   int _val = sqrt((long)HTEOPDreadRaw(muxsensor) * (long)10);
00109   return _val;
00110 }
00111 #endif // __HTSMUX_SUPPORT__
00112 
00113 
00114 /**
00115  * Set the range of the sensor to short range, this is done
00116  * by configuring the sensor as sensorRawValue
00117  * @param link the HTEOPD port number
00118  */
00119 void HTEOPDsetShortRange(tSensors link) {
00120   SetSensorType(link, HTEOPDSRType);
00121 }
00122 
00123 
00124 /**
00125  * Set the range of the sensor to short range, this is done
00126  * by switching off dig0
00127  * @param muxsensor the SMUX sensor port number
00128  */
00129 #ifdef __HTSMUX_SUPPORT__
00130 void HTEOPDsetShortRange(tMUXSensor muxsensor) {
00131   HTSMUXsetAnalogueInactive(muxsensor);
00132 }
00133 #endif // __HTSMUX_SUPPORT__
00134 
00135 
00136 /**
00137  * Set the range of the sensor to long range, this is done
00138  * by configuring the sensor as sensorLightActive and setting
00139  * it to modeRaw
00140  * @param link the HTEOPD port number
00141  */
00142 void HTEOPDsetLongRange(tSensors link) {
00143   SetSensorType(link, HTEOPDLRType);
00144 }
00145 
00146 
00147 /**
00148  * Set the range of the sensor to long range, this is done
00149  * by setting dig0 high (1).
00150  * @param muxsensor the SMUX sensor port number
00151  */
00152 #ifdef __HTSMUX_SUPPORT__
00153 void HTEOPDsetLongRange(tMUXSensor muxsensor) {
00154   HTSMUXsetAnalogueActive(muxsensor);
00155 }
00156 #endif // __HTSMUX_SUPPORT__
00157 
00158 #endif // __HTEOPD_H__
00159 
00160 /*
00161  * $Id: hitechnic-eopd.h 133 2013-03-10 15:15:38Z xander $
00162  */
00163 /* @} */
00164 /* @} */