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

HTEOPD-driver.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: HTEOPD-driver.h 49 2011-04-27 13:00:05Z xander $
00010  */
00011 
00012 #ifndef __HTEOPD_H__
00013 #define __HTEOPD_H__
00014 /** \file HTEOPD-driver.h
00015  * \brief HiTechnic EOPD Sensor driver
00016  *
00017  * HTEOPD-driver.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 2.00 AND HIGHER.
00038  * \author Xander Soldaat (mightor_at_gmail.com)
00039  * \date 20 February 2011
00040  * \version 0.6
00041  * \example HTEOPD-test1.c
00042  * \example HTEOPD-SMUX-test1.c
00043  */
00044 
00045 #pragma systemFile
00046 
00047 #ifndef __COMMON_H__
00048 #include "common.h"
00049 #endif
00050 
00051 // This ensures the correct sensor types are used.
00052 TSensorTypes LRType = sensorAnalogActive;
00053 TSensorTypes SRType = sensorAnalogInactive;
00054 
00055 int HTEOPDreadRaw(tSensors link);
00056 int HTEOPDreadProcessed(tSensors link);
00057 void HTEOPDsetShortRange(tSensors link);
00058 void HTEOPDsetLongRange(tSensors link);
00059 
00060 #ifdef __HTSMUX_SUPPORT__
00061 int HTEOPDreadRaw(tMUXSensor muxsensor);
00062 int HTEOPDreadProcessed(tMUXSensor muxsensor);
00063 void HTEOPDsetShortRange(tMUXSensor muxsensor);
00064 void HTEOPDsetLongRange(tMUXSensor muxsensor);
00065 #endif
00066 
00067 /**
00068  * Get the raw value from the sensor
00069  * @param link the HTEOPD port number
00070  * @return raw value of the sensor
00071  */
00072 int HTEOPDreadRaw(tSensors link) {
00073   return 1023 - SensorRaw[link];
00074 }
00075 
00076 
00077 /**
00078  * Get the raw value from the sensor
00079  * @param muxsensor the SMUX sensor port number
00080  * @return raw value of the sensor
00081  */
00082 #ifdef __HTSMUX_SUPPORT__
00083 int HTEOPDreadRaw(tMUXSensor muxsensor) {
00084   return 1023 - HTSMUXreadAnalogue(muxsensor);
00085 }
00086 #endif // __HTSMUX_SUPPORT__
00087 
00088 
00089 /**
00090  * Get the processed value from the sensor. This is obtained by using sqrt(raw value * 10)
00091  * @param link the HTEOPD port number
00092  * @return processed value of the sensor
00093  */
00094 int HTEOPDreadProcessed(tSensors link) {
00095   int _val = sqrt(HTEOPDreadRaw(link) * 10);
00096   return _val;
00097 }
00098 
00099 
00100 /**
00101  * Get the processed value from the sensor. This is obtained by using sqrt(raw value * 10)
00102  * @param muxsensor the SMUX sensor port number
00103  * @return processed value of the sensor
00104  */
00105 #ifdef __HTSMUX_SUPPORT__
00106 int HTEOPDreadProcessed(tMUXSensor muxsensor) {
00107   int _val = sqrt((long)HTEOPDreadRaw(muxsensor) * (long)10);
00108   return _val;
00109 }
00110 #endif // __HTSMUX_SUPPORT__
00111 
00112 
00113 /**
00114  * Set the range of the sensor to short range, this is done
00115  * by configuring the sensor as sensorRawValue
00116  * @param link the HTEOPD port number
00117  */
00118 void HTEOPDsetShortRange(tSensors link) {
00119   SetSensorType(link, SRType);
00120 }
00121 
00122 
00123 /**
00124  * Set the range of the sensor to short range, this is done
00125  * by switching off dig0
00126  * @param muxsensor the SMUX sensor port number
00127  */
00128 #ifdef __HTSMUX_SUPPORT__
00129 void HTEOPDsetShortRange(tMUXSensor muxsensor) {
00130   HTSMUXsetAnalogueInactive(muxsensor);
00131 }
00132 #endif // __HTSMUX_SUPPORT__
00133 
00134 
00135 /**
00136  * Set the range of the sensor to long range, this is done
00137  * by configuring the sensor as sensorLightActive and setting
00138  * it to modeRaw
00139  * @param link the HTEOPD port number
00140  */
00141 void HTEOPDsetLongRange(tSensors link) {
00142   SetSensorType(link, LRType);
00143 }
00144 
00145 
00146 /**
00147  * Set the range of the sensor to long range, this is done
00148  * by setting dig0 high (1).
00149  * @param muxsensor the SMUX sensor port number
00150  */
00151 #ifdef __HTSMUX_SUPPORT__
00152 void HTEOPDsetLongRange(tMUXSensor muxsensor) {
00153   HTSMUXsetAnalogueActive(muxsensor);
00154 }
00155 #endif // __HTSMUX_SUPPORT__
00156 
00157 #endif // __HTEOPD_H__
00158 
00159 /*
00160  * $Id: HTEOPD-driver.h 49 2011-04-27 13:00:05Z xander $
00161  */
00162 /* @} */
00163 /* @} */