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

LEGOTS-driver.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: LEGOTS-driver.h 47 2011-01-17 19:47:22Z xander $
00010  */
00011 
00012 #ifndef __LEGOTS_H__
00013 #define __LEGOTS_H__
00014 /** \file LEGOTS-driver.h
00015  * \brief Lego Touch Sensor driver
00016  *
00017  * LEGOTS-driver.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 2.00 AND HIGHER.
00025  * \author Xander Soldaat (mightor_at_gmail.com)
00026  * \date 08 December 2009
00027  * \version 0.1
00028  * \example LEGOTS-test1.c
00029  * \example LEGOTS-SMUX-test1.c
00030  */
00031 
00032 #pragma systemFile
00033 
00034 #ifndef __COMMON_H__
00035 #include "common.h"
00036 #endif
00037 
00038 // Function prototypes
00039 bool TSreadState(tSensors link);
00040 
00041 #ifdef __HTSMUX_SUPPORT__
00042 bool TSreadState(tMUXSensor muxsensor);
00043 #endif
00044 
00045 
00046 /**
00047  * Read the state of the touch sensor
00048  * @param link the Touch Sensor port number
00049  * @return true if the sensor is pressed, false if it's not
00050  */
00051 bool TSreadState(tSensors link) {
00052   if ((SensorType(link) !=  sensorTouch) && SensorMode(link) != modeBoolean) {
00053     SetSensorType(link, sensorTouch);
00054     SetSensorMode(link, modeBoolean);
00055     wait1Msec(10);
00056   }
00057 
00058   return (SensorRaw[link] < 500) ? true : false;
00059 }
00060 
00061 
00062 /**
00063  * Read the state of the touch sensor
00064  * @param muxsensor the SMUX sensor port number
00065  * @return true if the sensor is pressed, false if it's not
00066  */
00067 #ifdef __HTSMUX_SUPPORT__
00068 bool TSreadState(tMUXSensor muxsensor) {
00069   return (HTSMUXreadAnalogue(muxsensor) < 500) ? true : false;
00070 }
00071 #endif
00072 
00073 
00074 #endif // __LEGOTS_H__
00075 
00076 /*
00077  * $Id: LEGOTS-driver.h 47 2011-01-17 19:47:22Z xander $
00078  */
00079 /* @} */
00080 /* @} */