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

lego-touch.h

Go to the documentation of this file.
00001 /*!@addtogroup lego
00002  * @{
00003  * @defgroup legots Touch Sensor
00004  * Touch Sensor
00005  * @{
00006  */
00007 
00008 /*
00009  * $Id: lego-touch.h 133 2013-03-10 15:15:38Z xander $
00010  */
00011 
00012 #ifndef __LEGOTS_H__
00013 #define __LEGOTS_H__
00014 /** \file lego-touch.h
00015  * \brief Lego Touch Sensor driver
00016  *
00017  * lego-touch.h provides an API for the Lego Touch Sensor.
00018  *
00019  * Changelog:
00020  * - 0.1: Initial release
00021  *
00022  * License: You may use this code as you wish, provided you give credit where its due.
00023  *
00024  * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. 
00025 
00026  * \author Xander Soldaat (xander_at_botbench.com)
00027  * \date 08 December 2009
00028  * \version 0.1
00029  * \example lego-touch-test1.c
00030  * \example lego-touch-SMUX-test1.c
00031  */
00032 
00033 #pragma systemFile
00034 
00035 #ifndef __COMMON_H__
00036 #include "common.h"
00037 #endif
00038 
00039 // Function prototypes
00040 bool TSreadState(tSensors link);
00041 
00042 #ifdef __HTSMUX_SUPPORT__
00043 bool TSreadState(tMUXSensor muxsensor);
00044 #endif
00045 
00046 
00047 /**
00048  * Read the state of the touch sensor
00049  * @param link the Touch Sensor port number
00050  * @return true if the sensor is pressed, false if it's not
00051  */
00052 bool TSreadState(tSensors link) {
00053   if ((SensorType[link] !=  sensorTouch) && SensorMode[link] != modeBoolean) {
00054     SetSensorType(link, sensorTouch);
00055     SetSensorMode(link, modeBoolean);
00056     wait1Msec(10);
00057   }
00058 
00059   return (SensorRaw[link] < 500) ? true : false;
00060 }
00061 
00062 
00063 /**
00064  * Read the state of the touch sensor
00065  * @param muxsensor the SMUX sensor port number
00066  * @return true if the sensor is pressed, false if it's not
00067  */
00068 #ifdef __HTSMUX_SUPPORT__
00069 bool TSreadState(tMUXSensor muxsensor) {
00070   return (HTSMUXreadAnalogue(muxsensor) < 500) ? true : false;
00071 }
00072 #endif
00073 
00074 
00075 #endif // __LEGOTS_H__
00076 
00077 /*
00078  * $Id: lego-touch.h 133 2013-03-10 15:15:38Z xander $
00079  */
00080 /* @} */
00081 /* @} */