1 /** \file NXCDefs.h
2  * \brief Constants, macros, and API functions for NXC
3  *
4  * NXCDefs.h contains declarations for the NXC NXT API resources
5  *
6  * License:
7  *
8  * The contents of this file are subject to the Mozilla Public License
9  * Version 1.1 (the "License"); you may not use this file except in
10  * compliance with the License. You may obtain a copy of the License at
11  * http://www.mozilla.org/MPL/
12  *
13  * Software distributed under the License is distributed on an "AS IS"
14  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
15  * License for the specific language governing rights and limitations
16  * under the License.
17  *
18  * The Initial Developer of this code is John Hansen.
19  * Portions created by John Hansen are Copyright (C) 2009-2010 John Hansen.
20  * All Rights Reserved.
21  *
22  * ----------------------------------------------------------------------------
23  *
24  * \author John Hansen (bricxcc_at_comcast.net)
25  * \date 2011-03-15
26  * \version 93
27  */
28 #ifndef NXCDEFS_H
29 #define NXCDEFS_H
30 
31 #include "NBCCommon.h"
32 
33 /** @addtogroup MiscConstants
34  * @{
35  */
36 /** @defgroup TypeAliases Type aliases
37  *  Short type aliases indicating signed/unsigned and bit count for each type.
38  *  @{
39  */
40 #define u8 unsigned char  /*!< Unsigned 8 bit type */
41 #define s8 char           /*!< Signed 8 bit type */
42 #define u16 unsigned int  /*!< Unsigned 16 bit type */
43 #define s16 int           /*!< Signed 16 bit type */
44 #define u32 unsigned long /*!< Unsigned 32 bit type */
45 #define s32 long          /*!< Signed 32 bit type */
46 /** @} */  // end of TypeAliases group
47 /** @} */  // end of MiscConstants group
48 
49 
50 ///////////////////////////////////////////////////////////////////////////////
51 ///////////////////////////////// INPUT MODULE ////////////////////////////////
52 ///////////////////////////////////////////////////////////////////////////////
53 
54 
55 /** @addtogroup NXTFirmwareModules
56  * @{
57  */
58 /** @addtogroup InputModule
59  * @{
60  */
61 /** @addtogroup InputModuleConstants
62  * @{
63  */
64 /** @defgroup InPorts Input port constants
65  * Input port constants are used when calling NXC sensor control API functions.
66  * @{
67  */
68 #define S1 0 /*!< Input port 1 */
69 #define S2 1 /*!< Input port 2 */
70 #define S3 2 /*!< Input port 3 */
71 #define S4 3 /*!< Input port 4 */
72 /** @} */ // end of InPorts group
73 
74 /** @addtogroup InputModuleTypesAndModes
75  * @{
76  */
77 /** @defgroup SensorTypes Sensor type constants
78  *  Use sensor type constants to configure an input port for a specific type
79  *  of sensor.
80  *  \sa SetSensorType()
81  *  @{
82  */
83 #define SENSOR_TYPE_NONE            IN_TYPE_NO_SENSOR      /*!< No sensor configured */
84 #define SENSOR_TYPE_TOUCH           IN_TYPE_SWITCH         /*!< NXT or RCX touch sensor */
85 #define SENSOR_TYPE_TEMPERATURE     IN_TYPE_TEMPERATURE    /*!< RCX temperature sensor */
86 #define SENSOR_TYPE_LIGHT           IN_TYPE_REFLECTION     /*!< RCX light sensor */
87 #define SENSOR_TYPE_ROTATION        IN_TYPE_ANGLE          /*!< RCX rotation sensor */
88 #define SENSOR_TYPE_LIGHT_ACTIVE    IN_TYPE_LIGHT_ACTIVE   /*!< NXT light sensor with light */
89 #define SENSOR_TYPE_LIGHT_INACTIVE  IN_TYPE_LIGHT_INACTIVE /*!< NXT light sensor without light */
90 #define SENSOR_TYPE_SOUND_DB        IN_TYPE_SOUND_DB       /*!< NXT sound sensor with dB scaling */
91 #define SENSOR_TYPE_SOUND_DBA       IN_TYPE_SOUND_DBA      /*!< NXT sound sensor with dBA scaling */
92 #define SENSOR_TYPE_CUSTOM          IN_TYPE_CUSTOM         /*!< NXT custom sensor */
93 #define SENSOR_TYPE_LOWSPEED        IN_TYPE_LOWSPEED       /*!< NXT I2C digital sensor */
94 #define SENSOR_TYPE_LOWSPEED_9V     IN_TYPE_LOWSPEED_9V    /*!< NXT I2C digital sensor with 9V power */
95 #define SENSOR_TYPE_HIGHSPEED       IN_TYPE_HISPEED        /*!< NXT Hi-speed port (only S4) */
96 #if __FIRMWARE_VERSION > 107
97 #define SENSOR_TYPE_COLORFULL       IN_TYPE_COLORFULL      /*!< NXT 2.0 color sensor in full color mode */
98 #define SENSOR_TYPE_COLORRED        IN_TYPE_COLORRED       /*!< NXT 2.0 color sensor with red light */
99 #define SENSOR_TYPE_COLORGREEN      IN_TYPE_COLORGREEN     /*!< NXT 2.0 color sensor with green light */
100 #define SENSOR_TYPE_COLORBLUE       IN_TYPE_COLORBLUE      /*!< NXT 2.0 color sensor with blue light */
101 #define SENSOR_TYPE_COLORNONE       IN_TYPE_COLORNONE      /*!< NXT 2.0 color sensor with no light */
102 #endif
103 /** @} */ // end of SensorTypes group
104 
105 /** @defgroup SensorModes Sensor mode constants
106  * Use sensor mode constants to configure an input port for the desired
107  * sensor mode.
108  * \sa SetSensorMode()
109  * @{
110  */
111 #define SENSOR_MODE_RAW         IN_MODE_RAW           /*!< Raw value from 0 to 1023 */
112 #define SENSOR_MODE_BOOL        IN_MODE_BOOLEAN       /*!< Boolean value (0 or 1) */
113 #define SENSOR_MODE_EDGE        IN_MODE_TRANSITIONCNT /*!< Counts the number of boolean transitions */
114 #define SENSOR_MODE_PULSE       IN_MODE_PERIODCOUNTER /*!< Counts the number of boolean periods */
115 #define SENSOR_MODE_PERCENT     IN_MODE_PCTFULLSCALE  /*!< Scaled value from 0 to 100 */
116 #define SENSOR_MODE_CELSIUS     IN_MODE_CELSIUS       /*!< RCX temperature sensor value in degrees celcius */
117 #define SENSOR_MODE_FAHRENHEIT  IN_MODE_FAHRENHEIT    /*!< RCX temperature sensor value in degrees fahrenheit */
118 #define SENSOR_MODE_ROTATION    IN_MODE_ANGLESTEP     /*!< RCX rotation sensor (16 ticks per revolution) */
119 /** @} */ // end of SensorModes group
120 
121 /** @defgroup SensorTypeModes Combined sensor type and mode constants
122  * Use the combined sensor type and mode constants to configure both
123  * the sensor mode and type in a single function call.
124  * \sa SetSensor()
125  * @{
126  */
127 #define _SENSOR_CFG(_type,_mode)	(((_type)<<8)+(_mode))                               /*!< Macro for defining \ref SetSensor combined type and mode constants */
128 #define SENSOR_TOUCH		_SENSOR_CFG(SENSOR_TYPE_TOUCH, SENSOR_MODE_BOOL)             /*!< Touch sensor in boolean mode */
129 #define SENSOR_LIGHT		_SENSOR_CFG(SENSOR_TYPE_LIGHT, SENSOR_MODE_PERCENT)          /*!< RCX Light sensor in percent mode */
130 #define SENSOR_ROTATION		_SENSOR_CFG(SENSOR_TYPE_ROTATION, SENSOR_MODE_ROTATION)      /*!< RCX rotation sensor in rotation mode */
131 #define SENSOR_CELSIUS		_SENSOR_CFG(SENSOR_TYPE_TEMPERATURE, SENSOR_MODE_CELSIUS)    /*!< RCX temperature sensor in celcius mode */
132 #define SENSOR_FAHRENHEIT	_SENSOR_CFG(SENSOR_TYPE_TEMPERATURE, SENSOR_MODE_FAHRENHEIT) /*!< RCX temperature sensor in fahrenheit mode */
133 #define	SENSOR_PULSE		_SENSOR_CFG(SENSOR_TYPE_TOUCH, SENSOR_MODE_PULSE)            /*!< Touch sensor in pulse mode */
134 #define SENSOR_EDGE         _SENSOR_CFG(SENSOR_TYPE_TOUCH, SENSOR_MODE_EDGE)             /*!< Touch sensor in edge mode */
135 #define SENSOR_NXTLIGHT		_SENSOR_CFG(SENSOR_TYPE_LIGHT_ACTIVE, SENSOR_MODE_PERCENT)   /*!< NXT light sensor in active mode */
136 #define SENSOR_SOUND		_SENSOR_CFG(SENSOR_TYPE_SOUND_DB, SENSOR_MODE_PERCENT)       /*!< NXT sound sensor (dB) in percent mode */
137 #define SENSOR_LOWSPEED_9V  _SENSOR_CFG(SENSOR_TYPE_LOWSPEED_9V, SENSOR_MODE_RAW)        /*!< NXT I2C sensor with 9V power in raw mode */
138 #define SENSOR_LOWSPEED     _SENSOR_CFG(SENSOR_TYPE_LOWSPEED, SENSOR_MODE_RAW)           /*!< NXT I2C sensor without 9V power in raw mode */
139 #if __FIRMWARE_VERSION > 107
140 #define SENSOR_COLORFULL	_SENSOR_CFG(SENSOR_TYPE_COLORFULL, SENSOR_MODE_RAW)          /*!< NXT 2.0 color sensor (full) in raw mode */
141 #define SENSOR_COLORRED		_SENSOR_CFG(SENSOR_TYPE_COLORRED, SENSOR_MODE_PERCENT)       /*!< NXT 2.0 color sensor (red) in percent mode */
142 #define SENSOR_COLORGREEN	_SENSOR_CFG(SENSOR_TYPE_COLORGREEN, SENSOR_MODE_PERCENT)     /*!< NXT 2.0 color sensor (green) in percent mode */
143 #define SENSOR_COLORBLUE	_SENSOR_CFG(SENSOR_TYPE_COLORBLUE, SENSOR_MODE_PERCENT)      /*!< NXT 2.0 color sensor (blue) in percent mode */
144 #define SENSOR_COLORNONE	_SENSOR_CFG(SENSOR_TYPE_COLORNONE, SENSOR_MODE_PERCENT)      /*!< NXT 2.0 color sensor (none) in percent mode */
145 #endif
146 /** @} */ // end of SensorModes group
147 /** @} */ // end of InputModuleTypesAndModes group
148 /** @} */ // end of InputModuleConstants group
149 
150 /** @defgroup InputModuleTypes Input module types
151  * Types used by various input module functions.
152  * @{
153  */
154 #if __FIRMWARE_VERSION > 107
155 /**
156  * Parameters for the ColorSensorRead system call.
157  * This structure is used when calling the \ref SysColorSensorRead system call function.
158  * Choose the sensor port (\ref InPorts) and after calling the function
159  * read the sensor values from the ColorValue field or the raw, normalized, or
160  * scaled value arrays.
161  * \sa SysColorSensorRead()
162  */
163 struct ColorSensorReadType {
164  char Result;                    /*!< The function call result. \ref NO_ERR means it succeeded. */
165  byte Port;                      /*!< The sensor port. See the constants in the \ref InPorts group. */
166  int ColorValue;                 /*!< The color value returned by the sensor. See the \ref InputColorValueConstants group. */
167  unsigned int RawArray[];        /*!< Raw color values returned by the sensor. See the \ref InputColorIdxConstants group. */
168  unsigned int NormalizedArray[]; /*!< Normalized color values returned by the sensor. See the \ref InputColorIdxConstants group. */
169  int ScaledArray[];              /*!< Scaled color values returned by the sensor. See the \ref InputColorIdxConstants group. */
170  bool Invalid;                   /*!< Are the sensor values valid? */
171 };
172 #endif
173 
174 #if defined(__ENHANCED_FIRMWARE) && (__FIRMWARE_VERSION > 107)
175 /**
176  * Parameters for the \ref RemoteGetInputValues function.
177  * This structure is used when calling the \ref RemoteGetInputValues function.
178  * Choose the sensor port (\ref InPorts) and after calling the function
179  * read the sensor values from the various structure fields.
180  */
181 struct InputValuesType {
182   byte Port;                    /*!< The sensor port. See the \ref InPorts group. */
183   bool Valid;                   /*!< Is the sensor value valid? */
184   bool Calibrated;              /*!< Is the sensor calibrated? */
185   byte SensorType;              /*!< The sensor type. See the \ref SensorTypes group. */
186   byte SensorMode;              /*!< The sensor mode. See the \ref SensorModes group. */
187   unsigned int RawValue;        /*!< The raw value. */
188   unsigned int NormalizedValue; /*!< The normalized value. */
189   int ScaledValue;              /*!< The scaled value. */
190   int CalibratedValue;          /*!< The calibrated value. */
191 };
192 
193 /*
194 struct InputType {
195   unsigned int CustomZeroOffset;
196   unsigned int ADRaw;
197   unsigned int SensorRaw;
198   int SensorValue;
199   byte SensorType;
200   byte SensorMode;
201   bool SensorBoolean;
202   byte DigiPinsDir;
203   byte DigiPinsIn;
204   byte DigiPinsOut;
205   byte CustomPctFullScale;
206   byte CustomActiveStatus;
207   bool InvalidData;
208 };
209 */
210 
211 #endif
212 
213 /** @} */ // end of InputModuleTypes group
214 
215 /** @defgroup InputModuleFunctions Input module functions
216  * Functions for accessing and modifying input module features.
217  * @{
218  */
219 
220 /** @defgroup BasicSensorValues Basic analog sensor value names
221  * Read analog sensor values using these names.  Returns the current scaled value
222  * of the sensor on the specified port.
223  * @{
224  */
225 #define SENSOR_1 Sensor(S1) /*!< Read the value of the analog sensor on port S1 */
226 #define SENSOR_2 Sensor(S2) /*!< Read the value of the analog sensor on port S2 */
227 #define SENSOR_3 Sensor(S3) /*!< Read the value of the analog sensor on port S3 */
228 #define SENSOR_4 Sensor(S4) /*!< Read the value of the analog sensor on port S4 */
229 /** @} */ // end of BasicSensorValues group
230 
231 /**
232  * Set sensor type.
233  * Set a sensor's type, which must be one of the predefined sensor type
234  * constants.  After changing the type or the mode of a sensor
235  * port you must call \ref ResetSensor to give the firmware time to reconfigure
236  * the sensor port.
237  * \sa SetSensorMode(), SetSensor()
238  * \param port The port to configure. See \ref InPorts.
239  * \param type The desired sensor type.  See \ref SensorTypes.
240  */
SetSensorType(const byte & port,byte type)241 inline void SetSensorType(const byte & port, byte type) { asm { setin type, port, TypeField } }
242 
243 /**
244  * Set sensor mode.
245  * Set a sensor's mode, which should be one of the predefined sensor mode
246  * constants. A slope parameter for boolean conversion, if desired, may be
247  * added to the mode. After changing the type or the mode of a sensor
248  * port you must call \ref ResetSensor to give the firmware time to reconfigure
249  * the sensor port.
250  * \sa SetSensorType(), SetSensor()
251  * \param port The port to configure. See \ref InPorts.
252  * \param mode The desired sensor mode. See \ref SensorModes.
253  */
SetSensorMode(const byte & port,byte mode)254 inline void SetSensorMode(const byte & port, byte mode) { asm { setin mode, port, InputModeField } }
255 
256 /**
257  * Clear a sensor value.
258  * Clear the value of a sensor - only affects sensors that are configured
259  * to measure a cumulative quantity such as rotation or a pulse count.
260  * \param port The port to clear. See \ref InPorts.
261  */
ClearSensor(const byte & port)262 inline void ClearSensor(const byte & port) { asm { setin 0, port, ScaledValueField } }
263 
264 /**
265  * Reset the sensor port.
266  * Sets the invalid data flag on the specified port and waits for it to
267  * become valid again. After changing the type or the mode of a sensor
268  * port you must call this function to give the firmware time to reconfigure
269  * the sensor port.
270  * \param port The port to reset. See \ref InPorts.
271  */
ResetSensor(const byte & port)272 inline void ResetSensor(const byte & port) { asm { __ResetSensor(port) } }
273 
274 /**
275  * Set sensor configuration.
276  * Set the type and mode of the given sensor to the specified configuration,
277  * which must be a special constant containing both type and mode information.
278  * \sa SetSensorType(), SetSensorMode(), and ResetSensor()
279  * \param port The port to configure. See \ref InPorts.
280  * \param config The configuration constant containing both the type and mode.
281  * See \ref SensorTypeModes.
282  */
SetSensor(const byte & port,const unsigned int config)283 inline void SetSensor(const byte & port, const unsigned int config) {
284   asm {
285     setin config>>8, port, TypeField
286     setin config&0xff, port, InputModeField
287     __ResetSensor(port)
288   }
289 }
290 
291 /**
292  * Configure a touch sensor.
293  * Configure the sensor on the specified port as a touch sensor.
294  * \param port The port to configure. See \ref InPorts.
295  */
SetSensorTouch(const byte & port)296 inline void SetSensorTouch(const byte & port) { asm { __SetSensorTouch(port) } }
297 
298 /**
299  * Configure a light sensor.
300  * Configure the sensor on the specified port as an NXT light sensor.
301  * \param port The port to configure. See \ref InPorts.
302  * \param bActive A boolean flag indicating whether to configure the port
303  * as an active or inactive light sensor.  The default value for this
304  * optional parameter is true.
305  */
306 inline void SetSensorLight(const byte & port, bool bActive = true) {
307   SetSensorType(port, bActive ? SENSOR_TYPE_LIGHT_ACTIVE : SENSOR_TYPE_LIGHT_INACTIVE);
308   SetSensorMode(port, SENSOR_MODE_PERCENT);
309   ResetSensor(port);
310 }
311 
312 /**
313  * Configure a sound sensor.
314  * Configure the sensor on the specified port as a sound sensor.
315  * \param port The port to configure. See \ref InPorts.
316  * \param bdBScaling A boolean flag indicating whether to configure the port
317  * as a sound sensor with dB or dBA scaling.  The default value for this
318  * optional parameter is true, meaning dB scaling.
319  */
320 inline void SetSensorSound(const byte & port, bool bdBScaling = true) {
321   SetSensorType(port, bdBScaling ? SENSOR_TYPE_SOUND_DB : SENSOR_TYPE_SOUND_DBA);
322   SetSensorMode(port, SENSOR_MODE_PERCENT);
323   ResetSensor(port);
324 }
325 
326 /**
327  * Configure an I2C sensor.
328  * Configure the sensor on the specified port as an I2C digital sensor
329  * for either powered (9 volt) or unpowered devices.
330  * \param port The port to configure. See \ref InPorts.
331  * \param bIsPowered A boolean flag indicating whether to configure the port
332  * for powered or unpowered I2C devices.  The default value for this
333  * optional parameter is true.
334  */
335 inline void SetSensorLowspeed(const byte & port, bool bIsPowered = true) {
336   SetSensorType(port, bIsPowered ? SENSOR_TYPE_LOWSPEED_9V : SENSOR_TYPE_LOWSPEED);
337   SetSensorMode(port, SENSOR_MODE_RAW);
338   ResetSensor(port);
339 }
340 
341 /**
342  * Configure an ultrasonic sensor.
343  * Configure the sensor on the specified port as an ultrasonic sensor.
344  * \param port The port to configure. See \ref InPorts.
345  */
SetSensorUltrasonic(const byte & port)346 inline void SetSensorUltrasonic(const byte & port) { SetSensorLowspeed(port); }
347 
348 /**
349  * Configure an EMeter sensor.
350  * Configure the sensor on the specified port as an EMeter sensor.
351  * \param port The port to configure. See \ref InPorts.
352  */
SetSensorEMeter(const byte & port)353 inline void SetSensorEMeter(const byte & port) { SetSensorLowspeed(port); }
354 
355 /**
356  * Configure a temperature sensor.
357  * Configure the sensor on the specified port as a temperature sensor. Use this
358  * to setup the temperature sensor rather than \ref SetSensorLowspeed so that
359  * the sensor is properly configured in 12-bit conversion mode.
360  * \param port The port to configure. See \ref InPorts.
361  */
SetSensorTemperature(const byte & port)362 inline void SetSensorTemperature(const byte & port) {
363   SetSensorLowspeed(port);
364   asm {
365     __MSWriteToRegister(port, LEGO_ADDR_TEMP, TEMP_REG_CONFIG, TEMP_RES_12BIT, __WDSC_LSStatus)
366   }
367 }
368 
369 
370 #if __FIRMWARE_VERSION > 107
371 
372 /**
373  * Configure an NXT 2.0 full color sensor.
374  * Configure the sensor on the specified port as an NXT 2.0 color sensor
375  * in full color mode. Requires an NXT 2.0 compatible firmware.
376  * \param port The port to configure. See \ref InPorts.
377  *
378  * \warning This function requires an NXT 2.0 compatible firmware.
379  */
SetSensorColorFull(const byte & port)380 inline void SetSensorColorFull(const byte & port) { asm { __SetSensorColorFull(port) } }
381 
382 /**
383  * Configure an NXT 2.0 red light sensor.
384  * Configure the sensor on the specified port as an NXT 2.0 color sensor
385  * in red light mode. Requires an NXT 2.0 compatible firmware.
386  * \param port The port to configure. See \ref InPorts.
387  *
388  * \warning This function requires an NXT 2.0 compatible firmware.
389  */
SetSensorColorRed(const byte & port)390 inline void SetSensorColorRed(const byte & port) { asm { __SetSensorColorRed(port) } }
391 
392 /**
393  * Configure an NXT 2.0 green light sensor.
394  * Configure the sensor on the specified port as an NXT 2.0 color sensor
395  * in green light mode. Requires an NXT 2.0 compatible firmware.
396  * \param port The port to configure. See \ref InPorts.
397  *
398  * \warning This function requires an NXT 2.0 compatible firmware.
399  */
SetSensorColorGreen(const byte & port)400 inline void SetSensorColorGreen(const byte & port) { asm { __SetSensorColorGreen(port) } }
401 
402 /**
403  * Configure an NXT 2.0 blue light sensor.
404  * Configure the sensor on the specified port as an NXT 2.0 color sensor
405  * in blue light mode. Requires an NXT 2.0 compatible firmware.
406  * \param port The port to configure. See \ref InPorts.
407  *
408  * \warning This function requires an NXT 2.0 compatible firmware.
409  */
SetSensorColorBlue(const byte & port)410 inline void SetSensorColorBlue(const byte & port) { asm { __SetSensorColorBlue(port) } }
411 
412 /**
413  * Configure an NXT 2.0 no light sensor.
414  * Configure the sensor on the specified port as an NXT 2.0 color sensor
415  * in no light mode. Requires an NXT 2.0 compatible firmware.
416  * \param port The port to configure. See \ref InPorts.
417  *
418  * \warning This function requires an NXT 2.0 compatible firmware.
419  */
SetSensorColorNone(const byte & port)420 inline void SetSensorColorNone(const byte & port) { asm { __SetSensorColorNone(port) } }
421 
422 #endif
423 
424 #ifdef __DOXYGEN_DOCS
425 
426 /**
427  * Get an input field value.
428  * Return the value of the specified field of a sensor on the specified port.
429  *
430  * \param port The sensor port. See \ref InPorts.  A constant or a variable may
431  * be used (no expressions).
432  * \param field An input field constant.  See \ref InputFieldConstants.
433  * \return The input field value.
434  */
435 inline variant GetInput(const byte & port, const byte field);
436 
437 /**
438  * Set an input field value.
439  * Set the specified field of the sensor on the specified port to the value
440  * provided.
441  *
442  * \param port The sensor port. See \ref InPorts. A constant or a variable
443  * may be used (no expressions).
444  * \param field An input field constant. See \ref InputFieldConstants.
445  * \param value The new value, which may be any valid expression.
446  */
447 inline void SetInput(const byte & port, const int field, variant value);
448 
449 /**
450  * Read sensor scaled value.
451  * Return the processed sensor reading for a sensor on the specified port.
452  * This is the same value that is returned by the sensor value names
453  * (e.g. \ref SENSOR_1).
454  *
455  * \param port The sensor port. See \ref InPorts. A variable whose value is
456  * the desired sensor port may also be used.
457  * \return The sensor's scaled value.
458  */
459 inline unsigned int Sensor(const byte & port);
460 
461 /**
462  * Read sensor boolean value.
463  * Return the boolean value of a sensor on the specified port. Boolean
464  * conversion is either done based on preset cutoffs, or a slope parameter
465  * specified by calling SetSensorMode.
466  *
467  * \param port The sensor port. See \ref InPorts. Must be a constant.
468  * \return The sensor's boolean value.
469  */
470 inline bool SensorBoolean(const byte port);
471 
472 /**
473  * Read sensor digital pins direction.
474  * Return the digital pins direction value of a sensor on the specified port.
475  *
476  * \param port The sensor port. See \ref InPorts. Must be a constant.
477  * \return The sensor's digital pins direction.
478  */
479 inline byte SensorDigiPinsDirection(const byte port);
480 
481 /**
482  * Read sensor digital pins output level.
483  * Return the digital pins output level value of a sensor on the specified port.
484  *
485  * \param port The sensor port. See \ref InPorts. Must be a constant.
486  * \return The sensor's digital pins output level.
487  */
488 inline byte SensorDigiPinsOutputLevel(const byte port);
489 
490 /**
491  * Read sensor digital pins status.
492  * Return the digital pins status value of a sensor on the specified port.
493  *
494  * \param port The sensor port. See \ref InPorts. Must be a constant.
495  * \return The sensor's digital pins status.
496  */
497 inline byte SensorDigiPinsStatus(const byte port);
498 
499 /**
500  * Read sensor invalid data flag.
501  * Return the value of the InvalidData flag of a sensor on the specified port.
502  *
503  * \param port The sensor port. See \ref InPorts. A variable whose value is
504  * the desired sensor port may also be used.
505  * \return The sensor's invalid data flag.
506  */
507 inline bool SensorInvalid(const byte & port);
508 
509 /**
510  * Read sensor mode.
511  * Return the mode of a sensor on the specified port.
512  *
513  * \param port The sensor port. See \ref InPorts. A variable whose value is
514  * the desired sensor port may also be used.
515  * \return The sensor's mode. See \ref SensorModes.
516  */
517 inline byte SensorMode(const byte & port);
518 
519 /**
520  * Read sensor normalized value.
521  * Return the normalized value of a sensor on the specified port.
522  *
523  * \param port The sensor port. See \ref InPorts. A variable whose value is
524  * the desired sensor port may also be used.
525  * \return The sensor's normalized value.
526  */
527 inline unsigned int SensorNormalized(const byte & port);
528 
529 /**
530  * Read sensor raw value.
531  * Return the raw value of a sensor on the specified port.
532  *
533  * \param port The sensor port. See \ref InPorts. A variable whose value is
534  * the desired sensor port may also be used.
535  * \return The sensor's raw value.
536  */
537 inline unsigned int SensorRaw(const byte & port);
538 
539 /**
540  * Read sensor scaled value.
541  * Return the processed sensor reading for a sensor on the specified port.
542  * This is the same value that is returned by the sensor value names
543  * (e.g. \ref SENSOR_1) or the \ref Sensor function.
544  *
545  * \param port The sensor port. See \ref InPorts. A variable whose value is
546  * the desired sensor port may also be used.
547  * \return The sensor's scaled value.
548  */
549 inline unsigned int SensorScaled(const byte & port);
550 
551 /**
552  * Read sensor type.
553  * Return the type of a sensor on the specified port.
554  *
555  * \param port The sensor port. See \ref InPorts. A variable whose value is
556  * the desired sensor port may also be used.
557  * \return The sensor's type. See \ref SensorTypes.
558  */
559 inline byte SensorType(const byte & port);
560 
561 /**
562  * Read sensor scaled value.
563  * Return the processed sensor reading for a sensor on the specified port.
564  * This is the same value that is returned by the sensor value names
565  * (e.g. \ref SENSOR_1) or the \ref Sensor function.
566  *
567  * \param port The sensor port. See \ref InPorts. A variable whose value is
568  * the desired sensor port may also be used.
569  * \return The sensor's scaled value.
570  */
571 inline unsigned int SensorValue(const byte & port);
572 
573 /**
574  * Read sensor boolean value.
575  * Return the boolean value of a sensor on the specified port. Boolean
576  * conversion is either done based on preset cutoffs, or a slope parameter
577  * specified by calling SetSensorMode.
578  *
579  * \param port The sensor port. See \ref InPorts. Must be a constant.
580  * \return The sensor's boolean value.
581  */
582 inline bool SensorValueBool(const byte port);
583 
584 /**
585  * Read sensor raw value.
586  * Return the raw value of a sensor on the specified port.
587  *
588  * \param port The sensor port. See \ref InPorts. A variable whose value is
589  * the desired sensor port may also be used.
590  * \return The sensor's raw value.
591  */
592 inline unsigned int SensorValueRaw(const byte & port);
593 
594 /**
595  * Get the custom sensor active status.
596  * Return the custom sensor active status value of a sensor.
597  *
598  * \param port The sensor port. See \ref InPorts.
599  * \return The custom sensor active status.
600 */
601 inline byte CustomSensorActiveStatus(byte port);
602 
603 /**
604  * Get the custom sensor percent full scale.
605  * Return the custom sensor percent full scale value of a sensor.
606  *
607  * \param port The sensor port. See \ref InPorts.
608  * \return The custom sensor percent full scale.
609  */
610 inline byte CustomSensorPercentFullScale(byte port);
611 
612 /**
613  * Get the custom sensor zero offset.
614  * Return the custom sensor zero offset value of a sensor.
615  *
616  * \param port The sensor port. See \ref InPorts.
617  * \return The custom sensor zero offset.
618  */
619 inline unsigned int CustomSensorZeroOffset(byte port);
620 
621 /**
622  * Set active status.
623  * Sets the active status value of a custom sensor.
624  *
625  * \param port The sensor port. See \ref InPorts.
626  * \param activeStatus The new active status value.
627  */
628 inline void SetCustomSensorActiveStatus(byte port, byte activeStatus);
629 
630 /**
631  * Set percent full scale.
632  * Sets the percent full scale value of a custom sensor.
633  *
634  * \param port The sensor port. See \ref InPorts.
635  * \param pctFullScale The new percent full scale value.
636  */
637 inline void SetCustomSensorPercentFullScale(byte port, byte pctFullScale);
638 
639 /**
640  * Set custom zero offset.
641  * Sets the zero offset value of a custom sensor.
642  *
643  * \param port The sensor port. See \ref InPorts.
644  * \param zeroOffset The new zero offset value.
645  */
646 inline void SetCustomSensorZeroOffset(byte port, int zeroOffset);
647 
648 /**
649  * Set sensor boolean value.
650  * Sets the boolean value of a sensor.
651  *
652  * \param port The sensor port. See \ref InPorts.
653  * \param value The new boolean value.
654  */
655 inline void SetSensorBoolean(byte port, bool value);
656 
657 /**
658  * Set digital pins direction.
659  * Sets the digital pins direction value of a sensor.
660  *
661  * \param port The sensor port. See \ref InPorts.
662  * \param direction The new digital pins direction value.
663  */
664 inline void SetSensorDigiPinsDirection(byte port, byte direction);
665 
666 /**
667  * Set digital pins output level.
668  * Sets the digital pins output level value of a sensor.
669  *
670  * \param port The sensor port. See \ref InPorts.
671  * \param outputLevel The new digital pins output level value.
672  */
673 inline void SetSensorDigiPinsOutputLevel(byte port, byte outputLevel);
674 
675 /**
676  * Set digital pins status.
677  * Sets the digital pins status value of a sensor.
678  *
679  * \param port The sensor port. See \ref InPorts.
680  * \param status The new digital pins status value.
681  */
682 inline void SetSensorDigiPinsStatus(byte port, byte status);
683 
684 
685 #if __FIRMWARE_VERSION > 107
686 /**
687  * Read LEGO color sensor.
688  * This function lets you read the LEGO color sensor given the parameters you
689  * pass in via the \ref ColorSensorReadType structure.
690  *
691  * \param args The ColorSensorReadType structure containing the required parameters.
692  *
693  * \warning This function requires an NXT 2.0 compatible firmware.
694  */
695 inline void SysColorSensorRead(ColorSensorReadType & args);
696 
697 /**
698  * Read LEGO color sensor extra.
699  * This function lets you read the LEGO color sensor. It returns the color value,
700  * and three arrays containing raw, normalized, and scaled color values for
701  * red, green, blue, and none indices.
702  *
703  * \param port The sensor port. See \ref InPorts.
704  * \param colorval The color value. See \ref InputColorValueConstants.
705  * \param raw An array containing four raw color values. See \ref InputColorIdxConstants.
706  * \param norm An array containing four normalized color values. See \ref InputColorIdxConstants.
707  * \param scaled An array containing four scaled color values. See \ref InputColorIdxConstants.
708  * \return The function call result.
709  * \warning This function requires an NXT 2.0 compatible firmware.
710  */
711 inline int ReadSensorColorEx(const byte & port, int & colorval, unsigned int & raw[], unsigned int & norm[], int & scaled[]);
712 
713 /**
714  * Read LEGO color sensor raw values.
715  * This function lets you read the LEGO color sensor. It returns an array
716  * containing raw color values for red, green, blue, and none indices.
717  *
718  * \param port The sensor port. See \ref InPorts.
719  * \param rawVals An array containing four raw color values. See \ref InputColorIdxConstants.
720  * \return The function call result.
721  * \warning This function requires an NXT 2.0 compatible firmware.
722  */
723 inline int ReadSensorColorRaw(const byte & port, unsigned int & rawVals[]);
724 
725 /**
726  * Read a LEGO color sensor AD raw value.
727  * This function lets you directly access a specific LEGO color sensor AD raw value. Both the
728  * port and the color index must be constants.
729  *
730  * \param port The sensor port. See \ref InPorts.
731  * \param color The color index. See \ref InputColorIdxConstants.
732  * \return The AD raw value.
733  * \warning This function requires an NXT 2.0 compatible firmware.
734  */
735 inline unsigned int ColorADRaw(byte port, byte color);
736 
737 /**
738  * Read a LEGO color sensor boolean value.
739  * This function lets you directly access a specific LEGO color sensor boolean value. Both the
740  * port and the color index must be constants.
741  *
742  * \param port The sensor port. See \ref InPorts.
743  * \param color The color index. See \ref InputColorIdxConstants.
744  * \return The boolean value.
745  * \warning This function requires an NXT 2.0 compatible firmware.
746  */
747 inline bool ColorBoolean(byte port, byte color);
748 
749 /**
750  * Read a LEGO color sensor calibration point value.
751  * This function lets you directly access a specific LEGO color calibration point value.
752  * The port, point, and color index must be constants.
753  *
754  * \param port The sensor port. See \ref InPorts.
755  * \param point The calibration point. See \ref InputColorCalibrationConstants.
756  * \param color The color index. See \ref InputColorIdxConstants.
757  * \return The calibration point value.
758  * \warning This function requires an NXT 2.0 compatible firmware.
759  */
760 inline long ColorCalibration(byte port, byte point, byte color);
761 
762 /**
763  * Read LEGO color sensor calibration state.
764  * This function lets you directly access the LEGO color calibration state.
765  * The port must be a constant.
766  *
767  * \param port The sensor port. See \ref InPorts.
768  * \return The calibration state.
769  * \warning This function requires an NXT 2.0 compatible firmware.
770  */
771 inline byte ColorCalibrationState(byte port);
772 
773 /**
774  * Read a LEGO color sensor calibration limit value.
775  * This function lets you directly access a specific LEGO color calibration limit value.
776  * The port and the point must be constants.
777  *
778  * \param port The sensor port. See \ref InPorts.
779  * \param point The calibration point. See \ref InputColorCalibrationConstants.
780  * \return The calibration limit value.
781  * \warning This function requires an NXT 2.0 compatible firmware.
782  */
783 inline unsigned int ColorCalLimits(byte port, byte point);
784 
785 /**
786  * Read a LEGO color sensor raw value.
787  * This function lets you directly access a specific LEGO color sensor raw value. Both the
788  * port and the color index must be constants.
789  *
790  * \param port The sensor port. See \ref InPorts.
791  * \param color The color index. See \ref InputColorIdxConstants.
792  * \return The raw value.
793  * \warning This function requires an NXT 2.0 compatible firmware.
794  */
795 inline unsigned int ColorSensorRaw(byte port, byte color);
796 
797 /**
798  * Read a LEGO color sensor scaled value.
799  * This function lets you directly access a specific LEGO color sensor scaled value. Both the
800  * port and the color index must be constants.
801  *
802  * \param port The sensor port. See \ref InPorts.
803  * \param color The color index. See \ref InputColorIdxConstants.
804  * \return The scaled value.
805  * \warning This function requires an NXT 2.0 compatible firmware.
806  */
807 inline unsigned int ColorSensorValue(byte port, byte color);
808 
809 #endif
810 
811 #else
812 
813 enum InputFieldNames {
814   Type,
815   InputMode,
816   RawValue,
817   NormalizedValue,
818   ScaledValue,
819   InvalidData
820 };
821 
822 enum OutputFieldNames {
823   UpdateFlags,
824   OutputMode,
825   Power,
826   ActualSpeed,
827   TachoCount,
828   TachoLimit,
829   RunState,
830   TurnRatio,
831   RegMode,
832   Overload,
833   RegPValue,
834   RegIValue,
835   RegDValue,
836   BlockTachoCount,
837   RotationCount,
838   OutputOptions,
839   MaxSpeed,
840   MaxAcceleration
841 };
842 
843 // input fields
844 #define Sensor(_p) asm { ReadSensor(_p, __RETVAL__) }
845 #define SensorValue(_p) Sensor(_p)
846 #define SensorType(_p) GetInput(_p, TypeField)
847 #define SensorMode(_p) GetInput(_p, InputModeField)
848 #define SensorRaw(_p) GetInput(_p, RawValueField)
849 #define SensorNormalized(_p) GetInput(_p, NormalizedValueField)
850 #define SensorScaled(_p) GetInput(_p, ScaledValueField)
851 #define SensorInvalid(_p) GetInput(_p, InvalidDataField)
852 #define SensorValueBool(_p) SensorBoolean(_p)
853 #define SensorValueRaw(_p) SensorRaw(_p)
854 
855 #define CustomSensorZeroOffset(_p) asm { GetInCustomZeroOffset(_p, __TMPWORD__) __RETURN__ __TMPWORD__ }
856 #define CustomSensorPercentFullScale(_p) asm { GetInCustomPercentFullScale(_p, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
857 #define CustomSensorActiveStatus(_p) asm { GetInCustomActiveStatus(_p, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
858 #define SensorBoolean(_p) asm { GetInSensorBoolean(_p, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
859 #define SensorDigiPinsDirection(_p) asm { GetInDigiPinsDirection(_p, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
860 #define SensorDigiPinsStatus(_p) asm { GetInDigiPinsStatus(_p, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
861 #define SensorDigiPinsOutputLevel(_p) asm { GetInDigiPinsOutputLevel(_p, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
862 
863 #define SetCustomSensorZeroOffset(_p, _n) asm { __setInCustomZeroOffset(_p, _n) }
864 #define SetCustomSensorPercentFullScale(_p, _n) asm { __setInCustomPercentFullScale(_p, _n) }
865 #define SetCustomSensorActiveStatus(_p, _n) asm { __setInCustomActiveStatus(_p, _n) }
866 #define SetSensorBoolean(_p, _n) asm { __setInSensorBoolean(_p, _n) }
867 #define SetSensorDigiPinsDirection(_p, _n) asm { __setInDigiPinsDirection(_p, _n) }
868 #define SetSensorDigiPinsStatus(_p, _n) asm { __setInDigiPinsStatus(_p, _n) }
869 #define SetSensorDigiPinsOutputLevel(_p, _n) asm { __setInDigiPinsOutputLevel(_p, _n) }
870 
871 
872 #if __FIRMWARE_VERSION > 107
873 
874 #define SysColorSensorRead(_args) asm { \
875   compchktype _args, ColorSensorReadType \
876   syscall ColorSensorRead, _args \
877 }
878 
879 #define ReadSensorColorRaw(_port, _rawVals) asm { __ReadSensorColorRaw(_port, _rawVals, __RETVAL__) }
880 #define ReadSensorColorEx(_port, _colorval, _raw, _norm, _scaled) asm { __ReadSensorColorEx(_port, _colorval, _raw, _norm, _scaled, __RETVAL__) }
881 
882 #define ColorCalibration(_p, _np, _nc) asm { GetInColorCalibration(_p, _np, _nc, __TMPLONG__) __RETURN__ __TMPLONG__ }
883 #define ColorCalLimits(_p, _np) asm { GetInColorCalLimits(_p, _np, __TMPWORD__) __RETURN__ __TMPWORD__ }
884 #define ColorADRaw(_p, _nc) asm { GetInColorADRaw(_p, _nc, __TMPWORD__) __RETURN__ __TMPWORD__ }
885 #define ColorSensorRaw(_p, _nc) asm { GetInColorSensorRaw(_p, _nc, __TMPWORD__) __RETURN__ __TMPWORD__ }
886 #define ColorSensorValue(_p, _nc) asm { GetInColorSensorValue(_p, _nc, __TMPWORD__) __RETURN__ __TMPWORD__ }
887 #define ColorBoolean(_p, _nc) asm { GetInColorBoolean(_p, _nc, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
888 #define ColorCalibrationState(_p) asm { GetInColorCalibrationState(_p, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
889 
890 #endif
891 
892 #endif
893 /** @} */ // end of InputModuleFunctions group
894 /** @} */ // end of InputModule group
895 /** @} */ // end of NXTFirmwareModules group
896 
897 
898 ///////////////////////////////////////////////////////////////////////////////
899 //////////////////////////////// OUTPUT MODULE ////////////////////////////////
900 ///////////////////////////////////////////////////////////////////////////////
901 
902 
903 /** @addtogroup NXTFirmwareModules
904  * @{
905  */
906 /** @addtogroup OutputModule
907  * @{
908  */
909 /** @defgroup OutputModuleTypes Output module types
910  * Types used by various output module functions.
911  * @{
912  */
913 
914 #if defined(__ENHANCED_FIRMWARE) && (__FIRMWARE_VERSION > 107)
915 /**
916  * Parameters for the \ref RemoteGetOutputState function.
917  * This structure is used when calling the \ref RemoteGetOutputState function.
918  * Choose the sensor port (\ref OutputPortConstants) and after calling the function
919  * read the output status values from the various structure fields.
920  */
921 struct OutputStateType {
922   byte Port;                /*!< The output port. See the \ref OutputPortConstants group. */
923   char Power;               /*!< The output power level (-100..100). */
924   byte Mode;                /*!< The output mode. See \ref OutModeConstants group. */
925   byte RegMode;             /*!< The output regulation mode. See \ref OutRegModeConstants group. */
926   char TurnRatio;           /*!< The output turning ratio (-100..100). */
927   byte RunState;            /*!< The output run state. See \ref OutRunStateConstants group. */
928   unsigned long TachoLimit; /*!< The tachometer limit. */
929   long TachoCount;          /*!< The current tachometer count. */
930   long BlockTachoCount;     /*!< The current block tachometer count. */
931   long RotationCount;       /*!< The current rotation count. */
932 };
933 
934 #endif
935 
936 /** @} */ // end of OutputModuleTypes group
937 
938 /** @defgroup OutputModuleFunctions Output module functions
939  * Functions for accessing and modifying output module features.
940  * @{
941  */
942 
943 #ifdef __DOXYGEN_DOCS
944 
945 /**
946  * Set motor regulation frequency.
947  * Set the motor regulation frequency in milliseconds. By default this is set
948  * to 100ms.
949  * \param n The motor regulation frequency.
950  */
951 inline void SetMotorPwnFreq(byte n);
952 
953 /**
954  * Set regulation time.
955  * Set the motor regulation time in milliseconds. By default this is set
956  * to 100ms.
957  *
958  * \warning This function requires the enhanced NBC/NXC firmware version 1.31+
959  *
960  * \param n The motor regulation time.
961  */
962 inline void SetMotorRegulationTime(byte n);
963 
964 /**
965  * Set regulation options.
966  * Set the motor regulation options.
967  *
968  * \warning This function requires the enhanced NBC/NXC firmware version 1.31+
969  *
970  * \param n The motor regulation options.
971  */
972 inline void SetMotorRegulationOptions(byte n);
973 
974 /**
975  * Run motors forward synchronised with PID factors.
976  * Run the specified outputs forward with regulated synchronization using the
977  * specified turn ratio.
978  * Specify proportional, integral, and derivative factors.
979  *
980  * \param outputs Desired output ports. Can be a constant or a variable, see
981  * \ref OutputPortConstants. If you use a variable and want to control multiple
982  * outputs in a single call you need to use a byte array rather than a byte and
983  * store the output port values in the byte array before passing it into this function.
984  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
985  * \param turnpct Turn ratio, -100 to 100. The direction of your vehicle will
986  * depend on its construction.
987  * \param p Proportional factor used by the firmware's PID motor control
988  * algorithm. See \ref PIDConstants.
989  * \param i Integral factor used by the firmware's PID motor control
990  * algorithm. See \ref PIDConstants.
991  * \param d Derivative factor used by the firmware's PID motor control
992  * algorithm. See \ref PIDConstants.
993  */
994 inline void OnFwdSyncPID(byte outputs, char pwr, char turnpct, byte p, byte i, byte d);
995 
996 /**
997  * Run motors forward synchronised and reset counters with PID factors.
998  * Run the specified outputs forward with regulated synchronization using the
999  * specified turn ratio.
1000  * Specify proportional, integral, and derivative factors.
1001  *
1002  * \param outputs Desired output ports. Can be a constant or a variable, see
1003  * \ref OutputPortConstants. If you use a variable and want to control multiple
1004  * outputs in a single call you need to use a byte array rather than a byte and
1005  * store the output port values in the byte array before passing it into this function.
1006  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
1007  * \param turnpct Turn ratio, -100 to 100. The direction of your vehicle will
1008  * depend on its construction.
1009  * \param reset Position counters reset control. It must be a constant, see
1010  * \ref TachoResetConstants.
1011  * \param p Proportional factor used by the firmware's PID motor control
1012  * algorithm. See \ref PIDConstants.
1013  * \param i Integral factor used by the firmware's PID motor control
1014  * algorithm. See \ref PIDConstants.
1015  * \param d Derivative factor used by the firmware's PID motor control
1016  * algorithm. See \ref PIDConstants.
1017  */
1018 inline void OnFwdSyncExPID(byte outputs, char pwr, char turnpct, const byte reset, byte p, byte i, byte d);
1019 
1020 /**
1021  * Run motors backward synchronised with PID factors.
1022  * Run the specified outputs in reverse with regulated synchronization using
1023  * the specified turn ratio.
1024  * Specify proportional, integral, and derivative factors.
1025  *
1026  * \param outputs Desired output ports. Can be a constant or a variable, see
1027  * \ref OutputPortConstants. If you use a variable and want to control multiple
1028  * outputs in a single call you need to use a byte array rather than a byte and
1029  * store the output port values in the byte array before passing it into this function.
1030  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
1031  * \param turnpct Turn ratio, -100 to 100. The direction of your vehicle will
1032  * depend on its construction.
1033  * \param p Proportional factor used by the firmware's PID motor control
1034  * algorithm. See \ref PIDConstants.
1035  * \param i Integral factor used by the firmware's PID motor control
1036  * algorithm. See \ref PIDConstants.
1037  * \param d Derivative factor used by the firmware's PID motor control
1038  * algorithm. See \ref PIDConstants.
1039  */
1040 inline void OnRevSyncPID(byte outputs, char pwr, char turnpct, byte p, byte i, byte d);
1041 
1042 /**
1043  * Run motors backward synchronised and reset counters with PID factors.
1044  * Run the specified outputs in reverse with regulated synchronization using
1045  * the specified turn ratio.
1046  * Specify proportional, integral, and derivative factors.
1047  *
1048  * \param outputs Desired output ports. Can be a constant or a variable, see
1049  * \ref OutputPortConstants. If you use a variable and want to control multiple
1050  * outputs in a single call you need to use a byte array rather than a byte and
1051  * store the output port values in the byte array before passing it into this function.
1052  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
1053  * \param turnpct Turn ratio, -100 to 100. The direction of your vehicle will
1054  * depend on its construction.
1055  * \param reset Position counters reset control. It must be a constant, see
1056  * \ref TachoResetConstants.
1057  * \param p Proportional factor used by the firmware's PID motor control
1058  * algorithm. See \ref PIDConstants.
1059  * \param i Integral factor used by the firmware's PID motor control
1060  * algorithm. See \ref PIDConstants.
1061  * \param d Derivative factor used by the firmware's PID motor control
1062  * algorithm. See \ref PIDConstants.
1063  */
1064 inline void OnRevSyncExPID(byte outputs, char pwr, char turnpct, const byte reset, byte p, byte i, byte d);
1065 
1066 /**
1067  * Run motors forward regulated with PID factors.
1068  * Run the specified outputs forward using the specified regulation mode.
1069  * Specify proportional, integral, and derivative factors.
1070  *
1071  * \param outputs Desired output ports. Can be a constant or a variable, see
1072  * \ref OutputPortConstants. If you use a variable and want to control multiple
1073  * outputs in a single call you need to use a byte array rather than a byte and
1074  * store the output port values in the byte array before passing it into this function.
1075  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
1076  * \param regmode Regulation mode, see \ref OutRegModeConstants.
1077  * \param p Proportional factor used by the firmware's PID motor control
1078  * algorithm. See \ref PIDConstants.
1079  * \param i Integral factor used by the firmware's PID motor control
1080  * algorithm. See \ref PIDConstants.
1081  * \param d Derivative factor used by the firmware's PID motor control
1082  * algorithm. See \ref PIDConstants.
1083  */
1084 inline void OnFwdRegPID(byte outputs, char pwr, byte regmode, byte p, byte i, byte d);
1085 
1086 /**
1087  * Run motors forward regulated and reset counters with PID factors.
1088  * Run the specified outputs forward using the specified regulation mode.
1089  * Specify proportional, integral, and derivative factors.
1090  *
1091  * \param outputs Desired output ports. Can be a constant or a variable, see
1092  * \ref OutputPortConstants. If you use a variable and want to control multiple
1093  * outputs in a single call you need to use a byte array rather than a byte and
1094  * store the output port values in the byte array before passing it into this function.
1095  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
1096  * \param regmode Regulation mode, see \ref OutRegModeConstants.
1097  * \param reset Position counters reset control. It must be a constant, see
1098  * \ref TachoResetConstants.
1099  * \param p Proportional factor used by the firmware's PID motor control
1100  * algorithm. See \ref PIDConstants.
1101  * \param i Integral factor used by the firmware's PID motor control
1102  * algorithm. See \ref PIDConstants.
1103  * \param d Derivative factor used by the firmware's PID motor control
1104  * algorithm. See \ref PIDConstants.
1105  */
1106 inline void OnFwdRegExPID(byte outputs, char pwr, byte regmode, const byte reset, byte p, byte i, byte d);
1107 
1108 /**
1109  * Run motors reverse regulated with PID factors.
1110  * Run the specified outputs in reverse using the specified regulation mode.
1111  * Specify proportional, integral, and derivative factors.
1112  *
1113  * \param outputs Desired output ports. Can be a constant or a variable, see
1114  * \ref OutputPortConstants. If you use a variable and want to control multiple
1115  * outputs in a single call you need to use a byte array rather than a byte and
1116  * store the output port values in the byte array before passing it into this function.
1117  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
1118  * \param regmode Regulation mode, see \ref OutRegModeConstants.
1119  * \param p Proportional factor used by the firmware's PID motor control
1120  * algorithm. See \ref PIDConstants.
1121  * \param i Integral factor used by the firmware's PID motor control
1122  * algorithm. See \ref PIDConstants.
1123  * \param d Derivative factor used by the firmware's PID motor control
1124  * algorithm. See \ref PIDConstants.
1125  */
1126 inline void OnRevRegPID(byte outputs, char pwr, byte regmode, byte p, byte i, byte d);
1127 
1128 /**
1129  * Run motors backward regulated and reset counters with PID factors.
1130  * Run the specified outputs in reverse using the specified regulation mode.
1131  * Specify proportional, integral, and derivative factors.
1132  *
1133  * \param outputs Desired output ports. Can be a constant or a variable, see
1134  * \ref OutputPortConstants. If you use a variable and want to control multiple
1135  * outputs in a single call you need to use a byte array rather than a byte and
1136  * store the output port values in the byte array before passing it into this function.
1137  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
1138  * \param regmode Regulation mode, see \ref OutRegModeConstants.
1139  * \param reset Position counters reset control. It must be a constant, see
1140  * \ref TachoResetConstants.
1141  * \param p Proportional factor used by the firmware's PID motor control
1142  * algorithm. See \ref PIDConstants.
1143  * \param i Integral factor used by the firmware's PID motor control
1144  * algorithm. See \ref PIDConstants.
1145  * \param d Derivative factor used by the firmware's PID motor control
1146  * algorithm. See \ref PIDConstants.
1147  */
1148 inline void OnRevRegExPID(byte outputs, char pwr, byte regmode, const byte reset, byte p, byte i, byte d);
1149 
1150 /**
1151  * Turn motors off.
1152  * Turn the specified outputs off (with braking).
1153  *
1154  * \param outputs Desired output ports. Can be a constant or a variable, see
1155  * \ref OutputPortConstants. If you use a variable and want to control multiple
1156  * outputs in a single call you need to use a byte array rather than a byte and
1157  * store the output port values in the byte array before passing it into this function.
1158  */
1159 inline void Off(byte outputs);
1160 
1161 /**
1162  * Turn motors off and reset counters.
1163  * Turn the specified outputs off (with braking).
1164  *
1165  * \param outputs Desired output ports. Can be a constant or a variable, see
1166  * \ref OutputPortConstants. If you use a variable and want to control multiple
1167  * outputs in a single call you need to use a byte array rather than a byte and
1168  * store the output port values in the byte array before passing it into this function.
1169  * \param reset Position counters reset control. It must be a constant, see
1170  * \ref TachoResetConstants.
1171  */
1172 inline void OffEx(byte outputs, const byte reset);
1173 
1174 /**
1175  * Coast motors.
1176  * Turn off the specified outputs, making them coast to a stop.
1177  *
1178  * \param outputs Desired output ports. Can be a constant or a variable, see
1179  * \ref OutputPortConstants. If you use a variable and want to control multiple
1180  * outputs in a single call you need to use a byte array rather than a byte and
1181  * store the output port values in the byte array before passing it into this function.
1182  */
1183 inline void Coast(byte outputs);
1184 
1185 /**
1186  * Coast motors and reset counters.
1187  * Turn off the specified outputs, making them coast to a stop.
1188  *
1189  * \param outputs Desired output ports. Can be a constant or a variable, see
1190  * \ref OutputPortConstants. If you use a variable and want to control multiple
1191  * outputs in a single call you need to use a byte array rather than a byte and
1192  * store the output port values in the byte array before passing it into this function.
1193  * \param reset Position counters reset control. It must be a constant, see
1194  * \ref TachoResetConstants.
1195  */
1196 inline void CoastEx(byte outputs, const byte reset);
1197 
1198 /**
1199  * Float motors.
1200  * Make outputs float. Float is an alias for Coast.
1201  *
1202  * \param outputs Desired output ports. Can be a constant or a variable, see
1203  * \ref OutputPortConstants. If you use a variable and want to control multiple
1204  * outputs in a single call you need to use a byte array rather than a byte and
1205  * store the output port values in the byte array before passing it into this function.
1206  */
1207 inline void Float(byte outputs);
1208 
1209 /**
1210  * Run motors forward.
1211  * Set outputs to forward direction and turn them on.
1212  *
1213  * \param outputs Desired output ports. Can be a constant or a variable, see
1214  * \ref OutputPortConstants. If you use a variable and want to control multiple
1215  * outputs in a single call you need to use a byte array rather than a byte and
1216  * store the output port values in the byte array before passing it into this function.
1217  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
1218  */
1219 inline void OnFwd(byte outputs, char pwr);
1220 
1221 /**
1222  * Run motors forward and reset counters.
1223  * Set outputs to forward direction and turn them on.
1224  *
1225  * \param outputs Desired output ports. Can be a constant or a variable, see
1226  * \ref OutputPortConstants. If you use a variable and want to control multiple
1227  * outputs in a single call you need to use a byte array rather than a byte and
1228  * store the output port values in the byte array before passing it into this function.
1229  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
1230  * \param reset Position counters reset control. It must be a constant, see
1231  * \ref TachoResetConstants.
1232  */
1233 inline void OnFwdEx(byte outputs, char pwr, const byte reset);
1234 
1235 /**
1236  * Run motors backward.
1237  * Set outputs to reverse direction and turn them on.
1238  *
1239  * \param outputs Desired output ports. Can be a constant or a variable, see
1240  * \ref OutputPortConstants. If you use a variable and want to control multiple
1241  * outputs in a single call you need to use a byte array rather than a byte and
1242  * store the output port values in the byte array before passing it into this function.
1243  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
1244  */
1245 inline void OnRev(byte outputs, char pwr);
1246 
1247 /**
1248  * Run motors backward and reset counters.
1249  * Set outputs to reverse direction and turn them on.
1250  *
1251  * \param outputs Desired output ports. Can be a constant or a variable, see
1252  * \ref OutputPortConstants. If you use a variable and want to control multiple
1253  * outputs in a single call you need to use a byte array rather than a byte and
1254  * store the output port values in the byte array before passing it into this function.
1255  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
1256  * \param reset Position counters reset control. It must be a constant, see
1257  * \ref TachoResetConstants.
1258  */
1259 inline void OnRevEx(byte outputs, char pwr, const byte reset);
1260 
1261 /**
1262  * Run motors forward regulated.
1263  * Run the specified outputs forward using the specified regulation mode.
1264  *
1265  * \param outputs Desired output ports. Can be a constant or a variable, see
1266  * \ref OutputPortConstants. If you use a variable and want to control multiple
1267  * outputs in a single call you need to use a byte array rather than a byte and
1268  * store the output port values in the byte array before passing it into this function.
1269  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
1270  * \param regmode Regulation mode, see \ref OutRegModeConstants.
1271  */
1272 inline void OnFwdReg(byte outputs, char pwr, byte regmode);
1273 
1274 /**
1275  * Run motors forward regulated and reset counters.
1276  * Run the specified outputs forward using the specified regulation mode.
1277  *
1278  * \param outputs Desired output ports. Can be a constant or a variable, see
1279  * \ref OutputPortConstants. If you use a variable and want to control multiple
1280  * outputs in a single call you need to use a byte array rather than a byte and
1281  * store the output port values in the byte array before passing it into this function.
1282  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
1283  * \param regmode Regulation mode, see \ref OutRegModeConstants.
1284  * \param reset Position counters reset control. It must be a constant, see
1285  * \ref TachoResetConstants.
1286  */
1287 inline void OnFwdRegEx(byte outputs, char pwr, byte regmode, const byte reset);
1288 
1289 /**
1290  * Run motors forward regulated.
1291  * Run the specified outputs in reverse using the specified regulation mode.
1292  *
1293  * \param outputs Desired output ports. Can be a constant or a variable, see
1294  * \ref OutputPortConstants. If you use a variable and want to control multiple
1295  * outputs in a single call you need to use a byte array rather than a byte and
1296  * store the output port values in the byte array before passing it into this function.
1297  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
1298  * \param regmode Regulation mode, see \ref OutRegModeConstants.
1299  */
1300 inline void OnRevReg(byte outputs, char pwr, byte regmode);
1301 
1302 /**
1303  * Run motors backward regulated and reset counters.
1304  * Run the specified outputs in reverse using the specified regulation mode.
1305  *
1306  * \param outputs Desired output ports. Can be a constant or a variable, see
1307  * \ref OutputPortConstants. If you use a variable and want to control multiple
1308  * outputs in a single call you need to use a byte array rather than a byte and
1309  * store the output port values in the byte array before passing it into this function.
1310  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
1311  * \param regmode Regulation mode, see \ref OutRegModeConstants.
1312  * \param reset Position counters reset control. It must be a constant, see
1313  * \ref TachoResetConstants.
1314  */
1315 inline void OnRevRegEx(byte outputs, char pwr, byte regmode, const byte reset);
1316 
1317 /**
1318  * Run motors forward synchronised.
1319  * Run the specified outputs forward with regulated synchronization using the
1320  * specified turn ratio.
1321  *
1322  * \param outputs Desired output ports. Can be a constant or a variable, see
1323  * \ref OutputPortConstants. If you use a variable and want to control multiple
1324  * outputs in a single call you need to use a byte array rather than a byte and
1325  * store the output port values in the byte array before passing it into this function.
1326  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
1327  * \param turnpct Turn ratio, -100 to 100. The direction of your vehicle will
1328  * depend on its construction.
1329  */
1330 inline void OnFwdSync(byte outputs, char pwr, char turnpct);
1331 
1332 /**
1333  * Run motors forward synchronised and reset counters.
1334  * Run the specified outputs forward with regulated synchronization using the
1335  * specified turn ratio.
1336  *
1337  * \param outputs Desired output ports. Can be a constant or a variable, see
1338  * \ref OutputPortConstants. If you use a variable and want to control multiple
1339  * outputs in a single call you need to use a byte array rather than a byte and
1340  * store the output port values in the byte array before passing it into this function.
1341  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
1342  * \param turnpct Turn ratio, -100 to 100. The direction of your vehicle will
1343  * depend on its construction.
1344  * \param reset Position counters reset control. It must be a constant, see
1345  * \ref TachoResetConstants.
1346  */
1347 inline void OnFwdSyncEx(byte outputs, char pwr, char turnpct, const byte reset);
1348 
1349 /**
1350  * Run motors backward synchronised.
1351  * Run the specified outputs in reverse with regulated synchronization using
1352  * the specified turn ratio.
1353  *
1354  * \param outputs Desired output ports. Can be a constant or a variable, see
1355  * \ref OutputPortConstants. If you use a variable and want to control multiple
1356  * outputs in a single call you need to use a byte array rather than a byte and
1357  * store the output port values in the byte array before passing it into this function.
1358  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
1359  * \param turnpct Turn ratio, -100 to 100. The direction of your vehicle will
1360  * depend on its construction.
1361  */
1362 inline void OnRevSync(byte outputs, char pwr, char turnpct);
1363 
1364 /**
1365  * Run motors backward synchronised and reset counters.
1366  * Run the specified outputs in reverse with regulated synchronization using
1367  * the specified turn ratio.
1368  *
1369  * \param outputs Desired output ports. Can be a constant or a variable, see
1370  * \ref OutputPortConstants. If you use a variable and want to control multiple
1371  * outputs in a single call you need to use a byte array rather than a byte and
1372  * store the output port values in the byte array before passing it into this function.
1373  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
1374  * \param turnpct Turn ratio, -100 to 100. The direction of your vehicle will
1375  * depend on its construction.
1376  * \param reset Position counters reset control. It must be a constant, see
1377  * \ref TachoResetConstants.
1378  */
1379 inline void OnRevSyncEx(byte outputs, char pwr, char turnpct, const byte reset);
1380 
1381 /**
1382  * Rotate motor.
1383  * Run the specified outputs forward for the specified number of degrees.
1384  *
1385  * \param outputs Desired output ports. Can be a constant or a variable, see
1386  * \ref OutputPortConstants. If you use a variable and want to control multiple
1387  * outputs in a single call you need to use a byte array rather than a byte and
1388  * store the output port values in the byte array before passing it into this function.
1389  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
1390  * \param angle Angle limit, in degree. Can be negative to reverse direction.
1391  */
1392 inline void RotateMotor(byte outputs, char pwr, long angle);
1393 
1394 /**
1395  * Rotate motor with PID factors.
1396  * Run the specified outputs forward for the specified number of degrees.
1397  * Specify proportional, integral, and derivative factors.
1398  *
1399  * \param outputs Desired output ports. Can be a constant or a variable, see
1400  * \ref OutputPortConstants. If you use a variable and want to control multiple
1401  * outputs in a single call you need to use a byte array rather than a byte and
1402  * store the output port values in the byte array before passing it into this function.
1403  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
1404  * \param angle Angle limit, in degree. Can be negative to reverse direction.
1405  * \param p Proportional factor used by the firmware's PID motor control
1406  * algorithm. See \ref PIDConstants.
1407  * \param i Integral factor used by the firmware's PID motor control
1408  * algorithm. See \ref PIDConstants.
1409  * \param d Derivative factor used by the firmware's PID motor control
1410  * algorithm. See \ref PIDConstants.
1411  */
1412 inline void RotateMotorPID(byte outputs, char pwr, long angle, byte p, byte i, byte d);
1413 
1414 /**
1415  * Rotate motor.
1416  * Run the specified outputs forward for the specified number of degrees.
1417  *
1418  * \param outputs Desired output ports. Can be a constant or a variable, see
1419  * \ref OutputPortConstants. If you use a variable and want to control multiple
1420  * outputs in a single call you need to use a byte array rather than a byte and
1421  * store the output port values in the byte array before passing it into this function.
1422  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
1423  * \param angle Angle limit, in degree. Can be negative to reverse direction.
1424  * \param turnpct Turn ratio, -100 to 100. The direction of your vehicle will
1425  * depend on its construction.
1426  * \param sync Synchronise two motors. Should be set to true if a non-zero
1427  * turn percent is specified or no turning will occur.
1428  * \param stop Specify whether the motor(s) should brake at the end of the
1429  * rotation.
1430  */
1431 inline void RotateMotorEx(byte outputs, char pwr, long angle, char turnpct, bool sync, bool stop);
1432 
1433 /**
1434  * Rotate motor.
1435  * Run the specified outputs forward for the specified number of degrees.
1436  * Specify proportional, integral, and derivative factors.
1437  *
1438  * \param outputs Desired output ports. Can be a constant or a variable, see
1439  * \ref OutputPortConstants. If you use a variable and want to control multiple
1440  * outputs in a single call you need to use a byte array rather than a byte and
1441  * store the output port values in the byte array before passing it into this function.
1442  * \param pwr Output power, 0 to 100. Can be negative to reverse direction.
1443  * \param angle Angle limit, in degree. Can be negative to reverse direction.
1444  * \param turnpct Turn ratio, -100 to 100. The direction of your vehicle will
1445  * depend on its construction.
1446  * \param sync Synchronise two motors. Should be set to true if a non-zero
1447  * turn percent is specified or no turning will occur.
1448  * \param stop Specify whether the motor(s) should brake at the end of the
1449  * rotation.
1450  * \param p Proportional factor used by the firmware's PID motor control
1451  * algorithm. See \ref PIDConstants.
1452  * \param i Integral factor used by the firmware's PID motor control
1453  * algorithm. See \ref PIDConstants.
1454  * \param d Derivative factor used by the firmware's PID motor control
1455  * algorithm. See \ref PIDConstants.
1456  */
1457 inline void RotateMotorExPID(byte outputs, char pwr, long angle, char turnpct, bool sync, bool stop, byte p, byte i, byte d);
1458 
1459 /**
1460  * Reset tachometer counter.
1461  * Reset the tachometer count and tachometer limit goal for the specified
1462  * outputs.
1463  *
1464  * \param outputs Desired output ports. Can be a constant or a variable, see
1465  * \ref OutputPortConstants. For multiple outputs at the same time
1466  * you need to add single output port values into a byte array and pass the array
1467  * instead of a single numeric value.
1468  */
1469 inline void ResetTachoCount(byte outputs);
1470 
1471 /**
1472  * Reset block-relative counter.
1473  * Reset the block-relative position counter for the specified outputs.
1474  *
1475  * \param outputs Desired output ports. Can be a constant or a variable, see
1476  * \ref OutputPortConstants. For multiple outputs at the same time
1477  * you need to add single output port values into a byte array and pass the array
1478  * instead of a single numeric value.
1479  */
1480 inline void ResetBlockTachoCount(byte outputs);
1481 
1482 /**
1483  * Reset program-relative counter.
1484  * Reset the program-relative position counter for the specified outputs.
1485  *
1486  * \param outputs Desired output ports. Can be a constant or a variable, see
1487  * \ref OutputPortConstants. For multiple outputs at the same time
1488  * you need to add single output port values into a byte array and pass the array
1489  * instead of a single numeric value.
1490  */
1491 inline void ResetRotationCount(byte outputs);
1492 
1493 /**
1494  * Reset all tachometer counters.
1495  * Reset all three position counters and reset the current tachometer limit
1496  * goal for the specified outputs.
1497  *
1498  * \param outputs Desired output ports. Can be a constant or a variable, see
1499  * \ref OutputPortConstants. For multiple outputs at the same time
1500  * you need to add single output port values into a byte array and pass the array
1501  * instead of a single numeric value.
1502  */
1503 inline void ResetAllTachoCounts(byte outputs);
1504 
1505 /**
1506  * Set output fields.
1507  * Set the specified field of the outputs to the value provided. The field
1508  * must be a valid output field constant. This function takes a variable
1509  * number of field/value pairs.
1510  *
1511  * \param outputs Desired output ports. Can be a constant or a variable, see
1512  * \ref OutputPortConstants. For multiple outputs at the same time
1513  * you need to add single output port values into a byte array and pass the array
1514  * instead of a single numeric value.
1515  * \param field1 The 1st output port field to access, this should be a constant, see
1516  * \ref OutputFieldConstants.
1517  * \param val1 Value to set for the 1st field.
1518  * \param fieldN The Nth output port field to access, this should be a constant, see
1519  * \ref OutputFieldConstants.
1520  * \param valN The value to set for the Nth field.
1521  */
1522 inline void SetOutput(byte outputs, byte field1, variant val1, ..., byte fieldN, variant valN);
1523 
1524 /**
1525  * Get output field value.
1526  * Get the value of the specified field for the specified output.
1527  *
1528  * \param output Desired output port. Can be \ref OUT_A, \ref OUT_B, \ref
1529  * OUT_C or a variable containing one of these values, see \ref
1530  * OutputPortConstants.
1531  * \param field Output port field to access, this should be a constant, see
1532  * \ref OutputFieldConstants.
1533  * \return The requested output field value.
1534  */
1535 inline variant GetOutput(byte output, const byte field);
1536 
1537 /**
1538  * Get motor mode.
1539  * Get the mode of the specified output.
1540  *
1541  * \param output Desired output port. Can be \ref OUT_A, \ref OUT_B, \ref
1542  * OUT_C or a variable containing one of these values, see \ref
1543  * OutputPortConstants.
1544  * \return The mode of the specified output.
1545  */
1546 inline byte MotorMode(byte output);
1547 
1548 /**
1549  * Get motor power level.
1550  * Get the power level of the specified output.
1551  *
1552  * \param output Desired output port. Can be \ref OUT_A, \ref OUT_B, \ref
1553  * OUT_C or a variable containing one of these values, see \ref
1554  * OutputPortConstants.
1555  * \return The power level of the specified output.
1556  */
1557 inline char MotorPower(byte output);
1558 
1559 /**
1560  * Get motor actual speed.
1561  * Get the actual speed value of the specified output.
1562  *
1563  * \param output Desired output port. Can be \ref OUT_A, \ref OUT_B, \ref
1564  * OUT_C or a variable containing one of these values, see \ref
1565  * OutputPortConstants.
1566  * \return The actual speed value of the specified output.
1567  */
1568 inline char MotorActualSpeed(byte output);
1569 
1570 /**
1571  * Get motor tachometer counter.
1572  * Get the tachometer count value of the specified output.
1573  *
1574  * \param output Desired output port. Can be \ref OUT_A, \ref OUT_B, \ref
1575  * OUT_C or a variable containing one of these values, see \ref
1576  * OutputPortConstants.
1577  * \return The tachometer count value of the specified output.
1578  */
1579 inline long MotorTachoCount(byte output);
1580 
1581 /**
1582  * Get motor tachometer limit.
1583  * Get the tachometer limit value of the specified output.
1584  *
1585  * \param output Desired output port. Can be \ref OUT_A, \ref OUT_B, \ref
1586  * OUT_C or a variable containing one of these values, see \ref
1587  * OutputPortConstants.
1588  * \return The tachometer limit value of the specified output.
1589  */
1590 inline long MotorTachoLimit(byte output);
1591 
1592 /**
1593  * Get motor run state.
1594  * Get the RunState value of the specified output, see \ref
1595  * OutRunStateConstants.
1596  *
1597  * \param output Desired output port. Can be \ref OUT_A, \ref OUT_B, \ref
1598  * OUT_C or a variable containing one of these values, see \ref
1599  * OutputPortConstants.
1600  * \return The RunState value of the specified output.
1601  */
1602 inline byte MotorRunState(byte output);
1603 
1604 /**
1605  * Get motor turn ratio.
1606  * Get the turn ratio value of the specified output.
1607  *
1608  * \param output Desired output port. Can be \ref OUT_A, \ref OUT_B, \ref
1609  * OUT_C or a variable containing one of these values, see \ref
1610  * OutputPortConstants.
1611  * \return The turn ratio value of the specified output.
1612  */
1613 inline char MotorTurnRatio(byte output);
1614 
1615 /**
1616  * Get motor regulation mode.
1617  * Get the regulation value of the specified output.
1618  *
1619  * \param output Desired output port. Can be \ref OUT_A, \ref OUT_B, \ref
1620  * OUT_C or a variable containing one of these values, see \ref
1621  * OutputPortConstants.
1622  * \return The regulation value of the specified output.
1623  */
1624 inline byte MotorRegulation(byte output);
1625 
1626 /**
1627  * Get motor overload status.
1628  * Get the overload value of the specified output.
1629  *
1630  * \param output Desired output port. Can be \ref OUT_A, \ref OUT_B, \ref
1631  * OUT_C or a variable containing one of these values, see \ref
1632  * OutputPortConstants.
1633  * \return The overload value of the specified output.
1634  */
1635 inline bool MotorOverload(byte output);
1636 
1637 /**
1638  * Get motor P value.
1639  * Get the proportional PID value of the specified output.
1640  *
1641  * \param output Desired output port. Can be \ref OUT_A, \ref OUT_B, \ref
1642  * OUT_C or a variable containing one of these values, see \ref
1643  * OutputPortConstants.
1644  * \return The proportional PID value of the specified output.
1645  */
1646 inline byte MotorRegPValue(byte output);
1647 
1648 /**
1649  * Get motor I value.
1650  * Get the integral PID value of the specified output.
1651  *
1652  * \param output Desired output port. Can be \ref OUT_A, \ref OUT_B, \ref
1653  * OUT_C or a variable containing one of these values, see \ref
1654  * OutputPortConstants.
1655  * \return The integral PID value of the specified output.
1656  */
1657 inline byte MotorRegIValue(byte output);
1658 
1659 /**
1660  * Get motor D value.
1661  * Get the derivative PID value of the specified output.
1662  *
1663  * \param output Desired output port. Can be \ref OUT_A, \ref OUT_B, \ref
1664  * OUT_C or a variable containing one of these values, see \ref
1665  * OutputPortConstants.
1666  * \return The derivative PID value of the specified output.
1667  */
1668 inline byte MotorRegDValue(byte output);
1669 
1670 /**
1671  * Get motor block-relative counter.
1672  * Get the block-relative position counter value of the specified output.
1673  *
1674  * \param output Desired output port. Can be \ref OUT_A, \ref OUT_B, \ref
1675  * OUT_C or a variable containing one of these values, see \ref
1676  * OutputPortConstants.
1677  * \return The block-relative position counter value of the specified output.
1678  */
1679 inline long MotorBlockTachoCount(byte output);
1680 
1681 /**
1682  * Get motor program-relative counter.
1683  * Get the program-relative position counter value of the specified output.
1684  *
1685  * \param output Desired output port. Can be \ref OUT_A, \ref OUT_B, \ref
1686  * OUT_C or a variable containing one of these values, see \ref
1687  * OutputPortConstants.
1688  * \return The program-relative position counter value of the specified output.
1689  */
1690 inline long MotorRotationCount(byte output);
1691 
1692 /**
1693  * Get motor options.
1694  * Get the options value of the specified output.
1695  *
1696  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+
1697  *
1698  * \param output Desired output port. Can be \ref OUT_A, \ref OUT_B, \ref
1699  * OUT_C or a variable containing one of these values, see \ref
1700  * OutputPortConstants.
1701  * \return The options value of the specified output.
1702  */
1703 inline byte MotorOutputOptions(byte output);
1704 
1705 /**
1706  * Get motor max speed.
1707  * Get the max speed value of the specified output.
1708  *
1709  * \warning This function requires the enhanced NBC/NXC firmware version 1.31+
1710  *
1711  * \param output Desired output port. Can be \ref OUT_A, \ref OUT_B, \ref
1712  * OUT_C or a variable containing one of these values, see \ref
1713  * OutputPortConstants.
1714  * \return The max speed value of the specified output.
1715  */
1716 inline byte MotorMaxSpeed(byte output);
1717 
1718 /**
1719  * Get motor max acceleration.
1720  * Get the max acceleration value of the specified output.
1721  *
1722  * \warning This function requires the enhanced NBC/NXC firmware version 1.31+
1723  *
1724  * \param output Desired output port. Can be \ref OUT_A, \ref OUT_B, \ref
1725  * OUT_C or a variable containing one of these values, see \ref
1726  * OutputPortConstants.
1727  * \return The max acceleration value of the specified output.
1728  */
1729 inline byte MotorMaxAcceleration(byte output);
1730 
1731 /**
1732  * Get motor regulation frequency.
1733  * Get the current motor regulation frequency in milliseconds.
1734  * \return The motor regulation frequency.
1735  */
1736 inline byte MotorPwnFreq();
1737 
1738 /**
1739  * Get motor regulation time.
1740  * Get the current motor regulation time in milliseconds.
1741  * \return The motor regulation time.
1742  */
1743 inline byte MotorRegulationTime();
1744 
1745 /**
1746  * Get motor regulation options.
1747  * Get the current motor regulation options.
1748  * \return The motor regulation options.
1749  */
1750 inline byte MotorRegulationOptions();
1751 
1752 #else
1753 
1754 // output fields
1755 #define MotorMode(_p) GetOutput(_p, OutputMode)
1756 #define MotorPower(_p) GetOutput(_p, Power)
1757 #define MotorActualSpeed(_p) GetOutput(_p, ActualSpeed)
1758 #define MotorTachoCount(_p) GetOutput(_p, TachoCount)
1759 #define MotorTachoLimit(_p) GetOutput(_p, TachoLimit)
1760 #define MotorRunState(_p) GetOutput(_p, RunState)
1761 #define MotorTurnRatio(_p) GetOutput(_p, TurnRatio)
1762 #define MotorRegulation(_p) GetOutput(_p, RegMode)
1763 #define MotorOverload(_p) GetOutput(_p, Overload)
1764 #define MotorRegPValue(_p) GetOutput(_p, RegPValue)
1765 #define MotorRegIValue(_p) GetOutput(_p, RegIValue)
1766 #define MotorRegDValue(_p) GetOutput(_p, RegDValue)
1767 #define MotorBlockTachoCount(_p) GetOutput(_p, BlockTachoCount)
1768 #define MotorRotationCount(_p) GetOutput(_p, RotationCount)
1769 
1770 #define MotorPwnFreq() asm { GetOutPwnFreq(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
1771 #define SetMotorPwnFreq(_n) asm { __setOutPwnFreq(_n) }
1772 #define MotorRegulationTime() asm { GetOutRegulationTime(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
1773 #define SetMotorRegulationTime(_n) asm { __setOutRegulationTime(_n) }
1774 
1775 #if defined(__ENHANCED_FIRMWARE) && (__FIRMWARE_VERSION > 107)
1776 #define MotorOutputOptions(_p) GetOutput(_p, OutputOptions)
1777 #define MotorMaxSpeed(_p) GetOutput(_p, MaxSpeed)
1778 #define MotorMaxAcceleration(_p) GetOutput(_p, MaxAcceleration)
1779 #define MotorRegulationOptions() asm { GetOutRegulationOptions(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
1780 #define SetMotorRegulationOptions(_n) asm { __setOutRegulationOptions(_n) }
1781 #endif
1782 
1783 #endif
1784 
1785 /** @} */ // end of OutputModuleFunctions group
1786 /** @} */ // end of OutputModule group
1787 /** @} */ // end of NXTFirmwareModules group
1788 
1789 
1790 ///////////////////////////////////////////////////////////////////////////////
1791 /////////////////////////////// DISPLAY MODULE ////////////////////////////////
1792 ///////////////////////////////////////////////////////////////////////////////
1793 
1794 
1795 /** @addtogroup NXTFirmwareModules
1796  * @{
1797  */
1798 /** @addtogroup DisplayModule
1799  * @{
1800  */
1801 /** @defgroup DisplayModuleTypes Display module types
1802  * Types used by various display module functions.
1803  * @{
1804  */
1805 /**
1806  * A point on the NXT LCD screen.
1807  * This structure is by other system call structures to specify an X, Y
1808  * LCD screen coordinate.
1809  * \sa DrawTextType, DrawPointType, DrawLineType, DrawCircleType, DrawRectType,
1810  * DrawGraphicType, DrawGraphicArrayType, DrawPolygonType, DrawEllipseType,
1811  * DrawFontType
1812  */
1813 struct LocationType {
1814   int X;  /*!< The X coordinate. Valid range is from 0 to 99 inclusive.  */
1815   int Y;  /*!< The Y coordinate. Valid range is from 0 to 63 inclusive.
1816                For text drawing this value must be a multiple of 8. */
1817 };
1818 
1819 /**
1820  * Width and height dimensions for the DrawRect system call.
1821  * This structure is by the \ref DrawRectType to specify a width and
1822  * height for a rectangle.
1823  * \sa DrawRectType
1824  */
1825 struct SizeType {
1826   int Width;  /*!< The rectangle width. */
1827   int Height; /*!< The rectangle height. */
1828 };
1829 
1830 /**
1831  * Parameters for the DrawText system call.
1832  * This structure is used when calling the \ref SysDrawText system call function.
1833  * It lets you specify the text to draw, the LCD line and horizontal position using the
1834  * \ref LocationType structure member, as well as drawing options defined
1835  * in the \ref DisplayDrawOptionConstants group.
1836  * \sa SysDrawText()
1837  */
1838 struct DrawTextType {
1839   char Result;             /*!< The function call result. \ref NO_ERR means it succeeded. */
1840   LocationType Location;   /*!< The location in X, LCD line number coordinates. */
1841   string Text;             /*!< The text to draw on the LCD. */
1842   unsigned long Options;   /*!< The options to use when writing to the LCD.
1843                              \ref DisplayDrawOptionConstants */
1844 };
1845 
1846 /**
1847  * Parameters for the DrawPoint system call.
1848  * This structure is used when calling the \ref SysDrawPoint system call
1849  * function.
1850  * It lets you specify the pixel to draw using the
1851  * \ref LocationType structure member, as well as drawing options defined
1852  * in the \ref DisplayDrawOptionConstants group.
1853  * \sa SysDrawPoint()
1854  */
1855 struct DrawPointType {
1856   char Result;             /*!< The function call result. \ref NO_ERR means it succeeded. */
1857   LocationType Location;   /*!< The point location on screen. */
1858   unsigned long Options;   /*!< The options to use when writing to the LCD.
1859                              \ref DisplayDrawOptionConstants */
1860 };
1861 
1862 /**
1863  * Parameters for the DrawLine system call.
1864  * This structure is used when calling the \ref SysDrawLine system call
1865  * function.
1866  * It lets you specify the end points of the line to draw using two
1867  * \ref LocationType structure member, as well as drawing options defined
1868  * in the \ref DisplayDrawOptionConstants group.
1869  * \sa SysDrawLine()
1870  */
1871 struct DrawLineType {
1872   char Result;             /*!< The function call result. \ref NO_ERR means it succeeded. */
1873   LocationType StartLoc;   /*!< The location of the starting point. */
1874   LocationType EndLoc;     /*!< The location of the ending point. */
1875   unsigned long Options;   /*!< The options to use when writing to the LCD.
1876                              \ref DisplayDrawOptionConstants */
1877 };
1878 
1879 /**
1880  * Parameters for the DrawCircle system call.
1881  * This structure is used when calling the \ref SysDrawCircle system call
1882  * function.
1883  * It lets you specify the center of the circle to draw using the
1884  * \ref LocationType structure member, the radius, as well as drawing options defined
1885  * in the \ref DisplayDrawOptionConstants group.
1886  * \sa SysDrawCircle()
1887  */
1888 struct DrawCircleType {
1889   char Result;             /*!< The function call result. \ref NO_ERR means it succeeded. */
1890   LocationType Center;     /*!< The location of the circle center. */
1891   byte Size;               /*!< The circle radius. */
1892   unsigned long Options;   /*!< The options to use when writing to the LCD.
1893                              \ref DisplayDrawOptionConstants */
1894 };
1895 
1896 /**
1897  * Parameters for the DrawRect system call.
1898  * This structure is used when calling the \ref SysDrawRect system call
1899  * function.
1900  * It lets you specify the corner of the rectangle using the \ref LocationType structure member,
1901  * the width and height of the rectangle using the \ref SizeType structure member,
1902  * as well as drawing options defined in the \ref DisplayDrawOptionConstants group.
1903  * \sa SysDrawRect()
1904  */
1905 struct DrawRectType {
1906   char Result;             /*!< The function call result. \ref NO_ERR means it succeeded. */
1907   LocationType Location;   /*!< The top left corner location. */
1908   SizeType Size;           /*!< The width and height of the rectangle. */
1909   unsigned long Options;   /*!< The options to use when writing to the LCD.
1910                              \ref DisplayDrawOptionConstants */
1911 };
1912 
1913 /**
1914  * Parameters for the DrawGraphic system call.
1915  * This structure is used when calling the \ref SysDrawGraphic system call
1916  * function.
1917  * It lets you specify the screen location at which to draw the image using the
1918  * \ref LocationType structure member, the filename of the graphic image, the
1919  * image parameters (if needed), as well as drawing options defined
1920  * in the \ref DisplayDrawOptionConstants group.
1921  * \sa SysDrawGraphic()
1922  */
1923 struct DrawGraphicType {
1924   char Result;             /*!< The function call result. Possible values include
1925                              \ref LoaderErrors, \ref ERR_FILE, and \ref NO_ERR. */
1926   LocationType Location;   /*!< The location on screen. */
1927   string Filename;         /*!< The RIC file name. */
1928   long Variables[];         /*!< The variables passed as RIC arguments. */
1929   unsigned long Options;   /*!< The options to use when writing to the LCD.
1930                              \ref DisplayDrawOptionConstants */
1931 };
1932 
1933 /**
1934  * Parameters for the SetScreenMode system call.
1935  * This structure is used when calling the \ref SysSetScreenMode system call
1936  * function.
1937  * \sa SysSetScreenMode()
1938  */
1939 struct SetScreenModeType {
1940   char Result;                /*!< The function call result, always \ref NO_ERR. */
1941   unsigned long ScreenMode;   /*!< The requested screen mode.
1942 
1943                                 The standard NXT firmware only supports
1944                                 setting the ScreenMode to \ref SCREEN_MODE_RESTORE.
1945 
1946                                 If you install the NBC/NXC enhanced standard
1947                                 NXT firmware this system function also
1948                                 supports setting the ScreenMode to
1949                                 \ref SCREEN_MODE_CLEAR. */
1950 };
1951 
1952 #ifdef __ENHANCED_FIRMWARE
1953 /**
1954  * Parameters for the DisplayExecuteFunction system call.
1955  * This structure is used when calling the \ref SysDisplayExecuteFunction
1956  * system call function.
1957  *
1958  * The fields usage depends on the requested command and are documented in the
1959  * table below. If a field member is shown as 'x' it is ignored by the
1960  * specified display command.
1961  *
1962  * <table>
1963  * <tr><td>Cmd</td>
1964  *     <td>Meaning</td><td>Expected parameters</td></tr>
1965  * <tr><td>DISPLAY_ERASE_ALL</td>
1966  *     <td>erase entire screen</td><td>()</td></tr>
1967  * <tr><td>DISPLAY_PIXEL</td>
1968  *     <td>set pixel (on/off)</td><td>(true/false,X1,Y1,x,x)</td></tr>
1969  * <tr><td>DISPLAY_HORIZONTAL_LINE</td>
1970  *     <td>draw horizontal line</td><td>(true/false,X1,Y1,X2,x)</td></tr>
1971  * <tr><td>DISPLAY_VERTICAL_LINE</td>
1972  *     <td>draw vertical line</td><td>(true/false,X1,Y1,x,Y2)</td></tr>
1973  * <tr><td>DISPLAY_CHAR</td>
1974  *     <td>draw char (actual font)</td><td>(true/false,X1,Y1,Char,x)</td></tr>
1975  * <tr><td>DISPLAY_ERASE_LINE</td>
1976  *     <td>erase a single line</td><td>(x,LINE,x,x,x)</td></tr>
1977  * <tr><td>DISPLAY_FILL_REGION</td>
1978  *     <td>fill screen region</td><td>(true/false,X1,Y1,X2,Y2)</td></tr>
1979  * <tr><td>DISPLAY_FILLED_FRAME</td>
1980  *     <td>draw a frame (on / off)</td><td>(true/false,X1,Y1,X2,Y2)</td></tr>
1981  * </table>
1982  *
1983  * \sa SysDisplayExecuteFunction()
1984  */
1985 struct DisplayExecuteFunctionType {
1986   byte Status;   /*!< The function call result, always \ref NO_ERR. */
1987   byte Cmd;      /*!< The command to execute. */
1988   bool On;       /*!< The On parameter, see table. */
1989   byte X1;       /*!< The X1 parameter, see table. */
1990   byte Y1;       /*!< The Y1 parameter, see table. */
1991   byte X2;       /*!< The X2 parameter, see table. */
1992   byte Y2;       /*!< The Y2 parameter, see table. */
1993 };
1994 
1995 #if __FIRMWARE_VERSION > 107
1996 /**
1997  * Parameters for the DrawGraphicArray system call.
1998  * This structure is used when calling the \ref SysDrawGraphicArray system call
1999  * function.
2000  * It lets you specify the screen location at which to draw the image using the
2001  * \ref LocationType structure member, the graphic image data array, the
2002  * image parameters (if needed), as well as drawing options defined
2003  * in the \ref DisplayDrawOptionConstants group.
2004  * \sa SysDrawGraphicArray()
2005  */
2006 struct DrawGraphicArrayType {
2007   char Result;            /*!< The function call result. \ref NO_ERR means it succeeded. */
2008   LocationType Location;  /*!< The location on screen. */
2009   byte Data[];            /*!< A byte array containing the RIC opcodes. \ref RICMacros */
2010   long Variables[];       /*!< The variables passed as RIC arguments. */
2011   unsigned long Options;  /*!< The options to use when writing to the LCD. \ref DisplayDrawOptionConstants */
2012 };
2013 
2014 /**
2015  * Parameters for the DrawPolygon system call.
2016  * This structure is used when calling the \ref SysDrawPolygon system call
2017  * function.
2018  * It lets you specify the points of the polygon to draw using the
2019  * \ref LocationType array structure member, as well as drawing options defined
2020  * in the \ref DisplayDrawOptionConstants group.
2021  * \sa SysDrawPolygon()
2022  */
2023 struct DrawPolygonType {
2024   char Result;            /*!< The function call result. \ref NO_ERR means it succeeded. */
2025   LocationType Points[];  /*!< An array of LocationType structures which define the polygon's shape. */
2026   unsigned long Options;  /*!< The options to use when writing to the LCD. \ref DisplayDrawOptionConstants */
2027 };
2028 
2029 /**
2030  * Parameters for the DrawEllipse system call.
2031  * This structure is used when calling the \ref SysDrawEllipse system call
2032  * function.
2033  * It lets you specify the center of the ellipse using the
2034  * \ref LocationType structure member, the x and y axis radii,
2035  * as well as drawing options defined in the \ref DisplayDrawOptionConstants group.
2036  * \sa SysDrawEllipse()
2037  */
2038 struct DrawEllipseType {
2039   char Result;            /*!< The function call result. \ref NO_ERR means it succeeded. */
2040   LocationType Center;    /*!< The location of the ellipse center. */
2041   byte SizeX;             /*!< The horizontal ellipse radius. */
2042   byte SizeY;             /*!< The vertical ellipse radius. */
2043   unsigned long Options;  /*!< The options to use when writing to the LCD. \ref DisplayDrawOptionConstants */
2044 };
2045 
2046 /**
2047  * Parameters for the DrawFont system call.
2048  * This structure is used when calling the \ref SysDrawFont system call function.
2049  * It lets you specify the text to draw, the LCD line and horizontal position using the
2050  * \ref LocationType structure member, as well as drawing options defined
2051  * in the \ref DisplayDrawOptionConstants group.
2052  * \sa SysDrawFont()
2053  */
2054 struct DrawFontType {
2055   char Result;             /*!< The function call result. \ref NO_ERR means it succeeded. */
2056   LocationType Location;   /*!< The location in X, LCD line number coordinates. */
2057   string Filename;         /*!< The filename of the RIC-based font file. */
2058   string Text;             /*!< The text to draw on the LCD. */
2059   unsigned long Options;   /*!< The options to use when writing to the LCD.
2060                              \ref DisplayDrawOptionConstants */
2061 };
2062 #endif
2063 #endif
2064 /** @} */ // end of DisplayModuleTypes group
2065 
2066 /** @defgroup DisplayModuleFunctions Display module functions
2067  * Functions for accessing and modifying display module features.
2068  * @{
2069  */
2070 
2071 #ifdef __DOXYGEN_DOCS
2072 
2073 /**
2074  * Reset LCD screen.
2075  * This function lets you restore the standard NXT running program screen.
2076  */
2077 inline void ResetScreen();
2078 
2079 /**
2080  * Draw a circle.
2081  * This function lets you draw a circle on the screen with its center at the
2082  * specified x and y location, using the specified radius. Optionally specify
2083  * drawing options. If this argument is not specified it defaults to \ref DRAW_OPT_NORMAL.
2084  * Valid display option constants are listed in the \ref DisplayDrawOptionConstants group.
2085  * \sa SysDrawCircle, DrawCircleType
2086  *
2087  * \param x The x value for the center of the circle.
2088  * \param y The y value for the center of the circle.
2089  * \param radius The radius of the circle.
2090  * \param options The optional drawing options.
2091  * \return The result of the drawing operation.
2092  */
2093 inline char CircleOut(int x, int y, byte radius, unsigned long options=DRAW_OPT_NORMAL);
2094 
2095 /**
2096  * Draw a line.
2097  * This function lets you draw a line on the screen from x1, y1 to x2, y2.
2098  * Optionally specify drawing options. If this argument is not specified it
2099  * defaults to \ref DRAW_OPT_NORMAL. Valid display option constants are listed in
2100  * the \ref DisplayDrawOptionConstants group.
2101  * \sa SysDrawLine, DrawLineType
2102  *
2103  * \param x1 The x value for the start of the line.
2104  * \param y1 The y value for the start of the line.
2105  * \param x2 The x value for the end of the line.
2106  * \param y2 The y value for the end of the line.
2107  * \param options The optional drawing options.
2108  * \return The result of the drawing operation.
2109  */
2110 inline char LineOut(int x1, int y1, int x2, int y2, unsigned long options=DRAW_OPT_NORMAL);
2111 
2112 /**
2113  * Draw a point.
2114  * This function lets you draw a point on the screen at x, y.
2115  * Optionally specify drawing options. If this argument is not specified it
2116  * defaults to \ref DRAW_OPT_NORMAL. Valid display option constants are listed in
2117  * the \ref DisplayDrawOptionConstants group.
2118  * \sa SysDrawPoint, DrawPointType
2119  *
2120  * \param x The x value for the point.
2121  * \param y The y value for the point.
2122  * \param options The optional drawing options.
2123  * \return The result of the drawing operation.
2124  */
2125 inline char PointOut(int x, int y, unsigned long options=DRAW_OPT_NORMAL);
2126 
2127 /**
2128  * Draw a rectangle.
2129  * This function lets you draw a rectangle on the screen at x, y with the
2130  * specified width and height.
2131  * Optionally specify drawing options. If this argument is not specified it
2132  * defaults to \ref DRAW_OPT_NORMAL. Valid display option constants are listed in
2133  * the \ref DisplayDrawOptionConstants group.
2134  * \sa SysDrawRect, DrawRectType
2135  *
2136  * \param x The x value for the top left corner of the rectangle.
2137  * \param y The y value for the top left corner of the rectangle.
2138  * \param width The width of the rectangle.
2139  * \param height The height of the rectangle.
2140  * \param options The optional drawing options.
2141  * \return The result of the drawing operation.
2142  */
2143 inline char RectOut(int x, int y, int width, int height, unsigned long options=DRAW_OPT_NORMAL);
2144 
2145 /**
2146  * Draw text.
2147  * Draw a text value on the screen at the specified x and y location. The y
2148  * value must be a multiple of 8.  Valid line number constants are listed in
2149  * the \ref LineConstants group.
2150  * Optionally specify drawing options. If this argument is not specified it
2151  * defaults to \ref DRAW_OPT_NORMAL. Valid display option constants are listed in
2152  * the \ref DisplayDrawOptionConstants group.
2153  * \sa SysDrawText, DrawTextType
2154  *
2155  * \param x The x value for the start of the text output.
2156  * \param y The text line number for the text output.
2157  * \param str The text to output to the LCD screen.
2158  * \param options The optional drawing options.
2159  * \return The result of the drawing operation.
2160  */
2161 inline char TextOut(int x, int y, string str, unsigned long options=DRAW_OPT_NORMAL);
2162 
2163 /**
2164  * Draw a number.
2165  * Draw a numeric value on the screen at the specified x and y location. The y
2166  * value must be a multiple of 8.  Valid line number constants are listed in
2167  * the \ref LineConstants group.
2168  * Optionally specify drawing options. If this argument is not specified it
2169  * defaults to \ref DRAW_OPT_NORMAL. Valid display option constants are listed in
2170  * the \ref DisplayDrawOptionConstants group.
2171  * \sa SysDrawText, DrawTextType
2172  *
2173  * \param x The x value for the start of the number output.
2174  * \param y The text line number for the number output.
2175  * \param value The value to output to the LCD screen. Any numeric type is supported.
2176  * \param options The optional drawing options.
2177  * \return The result of the drawing operation.
2178  */
2179 inline char NumOut(int x, int y, variant value, unsigned long options=DRAW_OPT_NORMAL);
2180 
2181 /**
2182  * Draw an ellipse.
2183  * This function lets you draw an ellipse on the screen with its center at the
2184  * specified x and y location, using the specified radii. Optionally specify
2185  * drawing options. If this argument is not specified it defaults to \ref DRAW_OPT_NORMAL.
2186  * Valid display option constants are listed in the \ref DisplayDrawOptionConstants group.
2187  * \sa SysDrawEllipse, DrawEllipseType
2188  *
2189  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
2190  *
2191  * \param x The x value for the center of the ellipse.
2192  * \param y The y value for the center of the ellipse.
2193  * \param radiusX The x axis radius.
2194  * \param radiusY The y axis radius.
2195  * \param options The optional drawing options.
2196  * \return The result of the drawing operation.
2197  */
2198 inline char EllipseOut(int x, int y, byte radiusX, byte radiusY, unsigned long options=DRAW_OPT_NORMAL);
2199 
2200 /**
2201  * Draw a polygon.
2202  * This function lets you draw a polygon on the screen using an array of points.
2203  * Optionally specify drawing options. If this argument is not specified it
2204  * defaults to \ref DRAW_OPT_NORMAL. Valid display option constants are listed in
2205  * the \ref DisplayDrawOptionConstants group.
2206  * \sa SysDrawPolygon, DrawPolygonType
2207  *
2208  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
2209  *
2210  * \param points An array of LocationType points that define the polygon.
2211  * \param options The optional drawing options.
2212  * \return The result of the drawing operation.
2213  */
2214 inline char PolyOut(LocationType points[], unsigned long options=DRAW_OPT_NORMAL);
2215 
2216 /**
2217  * Draw text with font.
2218  * Draw a text value on the screen at the specified x and y location using
2219  * a custom RIC font. Optionally specify drawing options. If this argument is
2220  * not specified it defaults to \ref DRAW_OPT_NORMAL. Valid display option
2221  * constants are listed in the \ref DisplayDrawOptionConstants group.  See the
2222  * \ref DisplayFontDrawOptionConstants for options specific to the font
2223  * drawing functions.
2224  * \sa FontNumOut, SysDrawFont, DrawFontType
2225  *
2226  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
2227  *
2228  * \param x The x value for the start of the text output.
2229  * \param y The y value for the start of the text output.
2230  * \param filename The filename of the RIC font.
2231  * \param str The text to output to the LCD screen.
2232  * \param options The optional drawing options.
2233  * \return The result of the drawing operation.
2234  */
2235 inline char FontTextOut(int x, int y, string filename, string str, unsigned long options=DRAW_OPT_NORMAL);
2236 
2237 /**
2238  * Draw a number with font.
2239  * Draw a numeric value on the screen at the specified x and y location using
2240  * a custom RIC font. Optionally specify drawing options. If this argument is
2241  * not specified it defaults to \ref DRAW_OPT_NORMAL. Valid display option
2242  * constants are listed in the \ref DisplayDrawOptionConstants group.  See the
2243  * \ref DisplayFontDrawOptionConstants for options specific to the font
2244  * drawing functions.
2245  * \sa FontTextOut, SysDrawFont, DrawFontType
2246  *
2247  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
2248  *
2249  * \param x The x value for the start of the number output.
2250  * \param y The y value for the start of the number output.
2251  * \param filename The filename of the RIC font.
2252  * \param value The value to output to the LCD screen. Any numeric type is supported.
2253  * \param options The optional drawing options.
2254  * \return The result of the drawing operation.
2255  */
2256 inline char FontNumOut(int x, int y, string filename, variant value, unsigned long options=DRAW_OPT_NORMAL);
2257 
2258 /**
2259  * Draw a graphic image.
2260  * Draw a graphic image file on the screen at the specified x and y location.
2261  * Optionally specify drawing options. If this argument is not specified it
2262  * defaults to \ref DRAW_OPT_NORMAL. Valid display option constants are listed in
2263  * the \ref DisplayDrawOptionConstants group. If the file cannot be found then
2264  * nothing will be drawn and no errors will be reported.
2265  * \sa SysDrawGraphic, DrawGraphicType
2266  *
2267  * \param x The x value for the position of the graphic image.
2268  * \param y The y value for the position of the graphic image.
2269  * \param filename The filename of the RIC graphic image.
2270  * \param options The optional drawing options.
2271  * \return The result of the drawing operation.
2272  */
2273 inline char GraphicOut(int x, int y, string filename, unsigned long options=DRAW_OPT_NORMAL);
2274 
2275 /**
2276  * Draw a graphic image from byte array.
2277  * Draw a graphic image byte array on the screen at the specified x and y location.
2278  * Optionally specify drawing options. If this argument is not specified it
2279  * defaults to \ref DRAW_OPT_NORMAL. Valid display option constants are listed in
2280  * the \ref DisplayDrawOptionConstants group. If the file cannot be found then
2281  * nothing will be drawn and no errors will be reported.
2282  * \sa SysDrawGraphicArray, DrawGraphicArrayType
2283  *
2284  * \param x The x value for the position of the graphic image.
2285  * \param y The y value for the position of the graphic image.
2286  * \param data The byte array of the RIC graphic image.
2287  * \param options The optional drawing options.
2288  * \return The result of the drawing operation.
2289  */
2290 inline char GraphicArrayOut(int x, int y, byte data[], unsigned long options=DRAW_OPT_NORMAL);
2291 
2292 /**
2293  * Draw a graphic image with parameters.
2294  * Draw a graphic image file on the screen at the specified x and y location using
2295  * an array of parameters.
2296  * Optionally specify drawing options. If this argument is not specified it
2297  * defaults to \ref DRAW_OPT_NORMAL. Valid display option constants are listed in
2298  * the \ref DisplayDrawOptionConstants group. If the file cannot be found then
2299  * nothing will be drawn and no errors will be reported.
2300  * \sa SysDrawGraphic, DrawGraphicType
2301  *
2302  * \param x The x value for the position of the graphic image.
2303  * \param y The y value for the position of the graphic image.
2304  * \param filename The filename of the RIC graphic image.
2305  * \param vars The byte array of parameters.
2306  * \param options The optional drawing options.
2307  * \return The result of the drawing operation.
2308  */
2309 inline char GraphicOutEx(int x, int y, string filename, byte vars[], unsigned long options=DRAW_OPT_NORMAL);
2310 
2311 /**
2312  * Draw a graphic image from byte array with parameters.
2313  * Draw a graphic image byte array on the screen at the specified x and y location
2314  * using an array of parameters.
2315  * Optionally specify drawing options. If this argument is not specified it
2316  * defaults to \ref DRAW_OPT_NORMAL. Valid display option constants are listed in
2317  * the \ref DisplayDrawOptionConstants group. If the file cannot be found then
2318  * nothing will be drawn and no errors will be reported.
2319  * \sa SysDrawGraphicArray, DrawGraphicArrayType
2320  *
2321  * \param x The x value for the position of the graphic image.
2322  * \param y The y value for the position of the graphic image.
2323  * \param data The byte array of the RIC graphic image.
2324  * \param vars The byte array of parameters.
2325  * \param options The optional drawing options.
2326  * \return The result of the drawing operation.
2327  */
2328 inline char GraphicArrayOutEx(int x, int y, byte data[], byte vars[], unsigned long options=DRAW_OPT_NORMAL);
2329 
2330 /**
2331  * Read pixel data from the normal display buffer.
2332  * Read "cnt" bytes from the normal display memory into the data array. Start
2333  * reading from the specified x, line coordinate. Each byte of data read from
2334  * screen memory is a vertical strip of 8 bits at the desired location. Each
2335  * bit represents a single pixel on the LCD screen. Use TEXTLINE_1 through
2336  * TEXTLINE_8 for the "line" parameter.
2337  *
2338  * \param x The desired x position from which to read pixel data.
2339  * \param line The desired line from which to read pixel data.
2340  * \param cnt The number of bytes of pixel data to read.
2341  * \param data The array of bytes into which pixel data is read.
2342  */
2343 inline void GetDisplayNormal(const byte x, const byte line, unsigned int cnt, byte & data[]);
2344 
2345 /**
2346  * Write pixel data to the normal display buffer.
2347  * Write "cnt" bytes to the normal display memory from the data array. Start
2348  * writing at the specified x, line coordinate. Each byte of data is a
2349  * vertical strip of 8 bits at the desired location. Each
2350  * bit represents a single pixel on the LCD screen. Use TEXTLINE_1 through
2351  * TEXTLINE_8 for the "line" parameter.
2352  *
2353  * \param x The desired x position where you wish to write pixel data.
2354  * \param line The desired line where you wish to write pixel data.
2355  * \param cnt The number of bytes of pixel data to write.
2356  * \param data The array of bytes from which pixel data is read.
2357  */
2358 inline void SetDisplayNormal(const byte x, const byte line, unsigned int cnt, byte data[]);
2359 
2360 /**
2361  * Read pixel data from the popup display buffer.
2362  * Read "cnt" bytes from the popup display memory into the data array. Start
2363  * reading from the specified x, line coordinate. Each byte of data read from
2364  * screen memory is a vertical strip of 8 bits at the desired location. Each
2365  * bit represents a single pixel on the LCD screen. Use TEXTLINE_1 through
2366  * TEXTLINE_8 for the "line" parameter.
2367  *
2368  * \param x The desired x position from which to read pixel data.
2369  * \param line The desired line from which to read pixel data.
2370  * \param cnt The number of bytes of pixel data to read.
2371  * \param data The array of bytes into which pixel data is read.
2372  */
2373 inline void GetDisplayPopup(const byte x, const byte line, unsigned int cnt, byte & data[]);
2374 
2375 /**
2376  * Write pixel data to the popup display buffer.
2377  * Write "cnt" bytes to the popup display memory from the data array. Start
2378  * writing at the specified x, line coordinate. Each byte of data is a
2379  * vertical strip of 8 bits at the desired location. Each
2380  * bit represents a single pixel on the LCD screen. Use TEXTLINE_1 through
2381  * TEXTLINE_8 for the "line" parameter.
2382  *
2383  * \param x The desired x position where you wish to write pixel data.
2384  * \param line The desired line where you wish to write pixel data.
2385  * \param cnt The number of bytes of pixel data to write.
2386  * \param data The array of bytes from which pixel data is read.
2387  */
2388 inline void SetDisplayPopup(const byte x, const byte line, unsigned int cnt, byte data[]);
2389 
2390 /**
2391  * Read the display erase mask value.
2392  * This function lets you read the current display erase mask value.
2393  * \return The current display erase mask value.
2394  */
2395 inline unsigned long DisplayEraseMask();
2396 
2397 
2398 /**
2399  * Read the display update mask value.
2400  * This function lets you read the current display update mask value.
2401  * \return The current display update mask.
2402  */
2403 inline unsigned long DisplayUpdateMask();
2404 
2405 /**
2406  * Read the display font memory address.
2407  * This function lets you read the current display font memory address.
2408  * \return The current display font memory address.
2409  */
2410 inline unsigned long DisplayFont();
2411 
2412 /**
2413  * Read the display memory address.
2414  * This function lets you read the current display memory address.
2415  * \return The current display memory address.
2416  */
2417 inline unsigned long DisplayDisplay();
2418 
2419 /**
2420  * Read the display flags.
2421  * This function lets you read the current display flags.
2422  * Valid flag values are listed in the \ref DisplayFlagsGroup group.
2423  * \return The current display flags.
2424  */
2425 inline byte DisplayFlags();
2426 
2427 /**
2428  * Read the display text lines center flags.
2429  * This function lets you read the current display text lines center flags.
2430  * \return The current display text lines center flags.
2431  */
2432 inline byte DisplayTextLinesCenterFlags();
2433 
2434 /**
2435  * Draw text.
2436  * This function lets you draw text on the NXT LCD given the parameters you
2437  * pass in via the \ref DrawTextType structure.
2438  *
2439  * \param args The DrawTextType structure containing the drawing parameters.
2440  */
2441 inline void SysDrawText(DrawTextType & args);
2442 
2443 /**
2444  * Draw a point.
2445  * This function lets you draw a pixel on the NXT LCD given the parameters you
2446  * pass in via the \ref DrawPointType structure.
2447  *
2448  * \param args The DrawPointType structure containing the drawing parameters.
2449  */
2450 inline void SysDrawPoint(DrawPointType & args);
2451 
2452 /**
2453  * Draw a line.
2454  * This function lets you draw a line on the NXT LCD given the parameters you
2455  * pass in via the \ref DrawLineType structure.
2456  *
2457  * \param args The DrawLineType structure containing the drawing parameters.
2458  */
2459 inline void SysDrawLine(DrawLineType & args);
2460 
2461 /**
2462  * Draw a circle.
2463  * This function lets you draw a circle on the NXT LCD given the parameters you pass
2464  * in via the \ref DrawCircleType structure.
2465  *
2466  * \param args The DrawCircleType structure containing the drawing parameters.
2467  */
2468 inline void SysDrawCircle(DrawCircleType & args);
2469 
2470 /**
2471  * Draw a rectangle.
2472  * This function lets you draw a rectangle on the NXT LCD given the parameters
2473  * you pass in via the \ref DrawRectType structure.
2474  *
2475  * \param args The DrawRectType structure containing the drawing parameters.
2476  */
2477 inline void SysDrawRect(DrawRectType & args);
2478 
2479 /**
2480  * Draw a graphic (RIC file).
2481  * This function lets you draw a graphic image (RIC file) on the NXT LCD given
2482  * the parameters you pass in via the \ref DrawGraphicType structure.
2483  *
2484  * \param args The DrawGraphicType structure containing the drawing parameters.
2485  */
2486 inline void SysDrawGraphic(DrawGraphicType & args);
2487 
2488 /**
2489  * Set the screen mode.
2490  * This function lets you set the screen mode of the NXT LCD given the
2491  * parameters you pass in via the \ref DrawTextType structure.
2492  *
2493  * \param args The SetScreenModeType structure containing the screen mode parameters.
2494  */
2495 inline void SysSetScreenMode(SetScreenModeType & args);
2496 
2497 #ifdef __ENHANCED_FIRMWARE
2498 
2499 /**
2500  * Execute any Display module command.
2501  * This function lets you directly execute the Display module's primary
2502  * drawing function using the values specified via the \ref
2503  * DisplayExecuteFunctionType structure.
2504  *
2505  * \param args The DisplayExecuteFunctionType structure containing the drawing parameters.
2506  */
2507 inline void SysDisplayExecuteFunction(DisplayExecuteFunctionType & args);
2508 
2509 
2510 #if __FIRMWARE_VERSION > 107
2511 
2512 /**
2513  * Read the display contrast setting.
2514  * This function lets you read the current display contrast setting.
2515  * \return The current display contrast (byte).
2516  *
2517  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
2518  */
2519 inline byte DisplayContrast();
2520 
2521 /**
2522  * Draw a graphic image from a byte array.
2523  * This function lets you draw a graphic image on the NXT LCD given the parameters you pass
2524  * in via the \ref DrawGraphicArrayType structure.
2525  *
2526  * \param args The DrawGraphicArrayType structure containing the drawing parameters.
2527  *
2528  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
2529  */
2530 inline void SysDrawGraphicArray(DrawGraphicArrayType & args);
2531 
2532 /**
2533  * Draw a polygon.
2534  * This function lets you draw a polygon on the NXT LCD given the parameters you pass
2535  * in via the \ref DrawPolygonType structure.
2536  *
2537  * \param args The DrawPolygonType structure containing the drawing parameters.
2538  *
2539  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
2540  */
2541 inline void SysDrawPolygon(DrawPolygonType & args);
2542 
2543 /**
2544  * Draw an ellipse.
2545  * This function lets you draw an ellipse on the NXT LCD given the parameters you pass
2546  * in via the \ref DrawEllipseType structure.
2547  *
2548  * \param args The DrawEllipseType structure containing the drawing parameters.
2549  *
2550  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
2551  */
2552 inline void SysDrawEllipse(DrawEllipseType & args);
2553 
2554 /**
2555  * Draw text using a custom font.
2556  * This function lets you draw text on the NXT LCD using a custom font
2557  * with parameters you pass in via the \ref DrawFontType structure.
2558  *
2559  * \param args The DrawFontType structure containing the drawing parameters.
2560  *
2561  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
2562  */
2563 inline void SysDrawFont(DrawFontType & args);
2564 
2565 #endif
2566 #endif
2567 
2568 #else
2569 
2570 #define GetDisplayNormal(_x, _line, _cnt, _data) asm { __getDisplayNormal(_x, _line, _cnt, _data) }
2571 #define GetDisplayPopup(_x, _line, _cnt, _data) asm { __getDisplayPopup(_x, _line, _cnt, _data) }
2572 
2573 #define DisplayEraseMask() asm { GetDisplayEraseMask(__TMPLONG__) __RETURN__ __TMPLONG__ }
2574 #define DisplayUpdateMask() asm { GetDisplayUpdateMask(__TMPLONG__) __RETURN__ __TMPLONG__ }
2575 #define DisplayFont() asm { GetDisplayFont(__TMPLONG__) __RETURN__ __TMPLONG__ }
2576 #define DisplayDisplay() asm { GetDisplayDisplay(__TMPLONG__) __RETURN__ __TMPLONG__ }
2577 #define DisplayFlags() asm { GetDisplayFlags(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
2578 #define DisplayTextLinesCenterFlags() asm { GetDisplayTextLinesCenterFlags(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
2579 
2580 #define SetDisplayNormal(_x, _line, _cnt, _data) asm { __setDisplayNormal(_x, _line, _cnt, _data) }
2581 #define SetDisplayPopup(_x, _line, _cnt, _data) asm { __setDisplayPopup(_x, _line, _cnt, _data) }
2582 
2583 #define SysDrawText(_args) asm { \
2584   compchktype _args, DrawTextType \
2585   syscall DrawText, _args \
2586 }
2587 #define SysDrawPoint(_args) asm { \
2588   compchktype _args, DrawPointType \
2589   syscall DrawPoint, _args \
2590 }
2591 #define SysDrawLine(_args) asm { \
2592   compchktype _args, DrawLineType \
2593   syscall DrawLine, _args \
2594 }
2595 #define SysDrawCircle(_args) asm { \
2596   compchktype _args, DrawCircleType \
2597   syscall DrawCircle, _args \
2598 }
2599 #define SysDrawRect(_args) asm { \
2600   compchktype _args, DrawRectType \
2601   syscall DrawRect, _args \
2602 }
2603 #define SysDrawGraphic(_args) asm { \
2604   compchktype _args, DrawGraphicType \
2605   syscall DrawGraphic, _args \
2606 }
2607 #define SysSetScreenMode(_args) asm { \
2608   compchktype _args, SetScreenModeType \
2609   syscall SetScreenMode, _args \
2610 }
2611 
2612 #ifdef __ENHANCED_FIRMWARE
2613 
2614 #define SysDisplayExecuteFunction(_args) asm { \
2615   compchktype _args, DisplayExecuteFunctionType \
2616   syscall DisplayExecuteFunction, _args \
2617 }
2618 
2619 #if __FIRMWARE_VERSION > 107
2620 
2621 #define DisplayContrast() asm { GetDisplayContrast(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
2622 
2623 #define SysDrawGraphicArray(_args) asm { \
2624   compchktype _args, DrawGraphicArrayType \
2625   syscall DrawGraphicArray, _args \
2626 }
2627 #define SysDrawPolygon(_args) asm { \
2628   compchktype _args, DrawPolygonType \
2629   syscall DrawPolygon, _args \
2630 }
2631 #define SysDrawEllipse(_args) asm { \
2632   compchktype _args, DrawEllipseType \
2633   syscall DrawEllipse, _args \
2634 }
2635 #define SysDrawFont(_args) asm { \
2636   compchktype _args, DrawFontType \
2637   syscall DrawFont, _args \
2638 }
2639 #endif
2640 #endif
2641 #endif
2642 
2643 /**
2644  * Clear LCD screen.
2645  * This function lets you clear the NXT LCD to a blank screen.
2646  */
ClearScreen()2647 inline void ClearScreen() { asm { PointOutEx(200, 200, TRUE) } }
2648 
2649 /**
2650  * Clear a line on the LCD screen.
2651  * This function lets you clear a single line on the NXT LCD.
2652  * \param line The line you want to clear. See \ref LineConstants.
2653  */
ClearLine(byte line)2654 inline void ClearLine(byte line) { asm { TextOutEx(0, line, __BlankLine, 0) } }
2655 
2656 /**
2657  * Set the display font memory address.
2658  * This function lets you set the current display font memory address.
2659  *
2660  * \param fontaddr The new display font memory address.
2661  */
SetDisplayFont(unsigned long fontaddr)2662 inline void SetDisplayFont(unsigned long fontaddr) { asm { __setDisplayFont(fontaddr) } }
2663 
2664 /**
2665  * Set the display memory address.
2666  * This function lets you set the current display memory address.
2667  *
2668  * \param dispaddr The new display memory address.
2669  */
SetDisplayDisplay(unsigned long dispaddr)2670 inline void SetDisplayDisplay(unsigned long dispaddr) { asm { __setDisplayDisplay(dispaddr) } }
2671 
2672 /**
2673  * Set the display erase mask.
2674  * This function lets you set the current display erase mask.
2675  *
2676  * \param eraseMask The new display erase mask.
2677  */
SetDisplayEraseMask(unsigned long eraseMask)2678 inline void SetDisplayEraseMask(unsigned long eraseMask) { asm { __setDisplayEraseMask(eraseMask) } }
2679 
2680 /**
2681  * Set the display flags.
2682  * This function lets you set the current display flags.
2683  *
2684  * \param flags The new display flags. See \ref DisplayFlagsGroup.
2685  */
SetDisplayFlags(byte flags)2686 inline void SetDisplayFlags(byte flags) { asm { __setDisplayFlags(flags) } }
2687 
2688 /**
2689  * Set the display text lines center flags.
2690  * This function lets you set the current display text lines center flags.
2691  *
2692  * \param ctrFlags The new display text lines center flags.
2693  */
SetDisplayTextLinesCenterFlags(byte ctrFlags)2694 inline void SetDisplayTextLinesCenterFlags(byte ctrFlags) { asm { __setDisplayTextLinesCenterFlags(ctrFlags) } }
2695 
2696 /**
2697  * Set the display update mask.
2698  * This function lets you set the current display update mask.
2699  *
2700  * \param updateMask The new display update mask.
2701  */
SetDisplayUpdateMask(unsigned long updateMask)2702 inline void SetDisplayUpdateMask(unsigned long updateMask) { asm { __setDisplayUpdateMask(updateMask) } }
2703 
2704 #if (__FIRMWARE_VERSION > 107) && defined(__ENHANCED_FIRMWARE)
2705 /**
2706  * Set the display contrast.
2707  * This function lets you set the display contrast setting.
2708  *
2709  * \param contrast The desired display contrast.
2710  *
2711  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
2712  */
SetDisplayContrast(byte contrast)2713 inline void SetDisplayContrast(byte contrast) { asm { __setDisplayContrast(contrast) } }
2714 
2715 #endif
2716 
2717 /** @} */ // end of DisplayModuleFunctions group
2718 /** @} */ // end of DisplayModule group
2719 /** @} */ // end of NXTFirmwareModules group
2720 
2721 
2722 ///////////////////////////////////////////////////////////////////////////////
2723 ///////////////////////////////// SOUND MODULE ////////////////////////////////
2724 ///////////////////////////////////////////////////////////////////////////////
2725 
2726 
2727 /** @addtogroup NXTFirmwareModules
2728  * @{
2729  */
2730 /** @addtogroup SoundModule
2731  * @{
2732  */
2733 /** @defgroup SoundModuleTypes Sound module types
2734  * Types used by various sound module functions.
2735  * @{
2736  */
2737 
2738 /**
2739  * Type used with the PlayTones API function.
2740  * An array of this structure is used when calling the \ref PlayTones
2741  * API function.
2742  * \sa PlayTones()
2743  */
2744 struct Tone {
2745   unsigned int Frequency; /*!< The tone frequency. See the \ref ToneConstants group. */
2746   unsigned int Duration;  /*!< The tone duration in milliseconds. See the \ref TimeConstants group. */
2747 };
2748 
2749 /**
2750  * Parameters for the SoundPlayFile system call.
2751  * This structure is used when calling the \ref SysSoundPlayFile system call
2752  * function.
2753  * \sa SysSoundPlayFile()
2754  */
2755 struct SoundPlayFileType {
2756   char Result;       /*!< The function call result, always \ref NO_ERR. */
2757   string Filename;   /*!< The name of the file to play. */
2758   bool Loop;         /*!< If true, loops at end of file. */
2759   byte SoundLevel;   /*!< The sound level. Valid values range from 0 to 4. */
2760 };
2761 
2762 /**
2763  * Parameters for the SoundPlayTone system call.
2764  * This structure is used when calling the \ref SysSoundPlayTone system call
2765  * function.
2766  * \sa SysSoundPlayTone()
2767  */
2768 struct SoundPlayToneType {
2769   char Result;              /*!< The function call result, always \ref NO_ERR. */
2770   unsigned int Frequency;   /*!< The tone frequency. See the \ref ToneConstants group. */
2771   unsigned int Duration;    /*!< The tone duration in milliseconds. See the \ref TimeConstants group. */
2772   bool Loop;                /*!< If true, loops forever. */
2773   byte SoundLevel;          /*!< The sound level. Valid values range from 0 to 4. */
2774 };
2775 
2776 /**
2777  * Parameters for the SoundGetState system call.
2778  * This structure is used when calling the \ref SysSoundGetState system call
2779  * function.
2780  * \sa SysSoundGetState()
2781  */
2782 struct SoundGetStateType {
2783   byte State;   /*!< The returned sound state. See the \ref SoundStateConstants group. */
2784   byte Flags;   /*!< The returned sound flags. See the \ref SoundFlagsConstants group. */
2785 };
2786 
2787 /**
2788  * Parameters for the SoundSetState system call.
2789  * This structure is used when calling the \ref SysSoundSetState system call
2790  * function.
2791  * \sa SysSoundSetState()
2792  */
2793 struct SoundSetStateType {
2794   byte Result;   /*!< The function call result, same as State. */
2795   byte State;    /*!< The new sound state. See the \ref SoundStateConstants group. */
2796   byte Flags;    /*!< The new sound flags. See the \ref SoundFlagsConstants group. */
2797 };
2798 
2799 /** @} */ // end of SoundModuleTypes group
2800 
2801 /** @defgroup SoundModuleFunctions Sound module functions
2802  * Functions for accessing and modifying sound module features.
2803  * @{
2804  */
2805 
2806 #ifdef __DOXYGEN_DOCS
2807 
2808 /**
2809  * Play a file.
2810  * Play the specified file. The filename may be any valid string expression.
2811  * The sound file can either be an RSO file containing PCM or compressed ADPCM
2812  * samples or it can be an NXT melody (RMD) file containing frequency and
2813  * duration values.
2814  *
2815  * \param filename The name of the sound or melody file to play.
2816  */
2817 inline char PlayFile(string filename);
2818 
2819 /**
2820  * Play a file with extra options.
2821  * Play the specified file. The filename may be any valid string expression.
2822  * Volume should be a number from 0 (silent) to 4 (loudest). Play the file
2823  * repeatedly if loop is true.
2824  * The sound file can either be an RSO file containing PCM or compressed ADPCM
2825  * samples or it can be an NXT melody (RMD) file containing frequency and
2826  * duration values.
2827  *
2828  * \param filename The name of the sound or melody file to play.
2829  * \param volume The desired tone volume.
2830  * \param loop A boolean flag indicating whether to play the file repeatedly.
2831  */
2832 inline char PlayFileEx(string filename, byte volume, bool loop);
2833 
2834 /**
2835  * Play a tone.
2836  * Play a single tone of the specified frequency and duration. The frequency is
2837  * in Hz (see the \ref ToneConstants group). The duration is in 1000ths of a
2838  * second (see the \ref TimeConstants group). The tone is played at the loudest
2839  * sound level supported by the firmware and it is not looped.
2840  *
2841  * \param frequency The desired tone frequency, in Hz.
2842  * \param duration The desired tone duration, in ms.
2843  */
2844 inline char PlayTone(unsigned int frequency, unsigned int duration);
2845 
2846 /**
2847  * Play a tone with extra options.
2848  * Play a single tone of the specified frequency, duration, and volume. The
2849  * frequency is in Hz (see the \ref ToneConstants group). The duration is in
2850  * 1000ths of a second (see the \ref TimeConstants group). Volume should be a
2851  * number from 0 (silent) to 4 (loudest). Play the tone repeatedly if loop is
2852  * true.
2853  *
2854  * \param frequency The desired tone frequency, in Hz.
2855  * \param duration The desired tone duration, in ms.
2856  * \param volume The desired tone volume.
2857  * \param loop A boolean flag indicating whether to play the tone repeatedly.
2858  */
2859 inline char PlayToneEx(unsigned int frequency, unsigned int duration, byte volume, bool loop);
2860 
2861 /**
2862  * Get sound module state.
2863  * Return the current sound module state. See the \ref SoundStateConstants group.
2864  *
2865  * \sa SetSoundModuleState(), SysSoundSetState(), SysSoundGetState()
2866  * \return The current sound module state.
2867  */
2868 inline byte SoundState();
2869 
2870 /**
2871  * Get sound module flags.
2872  * Return the current sound module flags. See the \ref SoundFlagsConstants group.
2873  *
2874  * \sa SetSoundFlags(), SysSoundSetState(), SysSoundGetState()
2875  * \return The current sound module flags.
2876  */
2877 inline byte SoundFlags();
2878 
2879 /**
2880  * Stop sound.
2881  * Stop playing of the current tone or file.
2882  *
2883  * \return The result \todo ?.
2884  */
2885 inline byte StopSound();
2886 
2887 /**
2888  * Get sound frequency.
2889  * Return the current sound frequency.
2890  *
2891  * \sa SetSoundFrequency()
2892  * \return The current sound frequency.
2893  */
2894 inline unsigned int SoundFrequency();
2895 
2896 /**
2897  * Get sound duration.
2898  * Return the current sound duration.
2899  *
2900  * \sa SetSoundDuration()
2901  * \return The current sound duration.
2902  */
2903 inline unsigned int SoundDuration();
2904 
2905 /**
2906  * Get sample rate.
2907  * Return the current sound sample rate.
2908  *
2909  * \sa SetSoundSampleRate()
2910  * \return The current sound sample rate.
2911  */
2912 inline unsigned int SoundSampleRate();
2913 
2914 /**
2915  * Get sound mode.
2916  * Return the current sound mode.  See the \ref SoundModeConstants group.
2917  *
2918  * \sa SetSoundMode()
2919  * \return The current sound mode.
2920  */
2921 inline byte SoundMode();
2922 
2923 /**
2924  * Get volume.
2925  * Return the current sound volume.
2926  *
2927  * \sa SetSoundVolume()
2928  * \return The current sound volume.
2929  */
2930 inline byte SoundVolume();
2931 
2932 /**
2933  * Set sound duration.
2934  * Set the sound duration.
2935  *
2936  * \sa SoundDuration()
2937  * \param duration The new sound duration
2938  */
2939 inline void SetSoundDuration(unsigned int duration);
2940 
2941 /**
2942  * Set sound module flags.
2943  * Set the sound module flags. See the \ref SoundFlagsConstants group.
2944  *
2945  * \sa SetSoundFlags(), SysSoundSetState(), SysSoundGetState()
2946  * \param flags The new sound module flags
2947  */
2948 inline void SetSoundFlags(byte flags);
2949 
2950 /**
2951  * Set sound frequency.
2952  * Set the sound frequency.
2953  *
2954  * \sa SoundFrequency()
2955  * \param frequency The new sound frequency
2956  */
2957 inline void SetSoundFrequency(unsigned int frequency);
2958 
2959 /**
2960  * Set sound mode.
2961  * Set the sound mode.  See the \ref SoundModeConstants group.
2962  *
2963  * \sa SoundMode()
2964  * \param mode The new sound mode
2965  */
2966 inline void SetSoundMode(byte mode);
2967 
2968 /**
2969  * Set sound module state.
2970  * Set the sound module state. See the \ref SoundStateConstants group.
2971  *
2972  * \sa SoundState(), SysSoundSetState(), SysSoundGetState()
2973  * \param state The new sound state
2974  */
2975 inline void SetSoundModuleState(byte state);
2976 
2977 /**
2978  * Set sample rate.
2979  * Set the sound sample rate.
2980  *
2981  * \sa SoundSampleRate()
2982  * \param sampleRate The new sample rate
2983  */
2984 inline void SetSoundSampleRate(unsigned int sampleRate);
2985 
2986 /**
2987  * Set sound volume.
2988  * Set the sound volume.
2989  *
2990  * \sa SoundVolume()
2991  * \param volume The new volume
2992  */
2993 inline void SetSoundVolume(byte volume);
2994 
2995 /**
2996  * Play sound file.
2997  * This function lets you play a sound file given the parameters you pass in
2998  * via the \ref SoundPlayFileType structure. The sound file can either be an
2999  * RSO file containing PCM or compressed ADPCM samples or it can be an NXT
3000  * melody (RMD) file containing frequency and duration values.
3001  *
3002  * \param args The SoundPlayFileType structure containing the needed
3003  * parameters.
3004  */
3005 inline void SysSoundPlayFile(SoundPlayFileType & args);
3006 
3007 /**
3008  * Play tone.
3009  * This function lets you play a tone given the parameters you pass in via the
3010  * \ref SoundPlayToneType structure.
3011  *
3012  * \param args The SoundPlayToneType structure containing the needed
3013  * parameters.
3014  */
3015 inline void SysSoundPlayTone(SoundPlayToneType & args);
3016 
3017 /**
3018  * Get sound state.
3019  * This function lets you retrieve information about the sound module state
3020  * via the \ref SoundGetStateType structure.
3021  *
3022  * \param args The SoundGetStateType structure containing the needed
3023  * parameters.
3024  */
3025 inline void SysSoundGetState(SoundGetStateType & args);
3026 
3027 /**
3028  * Set sound state.
3029  * This function lets you set sound module state settings via the \ref
3030  * SoundSetStateType structure.
3031  *
3032  * \param args The SoundSetStateType structure containing the needed
3033  * parameters.
3034  */
3035 inline void SysSoundSetState(SoundSetStateType & args);
3036 
3037 #else
3038 
3039 #define PlayTone(_f, _d) PlayToneEx(_f, _d, 4, 0)
3040 #define PlayFile(_f) PlayFileEx(_f, 4, 0)
3041 
3042 #define SoundState() asm { GetSoundState(__RETVAL__, __TMPBYTE__) }
3043 #define SoundFlags() asm { GetSoundState(__TMPBYTE__, __RETVAL__) }
3044 #define StopSound() asm { __setSoundState(SOUND_STATE_STOP, 0, __RETVAL__) }
3045 
3046 #define SoundFrequency() asm { GetSoundFrequency(__TMPWORD__) __RETURN__ __TMPWORD__ }
3047 #define SoundDuration() asm { GetSoundDuration(__TMPWORD__) __RETURN__ __TMPWORD__ }
3048 #define SoundSampleRate() asm { GetSoundSampleRate(__TMPWORD__) __RETURN__ __TMPWORD__ }
3049 #define SoundMode() asm { GetSoundMode(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
3050 #define SoundVolume() asm { GetSoundVolume(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
3051 
3052 #define SetSoundFrequency(_n) asm { __setSoundFrequency(_n) }
3053 #define SetSoundDuration(_n) asm { __setSoundDuration(_n) }
3054 #define SetSoundSampleRate(_n) asm { __setSoundSampleRate(_n) }
3055 #define SetSoundFlags(_n) asm { __setSoundFlags(_n) }
3056 #define SetSoundModuleState(_n) asm { __setSoundModuleState(_n) }
3057 #define SetSoundMode(_n) asm { __setSoundMode(_n) }
3058 #define SetSoundVolume(_n) asm { __setSoundVolume(_n) }
3059 
3060 #define SysSoundPlayFile(_args) asm { \
3061   compchktype _args, SoundPlayFileType \
3062   syscall SoundPlayFile, _args \
3063 }
3064 #define SysSoundPlayTone(_args) asm { \
3065   compchktype _args, SoundPlayToneType \
3066   syscall SoundPlayTone, _args \
3067 }
3068 #define SysSoundGetState(_args) asm { \
3069   compchktype _args, SoundGetStateType \
3070   syscall SoundGetState, _args \
3071 }
3072 #define SysSoundSetState(_args) asm { \
3073   compchktype _args, SoundSetStateType \
3074   syscall SoundSetState, _args \
3075 }
3076 
3077 #endif
3078 
3079 /**
3080  * Play a system sound.
3081  * Play a sound that mimics the RCX system sounds using one of the
3082  * \ref RCXSoundConstants.
3083  * <TABLE BORDER=1>
3084  * <TR><TH>aCode</TH><TH>Resulting Sound</TH></TR>
3085  * <TR><TD>\ref SOUND_CLICK</TD><TD>key click sound</TD></TR>
3086  * <TR><TD>\ref SOUND_DOUBLE_BEEP</TD><TD>double beep</TD></TR>
3087  * <TR><TD>\ref SOUND_DOWN</TD><TD>sweep down</TD></TR>
3088  * <TR><TD>\ref SOUND_UP</TD><TD>sweep up</TD></TR>
3089  * <TR><TD>\ref SOUND_LOW_BEEP</TD><TD>error sound</TD></TR>
3090  * <TR><TD>\ref SOUND_FAST_UP</TD><TD>fast sweep up</TD></TR>
3091  * </TABLE>
3092  * \param aCode The system sound to play.  See \ref RCXSoundConstants.
3093  */
PlaySound(const int & aCode)3094 void PlaySound(const int &aCode)
3095 {
3096     if (aCode == SOUND_CLICK)
3097         PlayTone(600, MS_200);
3098     else if (aCode == SOUND_DOUBLE_BEEP)
3099     {
3100         PlayTone(600, MS_150);
3101         asm { wait MS_200 };
3102         PlayTone(600, MS_150);
3103         asm { wait MS_150 };
3104     }
3105     else if (aCode == SOUND_UP)
3106         for (int i = 4; i < 8; i++)
3107         {
3108             PlayTone(TONE_C5 * i / 4, MS_100);
3109             asm { wait MS_100 };
3110         }
3111     else if (aCode == SOUND_DOWN)
3112         for (int i = 7; i > 3; i--)
3113         {
3114             PlayTone(TONE_C5 * i / 4, MS_100);
3115             asm { wait MS_100 };
3116         }
3117     else if (aCode == SOUND_LOW_BEEP)
3118     {
3119         PlayTone(100, MS_500);
3120         asm { wait MS_500 };
3121     }
3122     else if (aCode == SOUND_FAST_UP)
3123         for (int i = 4; i < 8; i++)
3124         {
3125             PlayTone(TONE_C5 * i / 4, MS_50);
3126             asm { wait MS_50 };
3127         }
3128 }
3129 
3130 /**
3131  * Play multiple tones.
3132  * Play a series of tones contained in the tones array.  Each element
3133  * in the array is an instance of the \ref Tone structure, containing
3134  * a frequency and a duration.
3135  *
3136  * \param tones The array of tones to play.
3137  */
PlayTones(Tone tones[])3138 void PlayTones(Tone tones[])
3139 {
3140   for (int i = 0; i <  asm { arrsize __RETVAL__, tones }; i++) {
3141     Tone tmp = tones[i];
3142     PlayTone(tmp.Frequency, tmp.Duration);
3143     asm { waitv tmp.Duration };
3144   }
3145 }
3146 
3147 /** @} */ // end of SoundModuleFunctions group
3148 /** @} */ // end of SoundModule group
3149 /** @} */ // end of NXTFirmwareModules group
3150 
3151 
3152 ///////////////////////////////////////////////////////////////////////////////
3153 /////////////////////////////// LOWSPEED MODULE ///////////////////////////////
3154 ///////////////////////////////////////////////////////////////////////////////
3155 
3156 
3157 /** @addtogroup NXTFirmwareModules
3158  * @{
3159  */
3160 /** @addtogroup LowSpeedModule
3161  * @{
3162  */
3163 /** @defgroup LowSpeedModuleTypes LowSpeed module types
3164  * Types used by various low speed module functions.
3165  * @{
3166  */
3167 /**
3168  * Parameters for the CommLSWrite system call.
3169  * This structure is used when calling the \ref SysCommLSWrite system call
3170  * function.
3171  * \sa SysCommLSWrite()
3172  */
3173 struct CommLSWriteType {
3174   char Result;      /*!< The function call result. Possible values include
3175                       \ref ERR_COMM_CHAN_INVALID, \ref ERR_COMM_CHAN_NOT_READY,
3176                       \ref ERR_INVALID_SIZE, and \ref NO_ERR. */
3177   byte Port;        /*!< The port to which the I2C device is connected. */
3178   byte Buffer[];    /*!< The buffer containing data to be written to the I2C device. */
3179   byte ReturnLen;   /*!< The number of bytes that you want to read from the I2C device
3180                       after writing the data.  If no read is planned set this to zero. */
3181 };
3182 
3183 /**
3184  * Parameters for the CommLSRead system call.
3185  * This structure is used when calling the \ref SysCommLSRead system call
3186  * function.
3187  * \sa SysCommLSRead()
3188  */
3189 struct CommLSReadType {
3190   char Result;      /*!< The function call result. Possible values include
3191                       \ref ERR_COMM_BUS_ERR, \ref ERR_COMM_CHAN_INVALID,
3192                       \ref ERR_COMM_CHAN_NOT_READY, \ref ERR_INVALID_SIZE,
3193                       \ref STAT_COMM_PENDING, and \ref NO_ERR. */
3194   byte Port;        /*!< The port to which the I2C device is connected. */
3195   byte Buffer[];    /*!< The buffer used to store the bytes read from the I2C device. */
3196   byte BufferLen;   /*!< The size of the output buffer on input.  This field is not updated during the function call. */
3197 };
3198 
3199 /**
3200  * Parameters for the CommLSCheckStatus system call.
3201  * This structure is used when calling the \ref SysCommLSCheckStatus system
3202  * call function.
3203  * \sa SysCommLSCheckStatus()
3204  */
3205 struct CommLSCheckStatusType {
3206   char Result;       /*!< The function call result. Possible values include
3207                        \ref ERR_COMM_BUS_ERR, \ref ERR_COMM_CHAN_INVALID,
3208                        \ref ERR_COMM_CHAN_NOT_READY, \ref STAT_COMM_PENDING,
3209                        and \ref NO_ERR. */
3210   byte Port;         /*!< The port to which the I2C device is connected. */
3211   byte BytesReady;   /*!< The number of bytes ready to read from the specified port. */
3212 };
3213 
3214 #ifdef __ENHANCED_FIRMWARE
3215 /**
3216  * Parameters for the CommLSWriteEx system call.
3217  * This structure is used when calling the \ref SysCommLSWriteEx system call
3218  * function.
3219  * \sa SysCommLSWriteEx()
3220  */
3221 struct CommLSWriteExType {
3222   char Result;          /*!< The function call result. Possible values include
3223                       \ref ERR_COMM_CHAN_INVALID, \ref ERR_COMM_CHAN_NOT_READY,
3224                       \ref ERR_INVALID_SIZE, and \ref NO_ERR. */
3225   byte Port;            /*!< The port to which the I2C device is connected. */
3226   byte Buffer[];        /*!< The buffer written to the I2C device. */
3227   byte ReturnLen;       /*!< The number of bytes that you want to read from the I2C device. */
3228   bool NoRestartOnRead; /*!< Should a restart occur before reading from the device? */
3229 };
3230 #endif
3231 
3232 /** @} */ // end of LowSpeedModuleTypes group
3233 
3234 /** @defgroup LowSpeedModuleFunctions LowSpeed module functions
3235  * Functions for accessing and modifying low speed module features.
3236  * @{
3237  */
3238 
3239 #ifdef __DOXYGEN_DOCS
3240 
3241 /**
3242  * Read ultrasonic sensor value.
3243  * Return the ultrasonic sensor distance value. Since an
3244  * ultrasonic sensor is an I2C digital sensor its value cannot be read using
3245  * the standard Sensor(n) value.
3246  * The port must be configured as a Lowspeed port before using this function.
3247  * \param port The port to which the ultrasonic sensor is attached. See the
3248  * \ref InPorts group. You may use a constant or a variable.
3249  * \return The ultrasonic sensor distance value (0..255)
3250  */
3251 inline byte SensorUS(const byte port);
3252 
3253 /**
3254  * Read multiple ultrasonic sensor values.
3255  * Return eight ultrasonic sensor distance values.
3256  * \param port The port to which the ultrasonic sensor is attached. See the
3257  * \ref InPorts group. You may use a constant or a variable.
3258  * \param values An array of bytes that will contain the 8 distance values
3259  * read from the ultrasonic sensor.
3260  * \return A status code indicating whether the read completed successfully or not.
3261  * See \ref CommLSReadType for possible result values.
3262  */
3263 inline char ReadSensorUSEx(const byte port, byte & values[]);
3264 
3265 /**
3266  * Read the LEGO EMeter values.
3267  * Read all the LEGO EMeter register values.
3268  * They must all be read at once to ensure data coherency.
3269  *
3270  * \param port The port to which the LEGO EMeter sensor is attached. See the
3271  * \ref InPorts group. You may use a constant or a variable.
3272  * \param vIn Input voltage
3273  * \param aIn Input current
3274  * \param vOut Output voltage
3275  * \param aOut Output current
3276  * \param joules The number of joules stored in the EMeter
3277  * \param wIn The number of watts generated
3278  * \param wOut The number of watts consumed
3279  * \return A status code indicating whether the read completed successfully or not.
3280  * See \ref CommLSReadType for possible result values.
3281  */
3282 inline char ReadSensorEMeter(const byte & port, float &vIn, float &aIn, float &vOut, float &aOut, int &joules, float &wIn, float &wOut);
3283 
3284 /**
3285  * Configure LEGO Temperature sensor options.
3286  * Set various LEGO Temperature sensor options.
3287  *
3288  * \param port The port to which the temperature sensor is attached. See the
3289  * \ref InPorts group. You may use a constant or a variable.
3290  * \param config The temperature sensor configuration settings.  See
3291  * \ref TempI2CConstants for configuration constants that can be ORed or added
3292  * together.
3293  * \return A status code indicating whether the read completed successfully or not.
3294  * See \ref CommLSReadType for possible Result values.
3295  */
3296 inline char ConfigureTemperatureSensor(const byte & port, const byte & config);
3297 
3298 /**
3299  * Read the LEGO Temperature sensor value.
3300  * Return the temperature sensor value in degrees celcius. Since a
3301  * temperature sensor is an I2C digital sensor its value cannot be read using
3302  * the standard Sensor(n) value.
3303  * The port must be configured as a temperature sensor port before using this
3304  * function. Use \ref SetSensorTemperature to configure the port.
3305  * \param port The port to which the temperature sensor is attached. See the
3306  * \ref InPorts group. You may use a constant or a variable.
3307  * \return The temperature sensor value in degrees celcius.
3308  */
3309 inline float SensorTemperature(const byte & port);
3310 
3311 /**
3312  * Get lowspeed status.
3313  * This method checks the status of the I2C communication on the specified
3314  * port. If the last operation on this port was a successful LowspeedWrite
3315  * call that requested response data from the device then bytesready will
3316  * be set to the number of bytes in the internal read buffer.
3317  *
3318  * \param port The port to which the I2C device is attached. See the
3319  * \ref InPorts group. You may use a constant or a variable. Constants should
3320  * be used where possible to avoid blocking access to I2C devices on other
3321  * ports by code running on other threads.
3322  * \param bytesready The number of bytes available to be read from the internal I2C buffer.
3323  * The maximum number of bytes that can be read is 16.
3324  * \return A status code indicating whether the write completed successfully or not.
3325  * See \ref CommLSCheckStatusType for possible result values. If the return
3326  * value is \ref NO_ERR then the last operation did not cause any errors.
3327  * Avoid calls to \ref LowspeedRead or \ref LowspeedWrite while LowspeedStatus returns
3328  * \ref STAT_COMM_PENDING.
3329  * \sa I2CStatus, I2CRead, I2CWrite, I2CCheckStatus, I2CBytesReady, LowspeedRead,
3330  * LowspeedWrite, and LowspeedCheckStatus
3331  */
3332 inline long LowspeedStatus(const byte port, byte & bytesready);
3333 
3334 /**
3335  * Check lowspeed status.
3336  * This method checks the status of the I2C communication on the specified
3337  * port.
3338  *
3339  * \param port The port to which the I2C device is attached. See the
3340  * \ref InPorts group. You may use a constant or a variable. Constants should
3341  * be used where possible to avoid blocking access to I2C devices on other
3342  * ports by code running on other threads.
3343  * \return A status code indicating whether the write completed successfully or not.
3344  * See \ref CommLSCheckStatusType for possible result values. If the return
3345  * value is \ref NO_ERR then the last operation did not cause any errors.
3346  * Avoid calls to \ref LowspeedRead or \ref LowspeedWrite while LowspeedCheckStatus returns
3347  * \ref STAT_COMM_PENDING.
3348  * \sa I2CCheckStatus, I2CRead, I2CWrite, I2CStatus, I2CBytesReady, LowspeedRead,
3349  * LowspeedWrite, and LowspeedStatus
3350  */
3351 inline long LowspeedCheckStatus(const byte port);
3352 
3353 /**
3354  * Get lowspeed bytes ready.
3355  * This method checks the number of bytes that are ready to be read on the
3356  * specified port. If the last operation on this port was a successful
3357  * LowspeedWrite call that requested response data from the device then the
3358  * return value will be the number of bytes in the internal read buffer.
3359  *
3360  * \param port The port to which the I2C device is attached. See the
3361  * \ref InPorts group. You may use a constant or a variable. Constants should
3362  * be used where possible to avoid blocking access to I2C devices on other
3363  * ports by code running on other threads.
3364  * \return The number of bytes available to be read from the internal I2C buffer.
3365  * The maximum number of bytes that can be read is 16.
3366  * \sa I2CCheckStatus, I2CRead, I2CWrite, I2CStatus, I2CBytesReady, LowspeedRead,
3367  * LowspeedWrite, and LowspeedStatus
3368  */
3369 inline byte LowspeedBytesReady(const byte port);
3370 
3371 /**
3372  * Write lowspeed data.
3373  * This method starts a transaction to write the bytes contained in the array
3374  * buffer to the I2C device on the specified port. It also tells the I2C device
3375  * the number of bytes that should be included in the response. The maximum
3376  * number of bytes that can be written or read is 16.
3377  *
3378  * \param port The port to which the I2C device is attached. See the
3379  * \ref InPorts group. You may use a constant or a variable. Constants should
3380  * be used where possible to avoid blocking access to I2C devices on other
3381  * ports by code running on other threads.
3382  * \param retlen The number of bytes that should be returned by the I2C device.
3383  * \param buffer A byte array containing the address of the I2C device, the I2C
3384  * device register at which to write data, and up to 14 bytes of data to be
3385  * written at the specified register.
3386  * \return A status code indicating whether the write completed successfully or not.
3387  * See \ref CommLSWriteType for possible result values. If the return
3388  * value is \ref NO_ERR then the last operation did not cause any errors.
3389  * \sa I2CCheckStatus, I2CRead, I2CWrite, I2CStatus, I2CBytesReady, LowspeedRead,
3390  * LowspeedCheckStatus, LowspeedBytesReady, and LowspeedStatus
3391  */
3392 inline long LowspeedWrite(const byte port, byte retlen, byte buffer[]);
3393 
3394 /**
3395  * Read lowspeed data.
3396  * Read the specified number of bytes from the I2C device on the specified
3397  * port and store the bytes read in the byte array buffer provided.  The maximum
3398  * number of bytes that can be written or read is 16.
3399  *
3400  * \param port The port to which the I2C device is attached. See the
3401  * \ref InPorts group. You may use a constant or a variable. Constants should
3402  * be used where possible to avoid blocking access to I2C devices on other
3403  * ports by code running on other threads.
3404  * \param buflen The initial size of the output buffer.
3405  * \param buffer A byte array that contains the data read from the internal I2C
3406  * buffer.  If the return value is negative then the output buffer will be empty.
3407  * \return A status code indicating whether the write completed successfully or not.
3408  * See \ref CommLSReadType for possible result values. If the return
3409  * value is \ref NO_ERR then the last operation did not cause any errors.
3410  * \sa I2CCheckStatus, I2CRead, I2CWrite, I2CStatus, I2CBytesReady, LowspeedWrite,
3411  * LowspeedCheckStatus, LowspeedBytesReady, and LowspeedStatus
3412  */
3413 inline long LowspeedRead(const byte port, byte buflen, byte & buffer[]);
3414 
3415 /**
3416  * Get I2C status.
3417  * This method checks the status of the I2C communication on the specified
3418  * port. If the last operation on this port was a successful I2CWrite
3419  * call that requested response data from the device then bytesready will
3420  * be set to the number of bytes in the internal read buffer.
3421  *
3422  * \param port The port to which the I2C device is attached. See the
3423  * \ref InPorts group. You may use a constant or a variable. Constants should
3424  * be used where possible to avoid blocking access to I2C devices on other
3425  * ports by code running on other threads.
3426  * \param bytesready The number of bytes available to be read from the internal I2C buffer.
3427  * The maximum number of bytes that can be read is 16.
3428  * \return A status code indicating whether the write completed successfully or not.
3429  * See \ref CommLSCheckStatusType for possible return values. If the return
3430  * value is \ref NO_ERR then the last operation did not cause any errors.
3431  * Avoid calls to \ref I2CRead or \ref I2CWrite while I2CStatus returns
3432  * \ref STAT_COMM_PENDING.
3433  * \sa I2CCheckStatus, I2CRead, I2CWrite, LowspeedStatus, LowspeedRead,
3434  * LowspeedWrite, and LowspeedCheckStatus
3435  */
3436 inline long I2CStatus(const byte port, byte & bytesready);
3437 
3438 /**
3439  * Check I2C status.
3440  * This method checks the status of the I2C communication on the specified
3441  * port.
3442  *
3443  * \param port The port to which the I2C device is attached. See the
3444  * \ref InPorts group. You may use a constant or a variable. Constants should
3445  * be used where possible to avoid blocking access to I2C devices on other
3446  * ports by code running on other threads.
3447  * \return A status code indicating whether the write completed successfully or not.
3448  * See \ref CommLSCheckStatusType for possible result values. If the return
3449  * value is \ref NO_ERR then the last operation did not cause any errors.
3450  * Avoid calls to \ref I2CRead or \ref I2CWrite while this function returns
3451  * \ref STAT_COMM_PENDING.
3452  * \sa I2CStatus, I2CRead, I2CWrite, LowspeedStatus, LowspeedRead,
3453  * LowspeedWrite, and LowspeedCheckStatus
3454  */
3455 inline long I2CCheckStatus(const byte port);
3456 
3457 /**
3458  * Get I2C bytes ready.
3459  * This method checks the number of bytes that are ready to be read on the
3460  * specified port. If the last operation on this port was a successful
3461  * I2CWrite call that requested response data from the device then the
3462  * return value will be the number of bytes in the internal read buffer.
3463  *
3464  * \param port The port to which the I2C device is attached. See the
3465  * \ref InPorts group. You may use a constant or a variable. Constants should
3466  * be used where possible to avoid blocking access to I2C devices on other
3467  * ports by code running on other threads.
3468  * \return The number of bytes available to be read from the internal I2C buffer.
3469  * The maximum number of bytes that can be read is 16.
3470  * \sa I2CCheckStatus, I2CRead, I2CWrite, I2CStatus, LowspeedBytesReady, LowspeedRead,
3471  * LowspeedWrite, and LowspeedStatus
3472  */
3473 inline byte I2CBytesReady(const byte port);
3474 
3475 /**
3476  * Write I2C data.
3477  * This method starts a transaction to write the bytes contained in the array
3478  * buffer to the I2C device on the specified port. It also tells the I2C device
3479  * the number of bytes that should be included in the response. The maximum
3480  * number of bytes that can be written or read is 16.
3481  *
3482  * \param port The port to which the I2C device is attached. See the
3483  * \ref InPorts group. You may use a constant or a variable. Constants should
3484  * be used where possible to avoid blocking access to I2C devices on other
3485  * ports by code running on other threads.
3486  * \param retlen The number of bytes that should be returned by the I2C device.
3487  * \param buffer A byte array containing the address of the I2C device, the I2C
3488  * device register at which to write data, and up to 14 bytes of data to be
3489  * written at the specified register.
3490  * \return A status code indicating whether the write completed successfully or not.
3491  * See \ref CommLSWriteType for possible result values. If the return
3492  * value is \ref NO_ERR then the last operation did not cause any errors.
3493  * \sa I2CCheckStatus, I2CRead, I2CStatus, I2CBytesReady, LowspeedRead, LowspeedWrite,
3494  * LowspeedCheckStatus, LowspeedBytesReady, and LowspeedStatus
3495  */
3496 inline long I2CWrite(const byte port, byte retlen, byte buffer[]);
3497 
3498 /**
3499  * Read I2C data.
3500  * Read the specified number of bytes from the I2C device on the specified
3501  * port and store the bytes read in the byte array buffer provided.  The maximum
3502  * number of bytes that can be written or read is 16.
3503  *
3504  * \param port The port to which the I2C device is attached. See the
3505  * \ref InPorts group. You may use a constant or a variable. Constants should
3506  * be used where possible to avoid blocking access to I2C devices on other
3507  * ports by code running on other threads.
3508  * \param buflen The initial size of the output buffer.
3509  * \param buffer A byte array that contains the data read from the internal I2C
3510  * buffer.  If the return value is negative then the output buffer will be empty.
3511  * \return A status code indicating whether the write completed successfully or not.
3512  * See \ref CommLSReadType for possible result values. If the return
3513  * value is \ref NO_ERR then the last operation did not cause any errors.
3514  * \sa I2CCheckStatus, I2CWrite, I2CStatus, I2CBytesReady, LowspeedRead, LowspeedWrite,
3515  * LowspeedCheckStatus, LowspeedBytesReady, and LowspeedStatus
3516  */
3517 inline long I2CRead(const byte port, byte buflen, byte & buffer[]);
3518 
3519 /**
3520  * Perform an I2C write/read transaction.
3521  * This method writes the bytes contained in the input buffer (inbuf) to the
3522  * I2C device on the specified port, checks for the specified number of bytes
3523  * to be ready for reading, and then tries to read the specified number (count)
3524  * of bytes from the I2C device into the output buffer (outbuf).
3525  *
3526  * This is a higher-level wrapper around the three main I2C functions. It also
3527  * maintains a "last good read" buffer and returns values from that buffer if
3528  * the I2C communication transaction fails.
3529  *
3530  * \param port The port to which the I2C device is attached. See the
3531  * \ref InPorts group. You may use a constant or a variable. Constants should
3532  * be used where possible to avoid blocking access to I2C devices on other
3533  * ports by code running on other threads.
3534  * \param inbuf A byte array containing the address of the I2C device, the I2C
3535  * device register at which to write data, and up to 14 bytes of data to be
3536  * written at the specified register.
3537  * \param count The number of bytes that should be returned by the I2C device.
3538  * On output count is set to the number of bytes in outbuf.
3539  * \param outbuf A byte array that contains the data read from the internal I2C
3540  * buffer.
3541  * \return Returns true or false indicating whether the I2C transaction
3542  * succeeded or failed.
3543  * \sa I2CCheckStatus, I2CWrite, I2CStatus, I2CBytesReady, I2CRead, LowspeedRead, LowspeedWrite,
3544  * LowspeedCheckStatus, LowspeedBytesReady, and LowspeedStatus
3545  */
3546 inline long I2CBytes(const byte port, byte inbuf[], byte & count, byte & outbuf[]);
3547 
3548 /**
3549  * Read I2C register.
3550  * Read a single byte from an I2C device register.
3551  * \param port The port to which the I2C device is attached. See the
3552  * \ref InPorts group. You may use a constant or a variable.
3553  * \param i2caddr The I2C device address.
3554  * \param reg The I2C device register from which to read a single byte.
3555  * \param out The single byte read from the I2C device.
3556  * \return A status code indicating whether the read completed successfully or not.
3557  * See \ref CommLSReadType for possible result values.
3558  */
3559 inline char ReadI2CRegister(byte port, byte i2caddr, byte reg, byte & out);
3560 
3561 /**
3562  * Write I2C register.
3563  * Write a single byte to an I2C device register.
3564  * \param port The port to which the I2C device is attached. See the
3565  * \ref InPorts group. You may use a constant or a variable.
3566  * \param i2caddr The I2C device address.
3567  * \param reg The I2C device register to which to write a single byte.
3568  * \param val The byte to write to the I2C device.
3569  * \return A status code indicating whether the write completed successfully or not.
3570  * See \ref CommLSCheckStatusType for possible result values.
3571  */
3572 inline char WriteI2CRegister(byte port, byte i2caddr, byte reg, byte val);
3573 
3574 /**
3575  * Read I2C device information.
3576  * Read standard I2C device information: version, vendor, and device ID. The
3577  * I2C device uses the specified address.
3578  *
3579  * \param port The port to which the I2C device is attached. See the
3580  * \ref InPorts group. You may use a constant or a variable. Constants should
3581  * be used where possible to avoid blocking access to I2C devices on other
3582  * ports by code running on other threads.
3583  * \param i2caddr The I2C device address.
3584  * \param info A value indicating the type of device information you are requesting.
3585  * See \ref GenericI2CConstants.
3586  * \return A string containing the requested device information.
3587  */
3588 inline string I2CDeviceInfo(byte port, byte i2caddr, byte info);
3589 
3590 /**
3591  * Read I2C device version.
3592  * Read standard I2C device version. The I2C device uses the specified address.
3593  *
3594  * \param port The port to which the I2C device is attached. See the
3595  * \ref InPorts group. You may use a constant or a variable. Constants should
3596  * be used where possible to avoid blocking access to I2C devices on other
3597  * ports by code running on other threads.
3598  * \param i2caddr The I2C device address.
3599  * \return A string containing the device version.
3600  */
3601 inline string I2CVersion(byte port, byte i2caddr);
3602 
3603 /**
3604  * Read I2C device vendor.
3605  * Read standard I2C device vendor. The I2C device uses the specified address.
3606  *
3607  * \param port The port to which the I2C device is attached. See the
3608  * \ref InPorts group. You may use a constant or a variable. Constants should
3609  * be used where possible to avoid blocking access to I2C devices on other
3610  * ports by code running on other threads.
3611  * \param i2caddr The I2C device address.
3612  * \return A string containing the device vendor.
3613  */
3614 inline string I2CVendorId(byte port, byte i2caddr);
3615 
3616 /**
3617  * Read I2C device identifier.
3618  * Read standard I2C device identifier. The I2C device uses the specified address.
3619  *
3620  * \param port The port to which the I2C device is attached. See the
3621  * \ref InPorts group. You may use a constant or a variable. Constants should
3622  * be used where possible to avoid blocking access to I2C devices on other
3623  * ports by code running on other threads.
3624  * \param i2caddr The I2C device address.
3625  * \return A string containing the device identifier.
3626  */
3627 inline string I2CDeviceId(byte port, byte i2caddr);
3628 
3629 /**
3630  * Send an I2C command.
3631  * Send a command to an I2C device at the standard command register: \ref I2C_REG_CMD.
3632  * The I2C device uses the specified address.
3633  * \param port The port to which the I2C device is attached. See the
3634  * \ref InPorts group. You may use a constant or a variable. Constants should
3635  * be used where possible to avoid blocking access to I2C devices on other
3636  * ports by code running on other threads.
3637  * \param i2caddr The I2C device address.
3638  * \param cmd The command to send to the I2C device.
3639  * \return A status code indicating whether the write completed successfully or not.
3640  * See \ref CommLSCheckStatusType for possible result values.
3641  */
3642 inline long I2CSendCommand(byte port, byte i2caddr, byte cmd);
3643 
3644 /** @defgroup LowLevelLowSpeedModuleFunctions Low level LowSpeed module functions
3645  * Low level functions for accessing low speed module features.
3646  * @{
3647  */
3648 
3649 /**
3650  * Get I2C input buffer data.
3651  * This method reads count bytes of data from the I2C input buffer for the
3652  * specified port and writes it to the buffer provided.
3653  * \param port A constant port number (S1..S4). See \ref InPorts.
3654  * \param offset A constant offset into the I2C input buffer.
3655  * \param cnt The number of bytes to read.
3656  * \param data The byte array reference which will contain the data read from
3657  * the I2C input buffer.
3658  */
3659 inline void GetLSInputBuffer(const byte port, const byte offset, byte cnt, byte & data[]);
3660 
3661 /**
3662  * Get I2C output buffer data.
3663  * This method reads cnt bytes of data from the I2C output buffer for the
3664  * specified port and writes it to the buffer provided.
3665  * \param port A constant port number (S1..S4). See \ref InPorts.
3666  * \param offset A constant offset into the I2C output buffer.
3667  * \param cnt The number of bytes to read.
3668  * \param data The byte array reference which will contain the data read from
3669  * the I2C output buffer.
3670  */
3671 inline void GetLSOutputBuffer(const byte port, const byte offset, byte cnt, byte & data[]);
3672 
3673 /**
3674  * Get I2C input buffer in-pointer.
3675  * This method returns the value of the input pointer of the I2C input
3676  * buffer for the specified port.
3677  * \param port A constant port number (S1..S4). See \ref InPorts.
3678  * \return The I2C input buffer's in-pointer value.
3679  */
3680 inline byte LSInputBufferInPtr(const byte port);
3681 
3682 /**
3683  * Get I2C input buffer out-pointer.
3684  * This method returns the value of the output pointer of the I2C input
3685  * buffer for the specified port.
3686  * \param port A constant port number (S1..S4). See \ref InPorts.
3687  * \return The I2C input buffer's out-pointer value.
3688  */
3689 inline byte LSInputBufferOutPtr(const byte port);
3690 
3691 /**
3692  * Get I2C input buffer bytes to rx.
3693  * This method returns the value of the bytes to rx field of the I2C input
3694  * buffer for the specified port.
3695  * \param port A constant port number (S1..S4). See \ref InPorts.
3696  * \return The I2C input buffer's bytes to rx value.
3697  */
3698 inline byte LSInputBufferBytesToRx(const byte port);
3699 
3700 /**
3701  * Get I2C output buffer in-pointer.
3702  * This method returns the value of the input pointer of the I2C output
3703  * buffer for the specified port.
3704  * \param port A constant port number (S1..S4). See \ref InPorts.
3705  * \return The I2C output buffer's in-pointer value.
3706  */
3707 inline byte LSOutputBufferInPtr(const byte port);
3708 
3709 /**
3710  * Get I2C output buffer out-pointer.
3711  * This method returns the value of the output pointer of the I2C output
3712  * buffer for the specified port.
3713  * \param port A constant port number (S1..S4). See \ref InPorts.
3714  * \return The I2C output buffer's out-pointer value.
3715  */
3716 inline byte LSOutputBufferOutPtr(const byte port);
3717 
3718 /**
3719  * Get I2C output buffer bytes to rx.
3720  * This method returns the value of the bytes to rx field of the I2C output
3721  * buffer for the specified port.
3722  * \param port A constant port number (S1..S4). See \ref InPorts.
3723  * \return The I2C output buffer's bytes to rx value.
3724  */
3725 inline byte LSOutputBufferBytesToRx(const byte port);
3726 
3727 /**
3728  * Get I2C mode.
3729  * This method returns the value of the I2C mode for the specified port.
3730  * \param port A constant port number (S1..S4). See \ref InPorts.
3731  * \return The I2C port mode. See \ref LowSpeedModeConstants.
3732  */
3733 inline byte LSMode(const byte port);
3734 
3735 /**
3736  * Get I2C channel state.
3737  * This method returns the value of the I2C channel state for the specified port.
3738  * \param port A constant port number (S1..S4). See \ref InPorts.
3739  * \return The I2C port channel state. See \ref LowSpeedChannelStateConstants.
3740  */
3741 inline byte LSChannelState(const byte port);
3742 
3743 /**
3744  * Get I2C error type.
3745  * This method returns the value of the I2C error type for the specified port.
3746  * \param port A constant port number (S1..S4). See \ref InPorts.
3747  * \return The I2C port error type. See \ref LowSpeedErrorTypeConstants.
3748  */
3749 inline byte LSErrorType(const byte port);
3750 
3751 /**
3752  * Get I2C state.
3753  * This method returns the value of the I2C state.
3754  * \return The I2C state. See \ref LowSpeedStateConstants.
3755  */
3756 inline byte LSState();
3757 
3758 /**
3759  * Get I2C speed.
3760  * This method returns the value of the I2C speed.
3761  * \return The I2C speed.
3762  * \warning This function is unimplemented within the firmware.
3763  */
3764 inline byte LSSpeed();
3765 
3766 #ifdef __ENHANCED_FIRMWARE
3767 /**
3768  * Get I2C no restart on read setting.
3769  * This method returns the value of the I2C no restart on read field.
3770  * \return The I2C no restart on read field. See \ref LowSpeedNoRestartConstants.
3771  */
3772 inline byte LSNoRestartOnRead();
3773 
3774 #endif
3775 
3776 /*
3777 // these low speed module IOMap fields are essentially read-only
3778 inline void SetLSInputBuffer(const byte port, const byte offset, byte cnt, byte data[]);
3779 inline void SetLSInputBufferInPtr(const byte port, byte n);
3780 inline void SetLSInputBufferOutPtr(const byte port, byte n);
3781 inline void SetLSInputBufferBytesToRx(const byte port, byte n);
3782 inline void SetLSOutputBuffer(const byte port, const byte offset, byte cnt, byte data[]);
3783 inline void SetLSOutputBufferInPtr(const byte port, byte n);
3784 inline void SetLSOutputBufferOutPtr(const byte port, n);
3785 inline void SetLSOutputBufferBytesToRx(const byte port, byte n);
3786 inline void SetLSMode(const byte port, const byte mode);
3787 inline void SetLSChannelState(const byte port, const byte chState);
3788 inline void SetLSErrorType(const byte port, const byte errType);
3789 inline void SetLSState(const byte lsState);
3790 inline void SetLSSpeed(const byte lsSpeed);
3791 #ifdef __ENHANCED_FIRMWARE
3792 inline void SetLSNoRestartOnRead(const byte lsNoRestart);
3793 #endif
3794 */
3795 
3796 /** @} */ // end of LowLevelLowSpeedModuleFunctions group
3797 
3798 /** @defgroup LowSpeedModuleSystemCallFunctions LowSpeed module system call functions
3799  * System call functions for accessing low speed module features.
3800  * @{
3801  */
3802 
3803 /**
3804  * Write to a Lowspeed sensor.
3805  * This function lets you write to an I2C (Lowspeed) sensor using the values
3806  * specified via the \ref CommLSWriteType structure.
3807  *
3808  * \param args The CommLSWriteType structure containing the needed parameters.
3809  */
3810 inline void SysCommLSWrite(CommLSWriteType & args);
3811 
3812 /**
3813  * Read from a Lowspeed sensor.
3814  * This function lets you read from an I2C (Lowspeed) sensor using the values
3815  * specified via the \ref CommLSReadType structure.
3816  *
3817  * \param args The CommLSReadType structure containing the needed parameters.
3818  */
3819 inline void SysCommLSRead(CommLSReadType & args);
3820 
3821 /**
3822  * Check Lowspeed sensor status.
3823  * This function lets you check the status of an I2C (Lowspeed) sensor
3824  * transaction using the values specified via the \ref CommLSCheckStatusType
3825  * structure.
3826  *
3827  * \param args The CommLSCheckStatusType structure containing the needed
3828  * parameters.
3829  */
3830 inline void SysCommLSCheckStatus(CommLSCheckStatusType & args);
3831 
3832 #ifdef __ENHANCED_FIRMWARE
3833 /**
3834  * Write to a Lowspeed sensor (extra).
3835  * This function lets you write to an I2C (Lowspeed) sensor using the values
3836  * specified via the \ref CommLSWriteExType structure. This is the same as the
3837  * SysCommLSWrite function except that you also can specify whether or not the
3838  * Lowspeed module should issue a restart command to the I2C device before
3839  * beginning to read data from the device.
3840  *
3841  * \param args The CommLSWriteExType structure containing the desired parameters.
3842  */
3843 inline void SysCommLSWriteEx(CommLSWriteExType & args);
3844 
3845 #endif
3846 
3847 /** @} */ // end of LowSpeedModuleSystemCallFunctions group
3848 
3849 #else
3850 
3851 // ultrasonic sensor
3852 #define SensorUS(_p) asm { ReadSensorUS(_p, __RETVAL__) }
3853 #define ReadSensorUSEx(_port, _values) asm { __ReadSensorUSEx(_port, _values, __RETVAL__) }
3854 
3855 #define ReadSensorEMeter(_port, _vIn, _aIn, _vOut, _aOut, _joules, _wIn, _wOut) asm { __ReadSensorEMeter(_port, _vIn, _aIn, _vOut, _aOut, _joules, _wIn, _wOut, __RETVAL__) }
3856 
3857 #define ConfigureTemperatureSensor(_port, _config) asm { __TempSendCmd(_port, _config, __RETVAL__) }
3858 #if __FIRMWARE_VERSION > 107
3859 #define SensorTemperature(_port) asm { __ReadSensorTemperature(_port, __FLTRETVAL__) }
3860 #else
3861 #define SensorTemperature(_port) asm { __ReadSensorTemperature(_port, __RETVAL__) }
3862 #endif
3863 
3864 #define ReadI2CRegister(_port, _i2caddr, _reg, _out) asm { __MSReadValue(_port, _i2caddr, _reg, 1, _out, __RETVAL__) }
3865 #define WriteI2CRegister(_port, _i2caddr, _reg, _val) asm { __MSWriteToRegister(_port, _i2caddr, _reg, _val, __RETVAL__) }
3866 
3867 #define LowspeedStatus(_port, _bready) asm { __lowspeedStatus(_port, _bready, __RETVAL__) }
3868 #define LowspeedCheckStatus(_port) asm { __lowspeedStatus(_port, __TMPBYTE__, __RETVAL__) }
3869 #define LowspeedBytesReady(_port) asm { __lowspeedStatus(_port, __RETVAL__, __TMPBYTE__) }
3870 #define LowspeedWrite(_port, _retlen, _buffer) asm { __lowspeedWrite(_port, _retlen, _buffer, __RETVAL__) }
3871 #define LowspeedRead(_port, _buflen, _buffer) asm { __lowspeedRead(_port, _buflen, _buffer, __RETVAL__) }
3872 
3873 #define I2CStatus(_port, _bready) LowspeedStatus(_port, _bready)
3874 #define I2CCheckStatus(_port) LowspeedCheckStatus(_port)
3875 #define I2CBytesReady(_port) LowspeedBytesReady(_port)
3876 #define I2CWrite(_port, _retlen, _buffer) LowspeedWrite(_port, _retlen, _buffer)
3877 #define I2CRead(_port, _buflen, _buffer) LowspeedRead(_port, _buflen, _buffer)
3878 
3879 #define I2CBytes(_port, _inbuf, _count, _outbuf) asm { ReadI2CBytes(_port, _inbuf, _count, _outbuf, __RETVAL__) }
3880 
3881 #define I2CDeviceInfo(_port, _i2caddr, _info) asm { ReadI2CDeviceInfo(_port, _i2caddr, _info, __STRRETVAL__) }
3882 #define I2CVersion(_port, _i2caddr) asm { ReadI2CDeviceInfo(_port, _i2caddr, I2C_REG_VERSION, __STRRETVAL__) }
3883 #define I2CVendorId(_port, _i2caddr) asm { ReadI2CDeviceInfo(_port, _i2caddr, I2C_REG_VENDOR_ID, __STRRETVAL__) }
3884 #define I2CDeviceId(_port, _i2caddr) asm { ReadI2CDeviceInfo(_port, _i2caddr, I2C_REG_DEVICE_ID, __STRRETVAL__) }
3885 
3886 #define I2CSendCommand(_port, _i2caddr, _cmd) asm { __I2CSendCmd(_port, _i2caddr, _cmd, __RETVAL__) }
3887 
3888 #define GetLSInputBuffer(_p, _offset, _cnt, _data) asm { __getLSInputBuffer(_p, _offset, _cnt, _data) }
3889 #define GetLSOutputBuffer(_p, _offset, _cnt, _data) asm { __getLSOutputBuffer(_p, _offset, _cnt, _data) }
3890 
3891 #define LSInputBufferInPtr(_p) asm { GetLSInputBufferInPtr(_p, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
3892 #define LSInputBufferOutPtr(_p) asm { GetLSInputBufferOutPtr(_p, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
3893 #define LSInputBufferBytesToRx(_p) asm { GetLSInputBufferBytesToRx(_p, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
3894 #define LSOutputBufferInPtr(_p) asm { GetLSOutputBufferInPtr(_p, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
3895 #define LSOutputBufferOutPtr(_p) asm { GetLSOutputBufferOutPtr(_p, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
3896 #define LSOutputBufferBytesToRx(_p) asm { GetLSOutputBufferBytesToRx(_p, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
3897 #define LSMode(_p) asm { GetLSMode(_p, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
3898 #define LSChannelState(_p) asm { GetLSChannelState(_p, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
3899 #define LSErrorType(_p) asm { GetLSErrorType(_p, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
3900 #define LSState() asm { GetLSState(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
3901 #define LSSpeed() asm { GetLSSpeed(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
3902 #ifdef __ENHANCED_FIRMWARE
3903 #define LSNoRestartOnRead(_n) asm { GetLSNoRestartOnRead(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
3904 #endif
3905 
3906 #define SetLSInputBuffer(_p, _offset, _cnt, _data) asm { __setLSInputBuffer(_p, _offset, _cnt, _data) }
3907 
3908 #define SetLSInputBufferInPtr(_p, _n) asm { __setLSInputBufferInPtr(_p, _n) }
3909 #define SetLSInputBufferOutPtr(_p, _n) asm { __setLSInputBufferOutPtr(_p, _n) }
3910 #define SetLSInputBufferBytesToRx(_p, _n) asm { __setLSInputBufferBytesToRx(_p, _n) }
3911 
3912 #define SetLSOutputBuffer(_p, _offset, _cnt, _data) asm { __setLSOutputBuffer(_p, _offset, _cnt, _data) }
3913 
3914 #define SetLSOutputBufferInPtr(_p, _n) asm { __setLSOutputBufferInPtr(_p, _n) }
3915 #define SetLSOutputBufferOutPtr(_p, _n) asm { __setLSOutputBufferOutPtr(_p, _n) }
3916 #define SetLSOutputBufferBytesToRx(_p, _n) asm { __setLSOutputBufferBytesToRx(_p, _n) }
3917 #define SetLSMode(_p, _n) asm { __setLSMode(_p, _n) }
3918 #define SetLSChannelState(_p, _n) asm { __setLSChannelState(_p, _n) }
3919 #define SetLSErrorType(_p, _n) asm { __setLSErrorType(_p, _n) }
3920 #define SetLSState(_n) asm { __setLSState(_n) }
3921 #define SetLSSpeed(_n) asm { __setLSSpeed(_n) }
3922 #ifdef __ENHANCED_FIRMWARE
3923 #define SetLSNoRestartOnRead(_n) asm { __setLSNoRestartOnRead(_n) }
3924 #endif
3925 
3926 #define SysCommLSWrite(_args) asm { \
3927   compchktype _args, CommLSWriteType \
3928   syscall CommLSWrite, _args \
3929 }
3930 #define SysCommLSRead(_args) asm { \
3931   compchktype _args, CommLSReadType \
3932   syscall CommLSRead, _args \
3933 }
3934 #define SysCommLSCheckStatus(_args) asm { \
3935   compchktype _args, CommLSCheckStatusType \
3936   syscall CommLSCheckStatus, _args \
3937 }
3938 #ifdef __ENHANCED_FIRMWARE
3939 #define SysCommLSWriteEx(_args) asm { \
3940   compchktype _args, CommLSWriteExType \
3941   syscall CommLSWriteEx, _args \
3942 }
3943 #endif
3944 
3945 #endif
3946 
3947 /** @} */ // end of LowSpeedModuleFunctions group
3948 /** @} */ // end of LowSpeedModule group
3949 /** @} */ // end of NXTFirmwareModules group
3950 
3951 
3952 ///////////////////////////////////////////////////////////////////////////////
3953 /////////////////////////////// COMMAND MODULE ////////////////////////////////
3954 ///////////////////////////////////////////////////////////////////////////////
3955 
3956 
3957 /** @addtogroup NXTFirmwareModules
3958  * @{
3959  */
3960 /** @addtogroup CommandModule
3961  * @{
3962  */
3963 /** @defgroup CommandModuleTypes Command module types
3964  * Types used by various Command module functions.
3965  * @{
3966  */
3967 
3968 /**
3969  * Parameters for the GetStartTick system call.
3970  * This structure is used when calling the \ref SysGetStartTick system call
3971  * function.
3972  * \sa SysGetStartTick()
3973  */
3974 struct GetStartTickType {
3975   unsigned long Result;   /*!< The returned tick value. */
3976 };
3977 
3978 /**
3979  * Parameters for the KeepAlive system call.
3980  * This structure is used when calling the \ref SysKeepAlive system call
3981  * function.
3982  * \sa SysKeepAlive()
3983  */
3984 struct KeepAliveType {
3985   unsigned long Result;   /*!< The current sleep timeout in milliseconds. */
3986 };
3987 
3988 /**
3989  * Parameters for the IOMapRead system call.
3990  * This structure is used when calling the \ref SysIOMapRead system call
3991  * function.
3992  * \sa SysIOMapRead()
3993  */
3994 struct IOMapReadType {
3995   char Result;           /*!< The function call result. \ref NO_ERR means it succeeded. */
3996   string ModuleName;     /*!< The name of the module to read from. See the \ref ModuleNameConstants group. */
3997   unsigned int Offset;   /*!< The offset in the module IOMap where to start reading. */
3998   unsigned int Count;    /*!< The number of bytes to read. */
3999   byte Buffer[];         /*!< The buffer used to store read bytes. */
4000 };
4001 
4002 /**
4003  * Parameters for the IOMapWrite system call.
4004  * This structure is used when calling the \ref SysIOMapWrite system call
4005  * function.
4006  * \sa SysIOMapWrite()
4007  */
4008 struct IOMapWriteType {
4009   char Result;           /*!< The function call result. \ref NO_ERR means it succeeded. */
4010   string ModuleName;     /*!< The name of the module to write to. See the \ref ModuleNameConstants group. */
4011   unsigned int Offset;   /*!< The offset in the module IOMap where to start writing. */
4012   byte Buffer[];         /*!< The buffer containing bytes to write. */
4013 };
4014 
4015 #ifdef __ENHANCED_FIRMWARE
4016 /**
4017  * Parameters for the IOMapReadByID system call.
4018  * This structure is used when calling the \ref SysIOMapReadByID system call
4019  * function.
4020  * \sa SysIOMapReadByID()
4021  */
4022 struct IOMapReadByIDType {
4023   char Result;            /*!< The function call result. \ref NO_ERR means it succeeded. */
4024   unsigned long ModuleID; /*!< The identifier of the module to read from. See the \ref ModuleIDConstants group. */
4025   unsigned int Offset;    /*!< The offset in the module IOMap where to start reading. */
4026   unsigned int Count;     /*!< The number of bytes to read. */
4027   byte Buffer[];          /*!< The buffer used to store read bytes. */
4028 };
4029 
4030 /**
4031  * Parameters for the IOMapWriteByID system call.
4032  * This structure is used when calling the \ref SysIOMapWriteByID system call
4033  * function.
4034  * \sa SysIOMapWriteByID()
4035  */
4036 struct IOMapWriteByIDType {
4037   char Result;            /*!< The function call result. \ref NO_ERR means it succeeded. */
4038   unsigned long ModuleID; /*!< The identifier of the module to write to. See the \ref ModuleIDConstants group. */
4039   unsigned int Offset;    /*!< The offset in the module IOMap where to start writing. */
4040   byte Buffer[];          /*!< The buffer containing bytes to write. */
4041 };
4042 
4043 #endif
4044 
4045 #if __FIRMWARE_VERSION > 107
4046 
4047 /**
4048  * Parameters for the DatalogWrite system call.
4049  * This structure is used when calling the \ref SysDatalogWrite system call
4050  * function.
4051  * \sa SysDatalogWrite()
4052  */
4053 struct DatalogWriteType {
4054  char Result;     /*!< The function call result. \ref NO_ERR means it succeeded. */
4055  byte Message[];  /*!< A buffer containing data to write to the datalog. */
4056 };
4057 
4058 /**
4059  * Parameters for the DatalogGetTimes system call.
4060  * This structure is used when calling the \ref SysDatalogGetTimes system call
4061  * function.
4062  * \sa SysDatalogGetTimes()
4063  */
4064 struct DatalogGetTimesType {
4065  unsigned long SyncTime;  /*!< The datalog synchronized time. */
4066  unsigned long SyncTick;  /*!< The datalog synchronized tick. */
4067 };
4068 
4069 /**
4070  * Parameters for the ReadSemData system call.
4071  * This structure is used when calling the \ref SysReadSemData system call
4072  * function.
4073  * \sa SysReadSemData()
4074  */
4075 struct ReadSemDataType {
4076   byte SemData;  /*!< The semaphore data returned by the function call. */
4077   bool Request;  /*!< Which semaphore am I reading from, usage or request? */
4078 };
4079 
4080 /**
4081  * Parameters for the WriteSemData system call.
4082  * This structure is used when calling the \ref SysWriteSemData system call
4083  * function.
4084  * \sa SysWriteSemData()
4085  */
4086 struct WriteSemDataType {
4087   byte SemData;   /*!< The modified semaphore data returned by the function call. */
4088   bool Request;   /*!< Which semaphore am I writing to, usage or request? */
4089   byte NewVal;    /*!< The new semaphore data. */
4090   bool ClearBits; /*!< Should I clear existing bits? */
4091 };
4092 
4093 /**
4094  * Parameters for the UpdateCalibCacheInfo system call.
4095  * This structure is used when calling the \ref SysUpdateCalibCacheInfo system call
4096  * function.
4097  * \sa SysUpdateCalibCacheInfo()
4098  */
4099 struct UpdateCalibCacheInfoType {
4100   byte Result;          /*!< The function call result. \todo ?. */
4101   string Name;          /*!< The name of the sensor calibration cache. \todo ?. */
4102   unsigned int MinVal;  /*!< The minimum calibrated value. */
4103   unsigned int MaxVal;  /*!< The maximum calibrated value. */
4104 };
4105 
4106 /**
4107  * Parameters for the ComputeCalibValue system call.
4108  * This structure is used when calling the \ref SysComputeCalibValue system call
4109  * function.
4110  * \sa SysComputeCalibValue()
4111  */
4112 struct ComputeCalibValueType {
4113   byte Result;          /*!< The function call result. \todo ?. */
4114   string Name;          /*!< The name of the sensor calibration cache. \todo ?. */
4115   unsigned int RawVal;  /*!< The raw value. \todo ?. */
4116 };
4117 
4118 #ifdef __ENHANCED_FIRMWARE
4119 /**
4120  * Parameters for the MemoryManager system call.
4121  * This structure is used when calling the \ref SysMemoryManager system call
4122  * function.
4123  * \sa SysMemoryManager()
4124  */
4125 struct MemoryManagerType {
4126   char Result;                /*!< The returned status value. */
4127   bool Compact;               /*!< Should the dataspace be compacted or not. */
4128   unsigned int PoolSize;      /*!< The returned pool size. */
4129   unsigned int DataspaceSize; /*!< The returned dataspace size. */
4130 };
4131 
4132 /**
4133  * Parameters for the ReadLastResponse system call.
4134  * This structure is used when calling the \ref SysReadLastResponse system call
4135  * function.
4136  * \sa SysReadLastResponse()
4137  */
4138 struct ReadLastResponseType {
4139   char Result;   /*!< The response packet status value. */
4140   bool Clear;    /*!< Clear the response after reading it or not. */
4141   byte Length;   /*!< The response packet length. */
4142   byte Command;  /*!< The response packet command byte. */
4143   byte Buffer[]; /*!< The response packet buffer. */
4144 };
4145 #endif
4146 
4147 #endif
4148 /** @} */ // end of CommandModuleTypes group
4149 
4150 /** @defgroup CommandModuleFunctions Command module functions
4151  * Functions for accessing and modifying Command module features.
4152  * @{
4153  */
4154 
4155 #ifdef __DOXYGEN_DOCS
4156 
4157 /**
4158  * Read the current system tick.
4159  * This function lets you current system tick count.
4160  *
4161  * \return The current system tick count.
4162  */
4163 inline unsigned long CurrentTick();
4164 
4165 /**
4166  * Get the first tick.
4167  * Return an unsigned 32-bit value, which is the system timing value
4168  * (called a "tick") in milliseconds at the time that the program began
4169  * running.
4170  *
4171  * \return The tick count at the start of program execution.
4172  */
4173 inline unsigned long FirstTick();
4174 
4175 /**
4176  * Reset the sleep timer.
4177  * This function lets you reset the sleep timer.
4178  *
4179  * \return The result of resetting the sleep timer.
4180  */
4181 inline long ResetSleepTimer();
4182 
4183 //inline void SpawnProgram(string fname); // not ready to be documented
4184 
4185 /**
4186  * Call any system function.
4187  * This generic macro can be used to call any system function. No type
4188  * checking is performed so you need to make sure you use the correct
4189  * structure type given the selected system function ID. This is, however, the
4190  * fastest possible way to call a system function in NXC.
4191  *
4192  * Valid function ID constants are defined in the \ref SysCallConstants group.
4193  *
4194  * \param funcID The function ID constant corresponding to the function to be
4195  * called.
4196  * \param args The structure containing the needed parameters.
4197  */
4198 inline void SysCall(byte funcID, variant & args);
4199 
4200 /**
4201  * Get start tick.
4202  * This function lets you obtain the tick value at the time your program began
4203  * executing via the \ref GetStartTickType structure.
4204  *
4205  * \param args The GetStartTickType structure receiving results.
4206  */
4207 inline void SysGetStartTick(GetStartTickType & args);
4208 
4209 /**
4210  * Keep alive.
4211  * This function lets you reset the sleep timer via the \ref KeepAliveType
4212  * structure.
4213  *
4214  * \param args The KeepAliveType structure receiving results.
4215  */
4216 inline void SysKeepAlive(KeepAliveType & args);
4217 
4218 /**
4219  * Read from IOMap by name.
4220  * This function lets you read data from a firmware module's IOMap using the
4221  * values specified via the \ref IOMapReadType structure.
4222  *
4223  * \param args The IOMapReadType structure containing the needed parameters.
4224  */
4225 inline void SysIOMapRead(IOMapReadType & args);
4226 
4227 /**
4228  * Write to IOMap by name.
4229  * This function lets you write data to a firmware module's IOMap using the
4230  * values specified via the \ref IOMapWriteType structure.
4231  *
4232  * \param args The IOMapWriteType structure containing the needed parameters.
4233  */
4234 inline void SysIOMapWrite(IOMapWriteType & args);
4235 
4236 #ifdef __ENHANCED_FIRMWARE
4237 /**
4238  * Read from IOMap by identifier.
4239  * This function lets you read data from a firmware module's IOMap using the
4240  * values specified via the \ref IOMapReadByIDType structure. This function
4241  * can be as much as three times faster than using SysIOMapRead since it does
4242  * not have to do a string lookup using the ModuleName.
4243  *
4244  * \param args The IOMapReadByIDType structure containing the needed
4245  * parameters.
4246  *
4247  * \warning This function requires the enhanced NBC/NXC firmware.
4248  */
4249 inline void SysIOMapReadByID(IOMapReadByIDType & args);
4250 
4251 /**
4252  * Write to IOMap by identifier.
4253  * This function lets you write data to a firmware module's IOMap using the
4254  * values specified via the \ref IOMapWriteByIDType structure. This function
4255  * can be as much as three times faster than using SysIOMapWrite since it does
4256  * not have to do a string lookup using the ModuleName.
4257  *
4258  * \param args The IOMapWriteByIDType structure containing the needed
4259  * parameters.
4260  *
4261  * \warning This function requires the enhanced NBC/NXC firmware.
4262  */
4263 inline void SysIOMapWriteByID(IOMapWriteByIDType & args);
4264 
4265 #endif
4266 
4267 #if __FIRMWARE_VERSION > 107
4268 
4269 /**
4270  * Write to the datalog.
4271  * This function lets you write to the datalog using the
4272  * values specified via the \ref DatalogWriteType structure.
4273  *
4274  * \todo figure out what this function is intended for
4275  * \param args The DatalogWriteType structure containing the needed parameters.
4276  *
4277  * \warning This function requires an NXT 2.0 compatible firmware.
4278  */
4279 inline void SysDatalogWrite(DatalogWriteType & args);
4280 
4281 /**
4282  * Get datalog times.
4283  * This function lets you get datalog times using the
4284  * values specified via the \ref DatalogGetTimesType structure.
4285  *
4286  * \todo figure out what this function is intended for
4287  * \param args The DatalogGetTimesType structure containing the needed parameters.
4288  *
4289  * \warning This function requires an NXT 2.0 compatible firmware.
4290  */
4291 inline void SysDatalogGetTimes(DatalogGetTimesType & args);
4292 
4293 /**
4294  * Read semaphore data.
4295  * This function lets you read global motor semaphore data using the
4296  * values specified via the \ref ReadSemDataType structure.
4297  *
4298  * \param args The ReadSemDataType structure containing the needed parameters.
4299  *
4300  * \warning This function requires an NXT 2.0 compatible firmware.
4301  */
4302 inline void SysReadSemData(ReadSemDataType & args);
4303 
4304 /**
4305  * Write semaphore data.
4306  * This function lets you write global motor semaphore data using the
4307  * values specified via the \ref WriteSemDataType structure.
4308  *
4309  * \param args The WriteSemDataType structure containing the needed parameters.
4310  *
4311  * \warning This function requires an NXT 2.0 compatible firmware.
4312  */
4313 inline void SysWriteSemData(WriteSemDataType & args);
4314 
4315 /**
4316  * Update calibration cache information.
4317  * This function lets you update calibration cache information using the
4318  * values specified via the \ref UpdateCalibCacheInfoType structure.
4319  *
4320  * \todo figure out what this function is intended for
4321  * \param args The UpdateCalibCacheInfoType structure containing the needed parameters.
4322  *
4323  * \warning This function requires an NXT 2.0 compatible firmware.
4324  */
4325 inline void SysUpdateCalibCacheInfo(UpdateCalibCacheInfoType & args);
4326 
4327 /**
4328  * Compute calibration values.
4329  * This function lets you compute calibration values using the
4330  * values specified via the \ref ComputeCalibValueType structure.
4331  *
4332  * \todo figure out what this function is intended for
4333  * \param args The ComputeCalibValueType structure containing the needed parameters.
4334  *
4335  * \warning This function requires an NXT 2.0 compatible firmware.
4336  */
4337 inline void SysComputeCalibValue(ComputeCalibValueType & args);
4338 
4339 #endif
4340 
4341 #if defined(__ENHANCED_FIRMWARE) && (__FIRMWARE_VERSION > 107)
4342 /**
4343  * Read memory information.
4344  * Read the current pool size and dataspace size.  Optionally compact the
4345  * dataspace before returning the information. Running programs have a maximum
4346  * of 32k bytes of memory available.  The amount of free RAM can be calculated
4347  * by subtracting the value returned by this function from \ref POOL_MAX_SIZE.
4348  *
4349  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
4350  *
4351  * \param Compact A boolean value indicating whether to compact the dataspace or not.
4352  * \param PoolSize The current pool size.
4353  * \param DataspaceSize The current dataspace size.
4354  * \return The function call result. It will be \ref NO_ERR if the compact
4355  * operation is not performed.  Otherwise it will be the result of the compact
4356  * operation.
4357  */
4358 inline char GetMemoryInfo(bool Compact, unsigned int & PoolSize, unsigned int & DataspaceSize);
4359 
4360 /**
4361  * Read memory information.
4362  * This function lets you read memory information using the
4363  * values specified via the \ref MemoryManagerType structure.
4364  *
4365  * \param args The MemoryManagerType structure containing the required parameters.
4366  *
4367  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
4368  */
4369 inline void SysMemoryManager(MemoryManagerType & args);
4370 
4371 /**
4372  * Read last response information.
4373  * Read the last direct or system command response packet received by the NXT.
4374  * Optionally clear the response after retrieving the information.
4375  *
4376  * \warning This function requires the enhanced NBC/NXC firmware version 1.31+.
4377  *
4378  * \param Clear A boolean value indicating whether to clear the response or not.
4379  * \param Length The response packet length.
4380  * \param Command The original command byte.
4381  * \param Buffer The response packet buffer.
4382  * \return The response status code.
4383  */
4384 inline char GetLastResponseInfo(bool Clear, byte & Length, byte & Command, byte & Buffer[]);
4385 
4386 /**
4387  * Read last response information.
4388  * This function lets you read the last system or direct command response
4389  * received by the NXT using the values specified via the
4390  * \ref ReadLastResponseType structure.
4391  *
4392  * \param args The ReadLastResponseType structure containing the required parameters.
4393  *
4394  * \warning This function requires the enhanced NBC/NXC firmware version 1.31+.
4395  */
4396 inline void SysReadLastResponse(ReadLastResponseType & args);
4397 
4398 #endif
4399 
4400 
4401 #else
4402 
4403 #define CurrentTick() asm { gettick __URETVAL__ }
4404 #define FirstTick() asm { GetFirstTick(__URETVAL__) }
4405 #define ResetSleepTimer() asm { acquire __KeepAliveMutex \
4406   syscall KeepAlive, __KeepAliveArgs \
4407   mov __RETVAL__, __KeepAliveArgs.Result \
4408   release __KeepAliveMutex }
4409 
4410 #define SpawnProgram(_fname) asm { __spawnProgram(_fname) }
4411 
4412 #define SysCall(_func, _args) asm { syscall _func, _args }
4413 
4414 #define SysGetStartTick(_args) asm { \
4415   compchktype _args, GetStartTickType \
4416   syscall GetStartTick, _args \
4417 }
4418 
4419 #define SysKeepAlive(_args) asm { \
4420   compchktype _args, KeepAliveType \
4421   syscall KeepAlive, _args \
4422 }
4423 
4424 #define SysIOMapRead(_args) asm { \
4425   compchktype _args, IOMapReadType \
4426   syscall IOMapRead, _args \
4427 }
4428 #define SysIOMapWrite(_args) asm { \
4429   compchktype _args, IOMapWriteType \
4430   syscall IOMapWrite, _args \
4431 }
4432 
4433 #ifdef __ENHANCED_FIRMWARE
4434 #define SysIOMapReadByID(_args) asm { \
4435   compchktype _args, IOMapReadByIDType \
4436   syscall IOMapReadByID, _args \
4437 }
4438 #define SysIOMapWriteByID(_args) asm { \
4439   compchktype _args, IOMapWriteByIDType \
4440   syscall IOMapWriteByID, _args \
4441 }
4442 #endif
4443 #if __FIRMWARE_VERSION > 107
4444 
4445 #define SysDatalogWrite(_args) asm { \
4446   compchktype _args, DatalogWriteType \
4447   syscall DatalogWrite, _args \
4448 }
4449 #define SysDatalogGetTimes(_args) asm { \
4450   compchktype _args, DatalogGetTimesType \
4451   syscall DatalogGetTimes, _args \
4452 }
4453 #define SysReadSemData(_args) asm { \
4454   compchktype _args, ReadSemDataType \
4455   syscall ReadSemData, _args \
4456 }
4457 #define SysWriteSemData(_args) asm { \
4458   compchktype _args, WriteSemDataType \
4459   syscall WriteSemData, _args \
4460 }
4461 #define SysUpdateCalibCacheInfo(_args) asm { \
4462   compchktype _args, UpdateCalibCacheInfoType \
4463   syscall UpdateCalibCacheInfo, _args \
4464 }
4465 #define SysComputeCalibValue(_args) asm { \
4466   compchktype _args, ComputeCalibValueType \
4467   syscall ComputeCalibValue, _args \
4468 }
4469 #endif
4470 
4471 #if defined(__ENHANCED_FIRMWARE) && (__FIRMWARE_VERSION > 107)
4472 
4473 #define GetMemoryInfo(_Compact,_PoolSize,_DataspaceSize) asm { __GetMemoryInfo(_Compact,_PoolSize,_DataspaceSize,__RETVAL__) }
4474 
4475 #define SysMemoryManager(_args) asm { \
4476   compchktype _args, MemoryManagerType \
4477   syscall MemoryManager, _args \
4478 }
4479 
4480 #define GetLastResponseInfo(_Clear,_Length,_Command,_Buffer) asm { __GetLastResponseInfo(_Clear,_Length,_Command,_Buffer,__RETVAL__) }
4481 
4482 #define SysReadLastResponse(_args) asm { \
4483   compchktype _args, ReadLastResponseType \
4484   syscall ReadLastResponse, _args \
4485 }
4486 
4487 #endif
4488 
4489 #define until(_c) while(!(_c))
4490 
4491 #endif
4492 
4493 /**
4494  * Wait some milliseconds.
4495  * Make a task sleep for specified amount of time (in 1000ths of a second).
4496  *
4497  * \param ms The number of milliseconds to sleep.
4498  */
Wait(unsigned long ms)4499 inline void Wait(unsigned long ms) { asm { waitv ms } }
4500 
4501 /**
4502  * Yield to another task.
4503  * Make a task yield to another concurrently running task.
4504  */
Yield()4505 inline void Yield() { asm { wait 1 } }
4506 
4507 /**
4508  * Stop all tasks.
4509  * Stop all currently running tasks. This will halt the program completely,
4510  * so any code following this command will be ignored.
4511  */
StopAllTasks()4512 inline void StopAllTasks() { Stop(true); }
4513 
4514 
4515 #ifdef __DOXYGEN_DOCS
4516 /**
4517  * Stop the running program.
4518  * Stop the running program if bvalue is true. This will halt the program
4519  * completely, so any code following this command will be ignored.
4520  * \param bvalue If this value is true the program will stop executing.
4521  */
4522 inline void Stop(bool bvalue);
4523 
4524 /**
4525  * Exit to another task.
4526  * Immediately exit the current task and start executing the specified task.
4527  * \param newTask The task to start executing after exiting the current task.
4528  */
4529 inline void ExitTo(task newTask);
4530 
4531 /**
4532  * Declare tasks that this task precedes.
4533  * Schedule the listed tasks for execution once the current task has
4534  * completed executing. The tasks will all execute simultaneously unless other
4535  * dependencies prevent them from doing so. This statement should be used once
4536  * within a task - preferably at the start of the task definition. Any number
4537  * of tasks may be listed in the Precedes statement.
4538  * \param task1 The first task to start executing after the current task ends.
4539  * \param task2 The second task to start executing after the current task ends.
4540  * \param taskN The last task to start executing after the current task ends.
4541  */
4542 inline void Precedes(task task1, task task2, ..., task taskN);
4543 
4544 /**
4545  * Declare tasks that this task follows.
4546  * Schedule this task to follow the specified tasks so that it will execute
4547  * once any of the specified tasks has completed executing. This statement
4548  * should occur once within a task - preferably at the start of the task
4549  * definition. If multiple tasks declare that they follow the same task then
4550  * they will all execute simultaneously unless other dependencies prevent them
4551  * from doing so. Any number of tasks may be listed in the Follows statement.
4552  * \param task1 The first task that this task follows.
4553  * \param task2 The second task that this task follows.
4554  * \param taskN The last task that this task follows.
4555  */
4556 inline void Follows(task task1, task task2, ..., task taskN);
4557 
4558 /**
4559  * Acquire a mutex.
4560  * Acquire the specified mutex variable. If another task already has acquired
4561  * the mutex then the current task will be suspended until the mutex is
4562  * released by the other task. This function is used to ensure that the current
4563  * task has exclusive access to a shared resource, such as the display or a
4564  * motor. After the current task has finished using the shared resource the
4565  * program should call Release to allow other tasks to acquire the mutex.
4566  * \param m The mutex to acquire.
4567  */
4568 inline void Acquire(mutex m);
4569 
4570 /**
4571  * Acquire a mutex.
4572  * Release the specified mutex variable. Use this to relinquish a mutex so
4573  * that it can be acquired by another task. Release should always be called
4574  * after a matching call to Acquire and as soon as possible after a shared
4575  * resource is no longer needed.
4576  * \param m The mutex to release.
4577  */
4578 inline void Release(mutex m);
4579 
4580 /**
4581  * Start a task.
4582  * Start the specified task.
4583  * \param t The task to start.
4584  */
4585 inline void StartTask(task t);
4586 
4587 /**
4588  * Stop a task.
4589  * Stop the specified task.
4590  * \param t The task to stop.
4591  * \warning This function requires the enhanced NBC/NXC firmware.
4592  */
4593 inline void StopTask(task t);
4594 
4595 /** @defgroup ArrayFunctions Array API functions
4596  * Functions for use with NXC array types.
4597  * @{
4598  */
4599 
4600 /**
4601  * Build an array.
4602  * Build a new array from the specified source(s). The sources can be of any
4603  * type so long as the number of dimensions is equal to or one less than the
4604  * number of dimensions in the output array and the type is compatible with
4605  * the type of the output array. If a source is an array with the same number
4606  * of dimensions as the output array then all of its elements are added to
4607  * the output array.
4608  * \param aout The output array to build.
4609  * \param src1 The first source to build into the output array.
4610  * \param src2 The second source to build into the output array.
4611  * \param srcN The first source to build into the output array.
4612  */
4613 inline void ArrayBuild(variant & aout[], variant src1, variant src2, ..., variant srcN);
4614 
4615 /**
4616  * Get array length.
4617  * Return the length of the specified array. Any type of array of up to four
4618  * dimensions can be passed into this function.
4619  * \param data The array whose length you need to read.
4620  * \return The length of the specified array.
4621  */
4622 inline unsigned int ArrayLen(variant data[]);
4623 
4624 /**
4625  * Initialize an array.
4626  * Initialize the array to contain count elements with each element equal to
4627  * the value provided. To initialize a multi-dimensional array, the value
4628  * should be an array of N-1 dimensions, where N is the number of dimensions
4629  * in the array being initialized.
4630  * \param aout The output array to initialize.
4631  * \param value The value to initialize each element to.
4632  * \param count The number of elements to create in the output array.
4633  */
4634 inline void ArrayInit(variant & aout[], variant value, unsigned int count);
4635 
4636 /**
4637  * Copy an array subset.
4638  * Copy a subset of the source array starting at the specified index and
4639  * containing the specified number of elements into the destination array.
4640  * \param aout The output array containing the subset.
4641  * \param asrc The input array from which to copy a subset.
4642  * \param idx The start index of the array subset.
4643  * \param len The length of the array subset.
4644  */
4645 inline void ArraySubset(variant & aout[], variant asrc[], unsigned int idx, unsigned int len);
4646 
4647 #ifdef __ENHANCED_FIRMWARE
4648 
4649 /**
4650  * Calculate the sum of the elements in a numeric array.
4651  * This function calculates the sum of all or a subset of the elements in the
4652  * numeric src array.
4653  *
4654  * \warning This function requires the enhanced NBC/NXC firmware.
4655  *
4656  * \param src The source numeric array.
4657  * \param idx The index of the start of the array subset to process. Pass
4658  * \ref NA to start with the first element.
4659  * \param len The number of elements to include in the calculation. Pass
4660  * \ref NA to include the rest of the elements in the src array (from idx to
4661  * the end of the array).
4662  * \return The sum of len elements from the src numeric array (starting from idx).
4663  */
4664 inline variant ArraySum(const variant & src[], unsigned int idx, unsigned int len);
4665 
4666 /**
4667  * Calculate the mean of the elements in a numeric array.
4668  * This function calculates the mean of all or a subset of the elements in the
4669  * numeric src array.
4670  *
4671  * \warning This function requires the enhanced NBC/NXC firmware.
4672  *
4673  * \param src The source numeric array.
4674  * \param idx The index of the start of the array subset to process. Pass
4675  * \ref NA to start with the first element.
4676  * \param len The number of elements to include in the calculation. Pass
4677  * \ref NA to include the rest of the elements in the src array (from idx to
4678  * the end of the array).
4679  * \return The mean value of len elements from the src numeric array (starting from idx).
4680  */
4681 inline variant ArrayMean(const variant & src[], unsigned int idx, unsigned int len);
4682 
4683 /**
4684  * Calculate the sum of the squares of the elements in a numeric array.
4685  * This function calculates the sum of the squares of all or a subset of the elements in the
4686  * numeric src array.
4687  *
4688  * \warning This function requires the enhanced NBC/NXC firmware.
4689  *
4690  * \param src The source numeric array.
4691  * \param idx The index of the start of the array subset to process. Pass
4692  * \ref NA to start with the first element.
4693  * \param len The number of elements to include in the calculation. Pass
4694  * \ref NA to include the rest of the elements in the src array (from idx to
4695  * the end of the array).
4696  * \return The sum of the squares of len elements from the src numeric array (starting from idx).
4697  */
4698 inline variant ArraySumSqr(const variant & src[], unsigned int idx, unsigned int len);
4699 
4700 /**
4701  * Calculate the standard deviation of the elements in a numeric array.
4702  * This function calculates the standard deviation of all or a subset of the elements in the
4703  * numeric src array.
4704  *
4705  * \warning This function requires the enhanced NBC/NXC firmware.
4706  *
4707  * \param src The source numeric array.
4708  * \param idx The index of the start of the array subset to process. Pass
4709  * \ref NA to start with the first element.
4710  * \param len The number of elements to include in the calculation. Pass
4711  * \ref NA to include the rest of the elements in the src array (from idx to
4712  * the end of the array).
4713  * \return The standard deviation of len elements from the src numeric array (starting from idx).
4714  */
4715 inline variant ArrayStd(const variant & src[], unsigned int idx, unsigned int len);
4716 
4717 /**
4718  * Calculate the minimum of the elements in a numeric array.
4719  * This function calculates the minimum of all or a subset of the elements in the
4720  * numeric src array.
4721  *
4722  * \warning This function requires the enhanced NBC/NXC firmware.
4723  *
4724  * \param src The source numeric array.
4725  * \param idx The index of the start of the array subset to process. Pass
4726  * \ref NA to start with the first element.
4727  * \param len The number of elements to include in the calculation. Pass
4728  * \ref NA to include the rest of the elements in the src array (from idx to
4729  * the end of the array).
4730  * \return The minimum of len elements from the src numeric array (starting from idx).
4731  */
4732 inline variant ArrayMin(const variant & src[], unsigned int idx, unsigned int len);
4733 
4734 /**
4735  * Calculate the maximum of the elements in a numeric array.
4736  * This function calculates the maximum of all or a subset of the elements in the
4737  * numeric src array.
4738  *
4739  * \warning This function requires the enhanced NBC/NXC firmware.
4740  *
4741  * \param src The source numeric array.
4742  * \param idx The index of the start of the array subset to process. Pass
4743  * \ref NA to start with the first element.
4744  * \param len The number of elements to include in the calculation. Pass
4745  * \ref NA to include the rest of the elements in the src array (from idx to
4746  * the end of the array).
4747  * \return The maximum of len elements from the src numeric array (starting from idx).
4748  */
4749 inline variant ArrayMax(const variant & src[], unsigned int idx, unsigned int len);
4750 
4751 /**
4752  * Sort the elements in a numeric array.
4753  * This function sorts all or a subset of the elements in the
4754  * numeric src array in ascending order and saves the results in the
4755  * numeric dest array.
4756  *
4757  * \warning This function requires the enhanced NBC/NXC firmware.
4758  *
4759  * \param dest The destination numeric array.
4760  * \param src The source numeric array.
4761  * \param idx The index of the start of the array subset to process. Pass
4762  * \ref NA to start with the first element.
4763  * \param len The number of elements to include in the sorting process. Pass
4764  * \ref NA to include the rest of the elements in the src array (from idx to
4765  * the end of the array).
4766  */
4767 inline void ArraySort(variant & dest[], const variant & src[], unsigned int idx, unsigned int len);
4768 
4769 /**
4770  * Operate on numeric arrays.
4771  * This function lets you perform various operations on numeric arrays.
4772  *
4773  * \warning This function requires the enhanced NBC/NXC firmware.
4774  *
4775  * \param op  The array operation. See \ref ArrayOpConstants.
4776  * \param dest The destination variant type (scalar or array, depending on the operation).
4777  * \param src The source numeric array.
4778  * \param idx The index of the start of the array subset to process. Pass
4779  * \ref NA to start with the first element.
4780  * \param len The number of elements to include in the specified process. Pass
4781  * \ref NA to include the rest of the elements in the src array (from idx to
4782  * the end of the array).
4783  */
4784 inline void ArrayOp(const byte op, variant & dest, const variant & src[], unsigned int idx, unsigned int len);
4785 
4786 #endif
4787 
4788 /** @} */ // end of ArrayFunctions group
4789 
4790 #else
4791 
4792 #define StartTask(_t) start _t
4793 #define StopTask(_t) stop _t
4794 
4795 #if __FIRMWARE_VERSION <= 107
4796 #define IOMA(_n) asm { mov __RETVAL__, _n }
4797 #define SetIOMA(_n, _val) asm { mov _n, _val }
4798 #endif
4799 
4800 #define ArrayBuild(_aout, ...) asm { arrbuild _aout, __VA_ARGS__ }
4801 #define ArrayLen(_asrc) asm { arrsize __RETVAL__, _asrc }
4802 #define ArrayInit(_aout, _val, _cnt) asm { arrinit _aout, _val, _cnt }
4803 #define ArraySubset(_aout, _asrc, _idx, _len) asm { arrsubset _aout, _asrc, _idx, _len }
4804 
4805 #ifdef __ENHANCED_FIRMWARE
4806 #define ArraySum(_src, _idx, _len) asm { arrop OPARR_SUM, __RETVAL__, _src, _idx, _len }
4807 #define ArrayMean(_src, _idx, _len) asm { arrop OPARR_MEAN, __RETVAL__, _src, _idx, _len }
4808 #define ArraySumSqr(_src, _idx, _len) asm { arrop OPARR_SUMSQR, __RETVAL__, _src, _idx, _len }
4809 #define ArrayStd(_src, _idx, _len) asm { arrop OPARR_STD, __RETVAL__, _src, _idx, _len }
4810 #define ArrayMin(_src, _idx, _len) asm { arrop OPARR_MIN, __RETVAL__, _src, _idx, _len }
4811 #define ArrayMax(_src, _idx, _len) asm { arrop OPARR_MAX, __RETVAL__, _src, _idx, _len }
4812 #define ArraySort(_dest, _src, _idx, _len) asm { arrop OPARR_SORT, _dest, _src, _idx, _len }
4813 #define ArrayOp(_op, _dest, _src, _idx, _len) asm { arrop _op, _dest, _src, _idx, _len }
4814 #endif
4815 
4816 #endif
4817 
4818 
4819 #ifdef __DOXYGEN_DOCS
4820 
4821 /**
4822  * Set IOMap bytes by name.
4823  * Modify one or more bytes of data in an IOMap structure. The IOMap
4824  * structure is specified by its module name. You also provide the offset into
4825  * the IOMap structure where you want to start writing, the number of bytes to
4826  * write at that location, and a byte array containing the new data.
4827  * \param moduleName The module name of the IOMap to modify. See \ref ModuleNameConstants.
4828  * \param offset The number of bytes offset from the start of the IOMap
4829  * structure where the data should be written
4830  * \param count The number of bytes to write at the specified IOMap
4831  * offset.
4832  * \param data The byte array containing the data to write to the IOMap
4833  */
4834 inline void SetIOMapBytes(string moduleName, unsigned int offset, unsigned int count, byte data[]);
4835 
4836 /**
4837  * Set IOMap value by name.
4838  * Set one of the fields of an IOMap structure to a new value.  The IOMap
4839  * structure is specified by its module name. You also provide the offset into
4840  * the IOMap structure where you want to write the value along with a variable
4841  * containing the new value.
4842  * \param moduleName The module name of the IOMap to modify. See \ref ModuleNameConstants.
4843  * \param offset The number of bytes offset from the start of the IOMap
4844  * structure where the new value should be written
4845  * \param value A variable containing the new value to write to the IOMap
4846  */
4847 inline void SetIOMapValue(string moduleName, unsigned int offset, variant value);
4848 
4849 /**
4850  * Get IOMap bytes by name.
4851  * Read one or more bytes of data from an IOMap structure. The IOMap
4852  * structure is specified by its module name. You also provide the offset into
4853  * the IOMap structure where you want to start reading, the number of bytes to
4854  * read from that location, and a byte array where the data will be stored.
4855  * \param moduleName The module name of the IOMap. See \ref ModuleNameConstants.
4856  * \param offset The number of bytes offset from the start of the IOMap
4857  * structure where the data should be read
4858  * \param count The number of bytes to read from the specified IOMap
4859  * offset.
4860  * \param data A byte array that will contain the data read from the IOMap
4861  */
4862 inline void GetIOMapBytes(string moduleName, unsigned int offset, unsigned int count, byte & data[]);
4863 
4864 /**
4865  * Get IOMap value by name.
4866  * Read a value from an IOMap structure.  The IOMap
4867  * structure is specified by its module name. You also provide the offset into
4868  * the IOMap structure where you want to read the value along with a variable
4869  * that will contain the IOMap value.
4870  * \param moduleName The module name of the IOMap. See \ref ModuleNameConstants.
4871  * \param offset The number of bytes offset from the start of the IOMap
4872  * structure where the value should be read
4873  * \param value A variable that will contain the value read from the IOMap
4874  */
4875 inline void GetIOMapValue(string moduleName, unsigned int offset, variant & value);
4876 
4877 /**
4878  * Get Lowspeed module IOMap bytes.
4879  * Read one or more bytes of data from Lowspeed module IOMap structure.
4880  * You provide the offset into the Lowspeed module IOMap structure where you
4881  * want to start reading, the number of bytes to read from that location, and
4882  * a byte array where the data will be stored.
4883  * \param offset The number of bytes offset from the start of the Lowspeed
4884  * module IOMap structure where the data should be read. See \ref LowSpeedIOMAP.
4885  * \param count The number of bytes to read from the specified Lowspeed module
4886  * IOMap offset.
4887  * \param data A byte array that will contain the data read from the Lowspeed
4888  * module IOMap.
4889  */
4890 inline void GetLowSpeedModuleBytes(unsigned int offset, unsigned int count, byte & data[]);
4891 
4892 /**
4893  * Get Display module IOMap bytes.
4894  * Read one or more bytes of data from Display module IOMap structure.
4895  * You provide the offset into the Display module IOMap structure where you
4896  * want to start reading, the number of bytes to read from that location, and
4897  * a byte array where the data will be stored.
4898  * \param offset The number of bytes offset from the start of the Display
4899  * module IOMap structure where the data should be read. See \ref DisplayIOMAP.
4900  * \param count The number of bytes to read from the specified Display module
4901  * IOMap offset.
4902  * \param data A byte array that will contain the data read from the Display
4903  * module IOMap.
4904  */
4905 inline void GetDisplayModuleBytes(unsigned int offset, unsigned int count, byte & data[]);
4906 
4907 /**
4908  * Get Comm module IOMap bytes.
4909  * Read one or more bytes of data from Comm module IOMap structure.
4910  * You provide the offset into the Comm module IOMap structure where you
4911  * want to start reading, the number of bytes to read from that location, and
4912  * a byte array where the data will be stored.
4913  * \param offset The number of bytes offset from the start of the Comm module
4914  * IOMap structure where the data should be read. See \ref CommIOMAP.
4915  * \param count The number of bytes to read from the specified Comm module
4916  * IOMap offset.
4917  * \param data A byte array that will contain the data read from the Comm
4918  * module IOMap.
4919  */
4920 inline void GetCommModuleBytes(unsigned int offset, unsigned int count, byte & data[]);
4921 
4922 /**
4923  * Get Command module IOMap bytes.
4924  * Read one or more bytes of data from Command module IOMap structure.
4925  * You provide the offset into the Command module IOMap structure where you
4926  * want to start reading, the number of bytes to read from that location, and
4927  * a byte array where the data will be stored.
4928  * \param offset The number of bytes offset from the start of the Command module
4929  * IOMap structure where the data should be read. See \ref CommandIOMAP.
4930  * \param count The number of bytes to read from the specified Command module
4931  * IOMap offset.
4932  * \param data A byte array that will contain the data read from the Command
4933  * module IOMap.
4934  */
4935 inline void GetCommandModuleBytes(unsigned int offset, unsigned int count, byte & data[]);
4936 
4937 /**
4938  * Set Command module IOMap bytes.
4939  * Modify one or more bytes of data in the Command module IOMap structure. You
4940  * provide the offset into the Command module IOMap structure where you want
4941  * to start writing, the number of bytes to write at that location, and a byte
4942  * array containing the new data.
4943  * \param offset The number of bytes offset from the start of the Command module
4944  * IOMap structure where the data should be written. See \ref CommandIOMAP.
4945  * \param count The number of bytes to write at the specified Command module
4946  * IOMap offset.
4947  * \param data The byte array containing the data to write to the Command
4948  * module IOMap.
4949  */
4950 inline void SetCommandModuleBytes(unsigned int offset, unsigned int count, byte data[]);
4951 
4952 /**
4953  * Set Lowspeed module IOMap bytes.
4954  * Modify one or more bytes of data in the Lowspeed module IOMap structure. You
4955  * provide the offset into the Lowspeed module IOMap structure where you want
4956  * to start writing, the number of bytes to write at that location, and a byte
4957  * array containing the new data.
4958  * \param offset The number of bytes offset from the start of the Lowspeed
4959  * module IOMap structure where the data should be written. See \ref LowSpeedIOMAP.
4960  * \param count The number of bytes to write at the specified Lowspeed module
4961  * IOMap offset.
4962  * \param data The byte array containing the data to write to the Lowspeed
4963  * module IOMap.
4964  */
4965 inline void SetLowSpeedModuleBytes(unsigned int offset, unsigned int count, byte data[]);
4966 
4967 /**
4968  * Set Display module IOMap bytes.
4969  * Modify one or more bytes of data in the Display module IOMap structure. You
4970  * provide the offset into the Display module IOMap structure where you want to
4971  * start writing, the number of bytes to write at that location, and a byte
4972  * array containing the new data.
4973  * \param offset The number of bytes offset from the start of the Display module
4974  * IOMap structure where the data should be written. See \ref DisplayIOMAP.
4975  * \param count The number of bytes to write at the specified Display module
4976  * IOMap offset.
4977  * \param data The byte array containing the data to write to the Display
4978  * module IOMap.
4979  */
4980 inline void SetDisplayModuleBytes(unsigned int offset, unsigned int count, byte data[]);
4981 
4982 /**
4983  * Set Comm module IOMap bytes.
4984  * Modify one or more bytes of data in an IOMap structure. You provide the
4985  * offset into the Comm module IOMap structure where you want to start writing,
4986  * the number of bytes to write at that location, and a byte array containing
4987  * the new data.
4988  * \param offset The number of bytes offset from the start of the Comm module
4989  * IOMap structure where the data should be written. See \ref CommIOMAP.
4990  * \param count The number of bytes to write at the specified Comm module IOMap
4991  * offset.
4992  * \param data The byte array containing the data to write to the Comm module
4993  * IOMap.
4994  */
4995 inline void SetCommModuleBytes(unsigned int offset, unsigned int count, byte data[]);
4996 
4997 
4998 #ifdef __ENHANCED_FIRMWARE
4999 /**
5000  * Set IOMap bytes by ID.
5001  * Modify one or more bytes of data in an IOMap structure. The IOMap
5002  * structure is specified by its Module ID. You also provide the offset into
5003  * the IOMap structure where you want to start writing, the number of bytes to
5004  * write at that location, and a byte array containing the new data.
5005  * \param moduleId The module ID of the IOMap to modify. See \ref ModuleIDConstants.
5006  * \param offset The number of bytes offset from the start of the IOMap
5007  * structure where the data should be written.
5008  * \param count The number of bytes to write at the specified IOMap
5009  * offset.
5010  * \param data The byte array containing the data to write to the IOMap.
5011  * \warning This function requires the enhanced NBC/NXC firmware.
5012  */
5013 inline void SetIOMapBytesByID(unsigned long moduleId, unsigned int offset, unsigned int count, byte data[]);
5014 
5015 /**
5016  * Set IOMap value by ID.
5017  * Set one of the fields of an IOMap structure to a new value.  The IOMap
5018  * structure is specified by its Module ID. You also provide the offset into
5019  * the IOMap structure where you want to write the value along with a variable
5020  * containing the new value.
5021  * \param moduleId The module ID of the IOMap to modify. See \ref ModuleIDConstants.
5022  * \param offset The number of bytes offset from the start of the IOMap
5023  * structure where the new value should be written.
5024  * \param value A variable containing the new value to write to the IOMap.
5025  * \warning This function requires the enhanced NBC/NXC firmware.
5026  */
5027 inline void SetIOMapValueByID(unsigned long moduleId, unsigned int offset, variant value);
5028 
5029 /**
5030  * Get IOMap bytes by ID.
5031  * Read one or more bytes of data from an IOMap structure. The IOMap
5032  * structure is specified by its Module ID. You also provide the offset into
5033  * the IOMap structure where you want to start reading, the number of bytes to
5034  * read from that location, and a byte array where the data will be stored.
5035  * \param moduleId The module ID of the IOMap. See \ref ModuleIDConstants.
5036  * \param offset The number of bytes offset from the start of the IOMap
5037  * structure where the data should be read.
5038  * \param count The number of bytes to read from the specified IOMap
5039  * offset.
5040  * \param data A byte array that will contain the data read from the IOMap.
5041  * \warning This function requires the enhanced NBC/NXC firmware.
5042  */
5043 inline void GetIOMapBytesByID(unsigned long moduleId, unsigned int offset, unsigned int count, byte & data[]);
5044 
5045 /**
5046  * Get IOMap value by ID.
5047  * Read a value from an IOMap structure.  The IOMap
5048  * structure is specified by its Module ID. You also provide the offset into
5049  * the IOMap structure where you want to read the value along with a variable
5050  * that will contain the IOMap value.
5051  * \param moduleId The module ID of the IOMap. See \ref ModuleIDConstants.
5052  * \param offset The number of bytes offset from the start of the IOMap
5053  * structure where the value should be read.
5054  * \param value A variable that will contain the value read from the IOMap.
5055  * \warning This function requires the enhanced NBC/NXC firmware.
5056  */
5057 inline void GetIOMapValueByID(unsigned long moduleId, unsigned int offset, variant & value);
5058 
5059 #endif
5060 
5061 /**
5062  * Set Command module IOMap value.
5063  * Set one of the fields of the Command module IOMap structure to a new value.
5064  * You provide the offset into the Command module IOMap structure where you
5065  * want to write the value along with a variable containing the new value.
5066  * \param offset The number of bytes offset from the start of the Command
5067  * module IOMap structure where the new value should be written. See \ref CommandIOMAP.
5068  * \param value A variable containing the new value to write to the Command
5069  * module IOMap.
5070  */
5071 inline void SetCommandModuleValue(unsigned int offset, variant value);
5072 
5073 /**
5074  * Set IOCtrl module IOMap value.
5075  * Set one of the fields of the IOCtrl module IOMap structure to a new value.
5076  * You provide the offset into the IOCtrl module IOMap structure where you
5077  * want to write the value along with a variable containing the new value.
5078  * \param offset The number of bytes offset from the start of the IOCtrl
5079  * module IOMap structure where the new value should be written. See \ref IOCtrlIOMAP.
5080  * \param value A variable containing the new value to write to the IOCtrl
5081  * module IOMap.
5082  */
5083 inline void SetIOCtrlModuleValue(unsigned int offset, variant value);
5084 
5085 /**
5086  * Set Loader module IOMap value.
5087  * Set one of the fields of the Loader module IOMap structure to a new value.
5088  * You provide the offset into the Loader module IOMap structure where you
5089  * want to write the value along with a variable containing the new value.
5090  * \param offset The number of bytes offset from the start of the Loader
5091  * module IOMap structure where the new value should be written. See \ref LoaderIOMAP.
5092  * \param value A variable containing the new value to write to the Loader
5093  * module IOMap.
5094  */
5095 inline void SetLoaderModuleValue(unsigned int offset, variant value);
5096 
5097 /**
5098  * Set Ui module IOMap value.
5099  * Set one of the fields of the Ui module IOMap structure to a new value.
5100  * You provide the offset into the Ui module IOMap structure where you
5101  * want to write the value along with a variable containing the new value.
5102  * \param offset The number of bytes offset from the start of the Ui
5103  * module IOMap structure where the new value should be written. See \ref UiIOMAP.
5104  * \param value A variable containing the new value to write to the Ui
5105  * module IOMap.
5106  */
5107 inline void SetUIModuleValue(unsigned int offset, variant value);
5108 
5109 /**
5110  * Set Sound module IOMap value.
5111  * Set one of the fields of the Sound module IOMap structure to a new value.
5112  * You provide the offset into the Sound module IOMap structure where you
5113  * want to write the value along with a variable containing the new value.
5114  * \param offset The number of bytes offset from the start of the Sound
5115  * module IOMap structure where the new value should be written. See \ref SoundIOMAP.
5116  * \param value A variable containing the new value to write to the Sound
5117  * module IOMap.
5118  */
5119 inline void SetSoundModuleValue(unsigned int offset, variant value);
5120 
5121 /**
5122  * Set Button module IOMap value.
5123  * Set one of the fields of the Button module IOMap structure to a new value.
5124  * You provide the offset into the Button module IOMap structure where you
5125  * want to write the value along with a variable containing the new value.
5126  * \param offset The number of bytes offset from the start of the Button
5127  * module IOMap structure where the new value should be written. See \ref ButtonIOMAP.
5128  * \param value A variable containing the new value to write to the Button
5129  * module IOMap.
5130  */
5131 inline void SetButtonModuleValue(unsigned int offset, variant value);
5132 
5133 /**
5134  * Set Input module IOMap value.
5135  * Set one of the fields of the Input module IOMap structure to a new value.
5136  * You provide the offset into the Input module IOMap structure where you
5137  * want to write the value along with a variable containing the new value.
5138  * \param offset The number of bytes offset from the start of the Input
5139  * module IOMap structure where the new value should be written. See \ref InputIOMAP.
5140  * \param value A variable containing the new value to write to the Input
5141  * module IOMap.
5142  */
5143 inline void SetInputModuleValue(unsigned int offset, variant value);
5144 
5145 /**
5146  * Set Output module IOMap value.
5147  * Set one of the fields of the Output module IOMap structure to a new value.
5148  * You provide the offset into the Output module IOMap structure where you
5149  * want to write the value along with a variable containing the new value.
5150  * \param offset The number of bytes offset from the start of the Output
5151  * module IOMap structure where the new value should be written. See \ref OutputIOMAP.
5152  * \param value A variable containing the new value to write to the Output
5153  * module IOMap.
5154  */
5155 inline void SetOutputModuleValue(unsigned int offset, variant value);
5156 
5157 /**
5158  * Set Lowspeed module IOMap value.
5159  * Set one of the fields of the Lowspeed module IOMap structure to a new value.
5160  * You provide the offset into the Lowspeed module IOMap structure where you
5161  * want to write the value along with a variable containing the new value.
5162  * \param offset The number of bytes offset from the start of the Lowspeed
5163  * module IOMap structure where the new value should be written. See \ref LowSpeedIOMAP.
5164  * \param value A variable containing the new value to write to the Lowspeed
5165  * module IOMap.
5166  */
5167 inline void SetLowSpeedModuleValue(unsigned int offset, variant value);
5168 
5169 /**
5170  * Set Display module IOMap value.
5171  * Set one of the fields of the Display module IOMap structure to a new value.
5172  * You provide the offset into the Display module IOMap structure where you
5173  * want to write the value along with a variable containing the new value.
5174  * \param offset The number of bytes offset from the start of the Display
5175  * module IOMap structure where the new value should be written. See \ref DisplayIOMAP.
5176  * \param value A variable containing the new value to write to the Display
5177  * module IOMap.
5178  */
5179 inline void SetDisplayModuleValue(unsigned int offset, variant value);
5180 
5181 /**
5182  * Set Comm module IOMap value.
5183  * Set one of the fields of the Comm module IOMap structure to a new value.
5184  * You provide the offset into the Comm module IOMap structure where you
5185  * want to write the value along with a variable containing the new value.
5186  * \param offset The number of bytes offset from the start of the Comm
5187  * module IOMap structure where the new value should be written. See \ref CommIOMAP.
5188  * \param value A variable containing the new value to write to the Comm
5189  * module IOMap.
5190  */
5191 inline void SetCommModuleValue(unsigned int offset, variant value);
5192 
5193 /**
5194  * Get Command module IOMap value.
5195  * Read a value from the Command module IOMap structure.  You provide the
5196  * offset into the Command module IOMap structure where you want to read
5197  * the value from along with a variable that will store the value. The type
5198  * of the variable determines how many bytes are read from the IOMap.
5199  * \param offset The number of bytes offset from the start of the IOMap
5200  * structure where the value should be read. See \ref CommandIOMAP.
5201  * \param value A variable that will contain the value read from the IOMap.
5202  */
5203 inline void GetCommandModuleValue(unsigned int offset, variant & value);
5204 
5205 /**
5206  * Get Loader module IOMap value.
5207  * Read a value from the Loader module IOMap structure.  You provide the
5208  * offset into the Loader module IOMap structure where you want to read
5209  * the value from along with a variable that will store the value. The type
5210  * of the variable determines how many bytes are read from the IOMap.
5211  * \param offset The number of bytes offset from the start of the IOMap
5212  * structure where the value should be read. See \ref LoaderIOMAP.
5213  * \param value A variable that will contain the value read from the IOMap.
5214  */
5215 inline void GetLoaderModuleValue(unsigned int offset, variant & value);
5216 
5217 /**
5218  * Get Sound module IOMap value.
5219  * Read a value from the Sound module IOMap structure.  You provide the
5220  * offset into the Sound module IOMap structure where you want to read
5221  * the value from along with a variable that will store the value. The type
5222  * of the variable determines how many bytes are read from the IOMap.
5223  * \param offset The number of bytes offset from the start of the IOMap
5224  * structure where the value should be read. See \ref SoundIOMAP.
5225  * \param value A variable that will contain the value read from the IOMap.
5226  */
5227 inline void GetSoundModuleValue(unsigned int offset, variant & value);
5228 
5229 /**
5230  * Get Button module IOMap value.
5231  * Read a value from the Button module IOMap structure.  You provide the
5232  * offset into the Button module IOMap structure where you want to read
5233  * the value from along with a variable that will store the value. The type
5234  * of the variable determines how many bytes are read from the IOMap.
5235  * \param offset The number of bytes offset from the start of the IOMap
5236  * structure where the value should be read. See \ref ButtonIOMAP.
5237  * \param value A variable that will contain the value read from the IOMap.
5238  */
5239 inline void GetButtonModuleValue(unsigned int offset, variant & value);
5240 
5241 /**
5242  * Get Ui module IOMap value.
5243  * Read a value from the Ui module IOMap structure.  You provide the
5244  * offset into the Ui module IOMap structure where you want to read
5245  * the value from along with a variable that will store the value. The type
5246  * of the variable determines how many bytes are read from the IOMap.
5247  * \param offset The number of bytes offset from the start of the IOMap
5248  * structure where the value should be read. See \ref UiIOMAP.
5249  * \param value A variable that will contain the value read from the IOMap.
5250  */
5251 inline void GetUIModuleValue(unsigned int offset, variant & value);
5252 
5253 /**
5254  * Get Input module IOMap value.
5255  * Read a value from the Input module IOMap structure.  You provide the
5256  * offset into the Input module IOMap structure where you want to read
5257  * the value from along with a variable that will store the value. The type
5258  * of the variable determines how many bytes are read from the IOMap.
5259  * \param offset The number of bytes offset from the start of the IOMap
5260  * structure where the value should be read. See \ref InputIOMAP.
5261  * \param value A variable that will contain the value read from the IOMap.
5262  */
5263 inline void GetInputModuleValue(unsigned int offset, variant & value);
5264 
5265 /**
5266  * Get Output module IOMap value.
5267  * Read a value from the Output module IOMap structure.  You provide the
5268  * offset into the Output module IOMap structure where you want to read
5269  * the value from along with a variable that will store the value. The type
5270  * of the variable determines how many bytes are read from the IOMap.
5271  * \param offset The number of bytes offset from the start of the IOMap
5272  * structure where the value should be read. See \ref OutputIOMAP.
5273  * \param value A variable that will contain the value read from the IOMap.
5274  */
5275 inline void GetOutputModuleValue(unsigned int offset, variant & value);
5276 
5277 /**
5278  * Get LowSpeed module IOMap value.
5279  * Read a value from the LowSpeed module IOMap structure.  You provide the
5280  * offset into the Command module IOMap structure where you want to read
5281  * the value from along with a variable that will store the value. The type
5282  * of the variable determines how many bytes are read from the IOMap.
5283  * \param offset The number of bytes offset from the start of the IOMap
5284  * structure where the value should be read. See \ref LowSpeedIOMAP.
5285  * \param value A variable that will contain the value read from the IOMap.
5286  */
5287 inline void GetLowSpeedModuleValue(unsigned int offset, variant & value);
5288 
5289 /**
5290  * Get Display module IOMap value.
5291  * Read a value from the Display module IOMap structure.  You provide the
5292  * offset into the Display module IOMap structure where you want to read
5293  * the value from along with a variable that will store the value. The type
5294  * of the variable determines how many bytes are read from the IOMap.
5295  * \param offset The number of bytes offset from the start of the IOMap
5296  * structure where the value should be read. See \ref DisplayIOMAP.
5297  * \param value A variable that will contain the value read from the IOMap.
5298  */
5299 inline void GetDisplayModuleValue(unsigned int offset, variant & value);
5300 
5301 /**
5302  * Get Comm module IOMap value.
5303  * Read a value from the Comm module IOMap structure.  You provide the
5304  * offset into the Comm module IOMap structure where you want to read
5305  * the value from along with a variable that will store the value. The type
5306  * of the variable determines how many bytes are read from the IOMap.
5307  * \param offset The number of bytes offset from the start of the IOMap
5308  * structure where the value should be read. See \ref CommIOMAP.
5309  * \param value A variable that will contain the value read from the IOMap.
5310  */
5311 inline void GetCommModuleValue(unsigned int offset, variant & value);
5312 
5313 
5314 #else
5315 
5316 #define SetIOMapBytes(_modName, _offset, _cnt, _arrIn) asm { __SetIOMapBytes(_modName, _offset, _cnt, _arrIn) }
5317 #define SetIOMapValue(_modName, _offset, _n) asm { __SetIOMapValue(_modName, _offset, _n) }
5318 
5319 #define GetIOMapBytes(_modName, _offset, _cnt, _arrOut) asm { __getIOMapBytes(_modName, _offset, _cnt, _arrOut) }
5320 #define GetIOMapValue(_modName, _offset, _n) asm { __getIOMapValue(_modName, _offset, _n) }
5321 
5322 #define GetLowSpeedModuleBytes(_offset, _cnt, _arrOut) asm { __getLowSpeedModuleBytes(_offset, _cnt, _arrOut) }
5323 #define GetDisplayModuleBytes(_offset, _cnt, _arrOut) asm { __getDisplayModuleBytes(_offset, _cnt, _arrOut) }
5324 #define GetCommModuleBytes(_offset, _cnt, _arrOut) asm { __getCommModuleBytes(_offset, _cnt, _arrOut) }
5325 
5326 #ifdef __ENHANCED_FIRMWARE
5327 
5328 #define SetIOMapBytesByID(_modID, _offset, _cnt, _arrIn) asm { __SetIOMapBytesByID(_modID, _offset, _cnt, _arrIn) }
5329 #define SetIOMapValueByID(_modID, _offset, _n) asm { __SetIOMapValueByID(_modID, _offset, _n) }
5330 
5331 #define GetIOMapBytesByID(_modID, _offset, _cnt, _arrOut) asm { __getIOMapBytesByID(_modID, _offset, _cnt, _arrOut) }
5332 #define GetIOMapValueByID(_modID, _offset, _n) asm { __getIOMapValueByID(_modID, _offset, _n) }
5333 
5334 #define SetCommandModuleValue(_offset, _n) SetIOMapValueByID(CommandModuleID, _offset, _n)
5335 #define SetIOCtrlModuleValue(_offset, _n) SetIOMapValueByID(IOCtrlModuleID, _offset, _n)
5336 #define SetLoaderModuleValue(_offset, _n) SetIOMapValueByID(LoaderModuleID, _offset, _n)
5337 #define SetUIModuleValue(_offset, _n) SetIOMapValueByID(UIModuleID, _offset, _n)
5338 #define SetSoundModuleValue(_offset, _n) SetIOMapValueByID(SoundModuleID, _offset, _n)
5339 #define SetButtonModuleValue(_offset, _n) SetIOMapValueByID(ButtonModuleID, _offset, _n)
5340 #define SetInputModuleValue(_offset, _n) SetIOMapValueByID(InputModuleID, _offset, _n)
5341 #define SetOutputModuleValue(_offset, _n) SetIOMapValueByID(OutputModuleID, _offset, _n)
5342 #define SetLowSpeedModuleValue(_offset, _n) SetIOMapValueByID(LowSpeedModuleID, _offset, _n)
5343 #define SetDisplayModuleValue(_offset, _n) SetIOMapValueByID(DisplayModuleID, _offset, _n)
5344 #define SetCommModuleValue(_offset, _n) SetIOMapValueByID(CommModuleID, _offset, _n)
5345 
5346 #define SetCommandModuleBytes(_offset, _cnt, _arrIn) SetIOMapBytesByID(CommandModuleID, _offset, _cnt, _arrIn)
5347 #define SetLowSpeedModuleBytes(_offset, _cnt, _arrIn) SetIOMapBytesByID(LowSpeedModuleID, _offset, _cnt, _arrIn)
5348 #define SetDisplayModuleBytes(_offset, _cnt, _arrIn) SetIOMapBytesByID(DisplayModuleID, _offset, _cnt, _arrIn)
5349 #define SetCommModuleBytes(_offset, _cnt, _arrIn) SetIOMapBytesByID(CommModuleID, _offset, _cnt, _arrIn)
5350 
5351 #define GetCommandModuleValue(_offset, _n) GetIOMapValueByID(CommandModuleID, _offset, _n)
5352 #define GetLoaderModuleValue(_offset, _n) GetIOMapValueByID(LoaderModuleID, _offset, _n)
5353 #define GetSoundModuleValue(_offset, _n) GetIOMapValueByID(SoundModuleID, _offset, _n)
5354 #define GetButtonModuleValue(_offset, _n) GetIOMapValueByID(ButtonModuleID, _offset, _n)
5355 #define GetUIModuleValue(_offset, _n) GetIOMapValueByID(UIModuleID, _offset, _n)
5356 #define GetInputModuleValue(_offset, _n) GetIOMapValueByID(InputModuleID, _offset, _n)
5357 #define GetOutputModuleValue(_offset, _n) GetIOMapValueByID(OutputModuleID, _offset, _n)
5358 #define GetLowSpeedModuleValue(_offset, _n) GetIOMapValueByID(LowSpeedModuleID, _offset, _n)
5359 #define GetDisplayModuleValue(_offset, _n) GetIOMapValueByID(DisplayModuleID, _offset, _n)
5360 #define GetCommModuleValue(_offset, _n) GetIOMapValueByID(CommModuleID, _offset, _n)
5361 
5362 #else
5363 
5364 #define SetCommandModuleValue(_offset, _n) SetIOMapValue(CommandModuleName, _offset, _n)
5365 #define SetIOCtrlModuleValue(_offset, _n) SetIOMapValue(IOCtrlModuleName, _offset, _n)
5366 #define SetLoaderModuleValue(_offset, _n) SetIOMapValue(LoaderModuleName, _offset, _n)
5367 #define SetUIModuleValue(_offset, _n) SetIOMapValue(UIModuleName, _offset, _n)
5368 #define SetSoundModuleValue(_offset, _n) SetIOMapValue(SoundModuleName, _offset, _n)
5369 #define SetButtonModuleValue(_offset, _n) SetIOMapValue(ButtonModuleName, _offset, _n)
5370 #define SetInputModuleValue(_offset, _n) SetIOMapValue(InputModuleName, _offset, _n)
5371 #define SetOutputModuleValue(_offset, _n) SetIOMapValue(OutputModuleName, _offset, _n)
5372 #define SetLowSpeedModuleValue(_offset, _n) SetIOMapValue(LowSpeedModuleName, _offset, _n)
5373 #define SetDisplayModuleValue(_offset, _n) SetIOMapValue(DisplayModuleName, _offset, _n)
5374 #define SetCommModuleValue(_offset, _n) SetIOMapValue(CommModuleName, _offset, _n)
5375 
5376 #define SetCommandModuleBytes(_offset, _cnt, _arrIn) SetIOMapBytes(CommandModuleName, _offset, _cnt, _arrIn)
5377 #define SetLowSpeedModuleBytes(_offset, _cnt, _arrIn) SetIOMapBytes(LowSpeedModuleName, _offset, _cnt, _arrIn)
5378 #define SetDisplayModuleBytes(_offset, _cnt, _arrIn) SetIOMapBytes(DisplayModuleName, _offset, _cnt, _arrIn)
5379 #define SetCommModuleBytes(_offset, _cnt, _arrIn) SetIOMapBytes(CommModuleName, _offset, _cnt, _arrIn)
5380 
5381 #define GetCommandModuleValue(_offset, _n) GetIOMapValue(CommandModuleName, _offset, _n)
5382 #define GetLoaderModuleValue(_offset, _n) GetIOMapValue(LoaderModuleName, _offset, _n)
5383 #define GetSoundModuleValue(_offset, _n) GetIOMapValue(SoundModuleName, _offset, _n)
5384 #define GetButtonModuleValue(_offset, _n) GetIOMapValue(ButtonModuleName, _offset, _n)
5385 #define GetUIModuleValue(_offset, _n) GetIOMapValue(UIModuleName, _offset, _n)
5386 #define GetInputModuleValue(_offset, _n) GetIOMapValue(InputModuleName, _offset, _n)
5387 #define GetOutputModuleValue(_offset, _n) GetIOMapValue(OutputModuleName, _offset, _n)
5388 #define GetLowSpeedModuleValue(_offset, _n) GetIOMapValue(LowSpeedModuleName, _offset, _n)
5389 #define GetDisplayModuleValue(_offset, _n) GetIOMapValue(DisplayModuleName, _offset, _n)
5390 #define GetCommModuleValue(_offset, _n) GetIOMapValue(CommModuleName, _offset, _n)
5391 
5392 #endif
5393 
5394 #endif
5395 
5396 
5397 /** @} */ // end of CommandModuleFunctions group
5398 /** @} */ // end of CommandModule group
5399 /** @} */ // end of NXTFirmwareModules group
5400 
5401 
5402 ///////////////////////////////////////////////////////////////////////////////
5403 //////////////////////////////// IOCTRL MODULE ////////////////////////////////
5404 ///////////////////////////////////////////////////////////////////////////////
5405 
5406 
5407 /** @addtogroup NXTFirmwareModules
5408  * @{
5409  */
5410 /** @addtogroup IOCtrlModule
5411  * @{
5412  */
5413 /** @defgroup IOCtrlModuleTypes IOCtrl module types
5414  * Types used by various IOCtrl module functions.
5415  * @{
5416  */
5417 /** @} */ // end of IOCtrlModuleTypes group
5418 /** @defgroup IOCtrlModuleFunctions IOCtrl module functions
5419  * Functions for accessing and modifying IOCtrl module features.
5420  * @{
5421  */
5422 
5423 /**
5424  * Power down the NXT.
5425  * This function powers down the NXT.
5426  * The running program will terminate as a result of this action.
5427  */
PowerDown()5428 inline void PowerDown() {
5429   SetIOCtrlModuleValue(IOCtrlOffsetPowerOn, IOCTRL_POWERDOWN);
5430 }
5431 
5432 /**
5433  * Put the brick to sleep immediately.
5434  * This function lets you immediately put the NXT to sleep.
5435  * The running program will terminate as a result of this action.
5436  */
SleepNow()5437 inline void SleepNow() {
5438   SetIOCtrlModuleValue(IOCtrlOffsetPowerOn, IOCTRL_POWERDOWN);
5439 }
5440 
5441 /**
5442  * Reboot the NXT in firmware download mode.
5443  * This function lets you reboot the NXT into SAMBA or firmware download mode.
5444  * The running program will terminate as a result of this action.
5445  */
RebootInFirmwareMode()5446 inline void RebootInFirmwareMode() {
5447   SetIOCtrlModuleValue(IOCtrlOffsetPowerOn, IOCTRL_BOOT);
5448 }
5449 
5450 /** @} */ // end of IOCtrlModuleFunctions group
5451 /** @} */ // end of IOCtrlModule group
5452 /** @} */ // end of NXTFirmwareModules group
5453 
5454 
5455 ///////////////////////////////////////////////////////////////////////////////
5456 ///////////////////////////////// COMM MODULE /////////////////////////////////
5457 ///////////////////////////////////////////////////////////////////////////////
5458 
5459 
5460 /** @addtogroup NXTFirmwareModules
5461  * @{
5462  */
5463 /** @addtogroup CommModule
5464  * @{
5465  */
5466 /** @defgroup CommModuleTypes Comm module types
5467  * Types used by various Comm module functions.
5468  * @{
5469  */
5470 /**
5471  * Parameters for the MessageWrite system call.
5472  * This structure is used when calling the \ref SysMessageWrite system call
5473  * function.
5474  * \sa SysMessageWrite()
5475  */
5476 struct MessageWriteType {
5477   char Result;      /*!< The function call result. \ref NO_ERR means it succeeded. */
5478   byte QueueID;     /*!< The queue identifier. See the \ref MailboxConstants group. */
5479   string Message;   /*!< The message to write. */
5480 };
5481 
5482 /**
5483  * Parameters for the MessageRead system call.
5484  * This structure is used when calling the \ref SysMessageRead system call
5485  * function.
5486  * \sa SysMessageRead()
5487  */
5488 struct MessageReadType {
5489   char Result;       /*!< The function call result. \ref NO_ERR means it succeeded. */
5490   byte QueueID;     /*!< The queue identifier. See the \ref MailboxConstants group. */
5491   bool Remove;      /*!< If true, remove the read message from the queue. */
5492   string Message;   /*!< The contents of the mailbox/queue. */
5493 };
5494 
5495 /**
5496  * Parameters for the CommBTCheckStatus system call.
5497  * This structure is used when calling the \ref SysCommBTCheckStatus system
5498  * call function.
5499  * \sa SysCommBTCheckStatus()
5500  */
5501 struct CommBTCheckStatusType {
5502   char Result;       /*!< The function call result. Possible values include
5503                        \ref ERR_INVALID_PORT, \ref STAT_COMM_PENDING,
5504                        \ref ERR_COMM_CHAN_NOT_READY, and \ref LDR_SUCCESS. */
5505   byte Connection;   /*!< The connection to check. */
5506 };
5507 
5508 /**
5509  * Parameters for the CommBTWrite system call.
5510  * This structure is used when calling the \ref SysCommBTWrite system call
5511  * function.
5512  * \sa SysCommBTWrite()
5513  */
5514 struct CommBTWriteType {
5515   char Result;       /*!< The function call result.  Possible values include
5516                        \ref ERR_COMM_CHAN_NOT_READY
5517                        and \ref STAT_COMM_PENDING (write accepted). */
5518   byte Connection;   /*!< The connection to use. */
5519   byte Buffer[];     /*!< The data to write to the connection. */
5520 };
5521 
5522 #ifdef __ENHANCED_FIRMWARE
5523 /**
5524  * Parameters for the CommExecuteFunction system call.
5525  * This structure is used when calling the \ref SysCommExecuteFunction system
5526  * call function.
5527  *
5528  * The fields usage depends on the requested command and are documented in the
5529  * table below. If a field member is shown as 'x' it is ignored by the
5530  * specified command.
5531  *
5532  * <table>
5533  * <tr><td>Cmd</td>
5534  *     <td>Meaning</td><td>(Param1,Param2,Param3,Name)</td></tr>
5535  * <tr><td>INTF_SENDFILE</td>
5536  *     <td>Send a file over a Bluetooth connection</td><td>(Connection,x,x,Filename)</td></tr>
5537  * <tr><td>INTF_SEARCH</td>
5538  *     <td>Search for Bluetooth devices</td><td>(x,x,x,x)</td></tr>
5539  * <tr><td>INTF_STOPSEARCH</td>
5540  *     <td>Stop searching for Bluetooth devices</td><td>(x,x,x,x)</td></tr>
5541  * <tr><td>INTF_CONNECT</td>
5542  *     <td>Connect to a Bluetooth device</td><td>(DeviceIndex,Connection,x,x)</td></tr>
5543  * <tr><td>INTF_DISCONNECT</td>
5544  *     <td>Disconnect a Bluetooth device</td><td>(Connection,x,x,x)</td></tr>
5545  * <tr><td>INTF_DISCONNECTALL</td>
5546  *     <td>Disconnect all Bluetooth devices</td><td>(x,x,x,x)</td></tr>
5547  * <tr><td>INTF_REMOVEDEVICE</td>
5548  *     <td>Remove device from My Contacts</td><td>(DeviceIndex,x,x,x)</td></tr>
5549  * <tr><td>INTF_VISIBILITY</td>
5550  *     <td>Set Bluetooth visibility</td><td>(true/false,x,x,x)</td></tr>
5551  * <tr><td>INTF_SETCMDMODE</td>
5552  *     <td>Set command mode</td><td>(x,x,x,x)</td></tr>
5553  * <tr><td>INTF_OPENSTREAM</td>
5554  *     <td>Open a stream</td><td>(x,Connection,x,x)</td></tr>
5555  * <tr><td>INTF_SENDDATA</td>
5556  *     <td>Send data</td><td>(Length, Connection, WaitForIt, Buffer)</td></tr>
5557  * <tr><td>INTF_FACTORYRESET</td>
5558  *     <td>Bluetooth factory reset</td><td>(x,x,x,x)</td></tr>
5559  * <tr><td>INTF_BTON</td>
5560  *     <td>Turn Bluetooth on</td><td>(x,x,x,x)</td></tr>
5561  * <tr><td>INTF_BTOFF</td>
5562  *     <td>Turn Bluetooth off</td><td>(x,x,x,x)</td></tr>
5563  * <tr><td>INTF_SETBTNAME</td>
5564  *     <td>Set Bluetooth name</td><td>(x,x,x,x)</td></tr>
5565  * <tr><td>INTF_EXTREAD</td>
5566  *     <td>Handle external? read</td><td>(x,x,x,x)</td></tr>
5567  * <tr><td>INTF_PINREQ</td>
5568  *     <td>Handle Blueooth PIN request</td><td>(x,x,x,x)</td></tr>
5569  * <tr><td>INTF_CONNECTREQ</td>
5570  *     <td>Handle Bluetooth connect request</td><td>(x,x,x,x)</td></tr>
5571  * </table>
5572  *
5573  * \sa SysCommExecuteFunction()
5574  */
5575 struct CommExecuteFunctionType {
5576   unsigned int Result;   /*!< The function call result. Possible values
5577                            include \ref LoaderErrors. */
5578   byte Cmd;              /*!< The command to execute. */
5579   byte Param1;           /*!< The first parameter, see table. */
5580   byte Param2;           /*!< The second parameter, see table. */
5581   byte Param3;           /*!< The third parameter, see table. */
5582   string Name;           /*!< The name parameter, see table. */
5583   unsigned int RetVal;   /*!< The function call return value. Possible values
5584                            include \ref LoaderErrors. */
5585 };
5586 
5587 /**
5588  * Parameters for the CommHSControl system call.
5589  * This structure is used when calling the \ref SysCommHSControl system call
5590  * function.
5591  * \sa SysCommHSControl()
5592  */
5593 struct CommHSControlType {
5594  char Result;             /*!< The function call result. \todo values? */
5595  byte Command;            /*!< The hi-speed port configuration command.
5596                                See \ref CommHiSpeedCtrlConstants. */
5597  byte BaudRate;           /*!< The hi-speed port baud rate. See \ref CommHiSpeedBaudConstants. */
5598 #if __FIRMWARE_VERSION > 107
5599  unsigned int Mode;       /*!< The hi-speed port mode. See \ref CommHiSpeedDataBitsConstants,
5600                                \ref CommHiSpeedStopBitsConstants, \ref CommHiSpeedParityConstants,
5601                                and \ref CommHiSpeedCombinedConstants. */
5602 #endif
5603 };
5604 
5605 /**
5606  * Parameters for the CommHSCheckStatus system call.
5607  * This structure is used when calling the \ref SysCommHSCheckStatus system call
5608  * function.
5609  * \sa SysCommHSCheckStatus()
5610  */
5611 struct CommHSCheckStatusType {
5612  bool SendingData;     /*!< Is data currently being sent? */
5613  bool DataAvailable;   /*!< Is data available for reading? */
5614 };
5615 
5616 /**
5617  * Parameters for the CommHSReadWrite system call.
5618  * This structure is used when calling the \ref SysCommHSRead and
5619  * \ref SysCommHSWrite system call functions.
5620  * \sa SysCommHSRead(), SysCommHSWrite()
5621  */
5622 struct CommHSReadWriteType {
5623  char Status;    /*!< The result of the function call. */
5624  byte Buffer[];  /*!< The buffer of data to write or to contain the data read
5625                       from the hi-speed port. */
5626 };
5627 #endif
5628 
5629 #if __FIRMWARE_VERSION > 107
5630 /**
5631  * Parameters for the CommBTOnOff system call.
5632  * This structure is used when calling the \ref SysCommBTOnOff system call
5633  * function.
5634  * \sa SysCommBTOnOff()
5635  */
5636 struct CommBTOnOffType {
5637 #ifdef __ENHANCED_FIRMWARE
5638  unsigned int Result; /*!< The function call result. */
5639 #else
5640  char Result;         /*!< The function call result. */
5641 #endif
5642  bool PowerState;     /*!< If true then turn on bluetooth, otherwise, turn it off. */
5643 };
5644 
5645 /**
5646  * Parameters for the CommBTConnection system call.
5647  * This structure is used when calling the \ref SysCommBTConnection system call
5648  * function.
5649  * \sa SysCommBTConnection()
5650  */
5651 struct CommBTConnectionType {
5652 #ifdef __ENHANCED_FIRMWARE
5653  unsigned int Result; /*!< The function call result. */
5654 #else
5655  char Result;         /*!< The function call result. */
5656 #endif
5657  byte Action;         /*!< The connection action (connect or disconnect). */
5658  string Name;         /*!< The name of the device to connect or disconnect. */
5659  byte ConnectionSlot; /*!< The connection slot to connect or disconnect. */
5660 };
5661 #endif
5662 
5663 /** @} */ // end of CommModuleTypes group
5664 /** @defgroup CommModuleFunctions Comm module functions
5665  * Functions for accessing and modifying Comm module features.
5666  * @{
5667  */
5668 
5669 #ifdef __DOXYGEN_DOCS
5670 
5671 /**
5672  * Send a message to a queue/mailbox.
5673  * Write a message into a local mailbox.
5674  *
5675  * \param queue The mailbox number. See \ref MailboxConstants.
5676  * \param msg The message to write to the mailbox.
5677  * \return A char value indicating whether the function call succeeded or not.
5678  */
5679 inline char SendMessage(byte queue, string msg);
5680 
5681 /**
5682  * Read a message from a queue/mailbox.
5683  * Read a message from a mailbox and optionally remove it.  If the local mailbox
5684  * is empty and this NXT is the master then it attempts to poll one of its
5685  * slave NXTs for a message from the response mailbox that corresponds to the
5686  * specified local mailbox number.
5687  *
5688  * \param queue The mailbox number. See \ref MailboxConstants.
5689  * \param clear A flag indicating whether to remove the message from the mailbox
5690  * after it has been read.
5691  * \param msg The message that is read from the mailbox.
5692  * \return A char value indicating whether the function call succeeded or not.
5693  */
5694 inline char ReceiveMessage(byte queue, bool clear, string & msg);
5695 
5696 /**
5697  * Check bluetooth status.
5698  * Check the status of the bluetooth subsystem for the specified connection slot.
5699  *
5700  * \param conn The connection slot (0..3). Connections 0 through 3 are for
5701  * bluetooth connections.  See \ref CommConnectionConstants.
5702  * \return The bluetooth status for the specified connection.
5703  */
5704 inline char BluetoothStatus(byte conn);
5705 
5706 /**
5707  * Write to a bluetooth connection.
5708  * This method tells the NXT firmware to write the data in the buffer to the
5709  * device on the specified Bluetooth connection. Use \ref BluetoothStatus to
5710  * determine when this write request is completed.
5711  *
5712  * \param conn The connection slot (0..3). Connections 0 through 3 are for
5713  * bluetooth connections.  See \ref CommConnectionConstants.
5714  * \param buffer The data to be written (up to 128 bytes)
5715  * \return A char value indicating whether the function call succeeded or not.
5716  */
5717 inline char BluetoothWrite(byte conn, byte buffer[]);
5718 
5719 /**
5720  * Write to a remote connection.
5721  * This method tells the NXT firmware to write the data in the buffer to the
5722  * device on the specified connection.  Use \ref RemoteConnectionIdle to determine
5723  * when this write request is completed.
5724  *
5725  * \param conn The connection slot (0..4). Connections 0 through 3 are for
5726  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
5727  * See \ref CommConnectionConstants.
5728  * \param buffer The data to be written (up to 128 bytes)
5729  * \return A char value indicating whether the function call succeeded or not.
5730  *
5731  * \warning Writing to the RS485 hi-speed connection requires the enhanced
5732  * NBC/NXC firmware
5733  */
5734 inline char RemoteConnectionWrite(byte conn, byte buffer[]);
5735 
5736 /**
5737  * Check if remote connection is idle.
5738  * Check whether a Bluetooth or RS485 hi-speed port connection is idle,
5739  * i.e., not currently sending data.
5740  *
5741  * \param conn The connection slot (0..4). Connections 0 through 3 are for
5742  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
5743  * See \ref CommConnectionConstants.
5744  * \return A boolean value indicating whether the connection is idle or busy.
5745  *
5746  * \warning Checking the status of the RS485 hi-speed connection requires the
5747  * enhanced NBC/NXC firmware
5748  */
5749 inline bool RemoteConnectionIdle(byte conn);
5750 
5751 /**
5752  * Send a boolean value to a remote mailbox.
5753  * Send a boolean value on the specified connection to the
5754  * specified remote mailbox number.  Use \ref RemoteConnectionIdle to determine
5755  * when this write request is completed.
5756  *
5757  * \param conn The connection slot (0..4). Connections 0 through 3 are for
5758  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
5759  * See \ref CommConnectionConstants.
5760  * \param queue The mailbox number. See \ref MailboxConstants.
5761  * \param bval The boolean value to send.
5762  * \return A char value indicating whether the function call succeeded or not.
5763  */
5764 inline char SendRemoteBool(byte conn, byte queue, bool bval);
5765 
5766 /**
5767  * Send a numeric value to a remote mailbox.
5768  * Send a numeric value on the specified connection to the
5769  * specified remote mailbox number.  Use \ref RemoteConnectionIdle to determine
5770  * when this write request is completed.
5771  *
5772  * \param conn The connection slot (0..4). Connections 0 through 3 are for
5773  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
5774  * See \ref CommConnectionConstants.
5775  * \param queue The mailbox number. See \ref MailboxConstants.
5776  * \param val The numeric value to send.
5777  * \return A char value indicating whether the function call succeeded or not.
5778  */
5779 inline char SendRemoteNumber(byte conn, byte queue, long val);
5780 
5781 /**
5782  * Send a string value to a remote mailbox.
5783  * Send a string value on the specified connection to the
5784  * specified remote mailbox number.  Use \ref RemoteConnectionIdle to determine
5785  * when this write request is completed.
5786  *
5787  * \param conn The connection slot (0..4). Connections 0 through 3 are for
5788  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
5789  * See \ref CommConnectionConstants.
5790  * \param queue The mailbox number. See \ref MailboxConstants.
5791  * \param str The string value to send.
5792  * \return A char value indicating whether the function call succeeded or not.
5793  */
5794 inline char SendRemoteString(byte conn, byte queue, string str);
5795 
5796 /**
5797  * Write a boolean value to a local response mailbox.
5798  * Write a boolean value to a response mailbox (the mailbox number + 10).
5799  *
5800  * \param queue The mailbox number. See \ref MailboxConstants. This function
5801  * shifts the specified value into the range of response mailbox numbers by
5802  * adding 10.
5803  * \param bval The boolean value to write.
5804  * \return A char value indicating whether the function call succeeded or not.
5805  */
5806 inline char SendResponseBool(byte queue, bool bval);
5807 
5808 /**
5809  * Write a numeric value to a local response mailbox.
5810  * Write a numeric value to a response mailbox (the mailbox number + 10).
5811  *
5812  * \param queue The mailbox number. See \ref MailboxConstants. This function
5813  * shifts the specified value into the range of response mailbox numbers by
5814  * adding 10.
5815  * \param val The numeric value to write.
5816  * \return A char value indicating whether the function call succeeded or not.
5817  */
5818 inline char SendResponseNumber(byte queue, long val);
5819 
5820 /**
5821  * Write a string value to a local response mailbox.
5822  * Write a string value to a response mailbox (the mailbox number + 10).
5823  *
5824  * \param queue The mailbox number. See \ref MailboxConstants. This function
5825  * shifts the specified value into the range of response mailbox numbers by
5826  * adding 10.
5827  * \param str The string value to write.
5828  * \return A char value indicating whether the function call succeeded or not.
5829  */
5830 inline char SendResponseString(byte queue, string str);
5831 
5832 /**
5833  * Read a boolean value from a queue/mailbox.
5834  * Read a boolean value from a mailbox and optionally remove it.  If the local mailbox
5835  * is empty and this NXT is the master then it attempts to poll one of its
5836  * slave NXTs for a message from the response mailbox that corresponds to the
5837  * specified local mailbox number.
5838  *
5839  * \param queue The mailbox number. See \ref MailboxConstants.
5840  * \param clear A flag indicating whether to remove the message from the mailbox
5841  * after it has been read.
5842  * \param bval The boolean value that is read from the mailbox.
5843  * \return A char value indicating whether the function call succeeded or not.
5844  */
5845 inline char ReceiveRemoteBool(byte queue, bool clear, bool & bval);
5846 
5847 /**
5848  * Read a value from a queue/mailbox.
5849  * Read a value from a mailbox and optionally remove it.  If the local mailbox
5850  * is empty and this NXT is the master then it attempts to poll one of its
5851  * slave NXTs for a message from the response mailbox that corresponds to the
5852  * specified local mailbox number.  Output the value in string, number, and
5853  * boolean form.
5854  *
5855  * \param queue The mailbox number. See \ref MailboxConstants.
5856  * \param clear A flag indicating whether to remove the message from the mailbox
5857  * after it has been read.
5858  * \param str The string value that is read from the mailbox.
5859  * \param val The numeric value that is read from the mailbox.
5860  * \param bval The boolean value that is read from the mailbox.
5861  * \return A char value indicating whether the function call succeeded or not.
5862  */
5863 inline char ReceiveRemoteMessageEx(byte queue, bool clear, string & str, long & val, bool & bval);
5864 
5865 /**
5866  * Read a numeric value from a queue/mailbox.
5867  * Read a numeric value from a mailbox and optionally remove it.  If the local mailbox
5868  * is empty and this NXT is the master then it attempts to poll one of its
5869  * slave NXTs for a message from the response mailbox that corresponds to the
5870  * specified local mailbox number.
5871  *
5872  * \param queue The mailbox number. See \ref MailboxConstants.
5873  * \param clear A flag indicating whether to remove the message from the mailbox
5874  * after it has been read.
5875  * \param val The numeric value that is read from the mailbox.
5876  * \return A char value indicating whether the function call succeeded or not.
5877  */
5878 inline char ReceiveRemoteNumber(byte queue, bool clear, long & val);
5879 
5880 /**
5881  * Read a string value from a queue/mailbox.
5882  * Read a string value from a mailbox and optionally remove it.  If the local mailbox
5883  * is empty and this NXT is the master then it attempts to poll one of its
5884  * slave NXTs for a message from the response mailbox that corresponds to the
5885  * specified local mailbox number.
5886  *
5887  * \param queue The mailbox number. See \ref MailboxConstants.
5888  * \param clear A flag indicating whether to remove the message from the mailbox
5889  * after it has been read.
5890  * \param str The string value that is read from the mailbox.
5891  * \return A char value indicating whether the function call succeeded or not.
5892  */
5893 inline char ReceiveRemoteString(byte queue, bool clear, string & str);
5894 
5895 /** @defgroup CommModuleDCFunctions Direct Command functions
5896  * Functions for sending direct commands to another NXT.
5897  * @{
5898  */
5899 
5900 /**
5901  * Send a KeepAlive message.
5902  * This method sends a KeepAlive direct command to the device on the specified
5903  * connection. Use \ref RemoteConnectionIdle to determine when this write request is
5904  * completed.
5905  *
5906  * \param conn The connection slot (0..4). Connections 0 through 3 are for
5907  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
5908  * See \ref CommConnectionConstants.
5909  * \return A char value indicating whether the function call succeeded or not.
5910  */
5911 inline char RemoteKeepAlive(byte conn);
5912 
5913 /**
5914  * Send a MessageRead message.
5915  * This method sends a MessageRead direct command to the device on the
5916  * specified connection. Use \ref RemoteConnectionIdle to determine when this write
5917  * request is completed.
5918  *
5919  * \param conn The connection slot (0..4). Connections 0 through 3 are for
5920  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
5921  * See \ref CommConnectionConstants.
5922  * \param queue The mailbox to read. See \ref MailboxConstants.
5923  * \return A char value indicating whether the function call succeeded or not.
5924  */
5925 inline char RemoteMessageRead(byte conn, byte queue);
5926 
5927 /**
5928  * Send a MessageWrite message.
5929  * This method sends a MessageWrite direct command to the device on the
5930  * specified connection. Use \ref RemoteConnectionIdle to determine when this write
5931  * request is completed.
5932  *
5933  * \param conn The connection slot (0..4). Connections 0 through 3 are for
5934  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
5935  * See \ref CommConnectionConstants.
5936  * \param queue The mailbox to write. See \ref MailboxConstants.
5937  * \param msg The message to write to the mailbox.
5938  * \return A char value indicating whether the function call succeeded or not.
5939  */
5940 inline char RemoteMessageWrite(byte conn, byte queue, string msg);
5941 
5942 /**
5943  * Send a PlaySoundFile message.
5944  * Send the PlaySoundFile direct command on the specified connection slot.
5945  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
5946  *
5947  * \param conn The connection slot (0..4). Connections 0 through 3 are for
5948  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
5949  * See \ref CommConnectionConstants.
5950  * \param filename The name of the sound file to play.
5951  * \param bloop A boolean value indicating whether to loop the sound file or not.
5952  * \return A char value indicating whether the function call succeeded or not.
5953  */
5954 inline char RemotePlaySoundFile(byte conn, string filename, bool bloop);
5955 
5956 /**
5957  * Send a PlayTone message.
5958  * Send the PlayTone direct command on the specified connection slot.
5959  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
5960  *
5961  * \param conn The connection slot (0..4). Connections 0 through 3 are for
5962  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
5963  * See \ref CommConnectionConstants.
5964  * \param frequency The frequency of the tone.
5965  * \param duration The duration of the tone.
5966  * \return A char value indicating whether the function call succeeded or not.
5967  */
5968 inline char RemotePlayTone(byte conn, unsigned int frequency, unsigned int duration);
5969 
5970 /**
5971  * Send a ResetMotorPosition message.
5972  * Send the ResetMotorPosition direct command on the specified connection slot.
5973  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
5974  *
5975  * \param conn The connection slot (0..4). Connections 0 through 3 are for
5976  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
5977  * See \ref CommConnectionConstants.
5978  * \param port The output port to reset.
5979  * \param brelative A flag indicating whether the counter to reset is relative.
5980  * \return A char value indicating whether the function call succeeded or not.
5981  */
5982 inline char RemoteResetMotorPosition(byte conn, byte port, bool brelative);
5983 
5984 /**
5985  * Send a ResetScaledValue message.
5986  * Send the ResetScaledValue direct command on the specified connection slot.
5987  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
5988  *
5989  * \param conn The connection slot (0..4). Connections 0 through 3 are for
5990  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
5991  * See \ref CommConnectionConstants.
5992  * \param port The input port to reset.
5993  * \return A char value indicating whether the function call succeeded or not.
5994  */
5995 inline char RemoteResetScaledValue(byte conn, byte port);
5996 
5997 /**
5998  * Send a SetInputMode message.
5999  * Send the SetInputMode direct command on the specified connection slot.
6000  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
6001  *
6002  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6003  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6004  * See \ref CommConnectionConstants.
6005  * \param port The input port to configure. See \ref InPorts.
6006  * \param type The sensor type. See \ref SensorTypes.
6007  * \param mode The sensor mode. See \ref SensorModes.
6008  * \return A char value indicating whether the function call succeeded or not.
6009  */
6010 inline char RemoteSetInputMode(byte conn, byte port, byte type, byte mode);
6011 
6012 /**
6013  * Send a SetOutputMode message.
6014  * Send the SetOutputMode direct command on the specified connection slot.
6015  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
6016  *
6017  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6018  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6019  * See \ref CommConnectionConstants.
6020  * \param port The output port to configure. See \ref OutputPortConstants.
6021  * \param speed The motor speed. (-100..100)
6022  * \param mode The motor mode. See \ref OutModeConstants.
6023  * \param regmode The motor regulation mode. See \ref OutRegModeConstants.
6024  * \param turnpct The motor synchronized turn percentage. (-100..100)
6025  * \param runstate The motor run state. See \ref OutRunStateConstants.
6026  * \param tacholimit The motor tachometer limit.
6027  * \return A char value indicating whether the function call succeeded or not.
6028  */
6029 inline char RemoteSetOutputState(byte conn, byte port, char speed, byte mode, byte regmode, char turnpct, byte runstate, unsigned long tacholimit);
6030 
6031 /**
6032  * Send a StartProgram message.
6033  * Send the StartProgram direct command on the specified connection slot.
6034  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
6035  *
6036  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6037  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6038  * See \ref CommConnectionConstants.
6039  * \param filename The name of the program to start running.
6040  * \return A char value indicating whether the function call succeeded or not.
6041  */
6042 inline char RemoteStartProgram(byte conn, string filename);
6043 
6044 /**
6045  * Send a StopProgram message.
6046  * Send the StopProgram direct command on the specified connection slot.
6047  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
6048  *
6049  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6050  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6051  * See \ref CommConnectionConstants.
6052  * \return A char value indicating whether the function call succeeded or not.
6053  */
6054 inline char RemoteStopProgram(byte conn);
6055 
6056 /**
6057  * Send a StopSound message.
6058  * Send the StopSound direct command on the specified connection slot.
6059  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
6060  *
6061  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6062  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6063  * See \ref CommConnectionConstants.
6064  * \return A char value indicating whether the function call succeeded or not.
6065  */
6066 inline char RemoteStopSound(byte conn);
6067 
6068 #ifdef __ENHANCED_FIRMWARE
6069 
6070 /**
6071  * Send a GetOutputState message.
6072  * Send the GetOutputState direct command on the specified connection slot.
6073  *
6074  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6075  *
6076  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6077  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6078  * See \ref CommConnectionConstants.
6079  * \param params The input and output parameters for the function call. See \ref OutputStateType.
6080  * \return A char value indicating whether the function call succeeded or not.
6081  */
6082 inline char RemoteGetOutputState(byte conn, OutputStateType & params);
6083 
6084 /**
6085  * Send a GetInputValues message.
6086  * Send the GetInputValues direct command on the specified connection slot.
6087  *
6088  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6089  *
6090  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6091  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6092  * See \ref CommConnectionConstants.
6093  * \param params The input and output parameters for the function call. See \ref InputValuesType.
6094  * \return A char value indicating whether the function call succeeded or not.
6095  */
6096 inline char RemoteGetInputValues(byte conn, InputValuesType & params);
6097 
6098 /**
6099  * Send a GetBatteryLevel message.
6100  * Send the GetBatteryLevel direct command to the device on the specified
6101  * connection.
6102  *
6103  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6104  *
6105  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6106  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6107  * See \ref CommConnectionConstants.
6108  * \param value The battery level value.
6109  * \return A char value indicating whether the function call succeeded or not.
6110  */
6111 inline char RemoteGetBatteryLevel(byte conn, int & value);
6112 
6113 /**
6114  * Send a LowspeedGetStatus message.
6115  * This method sends a LowspeedGetStatus direct command to the device on the specified
6116  * connection.
6117  *
6118  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6119  *
6120  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6121  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6122  * See \ref CommConnectionConstants.
6123  * \param value The count of available bytes to read.
6124  * \return A char value indicating whether the function call succeeded or not.
6125  */
6126 inline char RemoteLowspeedGetStatus(byte conn, byte & value);
6127 
6128 /**
6129  * Send a LowspeedRead message.
6130  * Send the LowspeedRead direct command on the specified connection slot.
6131  *
6132  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6133  *
6134  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6135  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6136  * See \ref CommConnectionConstants.
6137  * \param port The input port from which to read I2C data. See \ref InPorts.
6138  * \param bread The number of bytes read.
6139  * \param data A byte array containing the data read from the I2C device.
6140  * \return A char value indicating whether the function call succeeded or not.
6141  */
6142 inline char RemoteLowspeedRead(byte conn, byte port, byte & bread, byte & data[]);
6143 
6144 /**
6145  * Send a GetCurrentProgramName message.
6146  * This method sends a GetCurrentProgramName direct command to the device on the specified
6147  * connection.
6148  *
6149  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6150  *
6151  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6152  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6153  * See \ref CommConnectionConstants.
6154  * \param name The current program name.
6155  * \return A char value indicating whether the function call succeeded or not.
6156  */
6157 inline char RemoteGetCurrentProgramName(byte conn, string & name);
6158 
6159 /**
6160  * Send a DatalogRead message.
6161  * Send the DatalogRead direct command on the specified connection slot.
6162  *
6163  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6164  *
6165  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6166  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6167  * See \ref CommConnectionConstants.
6168  * \param remove Remove the datalog message from the queue after reading it (true or false).
6169  * \param cnt The number of bytes read from the datalog.
6170  * \param log A byte array containing the datalog contents.
6171  * \return A char value indicating whether the function call succeeded or not.
6172  */
6173 inline char RemoteDatalogRead(byte conn, bool remove, byte & cnt, byte & log[]);
6174 
6175 /**
6176  * Send a GetContactCount message.
6177  * This method sends a GetContactCount direct command to the device on the specified
6178  * connection.
6179  *
6180  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6181  *
6182  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6183  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6184  * See \ref CommConnectionConstants.
6185  * \param cnt The number of contacts.
6186  * \return A char value indicating whether the function call succeeded or not.
6187  */
6188 inline char RemoteGetContactCount(byte conn, byte & cnt);
6189 
6190 /**
6191  * Send a GetContactName message.
6192  * Send the GetContactName direct command on the specified connection slot.
6193  *
6194  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6195  *
6196  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6197  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6198  * See \ref CommConnectionConstants.
6199  * \param idx The index of the contact.
6200  * \param name The name of the specified contact.
6201  * \return A char value indicating whether the function call succeeded or not.
6202  */
6203 inline char RemoteGetContactName(byte conn, byte idx, string & name);
6204 
6205 /**
6206  * Send a GetConnectionCount message.
6207  * This method sends a GetConnectionCount direct command to the device on the specified
6208  * connection.
6209  *
6210  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6211  *
6212  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6213  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6214  * See \ref CommConnectionConstants.
6215  * \param cnt The number of connections.
6216  * \return A char value indicating whether the function call succeeded or not.
6217  */
6218 inline char RemoteGetConnectionCount(byte conn, byte & cnt);
6219 
6220 /**
6221  * Send a GetConnectionName message.
6222  * Send the GetConnectionName direct command on the specified connection slot.
6223  *
6224  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6225  *
6226  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6227  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6228  * See \ref CommConnectionConstants.
6229  * \param idx The index of the connection.
6230  * \param name The name of the specified connection.
6231  * \return A char value indicating whether the function call succeeded or not.
6232  */
6233 inline char RemoteGetConnectionName(byte conn, byte idx, string & name);
6234 
6235 /**
6236  * Send a GetProperty message.
6237  * Send the GetProperty direct command on the specified connection slot.
6238  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
6239  *
6240  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6241  *
6242  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6243  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6244  * See \ref CommConnectionConstants.
6245  * \param property The property to read. See \ref RCPropertyConstants.
6246  * \param value The property value.
6247  * \return A char value indicating whether the function call succeeded or not.
6248  */
6249 inline char RemoteGetProperty(byte conn, byte property, variant & value);
6250 
6251 #endif
6252 
6253 /**
6254  * Send a ResetTachoCount message.
6255  * Send the ResetTachoCount direct command on the specified connection slot.
6256  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
6257  *
6258  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6259  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6260  * See \ref CommConnectionConstants.
6261  * \param port The output port to reset the tachometer count on. See \ref OutputPortConstants.
6262  * \return A char value indicating whether the function call succeeded or not.
6263  */
6264 inline char RemoteResetTachoCount(byte conn, byte port);
6265 
6266 /**
6267  * Send a DatalogSetTimes message.
6268  * Send the DatalogSetTimes direct command on the specified connection slot.
6269  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
6270  *
6271  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6272  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6273  * See \ref CommConnectionConstants.
6274  * \param synctime The datalog sync time.
6275  * \return A char value indicating whether the function call succeeded or not.
6276  */
6277 inline char RemoteDatalogSetTimes(byte conn, long synctime);
6278 
6279 /**
6280  * Send a SetProperty message.
6281  * Send the SetProperty direct command on the specified connection slot.
6282  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
6283  *
6284  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6285  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6286  * See \ref CommConnectionConstants.
6287  * \param prop The property to set. See \ref RCPropertyConstants.
6288  * \param value The new property value.
6289  * \return A char value indicating whether the function call succeeded or not.
6290  */
6291 inline char RemoteSetProperty(byte conn, byte prop, variant value);
6292 
6293 /**
6294  * Send a LowspeedWrite message.
6295  * Send the LowspeedWrite direct command on the specified connection slot.
6296  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
6297  *
6298  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6299  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6300  * See \ref CommConnectionConstants.
6301  * \param port The I2C port. See \ref InPorts.
6302  * \param txlen The number of bytes you are writing to the I2C device.
6303  * \param rxlen The number of bytes want to read from the I2C device.
6304  * \param data A byte array containing the data you are writing to the device.
6305  * \return A char value indicating whether the function call succeeded or not.
6306  */
6307 inline char RemoteLowspeedWrite(byte conn, byte port, byte txlen, byte rxlen, byte data[]);
6308 
6309 /** @} */ // end of CommModuleDCFunctions group
6310 
6311 /** @defgroup CommModuleSCFunctions System Command functions
6312  * Functions for sending system commands to another NXT.
6313  * @{
6314  */
6315 
6316 #ifdef __ENHANCED_FIRMWARE
6317 
6318 /**
6319  * Send an OpenRead message.
6320  * Send the OpenRead system command on the specified connection slot.
6321  *
6322  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6323  *
6324  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6325  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6326  * See \ref CommConnectionConstants.
6327  * \param filename The name of the file to open for reading.
6328  * \param handle The handle of the file.
6329  * \param size The size of the file.
6330  * \return A char value indicating whether the function call succeeded or not.
6331  */
6332 inline char RemoteOpenRead(byte conn, string filename, byte & handle, long & size);
6333 
6334 /**
6335  * Send an OpenAppendData message.
6336  * Send the OpenAppendData system command on the specified connection slot.
6337  *
6338  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6339  *
6340  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6341  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6342  * See \ref CommConnectionConstants.
6343  * \param filename The name of the file to open for appending.
6344  * \param handle The handle of the file.
6345  * \param size The size of the file.
6346  * \return A char value indicating whether the function call succeeded or not.
6347  */
6348 inline char RemoteOpenAppendData(byte conn, string filename, byte & handle, long & size);
6349 
6350 /**
6351  * Send a DeleteFile message.
6352  * Send the DeleteFile system command on the specified connection slot.
6353  *
6354  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6355  *
6356  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6357  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6358  * See \ref CommConnectionConstants.
6359  * \param filename The name of the file to delete.
6360  * \return A char value indicating whether the function call succeeded or not.
6361  */
6362 inline char RemoteDeleteFile(byte conn, string filename);
6363 
6364 /**
6365  * Send a FindFirstFile message.
6366  * Send the FindFirstFile system command on the specified connection slot.
6367  *
6368  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6369  *
6370  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6371  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6372  * See \ref CommConnectionConstants.
6373  * \param mask The filename mask for the files you want to find.
6374  * \param handle The handle of the found file.
6375  * \param name The name of the found file.
6376  * \param size The size of the found file.
6377  * \return A char value indicating whether the function call succeeded or not.
6378  */
6379 inline char RemoteFindFirstFile(byte conn, string mask, byte & handle, string & name, long & size);
6380 
6381 /**
6382  * Send a GetFirmwareVersion message.
6383  * This method sends a GetFirmwareVersion system command to the device on the specified
6384  * connection.
6385  *
6386  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6387  *
6388  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6389  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6390  * See \ref CommConnectionConstants.
6391  * \param pmin The protocol minor version byte.
6392  * \param pmaj The protocol major version byte.
6393  * \param fmin The firmware minor version byte.
6394  * \param fmaj The firmware major version byte.
6395  * \return A char value indicating whether the function call succeeded or not.
6396  */
6397 inline char RemoteGetFirmwareVersion(byte conn, byte & pmin, byte & pmaj, byte & fmin, byte & fmaj);
6398 
6399 /**
6400  * Send a GetBluetoothAddress message.
6401  * This method sends a GetBluetoothAddress system command to the device on the specified
6402  * connection.
6403  *
6404  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6405  *
6406  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6407  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6408  * See \ref CommConnectionConstants.
6409  * \param btaddr The bluetooth address of the remote device.
6410  * \return A char value indicating whether the function call succeeded or not.
6411  */
6412 inline char RemoteGetBluetoothAddress(byte conn, byte & btaddr[]);
6413 
6414 /**
6415  * Send a GetDeviceInfo message.
6416  * This method sends a GetDeviceInfo system command to the device on the specified
6417  * connection.
6418  *
6419  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6420  *
6421  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6422  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6423  * See \ref CommConnectionConstants.
6424  * \param name The name of the remote device.
6425  * \param btaddr The bluetooth address of the remote device.
6426  * \param btsignal The signal strength of each connection on the remote device.
6427  * \param freemem The number of bytes of free flash memory on the remote device.
6428  * \return A char value indicating whether the function call succeeded or not.
6429  */
6430 inline char RemoteGetDeviceInfo(byte conn, string & name, byte & btaddr[], byte & btsignal[], long & freemem);
6431 
6432 /**
6433  * Send a DeleteUserFlash message.
6434  * This method sends a DeleteUserFlash system command to the device on the specified
6435  * connection.
6436  *
6437  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6438  *
6439  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6440  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6441  * See \ref CommConnectionConstants.
6442  * \return A char value indicating whether the function call succeeded or not.
6443  */
6444 inline char RemoteDeleteUserFlash(byte conn);
6445 
6446 /**
6447  * Send an OpenWrite message.
6448  * Send the OpenWrite system command on the specified connection slot.
6449  *
6450  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6451  *
6452  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6453  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6454  * See \ref CommConnectionConstants.
6455  * \param filename The name of the file to open for writing (i.e., create the file).
6456  * \param size The size for the new file.
6457  * \param handle The handle of the new file.
6458  * \return A char value indicating whether the function call succeeded or not.
6459  */
6460 inline char RemoteOpenWrite(byte conn, string filename, long size, byte & handle);
6461 
6462 /**
6463  * Send an OpenWriteLinear message.
6464  * Send the OpenWriteLinear system command on the specified connection slot.
6465  *
6466  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6467  *
6468  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6469  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6470  * See \ref CommConnectionConstants.
6471  * \param filename The name of the file to open for writing (i.e., create the file).
6472  * \param size The size for the new file.
6473  * \param handle The handle of the new file.
6474  * \return A char value indicating whether the function call succeeded or not.
6475  */
6476 inline char RemoteOpenWriteLinear(byte conn, string filename, long size, byte & handle);
6477 
6478 /**
6479  * Send an OpenWriteData message.
6480  * Send the OpenWriteData system command on the specified connection slot.
6481  *
6482  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6483  *
6484  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6485  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6486  * See \ref CommConnectionConstants.
6487  * \param filename The name of the file to open for writing (i.e., create the file).
6488  * \param size The size for the new file.
6489  * \param handle The handle of the new file.
6490  * \return A char value indicating whether the function call succeeded or not.
6491  */
6492 inline char RemoteOpenWriteData(byte conn, string filename, long size, byte & handle);
6493 
6494 /**
6495  * Send a CloseFile message.
6496  * Send the CloseFile system command on the specified connection slot.
6497  *
6498  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6499  *
6500  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6501  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6502  * See \ref CommConnectionConstants.
6503  * \param handle The handle of the file to close.
6504  * \return A char value indicating whether the function call succeeded or not.
6505  */
6506 inline char RemoteCloseFile(byte conn, byte handle);
6507 
6508 /**
6509  * Send a FindNextFile message.
6510  * Send the FindNextFile system command on the specified connection slot.
6511  *
6512  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6513  *
6514  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6515  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6516  * See \ref CommConnectionConstants.
6517  * \param handle The handle returned by the last \ref FindFirstFile or FindNextFile call.
6518  * \param name The name of the next found file.
6519  * \param size The size of the next found file.
6520  * \return A char value indicating whether the function call succeeded or not.
6521  */
6522 inline char RemoteFindNextFile(byte conn, byte & handle, string & name, long & size);
6523 
6524 /**
6525  * Send a PollCommandLength message.
6526  * Send the PollCommandLength system command on the specified connection slot.
6527  *
6528  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6529  *
6530  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6531  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6532  * See \ref CommConnectionConstants.
6533  * \param bufnum The poll buffer you want to query (0=USBPoll, 1=HiSpeed).
6534  * \param length The number of bytes available for polling.
6535  * \return A char value indicating whether the function call succeeded or not.
6536  */
6537 inline char RemotePollCommandLength(byte conn, byte bufnum, byte & length);
6538 
6539 /**
6540  * Send a Write message.
6541  * Send the Write system command on the specified connection slot.
6542  *
6543  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6544  *
6545  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6546  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6547  * See \ref CommConnectionConstants.
6548  * \param handle The handle of the file you are writing to.
6549  * \param numbytes The number of bytes actually written.
6550  * \param data A byte array containing the data you are writing.
6551  * \return A char value indicating whether the function call succeeded or not.
6552  */
6553 inline char RemoteWrite(byte conn, byte & handle, int & numbytes, byte data[]);
6554 
6555 /**
6556  * Send a Read message.
6557  * Send the Read system command on the specified connection slot.
6558  *
6559  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6560  *
6561  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6562  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6563  * See \ref CommConnectionConstants.
6564  * \param handle The handle of the file you are reading from.
6565  * \param numbytes The number of bytes you want to read. Returns the number of
6566  * bytes actually read.
6567  * \param data A byte array containing the response data.
6568  * \return A char value indicating whether the function call succeeded or not.
6569  */
6570 inline char RemoteRead(byte conn, byte & handle, int & numbytes, byte & data[]);
6571 
6572 /**
6573  * Send an IOMapRead message.
6574  * Send the IOMapRead system command on the specified connection slot.
6575  *
6576  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6577  *
6578  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6579  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6580  * See \ref CommConnectionConstants.
6581  * \param id The ID of the module from which to read data.
6582  * \param offset The offset into the IOMap structure from which to read.
6583  * \param numbytes The number of bytes of data to read. Returns the number of
6584  * bytes actually read.
6585  * \param data A byte array containing the response data.
6586  * \return A char value indicating whether the function call succeeded or not.
6587  */
6588 inline char RemoteIOMapRead(byte conn, long id, int offset, int & numbytes, byte & data[]);
6589 
6590 /**
6591  * Send a PollCommand message.
6592  * Send the PollCommand system command on the specified connection slot to
6593  * write the data provided.
6594  *
6595  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6596  *
6597  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6598  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6599  * See \ref CommConnectionConstants.
6600  * \param bufnum The buffer from which to read data (0=USBPoll, 1=HiSpeed).
6601  * \param len The number of bytes to read.  Returns the number of
6602  * bytes actually read.
6603  * \param data A byte array containing the response data.
6604  * \return A char value indicating whether the function call succeeded or not.
6605  */
6606 inline char RemotePollCommand(byte conn, byte bufnum, byte & len, byte & data[]);
6607 
6608 /**
6609  * Send a RenameFile message.
6610  * Send the RenameFile system command on the specified connection slot to
6611  * write the data provided.
6612  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
6613  *
6614  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
6615  *
6616  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6617  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6618  * See \ref CommConnectionConstants.
6619  * \param oldname The old filename.
6620  * \param newname The new filename.
6621  * \return A char value indicating whether the function call succeeded or not.
6622  */
6623 inline char RemoteRenameFile(byte conn, string oldname, string newname);
6624 
6625 #endif
6626 
6627 /**
6628  * Send a BluetoothFactoryReset message.
6629  * This method sends a BluetoothFactoryReset system command to the device on the specified
6630  * connection. Use \ref RemoteConnectionIdle to determine when this write request is
6631  * completed.  This command cannot be sent over a bluetooth connection.
6632  *
6633  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6634  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6635  * See \ref CommConnectionConstants.
6636  * \return A char value indicating whether the function call succeeded or not.
6637  */
6638 inline char RemoteBluetoothFactoryReset(byte conn);
6639 
6640 /**
6641  * Send an IOMapWrite value message.
6642  * Send the IOMapWrite system command on the specified connection slot to
6643  * write the value provided.
6644  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
6645  *
6646  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6647  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6648  * See \ref CommConnectionConstants.
6649  * \param id The ID of the module to which to write data.
6650  * \param offset The offset into the IOMap structure to which to write.
6651  * \param value A scalar variable containing the value you are writing to the IOMap structure.
6652  * \return A char value indicating whether the function call succeeded or not.
6653  */
6654 inline char RemoteIOMapWriteValue(byte conn, long id, int offset, variant value);
6655 
6656 /**
6657  * Send an IOMapWrite bytes message.
6658  * Send the IOMapWrite system command on the specified connection slot to
6659  * write the data provided.
6660  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
6661  *
6662  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6663  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6664  * See \ref CommConnectionConstants.
6665  * \param id The ID of the module to which to write data.
6666  * \param offset The offset into the IOMap structure to which to write.
6667  * \param data A byte array containing the data you are writing to the IOMap structure.
6668  * \return A char value indicating whether the function call succeeded or not.
6669  */
6670 inline char RemoteIOMapWriteBytes(byte conn, long id, int offset, byte data[]);
6671 
6672 /**
6673  * Send a SetBrickName message.
6674  * Send the SetBrickName system command on the specified connection slot to
6675  * write the data provided.
6676  * Use \ref RemoteConnectionIdle to determine when this write request is completed.
6677  *
6678  * \param conn The connection slot (0..4). Connections 0 through 3 are for
6679  * bluetooth connections.  Connection 4 refers to the RS485 hi-speed port.
6680  * See \ref CommConnectionConstants.
6681  * \param name The new brick name.
6682  * \return A char value indicating whether the function call succeeded or not.
6683  */
6684 inline char RemoteSetBrickName(byte conn, string name);
6685 
6686 /** @} */ // end of CommModuleSCFunctions group
6687 
6688 
6689 /**
6690  * Use the RS485 port.
6691  * Configure port 4 for RS485 usage.
6692  *
6693  */
6694 inline void UseRS485(void);
6695 
6696 #ifdef __ENHANCED_FIRMWARE
6697 
6698 /**
6699  * Control the RS485 port.
6700  * Control the RS485 hi-speed port using the specified parameters.
6701  *
6702  * \param cmd The control command to send to the port. See \ref CommHiSpeedCtrlConstants.
6703  * \param baud The baud rate for the RS485 port. See \ref CommHiSpeedBaudConstants.
6704  * \param mode The RS485 port mode (data bits, stop bits, parity).  See \ref
6705  * CommHiSpeedDataBitsConstants, \ref CommHiSpeedStopBitsConstants, \ref
6706  * CommHiSpeedParityConstants, and \ref CommHiSpeedCombinedConstants.
6707  * \return A char value indicating whether the function call succeeded or not.
6708  *
6709  * \warning This function requires the enhanced NBC/NXC firmware.
6710  */
6711 inline char RS485Control(byte cmd, byte baud, unsigned int mode);
6712 
6713 /**
6714  * Check for RS485 available data.
6715  * Check the RS485 hi-speed port for available data.
6716  *
6717  * \return A value indicating whether data is available or not.
6718  *
6719  * \warning This function requires the enhanced NBC/NXC firmware.
6720  */
6721 inline bool RS485DataAvailable(void);
6722 
6723 /**
6724  * Initialize RS485 port.
6725  * Initialize the RS485 UART port to its default values.  The baud rate is
6726  * set to 921600 and the mode is set to 8N1 (8 data bits, no parity, 1 stop bit).
6727  * Data cannot be sent or received over the RS485 port until the port is
6728  * configured as as a hi-speed port, the port is turned on, and the UART is
6729  * initialized.
6730  *
6731  * \return A char value indicating whether the function call succeeded or not.
6732  *
6733  * \warning This function requires the enhanced NBC/NXC firmware.
6734  */
6735 inline char RS485Initialize(void);
6736 
6737 /**
6738  * Disable RS485.
6739  * Turn off the RS485 port.
6740  *
6741  * \return A char value indicating whether the function call succeeded or not.
6742  *
6743  * \warning This function requires the enhanced NBC/NXC firmware.
6744  */
6745 inline char RS485Disable(void);
6746 
6747 /**
6748  * Enable RS485.
6749  * Turn on the RS485 hi-speed port so that it can be used.
6750  *
6751  * \return A char value indicating whether the function call succeeded or not.
6752  *
6753  * \warning This function requires the enhanced NBC/NXC firmware.
6754  */
6755 inline char RS485Enable(void);
6756 
6757 /**
6758  * Read RS485 data.
6759  * Read data from the RS485 hi-speed port.
6760  *
6761  * \param buffer A byte array that will contain the data read from the RS485 port.
6762  * \return A char value indicating whether the function call succeeded or not.
6763  *
6764  * \warning This function requires the enhanced NBC/NXC firmware.
6765  */
6766 inline char RS485Read(byte & buffer[]);
6767 
6768 /**
6769  * Is RS485 sending data.
6770  * Check whether the RS485 is actively sending data.
6771  *
6772  * \return A value indicating whether data is being sent or not.
6773  *
6774  * \warning This function requires the enhanced NBC/NXC firmware.
6775  */
6776 inline bool RS485SendingData(void);
6777 
6778 /**
6779  * Check RS485 status.
6780  * Check the status of the RS485 hi-speed port.
6781  *
6782  * \param sendingData A boolean value set to true on output if data is being sent.
6783  * \param dataAvail A boolean value set to true on output if data is available to be read.
6784  *
6785  * \warning This function requires the enhanced NBC/NXC firmware.
6786  */
6787 inline void RS485Status(bool & sendingData, bool & dataAvail);
6788 
6789 /**
6790  * Configure RS485 UART.
6791  * Configure the RS485 UART parameters, including baud rate, data bits,
6792  * stop bits, and parity.
6793  *
6794  * \param baud The baud rate for the RS485 port. See \ref CommHiSpeedBaudConstants.
6795  * \param mode The RS485 port mode (data bits, stop bits, parity).  See \ref
6796  * CommHiSpeedDataBitsConstants, \ref CommHiSpeedStopBitsConstants, \ref
6797  * CommHiSpeedParityConstants, and \ref CommHiSpeedCombinedConstants.
6798  * \return A char value indicating whether the function call succeeded or not.
6799  *
6800  * \warning This function requires the enhanced NBC/NXC firmware.
6801  */
6802 inline char RS485Uart(byte baud, unsigned int mode);
6803 
6804 /**
6805  * Write RS485 data.
6806  * Write data to the RS485 hi-speed port.
6807  *
6808  * \param buffer A byte array containing the data to write to the RS485 port.
6809  * \return A char value indicating whether the function call succeeded or not.
6810  *
6811  * \warning This function requires the enhanced NBC/NXC firmware.
6812  */
6813 inline char RS485Write(byte buffer[]);
6814 
6815 /**
6816  * Write RS485 boolean.
6817  * Write a boolean value to the RS485 hi-speed port.
6818  *
6819  * \param bval A boolean value to write over the RS485 port.
6820  * \return A char value indicating whether the function call succeeded or not.
6821  *
6822  * \warning This function requires the enhanced NBC/NXC firmware.
6823  */
6824 inline char SendRS485Bool(bool bval);
6825 
6826 /**
6827  * Write RS485 numeric.
6828  * Write a numeric value to the RS485 hi-speed port.
6829  *
6830  * \param val A numeric value to write over the RS485 port.
6831  * \return A char value indicating whether the function call succeeded or not.
6832  *
6833  * \warning This function requires the enhanced NBC/NXC firmware.
6834  */
6835 inline char SendRS485Number(long val);
6836 
6837 /**
6838  * Write RS485 string.
6839  * Write a string value to the RS485 hi-speed port.
6840  *
6841  * \param str A string value to write over the RS485 port.
6842  * \return A char value indicating whether the function call succeeded or not.
6843  *
6844  * \warning This function requires the enhanced NBC/NXC firmware.
6845  */
6846 inline char SendRS485String(string str);
6847 
6848 #endif
6849 
6850 /**
6851  * Get bluetooth input buffer data.
6852  * This method reads count bytes of data from the Bluetooth input buffer and
6853  * writes it to the buffer provided.
6854  *
6855  * \param offset A constant offset into the bluetooth input buffer.
6856  * \param cnt The number of bytes to read.
6857  * \param data The byte array reference which will contain the data read from
6858  * the bluetooth input buffer.
6859  */
6860 inline void GetBTInputBuffer(const byte offset, byte cnt, byte & data[]);
6861 
6862 /**
6863  * Get bluetooth output buffer data.
6864  * This method reads count bytes of data from the Bluetooth output buffer and
6865  * writes it to the buffer provided.
6866  *
6867  * \param offset A constant offset into the bluetooth output buffer.
6868  * \param cnt The number of bytes to read.
6869  * \param data The byte array reference which will contain the data read from
6870  * the bluetooth output buffer.
6871  */
6872 inline void GetBTOutputBuffer(const byte offset, byte cnt, byte & data[]);
6873 
6874 /**
6875  * Get hi-speed port input buffer data.
6876  * This method reads count bytes of data from the hi-speed port input buffer and
6877  * writes it to the buffer provided.
6878  *
6879  * \param offset A constant offset into the hi-speed port input buffer.
6880  * \param cnt The number of bytes to read.
6881  * \param data The byte array reference which will contain the data read from
6882  * the hi-speed port input buffer.
6883  */
6884 inline void GetHSInputBuffer(const byte offset, byte cnt, byte & data[]);
6885 
6886 /**
6887  * Get hi-speed port output buffer data.
6888  * This method reads count bytes of data from the hi-speed port output buffer and
6889  * writes it to the buffer provided.
6890  *
6891  * \param offset A constant offset into the hi-speed port output buffer.
6892  * \param cnt The number of bytes to read.
6893  * \param data The byte array reference which will contain the data read from
6894  * the hi-speed port output buffer.
6895  */
6896 inline void GetHSOutputBuffer(const byte offset, byte cnt, byte & data[]);
6897 
6898 /**
6899  * Get usb input buffer data.
6900  * This method reads count bytes of data from the usb input buffer and
6901  * writes it to the buffer provided.
6902  *
6903  * \param offset A constant offset into the usb input buffer.
6904  * \param cnt The number of bytes to read.
6905  * \param data The byte array reference which will contain the data read from
6906  * the usb input buffer.
6907  */
6908 inline void GetUSBInputBuffer(const byte offset, byte cnt, byte & data[]);
6909 
6910 /**
6911  * Get usb output buffer data.
6912  * This method reads count bytes of data from the usb output buffer and
6913  * writes it to the buffer provided.
6914  * \param offset A constant offset into the usb output buffer.
6915  * \param cnt The number of bytes to read.
6916  * \param data The byte array reference which will contain the data read from
6917  * the usb output buffer.
6918  */
6919 inline void GetUSBOutputBuffer(const byte offset, byte cnt, byte & data[]);
6920 
6921 /**
6922  * Get usb poll buffer data.
6923  * This method reads count bytes of data from the usb poll buffer and
6924  * writes it to the buffer provided.
6925  * \param offset A constant offset into the usb poll buffer.
6926  * \param cnt The number of bytes to read.
6927  * \param data The byte array reference which will contain the data read from
6928  * the usb poll buffer.
6929  */
6930 inline void GetUSBPollBuffer(const byte offset, byte cnt, byte & data[]);
6931 
6932 /**
6933  * Get bluetooth device name.
6934  * This method returns the name of the device at the specified index in the
6935  * Bluetooth device table.
6936  * \param devidx The device table index.
6937  * \return The device name of the specified bluetooth device.
6938  */
6939 inline string BTDeviceName(const byte devidx);
6940 
6941 /**
6942  * Get bluetooth device name.
6943  * This method returns the name of the device at the specified index in the
6944  * Bluetooth connection table.
6945  * \param conn The connection slot (0..3).
6946  * \return The name of the bluetooth device at the specified connection slot.
6947  */
6948 inline string BTConnectionName(const byte conn);
6949 
6950 /**
6951  * Get bluetooth device pin code.
6952  * This method returns the pin code of the device at the specified index in the
6953  * Bluetooth connection table.
6954  * \param conn The connection slot (0..3).
6955  * \return The pin code for the bluetooth device at the specified connection slot.
6956  */
6957 inline string BTConnectionPinCode(const byte conn);
6958 
6959 /**
6960  * Get NXT name.
6961  * This method returns the name of the NXT.
6962  * \return The NXT's bluetooth name.
6963  */
6964 inline string BrickDataName(void);
6965 
6966 /**
6967  * Get bluetooth device address.
6968  * This method reads the address of the device at the specified index within
6969  * the Bluetooth device table and stores it in the data buffer provided.
6970  * \param devidx The device table index.
6971  * \param data The byte array reference that will contain the device address.
6972  */
6973 inline void GetBTDeviceAddress(const byte devidx, byte & data[]);
6974 
6975 /**
6976  * Get bluetooth device address.
6977  * This method reads the address of the device at the specified index within
6978  * the Bluetooth connection table and stores it in the data buffer provided.
6979  * \param conn The connection slot (0..3).
6980  * \param data The byte array reference that will contain the device address.
6981  */
6982 inline void GetBTConnectionAddress(const byte conn, byte & data[]);
6983 
6984 /**
6985  * Get NXT address.
6986  * This method reads the address of the NXT and stores it in the data buffer
6987  * provided.
6988  * \param data The byte array reference that will contain the device address.
6989  */
6990 inline void GetBrickDataAddress(byte & data[]);
6991 
6992 /**
6993  * Get bluetooth device class.
6994  * This method returns the class of the device at the specified index within
6995  * the Bluetooth device table.
6996  * \param devidx The device table index.
6997  * \return The device class of the specified bluetooth device.
6998  */
6999 inline long BTDeviceClass(const byte devidx);
7000 
7001 /**
7002  * Get bluetooth device status.
7003  * This method returns the status of the device at the specified index within
7004  * the Bluetooth device table.
7005  * \param devidx The device table index.
7006  * \return The status of the specified bluetooth device.
7007  */
7008 inline byte BTDeviceStatus(const byte devidx);
7009 
7010 /**
7011  * Get bluetooth device class.
7012  * This method returns the class of the device at the specified index within
7013  * the Bluetooth connection table.
7014  * \param conn The connection slot (0..3).
7015  * \return The class of the bluetooth device at the specified connection slot.
7016  */
7017 inline long BTConnectionClass(const byte conn);
7018 
7019 /**
7020  * Get bluetooth device handle number.
7021  * This method returns the handle number of the device at the specified index within
7022  * the Bluetooth connection table.
7023  * \param conn The connection slot (0..3).
7024  * \return The handle number of the bluetooth device at the specified connection slot.
7025  */
7026 inline byte BTConnectionHandleNum(const byte conn);
7027 
7028 /**
7029  * Get bluetooth device stream status.
7030  * This method returns the stream status of the device at the specified index within
7031  * the Bluetooth connection table.
7032  * \param conn The connection slot (0..3).
7033  * \return The stream status of the bluetooth device at the specified connection slot.
7034  */
7035 inline byte BTConnectionStreamStatus(const byte conn);
7036 
7037 /**
7038  * Get bluetooth device link quality.
7039  * This method returns the link quality of the device at the specified index within
7040  * the Bluetooth connection table.
7041  * \param conn The connection slot (0..3).
7042  * \return The link quality of the specified connection slot (unimplemented).
7043  * \warning This function is not implemented at the firmware level.
7044  */
7045 inline byte BTConnectionLinkQuality(const byte conn);
7046 
7047 /**
7048  * Get NXT bluecore version.
7049  * This method returns the bluecore version of the NXT.
7050  * \return The NXT's bluecore version number.
7051  */
7052 inline int BrickDataBluecoreVersion(void);
7053 
7054 /**
7055  * Get NXT bluetooth state status.
7056  * This method returns the Bluetooth state status of the NXT.
7057  * \return The NXT's bluetooth state status.
7058  */
7059 inline byte BrickDataBtStateStatus(void);
7060 
7061 /**
7062  * Get NXT bluetooth hardware status.
7063  * This method returns the Bluetooth hardware status of the NXT.
7064  * \return The NXT's bluetooth hardware status.
7065  */
7066 inline byte BrickDataBtHardwareStatus(void);
7067 
7068 /**
7069  * Get NXT bluetooth timeout value.
7070  * This method returns the Bluetooth timeout value of the NXT.
7071  * \return The NXT's bluetooth timeout value.
7072  */
7073 inline byte BrickDataTimeoutValue(void);
7074 
7075 /**
7076  * Get bluetooth input buffer in-pointer.
7077  * This method returns the value of the input pointer of the Bluetooth input
7078  * buffer.
7079  * \return The bluetooth input buffer's in-pointer value.
7080  */
7081 inline byte BTInputBufferInPtr(void);
7082 
7083 /**
7084  * Get bluetooth input buffer out-pointer.
7085  * This method returns the value of the output pointer of the Bluetooth input
7086  * buffer.
7087  * \return The bluetooth input buffer's out-pointer value.
7088  */
7089 inline byte BTInputBufferOutPtr(void);
7090 
7091 /**
7092  * Get bluetooth output buffer in-pointer.
7093  * This method returns the value of the input pointer of the Bluetooth output
7094  * buffer.
7095  * \return The bluetooth output buffer's in-pointer value.
7096  */
7097 inline byte BTOutputBufferInPtr(void);
7098 
7099 /**
7100  * Get bluetooth output buffer out-pointer.
7101  * This method returns the value of the output pointer of the Bluetooth output
7102  * buffer.
7103  * \return The bluetooth output buffer's out-pointer value.
7104  */
7105 inline byte BTOutputBufferOutPtr(void);
7106 
7107 /**
7108  * Get hi-speed port input buffer in-pointer.
7109  * This method returns the value of the input pointer of the hi-speed port input
7110  * buffer.
7111  * \return The hi-speed port input buffer's in-pointer value.
7112  */
7113 inline byte HSInputBufferInPtr(void);
7114 
7115 /**
7116  * Get hi-speed port input buffer out-pointer.
7117  * This method returns the value of the output pointer of the hi-speed port input
7118  * buffer.
7119  * \return The hi-speed port input buffer's out-pointer value.
7120  */
7121 inline byte HSInputBufferOutPtr(void);
7122 
7123 /**
7124  * Get hi-speed port output buffer in-pointer.
7125  * This method returns the value of the input pointer of the hi-speed port output
7126  * buffer.
7127  * \return The hi-speed port output buffer's in-pointer value.
7128  */
7129 inline byte HSOutputBufferInPtr(void);
7130 
7131 /**
7132  * Get hi-speed port output buffer out-pointer.
7133  * This method returns the value of the output pointer of the hi-speed port output
7134  * buffer.
7135  * \return The hi-speed port output buffer's out-pointer value.
7136  */
7137 inline byte HSOutputBufferOutPtr(void);
7138 
7139 /**
7140  * Get usb port input buffer in-pointer.
7141  * This method returns the value of the input pointer of the usb port input
7142  * buffer.
7143  * \return The USB port input buffer's in-pointer value.
7144  */
7145 inline byte USBInputBufferInPtr(void);
7146 
7147 /**
7148  * Get usb port input buffer out-pointer.
7149  * This method returns the value of the output pointer of the usb port input
7150  * buffer.
7151  * \return The USB port input buffer's out-pointer value.
7152  */
7153 inline byte USBInputBufferOutPtr(void);
7154 
7155 /**
7156  * Get usb port output buffer in-pointer.
7157  * This method returns the value of the input pointer of the usb port output
7158  * buffer.
7159  * \return The USB port output buffer's in-pointer value.
7160  */
7161 inline byte USBOutputBufferInPtr(void);
7162 
7163 /**
7164  * Get usb port output buffer out-pointer.
7165  * This method returns the value of the output pointer of the usb port output
7166  * buffer.
7167  * \return The USB port output buffer's out-pointer value.
7168  */
7169 inline byte USBOutputBufferOutPtr(void);
7170 
7171 /**
7172  * Get usb port poll buffer in-pointer.
7173  * This method returns the value of the input pointer of the usb port poll
7174  * buffer.
7175  * \return The USB port poll buffer's in-pointer value.
7176  */
7177 inline byte USBPollBufferInPtr(void);
7178 
7179 /**
7180  * Get usb port poll buffer out-pointer.
7181  * This method returns the value of the output pointer of the usb port poll
7182  * buffer.
7183  * \return The USB port poll buffer's out-pointer value.
7184  */
7185 inline byte USBPollBufferOutPtr(void);
7186 
7187 /**
7188  * Get bluetooth device count.
7189  * This method returns the number of devices defined within the Bluetooth
7190  * device table.
7191  * \return The count of known bluetooth devices.
7192  */
7193 inline byte BTDeviceCount(void);
7194 
7195 /**
7196  * Get bluetooth device name count.
7197  * This method returns the number of device names defined within the Bluetooth
7198  * device table. This usually has the same value as BTDeviceCount but it can
7199  * differ in some instances.
7200  * \return The count of known bluetooth device names.
7201  */
7202 inline byte BTDeviceNameCount(void);
7203 
7204 /**
7205  * Get hi-speed port flags.
7206  * This method returns the value of the hi-speed port flags.
7207  * \return The hi-speed port flags. See \ref CommHiSpeedFlagsConstants.
7208  */
7209 inline byte HSFlags(void);
7210 
7211 /**
7212  * Get hi-speed port speed.
7213  * This method returns the value of the hi-speed port speed (baud rate).
7214  * \return The hi-speed port speed (baud rate).  See \ref CommHiSpeedBaudConstants.
7215  */
7216 inline byte HSSpeed(void);
7217 
7218 /**
7219  * Get hi-speed port state.
7220  * This method returns the value of the hi-speed port state.
7221  * \return The hi-speed port state. See \ref CommHiSpeedStateConstants.
7222  */
7223 inline byte HSState(void);
7224 
7225 #if (__FIRMWARE_VERSION > 107) && defined(__ENHANCED_FIRMWARE)
7226 
7227 /**
7228  * Get hi-speed port mode.
7229  * This method returns the value of the hi-speed port mode.
7230  * \return The hi-speed port mode (data bits, stop bits, parity).  See
7231  * \ref CommHiSpeedDataBitsConstants, \ref CommHiSpeedStopBitsConstants,
7232  * \ref CommHiSpeedParityConstants, and \ref CommHiSpeedCombinedConstants.
7233  *
7234  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
7235  */
7236 inline int HSMode(void);
7237 
7238 /**
7239  * Get Bluetooth data mode.
7240  * This method returns the value of the Bluetooth data mode.
7241  * \return The Bluetooth data mode.  See \ref CommDataModeConstants.
7242  *
7243  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
7244  */
7245 inline int BTDataMode(void);
7246 
7247 /**
7248  * Get hi-speed port datamode.
7249  * This method returns the value of the hi-speed port data mode.
7250  * \return The hi-speed port data mode.  See \ref CommDataModeConstants.
7251  *
7252  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
7253  */
7254 inline int HSDataMode(void);
7255 
7256 #endif
7257 
7258 /**
7259  * Get USB state.
7260  * This method returns the value of the USB state.
7261  * \return The USB state.
7262  */
7263 inline byte USBState(void);
7264 
7265 /**
7266  * Set bluetooth input buffer data.
7267  * Write cnt bytes of data to the bluetooth input buffer at offset.
7268  * \param offset A constant offset into the input buffer
7269  * \param cnt The number of bytes to write
7270  * \param data A byte array containing the data to write
7271  */
7272 inline void SetBTInputBuffer(const byte offset, byte cnt, byte data[]);
7273 
7274 /**
7275  * Set bluetooth input buffer in-pointer.
7276  * Set the value of the input buffer in-pointer.
7277  * \param n The new in-pointer value (0..127).
7278  */
7279 inline void SetBTInputBufferInPtr(byte n);
7280 
7281 /**
7282  * Set bluetooth input buffer out-pointer.
7283  * Set the value of the input buffer out-pointer.
7284  * \param n The new out-pointer value (0..127).
7285  */
7286 inline void SetBTInputBufferOutPtr(byte n);
7287 
7288 /**
7289  * Set bluetooth output buffer data.
7290  * Write cnt bytes of data to the bluetooth output buffer at offset.
7291  * \param offset A constant offset into the output buffer
7292  * \param cnt The number of bytes to write
7293  * \param data A byte array containing the data to write
7294  */
7295 inline void SetBTOutputBuffer(const byte offset, byte cnt, byte data[]);
7296 
7297 /**
7298  * Set bluetooth output buffer in-pointer.
7299  * Set the value of the output buffer in-pointer.
7300  * \param n The new in-pointer value (0..127).
7301  */
7302 inline void SetBTOutputBufferInPtr(byte n);
7303 
7304 /**
7305  * Set bluetooth output buffer out-pointer.
7306  * Set the value of the output buffer out-pointer.
7307  * \param n The new out-pointer value (0..127).
7308  */
7309 inline void SetBTOutputBufferOutPtr(byte n);
7310 
7311 /**
7312  * Set hi-speed port input buffer data.
7313  * Write cnt bytes of data to the hi-speed port input buffer at offset.
7314  * \param offset A constant offset into the input buffer
7315  * \param cnt The number of bytes to write
7316  * \param data A byte array containing the data to write
7317  */
7318 inline void SetHSInputBuffer(const byte offset, byte cnt, byte data[]);
7319 
7320 /**
7321  * Set hi-speed port input buffer in-pointer.
7322  * Set the value of the input buffer in-pointer.
7323  * \param n The new in-pointer value (0..127).
7324  */
7325 inline void SetHSInputBufferInPtr(byte n);
7326 
7327 /**
7328  * Set hi-speed port input buffer out-pointer.
7329  * Set the value of the input buffer out-pointer.
7330  * \param n The new out-pointer value (0..127).
7331  */
7332 inline void SetHSInputBufferOutPtr(byte n);
7333 
7334 /**
7335  * Set hi-speed port output buffer data.
7336  * Write cnt bytes of data to the hi-speed port output buffer at offset.
7337  * \param offset A constant offset into the output buffer
7338  * \param cnt The number of bytes to write
7339  * \param data A byte array containing the data to write
7340  */
7341 inline void SetHSOutputBuffer(const byte offset, byte cnt, byte data[]);
7342 
7343 /**
7344  * Set hi-speed port output buffer in-pointer.
7345  * Set the value of the output buffer in-pointer.
7346  * \param n The new in-pointer value (0..127).
7347  */
7348 inline void SetHSOutputBufferInPtr(byte n);
7349 
7350 /**
7351  * Set hi-speed port output buffer out-pointer.
7352  * Set the value of the output buffer out-pointer.
7353  * \param n The new out-pointer value (0..127).
7354  */
7355 inline void SetHSOutputBufferOutPtr(byte n);
7356 
7357 /**
7358  * Set USB input buffer data.
7359  * Write cnt bytes of data to the USB input buffer at offset.
7360  * \param offset A constant offset into the input buffer
7361  * \param cnt The number of bytes to write
7362  * \param data A byte array containing the data to write
7363  */
7364 inline void SetUSBInputBuffer(const byte offset, byte cnt, byte data[]);
7365 
7366 /**
7367  * Set USB input buffer in-pointer.
7368  * Set the value of the input buffer in-pointer.
7369  * \param n The new in-pointer value (0..63).
7370  */
7371 inline void SetUSBInputBufferInPtr(byte n);
7372 
7373 /**
7374  * Set USB input buffer out-pointer.
7375  * Set the value of the input buffer out-pointer.
7376  * \param n The new out-pointer value (0..63).
7377  */
7378 inline void SetUSBInputBufferOutPtr(byte n);
7379 
7380 /**
7381  * Set USB output buffer data.
7382  * Write cnt bytes of data to the USB output buffer at offset.
7383  * \param offset A constant offset into the output buffer
7384  * \param cnt The number of bytes to write
7385  * \param data A byte array containing the data to write
7386  */
7387 inline void SetUSBOutputBuffer(const byte offset, byte cnt, byte data[]);
7388 
7389 /**
7390  * Set USB output buffer in-pointer.
7391  * Set the value of the output buffer in-pointer.
7392  * \param n The new in-pointer value (0..63).
7393  */
7394 inline void SetUSBOutputBufferInPtr(byte n);
7395 
7396 /**
7397  * Set USB output buffer out-pointer.
7398  * Set the value of the output buffer out-pointer.
7399  * \param n The new out-pointer value (0..63).
7400  */
7401 inline void SetUSBOutputBufferOutPtr(byte n);
7402 
7403 /**
7404  * Set USB poll buffer data.
7405  * Write cnt bytes of data to the USB poll buffer at offset.
7406  * \param offset A constant offset into the poll buffer
7407  * \param cnt The number of bytes to write
7408  * \param data A byte array containing the data to write
7409  */
7410 inline void SetUSBPollBuffer(const byte offset, byte cnt, byte data[]);
7411 
7412 /**
7413  * Set USB poll buffer in-pointer.
7414  * Set the value of the poll buffer in-pointer.
7415  * \param n The new in-pointer value (0..63).
7416  */
7417 inline void SetUSBPollBufferInPtr(byte n);
7418 
7419 /**
7420  * Set USB poll buffer out-pointer.
7421  * Set the value of the poll buffer out-pointer.
7422  * \param n The new out-pointer value (0..63).
7423  */
7424 inline void SetUSBPollBufferOutPtr(byte n);
7425 
7426 /**
7427  * Set hi-speed port flags.
7428  * This method sets the value of the hi-speed port flags.
7429  * \param hsFlags The hi-speed port flags. See \ref CommHiSpeedFlagsConstants.
7430  */
7431 inline void SetHSFlags(byte hsFlags);
7432 
7433 /**
7434  * Set hi-speed port speed.
7435  * This method sets the value of the hi-speed port speed (baud rate).
7436  * \param hsSpeed The hi-speed port speed (baud rate).  See \ref CommHiSpeedBaudConstants.
7437  */
7438 inline void SetHSSpeed(byte hsSpeed);
7439 
7440 /**
7441  * Set hi-speed port state.
7442  * This method sets the value of the hi-speed port state.
7443  * \param hsState The hi-speed port state. See \ref CommHiSpeedStateConstants.
7444  */
7445 inline void SetHSState(byte hsState);
7446 
7447 #if (__FIRMWARE_VERSION > 107) && defined(__ENHANCED_FIRMWARE)
7448 
7449 /**
7450  * Set hi-speed port mode.
7451  * This method sets the value of the hi-speed port mode.
7452  * \param hsMode The hi-speed port mode (data bits, stop bits, parity).  See
7453  * \ref CommHiSpeedDataBitsConstants, \ref CommHiSpeedStopBitsConstants,
7454  * \ref CommHiSpeedParityConstants, and \ref CommHiSpeedCombinedConstants.
7455  *
7456  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
7457  */
SetHSMode(unsigned int hsMode)7458 inline void SetHSMode(unsigned int hsMode) { asm { __setHSMode(_n) } }
7459 
7460 /**
7461  * Set Bluetooth data mode.
7462  * This method sets the value of the Bluetooth data mode.
7463  * \param dataMode The Bluetooth data mode.  See \ref CommDataModeConstants. Must be a constant.
7464  *
7465  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
7466  */
7467 inline void SetBTDataMode(const byte dataMode);
7468 
7469 /**
7470  * Set hi-speed port data mode.
7471  * This method sets the value of the hi-speed port data mode.
7472  * \param dataMode The hi-speed port data mode.  See \ref CommDataModeConstants. Must be a constant.
7473  *
7474  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
7475  */
7476 inline void SetHSDataMode(const byte dataMode);
7477 
7478 #endif
7479 
7480 /**
7481  * Set USB state.
7482  * This method sets the value of the USB state.
7483  * \param usbState The USB state.
7484  */
7485 inline void SetUSBState(byte usbState);
7486 
7487 /**
7488  * Write message.
7489  * This function lets you write a message to a queue (aka mailbox) using the
7490  * values specified via the \ref MessageWriteType structure.
7491  *
7492  * \param args The MessageWriteType structure containing the needed parameters.
7493  */
7494 void SysMessageWrite(MessageWriteType & args);
7495 
7496 /**
7497  * Read message.
7498  * This function lets you read a message from a queue (aka mailbox) using the
7499  * values specified via the \ref MessageReadType structure.
7500  *
7501  * \param args The MessageReadType structure containing the needed parameters.
7502  */
7503 void SysMessageRead(MessageReadType & args);
7504 
7505 /**
7506  * Write data to a Bluetooth connection.
7507  * This function lets you write to a Bluetooth connection using the values
7508  * specified via the \ref CommBTWriteType structure.
7509  *
7510  * \param args The CommBTWriteType structure containing the needed parameters.
7511  */
7512 void SysCommBTWrite(CommBTWriteType & args);
7513 
7514 /**
7515  * Check Bluetooth connection status.
7516  * This function lets you check the status of a Bluetooth connection using the
7517  * values specified via the \ref CommBTCheckStatusType structure.
7518  *
7519  * \param args The CommBTCheckStatusType structure containing the needed
7520  * parameters.
7521  */
7522 void SysCommBTCheckStatus(CommBTCheckStatusType & args);
7523 
7524 #ifdef __ENHANCED_FIRMWARE
7525 /**
7526  * Execute any Comm module command.
7527  * This function lets you directly execute the Comm module's primary function
7528  * using the values specified via the \ref CommExecuteFunctionType structure.
7529  *
7530  * \param args The CommExecuteFunctionType structure containing the needed
7531  * parameters.
7532  *
7533  * \warning This function requires the enhanced NBC/NXC firmware.
7534  */
7535 inline void SysCommExecuteFunction(CommExecuteFunctionType & args);
7536 
7537 /**
7538  * Control the hi-speed port.
7539  * This function lets you control the hi-speed port
7540  * using the values specified via the \ref CommHSControlType structure.
7541  *
7542  * \param args The CommHSControlType structure containing the needed
7543  * parameters.
7544  *
7545  * \warning This function requires the enhanced NBC/NXC firmware.
7546  */
7547 inline void SysCommHSControl(CommHSControlType & args);
7548 
7549 /**
7550  * Check the hi-speed port status.
7551  * This function lets you check the hi-speed port status
7552  * using the values specified via the \ref CommHSCheckStatusType structure.
7553  *
7554  * \param args The CommHSCheckStatusType structure containing the needed
7555  * parameters.
7556  *
7557  * \warning This function requires the enhanced NBC/NXC firmware.
7558  */
7559 inline void SysCommHSCheckStatus(CommHSCheckStatusType & args);
7560 
7561 /**
7562  * Read from the hi-speed port.
7563  * This function lets you read from the hi-speed port
7564  * using the values specified via the \ref CommHSReadWriteType structure.
7565  *
7566  * \param args The CommHSReadWriteType structure containing the needed
7567  * parameters.
7568  *
7569  * \warning This function requires the enhanced NBC/NXC firmware.
7570  */
7571 inline void SysCommHSRead(CommHSReadWriteType & args);
7572 
7573 /**
7574  * Write to the hi-speed port.
7575  * This function lets you write to the hi-speed port
7576  * using the values specified via the \ref CommHSReadWriteType structure.
7577  *
7578  * \param args The CommHSReadWriteType structure containing the needed
7579  * parameters.
7580  *
7581  * \warning This function requires the enhanced NBC/NXC firmware.
7582  */
7583 inline void SysCommHSWrite(CommHSReadWriteType & args);
7584 
7585 #endif
7586 
7587 #if __FIRMWARE_VERSION > 107
7588 /**
7589  * Turn on or off the bluetooth subsystem.
7590  * This function lets you turn on or off the bluetooth subsystem
7591  * using the values specified via the \ref CommBTOnOffType structure.
7592  *
7593  * \param args The CommBTOnOffType structure containing the needed
7594  * parameters.
7595  *
7596  * \warning This function requires an NXT 2.0 compatible firmware.
7597  */
7598 inline void SysCommBTOnOff(CommBTOnOffType & args);
7599 
7600 /**
7601  * Connect or disconnect a bluetooth device.
7602  * This function lets you connect or disconnect a bluetooth device
7603  * using the values specified via the \ref CommBTConnectionType structure.
7604  *
7605  * \param args The CommBTConnectionType structure containing the needed
7606  * parameters.
7607  *
7608  * \warning This function requires an NXT 2.0 compatible firmware.
7609  */
7610 inline void SysCommBTConnection(CommBTConnectionType & args);
7611 
7612 #endif
7613 
7614 /*
7615 // these functions really cannot be used for any useful purpose (read-only)
7616 inline void SetBTDeviceName(const byte devidx, string str);
7617 inline void SetBTDeviceAddress(const byte devidx, const byte btaddr[]);
7618 inline void SetBTConnectionName(const byte conn, string str);
7619 inline void SetBTConnectionPinCode(const byte conn, const byte code[]);
7620 inline void SetBTConnectionAddress(const byte conn, const byte btaddr[]);
7621 inline void SetBrickDataName(string str);
7622 inline void SetBrickDataAddress(const byte p, byte btaddr[]);
7623 inline void SetBTDeviceClass(const byte devidx, unsigned long class);
7624 inline void SetBTDeviceStatus(const byte devidx, const byte status);
7625 inline void SetBTConnectionClass(const byte conn, unsigned long class);
7626 inline void SetBTConnectionHandleNum(const byte conn, const byte handleNum);
7627 inline void SetBTConnectionStreamStatus(const byte conn, const byte status);
7628 inline void SetBTConnectionLinkQuality(const byte conn, const byte quality);
7629 inline void SetBrickDataBluecoreVersion(int version);
7630 inline void SetBrickDataBtStateStatus(byte status);
7631 inline void SetBrickDataBtHardwareStatus(byte status);
7632 inline void SetBrickDataTimeoutValue(const byte timeout);
7633 inline void SetBTDeviceCount(byte count);
7634 inline void SetBTDeviceNameCount(byte count);
7635 */
7636 
7637 #else
7638 
7639 #define SendMessage(_queue, _msg) asm { __sendMessage(_queue, _msg, __RETVAL__) }
7640 #define ReceiveMessage(_queue, _clear, _msg) asm { __receiveMessage(_queue, _clear, _msg, __RETVAL__) }
7641 
7642 #define BluetoothStatus(_conn) asm { __bluetoothStatus(_conn, __RETVAL__) }
7643 #define BluetoothWrite(_conn, _buffer) asm { __bluetoothWrite(_conn, _buffer, __RETVAL__) }
7644 #define RemoteConnectionWrite(_conn, _buffer) asm { __connectionRawWrite(_conn, _buffer, __RETVAL__) }
7645 #define RemoteConnectionIdle(_conn) asm { __remoteConnectionIdle(_conn, __RETVAL__) }
7646 
7647 #define SendRemoteBool(_conn, _queue, _bval) asm { __sendRemoteBool(_conn, _queue, _bval, __RETVAL__) }
7648 #define SendRemoteNumber(_conn, _queue, _val) asm { __sendRemoteNumber(_conn, _queue, _val, __RETVAL__) }
7649 #define SendRemoteString(_conn, _queue, _str) asm { __sendRemoteString(_conn, _queue, _str, __RETVAL__) }
7650 
7651 #define SendResponseBool(_queue, _bval) asm { __sendResponseBool(_queue, _bval, __RETVAL__) }
7652 #define SendResponseNumber(_queue, _val) asm { __sendResponseNumber(_queue, _val, __RETVAL__) }
7653 #define SendResponseString(_queue, _msg) asm { __sendResponseString(_queue, _msg, __RETVAL__) }
7654 
7655 #define ReceiveRemoteBool(_queue, _clear, _bval) asm { __receiveRemoteBool(_queue, _clear, _bval, __RETVAL__) }
7656 #define ReceiveRemoteNumber(_queue, _clear, _val) asm { __receiveRemoteNumber(_queue, _clear, _val, __RETVAL__) }
7657 #define ReceiveRemoteString(_queue, _clear, _str) asm { __receiveMessage(_queue, _clear, _str, __RETVAL__) }
7658 #define ReceiveRemoteMessageEx(_queue, _clear, _str, _val, _bval) asm { __receiveRemoteMessageEx(_queue, _clear, _str, _val, _bval, __RETVAL__) }
7659 
7660 #define RemoteMessageRead(_conn, _queue) asm { __remoteMessageRead(_conn, _queue, __RETVAL__) }
7661 #define RemoteMessageWrite(_conn, _queue, _msg) asm { __sendRemoteString(_conn, _queue, _msg, __RETVAL__) }
7662 #define RemoteStartProgram(_conn, _filename) asm { __remoteStartProgram(_conn, _filename, __RETVAL__) }
7663 #define RemoteStopProgram(_conn) asm { __connectionWrite(_conn, __DCStopProgramPacket, __RETVAL__) }
7664 #define RemotePlaySoundFile(_conn, _filename, _bloop) asm { __remotePlaySoundFile(_conn, _filename, _bloop, __RETVAL__) }
7665 #define RemotePlayTone(_conn, _frequency, _duration) asm { __remotePlayTone(_conn, _frequency, _duration, __RETVAL__) }
7666 #define RemoteStopSound(_conn) asm { __connectionWrite(_conn, __DCStopSoundPacket, __RETVAL__) }
7667 #define RemoteKeepAlive(_conn) asm { __connectionWrite(_conn, __DCKeepAlivePacket, __RETVAL__) }
7668 #define RemoteResetScaledValue(_conn, _port) asm { __remoteResetScaledValue(_conn, _port, __RETVAL__) }
7669 #define RemoteResetMotorPosition(_conn, _port, _brelative) asm { __remoteResetMotorPosition(_conn, _port, _brelative, __RETVAL__) }
7670 #define RemoteSetInputMode(_conn, _port, _type, _mode) asm { __remoteSetInputMode(_conn, _port, _type, _mode, __RETVAL__) }
7671 #define RemoteSetOutputState(_conn, _port, _speed, _mode, _regmode, _turnpct, _runstate, _tacholimit) asm { __remoteSetOutputState(_conn, _port, _speed, _mode, _regmode, _turnpct, _runstate, _tacholimit, __RETVAL__) }
7672 #define RemoteResetTachoCount(_conn, _port) asm { __remoteResetTachoCount(_conn, _port, __RETVAL__) }
7673 #define RemoteDatalogSetTimes(_conn, _synctime) asm { __remoteDatalogSetTimes(_conn, _synctime, __RETVAL__) }
7674 #define RemoteSetProperty(_conn, _prop, _value) asm { __remoteSetProperty(_conn, _prop, _value, __RETVAL__) }
7675 #define RemoteLowspeedWrite(_conn, _port, _txlen, _rxlen, _data) asm { __remoteLowspeedWrite(_conn, _port, _txlen, _rxlen, _data, __RETVAL__) }
7676 
7677 #ifdef __ENHANCED_FIRMWARE
7678 #define RemoteGetOutputState(_conn, _params) asm { \
7679   compchktype _params, OutputStateType \
7680   __remoteGetOutputState(_conn, _params, __RETVAL__) \
7681 }
7682 #define RemoteGetInputValues(_conn, _params) asm { \
7683   compchktype _params, InputValuesType \
7684   __remoteGetInputValues(_conn, _params, __RETVAL__) \
7685 }
7686 #define RemoteGetBatteryLevel(_conn, _value) asm { __remoteGetBatteryLevel(_conn, _value, __RETVAL__) }
7687 #define RemoteLowspeedGetStatus(_conn, _value) asm { __remoteLowspeedGetStatus(_conn, _value, __RETVAL__) }
7688 #define RemoteLowspeedRead(_conn, _port, _bread, _data) asm { __remoteLowspeedRead(_conn, _port, _bread, _data, __RETVAL__) }
7689 #define RemoteGetCurrentProgramName(_conn, _name) asm { __remoteGetCurrentProgramName(_conn, _name, __RETVAL__) }
7690 #define RemoteDatalogRead(_conn, _remove, _cnt, _log) asm { __remoteDatalogRead(_conn, _remove, _cnt, _log, __RETVAL__) }
7691 #define RemoteGetContactCount(_conn, _cnt) asm { __remoteGetContactCount(_conn, _cnt, __RETVAL__) }
7692 #define RemoteGetContactName(_conn, _idx, _name) asm { __remoteGetContactName(_conn, _idx, _name, __RETVAL__) }
7693 #define RemoteGetConnectionCount(_conn, _cnt) asm { __remoteGetConnectionCount(_conn, _cnt, __RETVAL__) }
7694 #define RemoteGetConnectionName(_conn, _idx, _name) asm { __remoteGetConnectionName(_conn, _idx, _name, __RETVAL__) }
7695 
7696 #define RemoteGetProperty(_conn, _property, _value) asm { __remoteGetProperty(_conn, _property, _value, __RETVAL__) }
7697 
7698 #else
7699 
7700 #define RemoteGetOutputState(_conn, _port) asm { __remoteGetOutputState(_conn, _port, __RETVAL__) }
7701 #define RemoteGetInputValues(_conn, _port) asm { __remoteGetInputValues(_conn, _port, __RETVAL__) }
7702 #define RemoteGetBatteryLevel(_conn) asm { __remoteGetBatteryLevel(_conn, __RETVAL__) }
7703 #define RemoteLowspeedGetStatus(_conn) asm { __remoteLowspeedGetStatus(_conn, __RETVAL__) }
7704 #define RemoteLowspeedRead(_conn, _port) asm { __remoteLowspeedRead(_conn, _port, __RETVAL__) }
7705 #define RemoteGetCurrentProgramName(_conn) asm { __remoteGetCurrentProgramName(_conn, __RETVAL__) }
7706 #define RemoteDatalogRead(_conn, _remove) asm { __remoteDatalogRead(_conn, _remove, __RETVAL__) }
7707 #define RemoteGetContactCount(_conn) asm { __remoteGetContactCount(_conn, __RETVAL__) }
7708 #define RemoteGetContactName(_conn, _idx) asm { __remoteGetContactName(_conn, _idx, __RETVAL__) }
7709 #define RemoteGetConnectionCount(_conn) asm { __remoteGetConnectionCount(_conn, __RETVAL__) }
7710 #define RemoteGetConnectionName(_conn, _idx) asm { __remoteGetConnectionName(_conn, _idx, __RETVAL__) }
7711 #define RemoteGetProperty(_conn, _property) asm { __remoteGetProperty(_conn, _property, __RETVAL__) }
7712 
7713 #endif
7714 
7715 #ifdef __ENHANCED_FIRMWARE
7716 
7717 #define RemoteOpenRead(_conn, _filename, _handle, _size) asm { __remoteOpenRead(_conn, _filename, _handle, _size, __RETVAL__) }
7718 #define RemoteOpenWrite(_conn, _filename, _size, _handle) asm { __remoteOpenWrite(_conn, _filename, _size, _handle, __RETVAL__) }
7719 #define RemoteRead(_conn, _handle, _numbytes, _data) asm { __remoteRead(_conn, _handle, _numbytes, _data, __RETVAL__) }
7720 #define RemoteWrite(_conn, _handle, _numbytes, _data) asm { __remoteWrite(_conn, _handle, _numbytes, _data, __RETVAL__) }
7721 #define RemoteCloseFile(_conn, _handle) asm { __remoteCloseFile(_conn, _handle, __RETVAL__) }
7722 #define RemoteDeleteFile(_conn, _filename) asm { __remoteDeleteFile(_conn, _filename, __RETVAL__) }
7723 #define RemoteDeleteUserFlash(_conn) asm { __remoteDeleteUserFlash(_conn, __RETVAL__) }
7724 #define RemoteFindFirstFile(_conn, _mask, _handle, _name, _size) asm { __remoteFindFirstFile(_conn, _mask, _handle, _name, _size, __RETVAL__) }
7725 #define RemoteFindNextFile(_conn, _handle, _name, _size) asm { __remoteFindNextFile(_conn, _handle, _name, _size, __RETVAL__) }
7726 #define RemoteGetFirmwareVersion(_conn, _pmin, _pmaj, _fmin, _fmaj) asm { __remoteGetFirmwareVersion(_conn, _pmin, _pmaj, _fmin, _fmaj, __RETVAL__) }
7727 #define RemoteOpenWriteLinear(_conn, _filename, _size, _handle) asm { __remoteOpenWriteLinear(_conn, _filename, _size, _handle, __RETVAL__) }
7728 #define RemoteOpenWriteData(_conn, _filename, _size, _handle) asm { __remoteOpenWriteData(_conn, _filename, _size, _handle, __RETVAL__) }
7729 #define RemoteOpenAppendData(_conn, _filename, _handle, _size) asm { __remoteOpenAppendData(_conn, _filename, _handle, _size, __RETVAL__) }
7730 #define RemoteGetDeviceInfo(_conn, _name, _btaddr, _btsignal, _freemem) asm { __remoteGetDeviceInfo(_conn, _name, _btaddr, _btsignal, _freemem, __RETVAL__) }
7731 #define RemotePollCommandLength(_conn, _bufnum, _length) asm { __remotePollCommandLength(_conn, _bufnum, _length, __RETVAL__) }
7732 #define RemotePollCommand(_conn, _bufnum, _len, _data) asm { __remotePollCommand(_conn, _bufnum, _len, _data, __RETVAL__) }
7733 #define RemoteIOMapRead(_conn, _id, _offset, _numbytes, _data) asm { __remoteIOMapRead(_conn, _id, _offset, _numbytes, _data, __RETVAL__) }
7734 #define RemoteGetBluetoothAddress(_conn, _btaddr) asm { __remoteGetBluetoothAddress(_conn, _btaddr, __RETVAL__) }
7735 
7736 #define RemoteRenameFile(_conn, _oldname, _newname) asm { __remoteRenameFile(_conn, _oldname, _newname, __RETVAL__) }
7737 
7738 #else
7739 
7740 #define RemoteOpenRead(_conn, _filename) asm { __remoteOpenRead(_conn, _filename, __RETVAL__) }
7741 #define RemoteOpenWrite(_conn, _filename, _size) asm { __remoteOpenWrite(_conn, _filename, _size, __RETVAL__) }
7742 #define RemoteRead(_conn, _handle, _numbytes) asm { __remoteRead(_conn, _handle, _numbytes, __RETVAL__) }
7743 #define RemoteWrite(_conn, _handle, _data) asm { __remoteWrite(_conn, _handle, _data, __RETVAL__) }
7744 #define RemoteCloseFile(_conn, _handle) asm { __remoteCloseFile(_conn, _handle, __RETVAL__) }
7745 #define RemoteDeleteFile(_conn, _filename) asm { __remoteDeleteFile(_conn, _filename, __RETVAL__) }
7746 #define RemoteDeleteUserFlash(_conn) asm { __connectionWrite(_conn, __SCDeleteUserFlashPacket, __RETVAL__) }
7747 #define RemoteFindFirstFile(_conn, _mask) asm { __remoteFindFirstFile(_conn, _mask, __RETVAL__) }
7748 #define RemoteFindNextFile(_conn, _handle) asm { __remoteFindNextFile(_conn, _handle, __RETVAL__) }
7749 #define RemoteGetFirmwareVersion(_conn) asm { __connectionWrite(_conn, __SCGetFirmwareVerPacket, __RETVAL__) }
7750 #define RemoteOpenWriteLinear(_conn, _filename, _size) asm { __remoteOpenWriteLinear(_conn, _filename, _size, __RETVAL__) }
7751 #define RemoteOpenWriteData(_conn, _filename, _size) asm { __remoteOpenWriteData(_conn, _filename, _size, __RETVAL__) }
7752 #define RemoteOpenAppendData(_conn, _filename) asm { __remoteOpenAppendData(_conn, _filename, __RETVAL__) }
7753 #define RemoteGetDeviceInfo(_conn) asm { __connectionWrite(_conn, __SCGetDeviceInfoPacket, __RETVAL__) }
7754 #define RemotePollCommandLength(_conn, _bufnum) asm { __remotePollCommandLength(_conn, _bufnum, __RETVAL__) }
7755 #define RemotePollCommand(_conn, _bufnum, _len) asm { __remotePollCommand(_conn, _bufnum, _len, __RETVAL__) }
7756 #define RemoteIOMapRead(_conn, _id, _offset, _numbytes) asm { __remoteIOMapRead(_conn, _id, _offset, _numbytes, __RETVAL__) }
7757 #define RemoteGetBluetoothAddress(_conn) asm { __connectionWrite(_conn, __SCBTGetAddressPacket, __RETVAL__) }
7758 
7759 #endif
7760 
7761 #define RemoteBluetoothFactoryReset(_conn) asm { __connectionWrite(_conn, __SCBTFactoryResetPacket, __RETVAL__) }
7762 #define RemoteIOMapWriteValue(_conn, _id, _offset, _value) asm { __remoteIOMapWriteValue(_conn, _id, _offset, _value, __RETVAL__) }
7763 #define RemoteIOMapWriteBytes(_conn, _id, _offset, _data) asm { __remoteIOMapWriteBytes(_conn, _id, _offset, _data, __RETVAL__) }
7764 #define RemoteSetBrickName(_conn, _name) asm { __remoteSetBrickName(_conn, _name, __RETVAL__) }
7765 
7766 #define UseRS485() asm { __UseRS485() }
7767 
7768 #ifdef __ENHANCED_FIRMWARE
7769 
7770 #define RS485Status(_sendingData, _dataAvail) asm { __RS485Status(_sendingData, _dataAvail) }
7771 #define RS485SendingData() asm { __RS485Status(__RETVAL__, __TMPBYTE__) }
7772 #define RS485DataAvailable() asm { __RS485Status(__TMPBYTE__, __RETVAL__) }
7773 #define RS485Write(_buffer) asm { __RS485Write(_buffer, __RETVAL__) }
7774 #define RS485Read(_buffer) asm { __RS485Read(_buffer, __RETVAL__) }
7775 
7776 #if __FIRMWARE_VERSION > 107
7777 
7778 #define RS485Control(_cmd, _baud, _mode) asm { __RS485Control(_cmd, _baud, _mode, __RETVAL__) }
7779 #define RS485Uart(_baud, _mode) asm { __RS485Control(HS_CTRL_UART, _baud, _mode, __RETVAL__) }
7780 #define RS485Initialize() asm { __RS485Control(HS_CTRL_UART, HS_BAUD_DEFAULT, HS_MODE_DEFAULT, __RETVAL__) }
7781 #define RS485Enable() asm { __RS485Control(HS_CTRL_INIT, HS_BAUD_DEFAULT, HS_MODE_DEFAULT, __RETVAL__) }
7782 #define RS485Disable() asm { __RS485Control(HS_CTRL_EXIT, HS_BAUD_DEFAULT, HS_MODE_DEFAULT, __RETVAL__) }
7783 
7784 #else
7785 
7786 #define RS485Control(_cmd, _baud) asm { __RS485Control(_cmd, _baud, __RETVAL__) }
7787 #define RS485Uart(_baud) asm { __RS485Control(HS_CTRL_UART, _baud, __RETVAL__) }
7788 #define RS485Initialize() asm { __RS485Control(HS_CTRL_UART, HS_BAUD_DEFAULT, __RETVAL__) }
7789 #define RS485Enable() asm { __RS485Control(HS_CTRL_INIT, HS_BAUD_DEFAULT, __RETVAL__) }
7790 #define RS485Disable() asm { __RS485Control(HS_CTRL_EXIT, HS_BAUD_DEFAULT, __RETVAL__) }
7791 
7792 #endif
7793 
7794 #define SendRS485Bool(_bval) asm { __sendRS485Bool(_bval, __RETVAL__) }
7795 #define SendRS485Number(_val) asm { __sendRS485Number(_val, __RETVAL__) }
7796 #define SendRS485String(_str) asm { __sendRS485String(_str, __RETVAL__) }
7797 
7798 #endif
7799 
7800 #define GetBTInputBuffer(_offset, _cnt, _data) asm { __getBTInputBuffer(_offset, _cnt, _data) }
7801 #define GetBTOutputBuffer(_offset, _cnt, _data) asm { __getBTOutputBuffer(_offset, _cnt, _data) }
7802 #define GetHSInputBuffer(_offset, _cnt, _data) asm { __getHSInputBuffer(_offset, _cnt, _data) }
7803 #define GetHSOutputBuffer(_offset, _cnt, _data) asm { __getHSOutputBuffer(_offset, _cnt, _data) }
7804 #define GetUSBInputBuffer(_offset, _cnt, _data) asm { __getUSBInputBuffer(_offset, _cnt, _data) }
7805 #define GetUSBOutputBuffer(_offset, _cnt, _data) asm { __getUSBOutputBuffer(_offset, _cnt, _data) }
7806 #define GetUSBPollBuffer(_offset, _cnt, _data) asm { __getUSBPollBuffer(_offset, _cnt, _data) }
7807 
7808 #define BTDeviceName(_p) asm { GetBTDeviceName(_p, __STRRETVAL__) }
7809 #define BTConnectionName(_p) asm { GetBTConnectionName(_p, __STRRETVAL__) }
7810 #define BTConnectionPinCode(_p) asm { GetBTConnectionPinCode(_p, __STRRETVAL__) }
7811 #define BrickDataName() asm { GetBrickDataName(__STRRETVAL__) }
7812 
7813 #define GetBTDeviceAddress(_p, _data) asm { __getBTDeviceAddress(_p, _data) }
7814 #define GetBTConnectionAddress(_p, _data) asm { __getBTConnectionAddress(_p, _data) }
7815 #define GetBrickDataAddress(_data) asm { __getCommModuleBytes(CommOffsetBrickDataBdAddr, 7, _data) }
7816 
7817 #define BTDeviceClass(_p) asm { GetBTDeviceClass(_p, __TMPLONG__) __RETURN__ __TMPLONG__ }
7818 #define BTDeviceStatus(_p) asm { GetBTDeviceStatus(_p, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
7819 #define BTConnectionClass(_p) asm { GetBTConnectionClass(_p, __TMPLONG__) __RETURN__ __TMPLONG__ }
7820 #define BTConnectionHandleNum(_p) asm { GetBTConnectionHandleNum(_p, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
7821 #define BTConnectionStreamStatus(_p) asm { GetBTConnectionStreamStatus(_p, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
7822 #define BTConnectionLinkQuality(_p) asm { GetBTConnectionLinkQuality(_p, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
7823 #define BrickDataBluecoreVersion() asm { GetBrickDataBluecoreVersion(__TMPWORD__) __RETURN__ __TMPWORD__ }
7824 #define BrickDataBtStateStatus() asm { GetBrickDataBtStateStatus(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7825 #define BrickDataBtHardwareStatus() asm { GetBrickDataBtHardwareStatus(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7826 #define BrickDataTimeoutValue() asm { GetBrickDataTimeoutValue(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7827 #define BTInputBufferInPtr() asm { GetBTInputBufferInPtr(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7828 #define BTInputBufferOutPtr() asm { GetBTInputBufferOutPtr(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7829 #define BTOutputBufferInPtr() asm { GetBTOutputBufferInPtr(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7830 #define BTOutputBufferOutPtr() asm { GetBTOutputBufferOutPtr(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7831 #define HSInputBufferInPtr() asm { GetHSInputBufferInPtr(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7832 #define HSInputBufferOutPtr() asm { GetHSInputBufferOutPtr(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7833 #define HSOutputBufferInPtr() asm { GetHSOutputBufferInPtr(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7834 #define HSOutputBufferOutPtr() asm { GetHSOutputBufferOutPtr(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7835 #define USBInputBufferInPtr() asm { GetUSBInputBufferInPtr(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7836 #define USBInputBufferOutPtr() asm { GetUSBInputBufferOutPtr(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7837 #define USBOutputBufferInPtr() asm { GetUSBOutputBufferInPtr(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7838 #define USBOutputBufferOutPtr() asm { GetUSBOutputBufferOutPtr(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7839 #define USBPollBufferInPtr() asm { GetUSBPollBufferInPtr(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7840 #define USBPollBufferOutPtr() asm { GetUSBPollBufferOutPtr(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7841 #define BTDeviceCount() asm { GetBTDeviceCount(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7842 #define BTDeviceNameCount() asm { GetBTDeviceNameCount(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7843 #define HSFlags() asm { GetHSFlags(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7844 #define HSSpeed() asm { GetHSSpeed(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7845 #define HSState() asm { GetHSState(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7846 #define USBState() asm { GetUSBState(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7847 
7848 #if (__FIRMWARE_VERSION > 107) && defined(__ENHANCED_FIRMWARE)
7849 #define HSMode() asm { GetHSMode(__TMPWORD__) __RETURN__ __TMPWORD__ }
7850 #define BTDataMode() asm { GetBTDataMode(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7851 #define HSDataMode() asm { GetHSDataMode(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
7852 #endif
7853 
7854 #define SetBTDeviceName(_p, _str) asm { __setBTDeviceName(_p, _str) }
7855 #define SetBTDeviceAddress(_p, _btaddr) asm { __setBTDeviceAddress(_p, _btaddr) }
7856 #define SetBTConnectionName(_p, _str) asm { __setBTConnectionName(_p, _str) }
7857 #define SetBTConnectionPinCode(_p, _code) asm { __setBTConnectionPinCode(_p, _code) }
7858 #define SetBTConnectionAddress(_p, _btaddr) asm { __setBTConnectionAddress(_p, _btaddr) }
7859 #define SetBrickDataName(_str) SetCommModuleBytes(CommOffsetBrickDataName, 16, _str)
7860 #define SetBrickDataAddress(_btaddr) SetCommModuleBytes(CommOffsetBrickDataBdAddr, 7, _btaddr)
7861 
7862 #define SetBTDeviceClass(_p, _n) asm { __setBTDeviceClass(_p, _n) }
7863 #define SetBTDeviceStatus(_p, _n) asm { __setBTDeviceStatus(_p, _n) }
7864 #define SetBTConnectionClass(_p, _n) asm { __setBTConnectionClass(_p, _n) }
7865 #define SetBTConnectionHandleNum(_p, _n) asm { __setBTConnectionHandleNum(_p, _n) }
7866 #define SetBTConnectionStreamStatus(_p, _n) asm { __setBTConnectionStreamStatus(_p, _n) }
7867 #define SetBTConnectionLinkQuality(_p, _n) asm { __setBTConnectionLinkQuality(_p, _n) }
7868 #define SetBrickDataBluecoreVersion(_n) asm { __setBrickDataBluecoreVersion(_n) }
7869 #define SetBrickDataBtStateStatus(_n) asm { __setBrickDataBtStateStatus(_n) }
7870 #define SetBrickDataBtHardwareStatus(_n) asm { __setBrickDataBtHardwareStatus(_n) }
7871 #define SetBrickDataTimeoutValue(_n) asm { __setBrickDataTimeoutValue(_n) }
7872 
7873 #define SetBTDeviceCount(_n) asm { __setBTDeviceCount(_n) }
7874 #define SetBTDeviceNameCount(_n) asm { __setBTDeviceNameCount(_n) }
7875 
7876 #define SetBTInputBuffer(_offset, _cnt, _data) asm { __setBTInputBuffer(_offset, _cnt, _data) }
7877 
7878 #define SetBTInputBufferInPtr(_n) asm { __setBTInputBufferInPtr(_n) }
7879 #define SetBTInputBufferOutPtr(_n) asm { __setBTInputBufferOutPtr(_n) }
7880 
7881 #define SetBTOutputBuffer(_offset, _cnt, _data) asm { __setBTOutputBuffer(_offset, _cnt, _data) }
7882 
7883 #define SetBTOutputBufferInPtr(_n) asm { __setBTOutputBufferInPtr(_n) }
7884 #define SetBTOutputBufferOutPtr(_n) asm { __setBTOutputBufferOutPtr(_n) }
7885 
7886 #define SetHSInputBuffer(_offset, _cnt, _data) asm { __setHSInputBuffer(_offset, _cnt, _data) }
7887 
7888 #define SetHSInputBufferInPtr(_n) asm { __setHSInputBufferInPtr(_n) }
7889 #define SetHSInputBufferOutPtr(_n) asm { __setHSInputBufferOutPtr(_n) }
7890 
7891 #define SetHSOutputBuffer(_offset, _cnt, _data) asm { __setHSOutputBuffer(_offset, _cnt, _data) }
7892 
7893 #define SetHSOutputBufferInPtr(_n) asm { __setHSOutputBufferInPtr(_n) }
7894 #define SetHSOutputBufferOutPtr(_n) asm { __setHSOutputBufferOutPtr(_n) }
7895 
7896 #define SetUSBInputBuffer(_offset, _cnt, _data) asm { __setUSBInputBuffer(_offset, _cnt, _data) }
7897 
7898 #define SetUSBInputBufferInPtr(_n) asm { __setUSBInputBufferInPtr(_n) }
7899 #define SetUSBInputBufferOutPtr(_n) asm { __setUSBInputBufferOutPtr(_n) }
7900 
7901 #define SetUSBOutputBuffer(_offset, _cnt, _data) asm { __setUSBOutputBuffer(_offset, _cnt, _data) }
7902 
7903 #define SetUSBOutputBufferInPtr(_n) asm { __setUSBOutputBufferInPtr(_n) }
7904 #define SetUSBOutputBufferOutPtr(_n) asm { __setUSBOutputBufferOutPtr(_n) }
7905 
7906 #define SetUSBPollBuffer(_offset, _cnt, _data) asm { __setUSBPollBuffer(_offset, _cnt, _data) }
7907 
7908 #define SetUSBPollBufferInPtr(_n) asm { __setUSBPollBufferInPtr(_n) }
7909 #define SetUSBPollBufferOutPtr(_n) asm { __setUSBPollBufferOutPtr(_n) }
7910 
7911 #define SetHSFlags(_n) asm { __setHSFlags(_n) }
7912 #define SetHSSpeed(_n) asm { __setHSSpeed(_n) }
7913 #define SetHSState(_n) asm { __setHSState(_n) }
7914 #define SetUSBState(_n) asm { __setUSBState(_n) }
7915 
7916 #if (__FIRMWARE_VERSION > 107) && defined(__ENHANCED_FIRMWARE)
7917 #define SetBTDataMode(_n) asm { __setBTDataMode(_n) }
7918 #define SetHSDataMode(_n) asm { __setHSDataMode(_n) }
7919 #endif
7920 
7921 #define SysMessageWrite(_args) asm { \
7922   compchktype _args, MessageWriteType \
7923   syscall MessageWrite, _args \
7924 }
7925 #define SysMessageRead(_args) asm { \
7926   compchktype _args, MessageReadType \
7927   syscall MessageRead, _args \
7928 }
7929 #define SysCommBTWrite(_args) asm { \
7930   compchktype _args, CommBTWriteType \
7931   syscall CommBTWrite, _args \
7932 }
7933 #define SysCommBTCheckStatus(_args) asm { \
7934   compchktype _args, CommBTCheckStatusType \
7935   syscall CommBTCheckStatus, _args \
7936 }
7937 #ifdef __ENHANCED_FIRMWARE
7938 #define SysCommExecuteFunction(_args) asm { \
7939   compchktype _args, CommExecuteFunctionType \
7940   syscall CommExecuteFunction, _args \
7941 }
7942 #define SysCommHSControl(_args) asm { \
7943   compchktype _args, CommHSControlType \
7944   syscall CommHSControl, _args \
7945 }
7946 #define SysCommHSCheckStatus(_args) asm { \
7947   compchktype _args, CommHSCheckStatusType \
7948   syscall CommHSCheckStatus, _args \
7949 }
7950 #define SysCommHSRead(_args) asm { \
7951   compchktype _args, CommHSReadWriteType \
7952   syscall CommHSRead, _args \
7953 }
7954 #define SysCommHSWrite(_args) asm { \
7955   compchktype _args, CommHSReadWriteType \
7956   syscall CommHSWrite, _args \
7957 }
7958 #endif
7959 #if __FIRMWARE_VERSION > 107
7960 #define SysCommBTOnOff(_args) asm { \
7961   compchktype _args, CommBTOnOffType \
7962   syscall CommBTOnOff, _args \
7963 }
7964 #define SysCommBTConnection(_args) asm { \
7965   compchktype _args, CommBTConnectionType \
7966   syscall CommBTConnection, _args \
7967 }
7968 #endif
7969 
7970 #endif
7971 /** @} */ // end of CommModuleFunctions group
7972 /** @} */ // end of CommModule group
7973 /** @} */ // end of NXTFirmwareModules group
7974 
7975 
7976 ///////////////////////////////////////////////////////////////////////////////
7977 //////////////////////////////// BUTTON MODULE ////////////////////////////////
7978 ///////////////////////////////////////////////////////////////////////////////
7979 
7980 
7981 /** @addtogroup NXTFirmwareModules
7982  * @{
7983  */
7984 /** @addtogroup ButtonModule
7985  * @{
7986  */
7987 /** @defgroup ButtonModuleTypes Button module types
7988  * Types used by various Button module functions.
7989  * @{
7990  */
7991 /**
7992  * Parameters for the ReadButton system call.
7993  * This structure is used when calling the \ref SysReadButton system call
7994  * function.
7995  * \sa SysReadButton()
7996  */
7997 struct ReadButtonType {
7998   char Result;   /*!< The function call result, \ref ERR_INVALID_PORT or \ref NO_ERR. */
7999   byte Index;    /*!< The requested button index. See the \ref ButtonNameConstants group. */
8000   bool Pressed;  /*!< The returned button state. */
8001   byte Count;    /*!< The returned button pressed count. */
8002   bool Reset;    /*!< If true, the count is reset after reading. */
8003 };
8004 /** @} */ // end of ButtonModuleTypes group
8005 /** @defgroup ButtonModuleFunctions Button module functions
8006  * Functions for accessing and modifying Button module features.
8007  * @{
8008  */
8009 
8010 #ifdef __DOXYGEN_DOCS
8011 
8012 /**
8013  * Check for button press.
8014  * This function checks whether the specified button is pressed or not. You may
8015  * optionally reset the press count.
8016  *
8017  * \param btn The button to check. See \ref ButtonNameConstants.
8018  * \param resetCount Whether or not to reset the press counter.
8019  * \return A boolean value indicating whether the button is pressed or not.
8020  */
8021 inline bool ButtonPressed(const byte btn, bool resetCount);
8022 
8023 /**
8024  * Get button press count.
8025  * Return the number of times the specified button has been pressed since
8026  * the last time the button press count was reset. Optionally clear the count
8027  * after reading it.
8028  *
8029  * \param btn The button to check. See \ref ButtonNameConstants.
8030  * \param resetCount Whether or not to reset the press counter.
8031  * \return The button press count.
8032  */
8033 inline byte ButtonCount(const byte btn, bool resetCount);
8034 
8035 /**
8036  * Read button information.
8037  * Read the specified button. Set the pressed and count parameters with the
8038  * current state of the button. Optionally reset the press count after
8039  * reading it.
8040  *
8041  * \param btn The button to check. See \ref ButtonNameConstants.
8042  * \param reset Whether or not to reset the press counter.
8043  * \param pressed The button pressed state.
8044  * \param count The button press count.
8045  * \return The function call result.
8046  */
8047 inline char ReadButtonEx(const byte btn, bool reset, bool & pressed, unsigned int & count);
8048 
8049 /**
8050  * Get button press count.
8051  * Return the press count of the specified button.
8052  * \param btn The button to check. See \ref ButtonNameConstants.
8053  * \return The button press count.
8054  */
8055 inline byte ButtonPressCount(const byte btn);
8056 
8057 /**
8058  * Get button long press count.
8059  * Return the long press count of the specified button.
8060  *
8061  * \param btn The button to check. See \ref ButtonNameConstants.
8062  * \return The button long press count.
8063  */
8064 inline byte ButtonLongPressCount(const byte btn);
8065 
8066 /**
8067  * Get button short release count.
8068  * Return the short release count of the specified button.
8069  *
8070  * \param btn The button to check. See \ref ButtonNameConstants.
8071  * \return The button short release count.
8072  */
8073 inline byte ButtonShortReleaseCount(const byte btn);
8074 
8075 /**
8076  * Get button long release count.
8077  * Return the long release count of the specified button.
8078  *
8079  * \param btn The button to check. See \ref ButtonNameConstants.
8080  * \return The button long release count.
8081  */
8082 inline byte ButtonLongReleaseCount(const byte btn);
8083 
8084 /**
8085  * Get button release count.
8086  * Return the release count of the specified button.
8087  *
8088  * \param btn The button to check. See \ref ButtonNameConstants.
8089  * \return The button release count.
8090 */
8091 inline byte ButtonReleaseCount(const byte btn);
8092 
8093 /**
8094  * Get button state.
8095  * Return the state of the specified button. See \ref ButtonStateConstants.
8096  *
8097  * \param btn The button to check. See \ref ButtonNameConstants.
8098  * \return The button state.
8099  */
8100 inline byte ButtonState(const byte btn);
8101 
8102 /**
8103  * Set button long press count.
8104  * Set the long press count of the specified button.
8105  *
8106  * \param btn The button number. See \ref ButtonNameConstants.
8107  * \param n The new long press count value.
8108  */
8109 inline void SetButtonLongPressCount(const byte btn, const byte n);
8110 
8111 /**
8112  * Set button long release count.
8113  * Set the long release count of the specified button.
8114  *
8115  * \param btn The button number. See \ref ButtonNameConstants.
8116  * \param n The new long release count value.
8117  */
8118 inline void SetButtonLongReleaseCount(const byte btn, const byte n);
8119 
8120 /**
8121  * Set button press count.
8122  * Set the press count of the specified button.
8123  *
8124  * \param btn The button number. See \ref ButtonNameConstants.
8125  * \param n The new press count value.
8126  */
8127 inline void SetButtonPressCount(const byte btn, const byte n);
8128 
8129 /**
8130  * Set button release count.
8131  * Set the release count of the specified button.
8132  *
8133  * \param btn The button number. See \ref ButtonNameConstants.
8134  * \param n The new release count value.
8135  */
8136 inline void SetButtonReleaseCount(const byte btn, const byte n);
8137 
8138 /**
8139  * Set button short release count.
8140  * Set the short release count of the specified button.
8141  *
8142  * \param btn The button number. See \ref ButtonNameConstants.
8143  * \param n The new short release count value.
8144  */
8145 inline void SetButtonShortReleaseCount(const byte btn, const byte n);
8146 
8147 /**
8148  * Set button state.
8149  * Set the state of the specified button.
8150  *
8151  * \param btn The button to check. See \ref ButtonNameConstants.
8152  * \param state The new button state. See \ref ButtonStateConstants.
8153 */
8154 inline void SetButtonState(const byte btn, const byte state);
8155 
8156 /**
8157  * Read button.
8158  * This function lets you read button state information via the \ref
8159  * ReadButtonType structure.
8160  *
8161  * \param args The ReadButtonType structure containing the needed parameters.
8162  */
8163 inline void SysReadButton(ReadButtonType & args);
8164 
8165 #else
8166 
8167 #define ButtonPressCount(_b) asm { GetButtonPressCount(_b, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
8168 #define ButtonLongPressCount(_b) asm { GetButtonLongPressCount(_b, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
8169 #define ButtonShortReleaseCount(_b) asm { GetButtonShortReleaseCount(_b, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
8170 #define ButtonLongReleaseCount(_b) asm { GetButtonLongReleaseCount(_b, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
8171 #define ButtonReleaseCount(_b) asm { GetButtonReleaseCount(_b, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
8172 #define ButtonState(_b) asm { GetButtonState(_b, __TMPBYTE__) __RETURN__ __TMPBYTE__ }
8173 
8174 #define SetButtonPressCount(_b, _n) asm { __setButtonPressCount(_b, _n) }
8175 #define SetButtonLongPressCount(_b, _n) asm { __setButtonLongPressCount(_b, _n) }
8176 #define SetButtonShortReleaseCount(_b, _n) asm { __setButtonShortReleaseCount(_b, _n) }
8177 #define SetButtonLongReleaseCount(_b, _n) asm { __setButtonLongReleaseCount(_b, _n) }
8178 #define SetButtonReleaseCount(_b, _n) asm { __setButtonReleaseCount(_b, _n) }
8179 #define SetButtonState(_b, _n) asm { __setButtonState(_b, _n) }
8180 
8181 #define SysReadButton(_args) asm { \
8182   compchktype _args, ReadButtonType \
8183   syscall ReadButton, _args \
8184 }
8185 #endif
8186 /** @} */ // end of ButtonModuleFunctions group
8187 /** @} */ // end of ButtonModule group
8188 /** @} */ // end of NXTFirmwareModules group
8189 
8190 
8191 ///////////////////////////////////////////////////////////////////////////////
8192 ////////////////////////////////// UI MODULE //////////////////////////////////
8193 ///////////////////////////////////////////////////////////////////////////////
8194 
8195 
8196 /** @addtogroup NXTFirmwareModules
8197  * @{
8198  */
8199 /** @addtogroup UiModule
8200  * @{
8201  */
8202 /** @defgroup UiModuleTypes Ui module types
8203  * Types used by various Ui module functions.
8204  * @{
8205  */
8206 
8207 #if __FIRMWARE_VERSION > 107
8208 /**
8209  * Parameters for the SetSleepTimeout system call.
8210  * This structure is used when calling the \ref SysSetSleepTimeout system call
8211  * function.
8212  * \sa SysSetSleepTimeout()
8213  */
8214 struct SetSleepTimeoutType {
8215  char Result;                     /*!< The result of the system call function. */
8216  unsigned long TheSleepTimeoutMS; /*!< The new sleep timeout value in milliseconds. */
8217 };
8218 #endif
8219 
8220 /** @} */ // end of UiModuleTypes group
8221 /** @defgroup UiModuleFunctions Ui module functions
8222  * Functions for accessing and modifying Ui module features.
8223  * @{
8224  */
8225 
8226 #ifdef __DOXYGEN_DOCS
8227 
8228 /**
8229  * Get command flags.
8230  * Return the command flags.
8231  * \return Command flags. See \ref UiFlagsConstants
8232  */
8233 inline byte CommandFlags(void);
8234 
8235 /**
8236  * Get UI module state.
8237  * Return the user interface state.
8238  * \return The UI module state. See \ref UiStateConstants.
8239  */
8240 inline byte UIState(void);
8241 
8242 /**
8243  * Read UI button.
8244  * Return user interface button information.
8245  * \return A UI button value.  See \ref UiButtonConstants.
8246  */
8247 inline byte UIButton(void);
8248 
8249 /**
8250  * Read VM run state.
8251  * Return VM run state information.
8252  * \return VM run state. See \ref UiVMRunStateConstants.
8253  */
8254 inline byte VMRunState(void);
8255 
8256 /**
8257  * Get battery state.
8258  * Return battery state information (0..4).
8259  * \return The battery state (0..4)
8260  */
8261 inline byte BatteryState(void);
8262 
8263 /**
8264  * Get bluetooth state.
8265  * Return the bluetooth state.
8266  * \return The bluetooth state. See \ref UiBluetoothStateConstants.
8267  */
8268 inline byte BluetoothState(void);
8269 
8270 /**
8271  * Get UI module USB state.
8272  * This method returns the UI module USB state.
8273  * \return The UI module USB state.  (0=disconnected, 1=connected, 2=working)
8274  */
8275 inline byte UsbState(void);
8276 
8277 /**
8278  * Read sleep timeout.
8279  * Return the number of minutes that the NXT will remain on before
8280  * it automatically shuts down.
8281  * \return The sleep timeout value
8282  */
8283 inline byte SleepTimeout(void);
8284 
8285 /**
8286  * Read sleep time.
8287  * Return the number of minutes that the NXT will remain on before
8288  * it automatically shuts down.
8289  * \return The sleep time value
8290  * \sa SleepTimeout
8291  */
8292 inline byte SleepTime(void);
8293 
8294 /**
8295  * Read sleep timer.
8296  * Return the number of minutes left in the countdown to zero from the
8297  * original SleepTimeout value. When the SleepTimer value reaches zero the
8298  * NXT will shutdown.
8299  * \return The sleep timer value
8300  */
8301 inline byte SleepTimer(void);
8302 
8303 /**
8304  * Read battery type.
8305  * Return whether the NXT has a rechargeable battery installed or not.
8306  * \return Whether the battery is rechargeable or not. (false = no, true = yes)
8307  */
8308 inline bool RechargeableBattery(void);
8309 
8310 /**
8311  * Read volume.
8312  * Return the user interface volume level. Valid values are from 0 to 4.
8313  * \return The UI module volume. (0..4)
8314  */
8315 inline byte Volume(void);
8316 
8317 /**
8318  * Read the on brick program pointer value.
8319  * Return the current OBP (on-brick program) step
8320  *
8321  * \return On brick program pointer (step).
8322  */
8323 inline byte OnBrickProgramPointer(void);
8324 
8325 /**
8326  * Read abort flag.
8327  * Return the enhanced NBC/NXC firmware's abort flag.
8328  *
8329  * \return The current abort flag value.  See \ref ButtonStateConstants.
8330  * \warning This function requires the enhanced NBC/NXC firmware.
8331 */
8332 inline byte AbortFlag(void);
8333 
8334 /**
8335  * Read long abort setting.
8336  * Return the enhanced NBC/NXC firmware's long abort setting.
8337  *
8338  * \sa AbortFlag
8339  * \return The current abort flag value.  See \ref ButtonStateConstants.
8340  * \warning This function requires the enhanced NBC/NXC firmware.
8341 */
8342 inline byte LongAbort(void);
8343 
8344 /**
8345  * Get battery Level.
8346  * Return the battery level in millivolts.
8347  * \return The battery level
8348  */
8349 inline unsigned int BatteryLevel(void);
8350 
8351 /**
8352  * Set command flags.
8353  * Set the command flags.
8354  *
8355  * \param cmdFlags The new command flags. See \ref UiFlagsConstants.
8356  */
8357 inline void SetCommandFlags(const byte cmdFlags);
8358 
8359 /**
8360  * Set UI button.
8361  * Set user interface button information.
8362  *
8363  * \param btn A user interface button value. See \ref UiButtonConstants.
8364  */
8365 inline void SetUIButton(byte btn);
8366 
8367 /**
8368  * Set UI state.
8369  * Set the user interface state.
8370  *
8371  * \param state A user interface state value. See \ref UiStateConstants.
8372  */
8373 inline void SetUIState(byte state);
8374 
8375 /**
8376  * Set VM run state.
8377  * Set VM run state information.
8378  *
8379  * \param vmRunState The desired VM run state. See \ref UiVMRunStateConstants.
8380  *
8381  * \warning It is not a good idea to change the VM run state from within a
8382  * running program unless you know what you are doing.
8383  */
8384 inline void SetVMRunState(const byte vmRunState);
8385 
8386 /**
8387  * Set battery state.
8388  * Set battery state information.
8389  *
8390  * \param state The desired battery state (0..4).
8391  */
8392 inline void SetBatteryState(byte state);
8393 
8394 /**
8395  * Set bluetooth state.
8396  * Set the Bluetooth state.
8397  *
8398  * \param state The desired bluetooth state. See \ref UiBluetoothStateConstants.
8399  */
8400 inline void SetBluetoothState(byte state);
8401 
8402 /**
8403  * Set sleep timeout.
8404  * Set the NXT sleep timeout value to the specified number of minutes.
8405  *
8406  * \param n The minutes to wait before sleeping.
8407  */
8408 inline void SetSleepTimeout(const byte n);
8409 
8410 /**
8411  * Set sleep time.
8412  * Set the NXT sleep timeout value to the specified number of minutes.
8413  *
8414  * \param n The minutes to wait before sleeping.
8415  * \sa SetSleepTimeout, SleepTimeout
8416  */
8417 inline void SetSleepTime(const byte n);
8418 
8419 /**
8420  * Set the sleep timer.
8421  * Set the system sleep timer to the specified number of minutes.
8422  *
8423  * \param n The minutes left on the timer.
8424  */
8425 inline void SetSleepTimer(const byte n);
8426 
8427 /**
8428  * Set volume.
8429  * Set the user interface volume level. Valid values are from 0 to 4.
8430  *
8431  * \param volume The new volume level.
8432  */
8433 inline void SetVolume(byte volume);
8434 
8435 /**
8436  * Set on-brick program pointer.
8437  * Set the current OBP (on-brick program) step.
8438  *
8439  * \param obpStep The new on-brick program step.
8440  */
8441 inline void SetOnBrickProgramPointer(byte obpStep);
8442 
8443 /**
8444  * Turn off NXT.
8445  * Force the NXT to turn off if the specified value is greater than zero.
8446  * \param num If greater than zero the NXT will turn off.
8447 */
8448 inline void ForceOff(byte num);
8449 
8450 /**
8451  * Set abort flag.
8452  * Set the enhanced NBC/NXC firmware's program abort flag. By default the
8453  * running program can be interrupted by a short press of the escape button.
8454  * You can change this to any other button state flag.
8455  *
8456  * \param abortFlag The new abort flag value. See \ref ButtonStateConstants
8457  *
8458  * \warning This function requires the enhanced NBC/NXC firmware.
8459  */
8460 inline void SetAbortFlag(byte abortFlag);
8461 
8462 /**
8463  * Set long abort.
8464  * Set the enhanced NBC/NXC firmware's long abort setting (true or false). If
8465  * set to true then a program has access the escape button. Aborting a program
8466  * requires a long press of the escape button.
8467  *
8468  * \param longAbort If true then require a long press of the escape button
8469  * to abort a program, otherwise a short press will abort it.
8470  *
8471  * \warning This function requires the enhanced NBC/NXC firmware.
8472  */
8473 inline void SetLongAbort(bool longAbort);
8474 
8475 #if __FIRMWARE_VERSION > 107
8476 /**
8477  * Set system sleep timeout.
8478  * This function lets you set the system sleep timeout value given the parameters you
8479  * pass in via the \ref SetSleepTimeoutType structure.
8480  *
8481  * \param args The SetSleepTimeoutType structure containing the required parameters.
8482  *
8483  * \warning This function requires an NXT 2.0 compatible firmware.
8484  */
8485 inline void SysSetSleepTimeout(SetSleepTimeoutType & args);
8486 #endif
8487 
8488 #else
8489 
8490 #define CommandFlags() asm { GetCommandFlags(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
8491 #define UIState() asm { GetUIState(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
8492 #define UIButton() asm { GetUIButton(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
8493 #define VMRunState() asm { GetVMRunState(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
8494 #define BatteryState() asm { GetBatteryState(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
8495 #define BluetoothState() asm { GetBluetoothState(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
8496 #define UsbState() asm { GetUsbState(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
8497 #define SleepTimeout() asm { GetSleepTimeout(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
8498 #define SleepTime() SleepTimeout()
8499 #define SleepTimer() asm { GetSleepTimer(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
8500 #define RechargeableBattery() asm { GetRechargeableBattery(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
8501 #define Volume() asm { GetVolume(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
8502 #define OnBrickProgramPointer() asm { GetOnBrickProgramPointer(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
8503 #define AbortFlag() asm { GetAbortFlag(__TMPBYTE__) __RETURN__ __TMPBYTE__ }
8504 #define LongAbort() AbortFlag()
8505 #define BatteryLevel() asm { GetBatteryLevel(__TMPWORD__) __RETURN__ __TMPWORD__ }
8506 
8507 #define SetCommandFlags(_n) asm { __setCommandFlags(_n) }
8508 #define SetUIState(_n) asm { __setUIState(_n) }
8509 #define SetUIButton(_n) asm { __setUIButton(_n) }
8510 #define SetVMRunState(_n) asm { __setVMRunState(_n) }
8511 #define SetBatteryState(_n) asm { __setBatteryState(_n) }
8512 #define SetBluetoothState(_n) asm { __setBluetoothState(_n) }
8513 #define SetUsbState(_n) asm { __setUsbState(_n) }
8514 #define SetSleepTimeout(_n) asm { __setSleepTimeout(_n) }
8515 #define SetSleepTime(_n) SetSleepTimeout(_n)
8516 #define SetSleepTimer(_n) asm { __setSleepTimer(_n) }
8517 #define SetVolume(_n) asm { __setVolume(_n) }
8518 #define SetOnBrickProgramPointer(_n) asm { __setOnBrickProgramPointer(_n) }
8519 #define ForceOff(_n) asm { __forceOff(_n) }
8520 #define SetAbortFlag(_n) asm { __setAbortFlag(_n) }
8521 #define SetLongAbort(_n) do { \
8522   if (_n) { \
8523     asm { __setAbortFlag(BTNSTATE_LONG_PRESSED_EV) } \
8524   } else { \
8525     asm { __setAbortFlag(BTNSTATE_PRESSED_EV) } \
8526   } \
8527 } while(false)
8528 
8529 #if __FIRMWARE_VERSION > 107
8530 #define SysSetSleepTimeout(_args) asm { \
8531   compchktype _args, SetSleepTimeoutType \
8532   syscall SetSleepTimeoutVal, _args \
8533 }
8534 #endif
8535 
8536 #endif
8537 /** @} */ // end of UiModuleFunctions group
8538 /** @} */ // end of UiModule group
8539 /** @} */ // end of NXTFirmwareModules group
8540 
8541 
8542 ///////////////////////////////////////////////////////////////////////////////
8543 //////////////////////////////// LOADER MODULE ////////////////////////////////
8544 ///////////////////////////////////////////////////////////////////////////////
8545 
8546 
8547 /** @addtogroup NXTFirmwareModules
8548  * @{
8549  */
8550 /** @addtogroup LoaderModule
8551  * @{
8552  */
8553 /** @defgroup LoaderModuleTypes Loader module types
8554  * Types used by various Loader module functions.
8555  * @{
8556  */
8557 /**
8558  * Parameters for the FileOpen system call.
8559  * This structure is used when calling the \ref SysFileOpenAppend, \ref
8560  * SysFileOpenRead, \ref SysFileOpenWrite, \ref SysFileOpenReadLinear,
8561  * \ref SysFileOpenWriteLinear and \ref SysFileOpenWriteNonLinear system call
8562  * functions.
8563  * \sa SysFileOpenAppend(), SysFileOpenRead(), SysFileOpenWrite(),
8564  * SysFileOpenReadLinear(), SysFileOpenWriteLinear()
8565  */
8566 struct FileOpenType {
8567   unsigned int Result;    /*!< The function call result. Possible values
8568                             include \ref LoaderErrors. */
8569   byte FileHandle;        /*!< The returned file handle to use for subsequent
8570                             file operations. */
8571   string Filename;        /*!< The name of the file to open or create. */
8572   unsigned long Length;   /*!< For SysFileOpenWrite(),
8573                             SysFileOpenWriteLinear() and
8574                             SysFileOpenWriteNonLinear(): the desired maximum
8575                             file capacity.
8576 
8577                             For SysFileOpenAppend(), SysFileOpenRead() and
8578                             SysFileOpenReadLinear(): the returned available
8579                             length in the file. */
8580 };
8581 
8582 /**
8583  * Parameters for the FileReadWrite system call.
8584  * This structure is used when calling the \ref SysFileRead and \ref SysFileWrite
8585  * system call functions.
8586  * \sa SysFileRead() and SysFileWrite()
8587  */
8588 struct FileReadWriteType {
8589   unsigned int Result;    /*!< The function call result. Possible values
8590                             include \ref LoaderErrors. */
8591   byte FileHandle;        /*!< The file handle to access. */
8592   string Buffer;          /*!< The buffer to store read bytes or containing
8593                             bytes to write. */
8594   unsigned long Length;   /*!< The number of bytes to read or the returned
8595                             number of bytes written. */
8596 };
8597 
8598 /**
8599  * Parameters for the FileClose system call.
8600  * This structure is used when calling the \ref SysFileClose system call function.
8601  * \sa SysFileClose()
8602  */
8603 struct FileCloseType {
8604   unsigned int Result;   /*!< The function call result. Possible values
8605                            include \ref LoaderErrors. */
8606   byte FileHandle;       /*!< The file handle to close. */
8607 };
8608 
8609 /**
8610  * Parameters for the FileResolveHandle system call.
8611  * This structure is used when calling the \ref SysFileResolveHandle system
8612  * call function.
8613  * \sa SysFileResolveHandle()
8614  */
8615 struct FileResolveHandleType {
8616   unsigned int Result;   /*!< The function call result. Possible values
8617                            include \ref LDR_HANDLEALREADYCLOSED and \ref LDR_SUCCESS. */
8618   byte FileHandle;       /*!< The returned resolved file handle. */
8619   bool WriteHandle;      /*!< True if the returned handle is a write handle. */
8620   string Filename;       /*!< The name of the file for which to resolve a handle. */
8621 };
8622 
8623 /**
8624  * Parameters for the FileRename system call.
8625  * This structure is used when calling the \ref SysFileRename system call
8626  * function.
8627  * \sa SysFileRename()
8628  */
8629 struct FileRenameType {
8630   unsigned int Result;   /*!< The function call result. Possible values
8631                            include \ref LoaderErrors. */
8632   string OldFilename;    /*!< The name of the file to be renamed. */
8633   string NewFilename;    /*!< The new name to give to the file. */
8634 };
8635 
8636 /**
8637  * Parameters for the FileDelete system call.
8638  * This structure is used when calling the \ref SysFileDelete system call
8639  * function.
8640  * \sa SysFileDelete()
8641  */
8642 struct FileDeleteType {
8643   unsigned int Result;   /*!< The function call result. Possible values
8644                            include \ref LoaderErrors. */
8645   string Filename;       /*!< The name of the file to delete. */
8646 };
8647 
8648 #ifdef __ENHANCED_FIRMWARE
8649 /**
8650  * Parameters for the LoaderExecuteFunction system call.
8651  * This structure is used when calling the \ref SysLoaderExecuteFunction
8652  * system call function.
8653  *
8654  * The fields usage depends on the requested command and are documented in the
8655  * table below.
8656  *
8657  * <table>
8658  * <tr><td>Cmd</td>
8659  *     <td>Meaning</td><td>Expected Parameters</td></tr>
8660  * <tr><td>LDR_CMD_OPENREAD</td>
8661  *     <td>Open a file for reading</td><td>(Filename, Length)</td></tr>
8662  * <tr><td>LDR_CMD_OPENWRITE</td>
8663  *     <td>Create a file</td><td>(Filename, Length)</td></tr>
8664  * <tr><td>LDR_CMD_READ</td>
8665  *     <td>Read from a file</td><td>(Filename, Buffer, Length)</td></tr>
8666  * <tr><td>LDR_CMD_WRITE</td>
8667  *     <td>Write to a file</td><td>(Filename, Buffer, Length)</td></tr>
8668  * <tr><td>LDR_CMD_CLOSE</td>
8669  *     <td>Close a file</td><td>(Filename)</td></tr>
8670  * <tr><td>LDR_CMD_DELETE</td>
8671  *     <td>Delete a file</td><td>(Filename)</td></tr>
8672  * <tr><td>LDR_CMD_FINDFIRST</td>
8673  *     <td>Start iterating files</td><td>(Filename, Buffer, Length)</td></tr>
8674  * <tr><td>LDR_CMD_FINDNEXT</td>
8675  *     <td>Continue iterating files</td><td>(Filename, Buffer, Length)</td></tr>
8676  * <tr><td>LDR_CMD_OPENWRITELINEAR</td>
8677  *     <td>Create a linear file</td><td>(Filename, Length)</td></tr>
8678  * <tr><td>LDR_CMD_OPENREADLINEAR</td>
8679  *     <td>Read a linear file</td><td>(Filename, Buffer, Length)</td></tr>
8680  * <tr><td>LDR_CMD_OPENAPPENDDATA</td>
8681  *     <td>Open a file for writing</td><td>(Filename, Length)</td></tr>
8682  * <tr><td>LDR_CMD_FINDFIRSTMODULE</td>
8683  *     <td>Start iterating modules</td><td>(Filename, Buffer)</td></tr>
8684  * <tr><td>LDR_CMD_FINDNEXTMODULE</td>
8685  *     <td>Continue iterating modules</td><td>(Buffer)</td></tr>
8686  * <tr><td>LDR_CMD_CLOSEMODHANDLE</td>
8687  *     <td>Close module handle</td><td>()</td></tr>
8688  * <tr><td>LDR_CMD_IOMAPREAD</td>
8689  *     <td>Read IOMap data</td><td>(Filename, Buffer, Length)</td></tr>
8690  * <tr><td>LDR_CMD_IOMAPWRITE</td>
8691  *     <td>Write IOMap data</td><td>(Filename, Buffer, Length)</td></tr>
8692  * <tr><td>LDR_CMD_DELETEUSERFLASH</td>
8693  *     <td>Delete all files</td><td>()</td></tr>
8694  * <tr><td>LDR_CMD_RENAMEFILE</td>
8695  *     <td>Rename file</td><td>(Filename, Buffer, Length)</td></tr>
8696  * </table>
8697  *
8698  * \sa SysLoaderExecuteFunction()
8699  */
8700 struct LoaderExecuteFunctionType {
8701   unsigned int Result;    /*!< The function call result. Possible values
8702                             include \ref LoaderErrors. */
8703   byte Cmd;               /*!< The command to execute. */
8704   string Filename;        /*!< The Filename parameter, see table. */
8705   byte Buffer[];          /*!< The Buffer parameter, see table. */
8706   unsigned long Length;   /*!< The Length parameter, see table. */
8707 };
8708 
8709 /**
8710  * Parameters for the FileFind system call.
8711  * This structure is used when calling the \ref SysFileFindFirst and \ref
8712  * SysFileFindNext system call functions.
8713  * \sa SysFileFindFirst() and SysFileFindNext()
8714  */
8715 struct FileFindType {
8716   unsigned int Result;    /*!< The function call result. Possible values
8717                             include \ref LoaderErrors. */
8718   byte FileHandle;        /*!< The returned file handle to be used to continue
8719                             iterations. Close it after usage. */
8720   string Filename;        /*!< The pattern to match file name, then the
8721                             returned found file name. */
8722   unsigned long Length;   /*!< The found file length. */
8723 };
8724 
8725 #if __FIRMWARE_VERSION > 107
8726 /**
8727  * Parameters for the FileSeek system call.
8728  * This structure is used when calling the \ref SysFileSeek system call function.
8729  * \sa SysFileSeek()
8730  */
8731 struct FileSeekType {
8732  unsigned int Result; /*!< The function call result. Possible values include
8733                         \ref LoaderErrors. */
8734  byte FileHandle;     /*!< The handle of the file to seek in. */
8735  byte Origin;         /*!< The origin of the file seek operation. See \ref fseekConstants. */
8736  long Length;         /*!< The offset from the origin to seek to. */
8737 };
8738 
8739 /**
8740  * Parameters for the FileResize system call.
8741  * This structure is used when calling the \ref SysFileResize system call function.
8742  * \sa SysFileResize()
8743  */
8744 struct FileResizeType {
8745  unsigned int Result;   /*!< The function call result. Possible values include
8746                          \ref LoaderErrors. */
8747  byte FileHandle;       /*!< The handle of the file to resize. */
8748  unsigned int NewSize;  /*!< The new file size. */
8749 };
8750 
8751 /**
8752  * Parameters for the FileTell system call.
8753  * This structure is used when calling the \ref SysFileTell system call function.
8754  * \sa SysFileTell()
8755  */
8756 struct FileTellType {
8757  unsigned int Result;     /*!< The function call result. Possible values include
8758                            \ref LoaderErrors. */
8759  byte FileHandle;         /*!< The handle of the open file. */
8760  unsigned long Position;  /*!< The current file position in the open file. */
8761 };
8762 
8763 #endif
8764 #endif
8765 #if __FIRMWARE_VERSION > 107
8766 /**
8767  * Parameters for the ListFiles system call.
8768  * This structure is used when calling the \ref SysListFiles system call function.
8769  * \sa SysListFiles()
8770  */
8771 struct ListFilesType {
8772  char Result;       /*!< The function call result. Possible values include
8773                          \ref LoaderErrors. */
8774  string Pattern;    /*!< The file search pattern. */
8775  string FileList[]; /*!< An array of strings containing the list of filenames
8776                          that matched the file search pattern. */
8777 };
8778 #endif
8779 /** @} */ // end of LoaderModuleTypes group
8780 /** @defgroup LoaderModuleFunctions Loader module functions
8781  * Functions for accessing and modifying Loader module features.
8782  * @{
8783  */
8784 #ifdef __DOXYGEN_DOCS
8785 
8786 /**
8787  * Get free flash memory.
8788  * Get the number of bytes of flash memory that are available for use.
8789  * \return The number of bytes of unused flash memory.
8790  */
8791 inline unsigned int FreeMemory(void);
8792 
8793 /**
8794  * Create a file.
8795  * Create a new file with the specified filename and size and open it for
8796  * writing. The file handle is returned in the last parameter, which must be a
8797  * variable. The loader result code is returned as the value of the function
8798  * call. The filename and size parameters must be constants, constant
8799  * expressions, or variables. A file created with a size of zero bytes cannot
8800  * be written to since the NXC file writing functions do not grow the file if
8801  * its capacity is exceeded during a write attempt.
8802  *
8803  * \param fname The name of the file to create.
8804  * \param fsize The size of the file.
8805  * \param handle The file handle output from the function call.
8806  * \return The function call result. See \ref LoaderErrors.
8807  */
8808 inline unsigned int CreateFile(string fname, unsigned int fsize, byte & handle);
8809 
8810 /**
8811  * Open a file for appending.
8812  * Open an existing file with the specified filename for writing. The file
8813  * size is returned in the second parameter, which must be a variable. The
8814  * file handle is returned in the last parameter, which must be a variable.
8815  * The loader result code is returned as the value of the function call.
8816  * The filename parameter must be a constant or a variable.
8817  *
8818  * \param fname The name of the file to open.
8819  * \param fsize The size of the file returned by the function.
8820  * \param handle The file handle output from the function call.
8821  * \return The function call result. See \ref LoaderErrors.
8822  */
8823 inline unsigned int OpenFileAppend(string fname, unsigned int & fsize, byte & handle);
8824 
8825 /**
8826  * Open a file for reading.
8827  * Open an existing file with the specified filename for reading. The file
8828  * size is returned in the second parameter, which must be a variable. The
8829  * file handle is returned in the last parameter, which must be a variable.
8830  * The loader result code is returned as the value of the function call. The
8831  * filename parameter must be a constant or a variable.
8832  *
8833  * \param fname The name of the file to open.
8834  * \param fsize The size of the file returned by the function.
8835  * \param handle The file handle output from the function call.
8836  * \return The function call result. See \ref LoaderErrors.
8837  */
8838 inline unsigned int OpenFileRead(string fname, unsigned int & fsize, byte & handle);
8839 
8840 /**
8841  * Close a file.
8842  * Close the file associated with the specified file handle. The loader
8843  * result code is returned as the value of the function call. The handle
8844  * parameter must be a constant or a variable.
8845  *
8846  * \param handle The file handle.
8847  * \return The function call result. See \ref LoaderErrors.
8848  */
8849 inline unsigned int CloseFile(byte handle);
8850 
8851 /**
8852  * Resolve a handle.
8853  * Resolve a file handle from the specified filename. The file handle is
8854  * returned in the second parameter, which must be a variable. A boolean
8855  * value indicating whether the handle can be used to write to the file or
8856  * not is returned in the last parameter, which must be a variable. The
8857  * loader result code is returned as the value of the function call. The
8858  * filename parameter must be a constant or a variable.
8859  *
8860  * \param filename The name of the file for which to resolve a handle.
8861  * \param handle The file handle output from the function call.
8862  * \param writeable A boolean flag indicating whether the handle is
8863  * to a file open for writing (true) or reading (false).
8864  * \return The function call result. See \ref LoaderErrors.
8865  */
8866 inline unsigned int ResolveHandle(string filename, byte & handle, bool & writeable);
8867 
8868 /**
8869  * Rename a file.
8870  * Rename a file from the old filename to the new filename. The loader
8871  * result code is returned as the value of the function call. The filename
8872  * parameters must be constants or variables.
8873  *
8874  * \param oldname The old filename.
8875  * \param newname The new filename.
8876  * \return The function call result. See \ref LoaderErrors.
8877  */
8878 inline unsigned int RenameFile(string oldname, string newname);
8879 
8880 /**
8881  * Delete a file.
8882  * Delete the specified file. The loader result code is returned as the
8883  * value of the function call. The filename parameter must be a constant or a
8884  * variable.
8885  *
8886  * \param fname The name of the file to delete.
8887  * \return The function call result. See \ref LoaderErrors.
8888  */
8889 inline unsigned int DeleteFile(string fname);
8890 
8891 /**
8892  * Resize a file.
8893  * Resize the specified file. The loader result code is returned as the
8894  * value of the function call. The filename parameter must be a constant or a
8895  * variable.
8896  *
8897  * \param fname The name of the file to resize.
8898  * \param newsize The new size for the file.
8899  * \return The function call result. See \ref LoaderErrors.
8900  */
8901 inline unsigned int ResizeFile(string fname, const unsigned int newsize);
8902 
8903 #ifdef __ENHANCED_FIRMWARE
8904 /**
8905  * Create a linear file.
8906  * Create a new linear file with the specified filename and size and open it for
8907  * writing. The file handle is returned in the last parameter, which must be a
8908  * variable. The loader result code is returned as the value of the function
8909  * call. The filename and size parameters must be constants, constant
8910  * expressions, or variables. A file created with a size of zero bytes cannot
8911  * be written to since the NXC file writing functions do not grow the file if
8912  * its capacity is exceeded during a write attempt.
8913  *
8914  * \param fname The name of the file to create.
8915  * \param fsize The size of the file.
8916  * \param handle The file handle output from the function call.
8917  * \return The function call result. See \ref LoaderErrors.
8918  * \warning This function requires the enhanced NBC/NXC firmware.
8919  */
8920 inline unsigned int CreateFileLinear(string fname, unsigned int fsize, byte & handle);
8921 
8922 /**
8923  * Create a non-linear file.
8924  * Create a new non-linear file with the specified filename and size and open it for
8925  * writing. The file handle is returned in the last parameter, which must be a
8926  * variable. The loader result code is returned as the value of the function
8927  * call. The filename and size parameters must be constants, constant
8928  * expressions, or variables. A file created with a size of zero bytes cannot
8929  * be written to since the NXC file writing functions do not grow the file if
8930  * its capacity is exceeded during a write attempt.
8931  *
8932  * \param fname The name of the file to create.
8933  * \param fsize The size of the file.
8934  * \param handle The file handle output from the function call.
8935  * \return The function call result. See \ref LoaderErrors.
8936  * \warning This function requires the enhanced NBC/NXC firmware.
8937  */
8938 inline unsigned int CreateFileNonLinear(string fname, unsigned int fsize, byte & handle);
8939 
8940 /**
8941  * Open a linear file for reading.
8942  * Open an existing linear file with the specified filename for reading. The file
8943  * size is returned in the second parameter, which must be a variable. The
8944  * file handle is returned in the last parameter, which must be a variable.
8945  * The loader result code is returned as the value of the function call. The
8946  * filename parameter must be a constant or a variable.
8947  *
8948  * \param fname The name of the file to open.
8949  * \param fsize The size of the file returned by the function.
8950  * \param handle The file handle output from the function call.
8951  * \return The function call result. See \ref LoaderErrors.
8952  * \warning This function requires the enhanced NBC/NXC firmware.
8953  */
8954 inline unsigned int OpenFileReadLinear(string fname, unsigned int & fsize, byte & handle);
8955 
8956 /**
8957  * Start searching for files.
8958  * This function lets you begin iterating through files stored on the NXT.
8959  *
8960  * \param fname On input this contains the filename pattern you are searching
8961  * for. On output this contains the name of the first file found that matches
8962  * the pattern.
8963  * \param handle The search handle input to and output from the function call.
8964  * \return The function call result. See \ref LoaderErrors.
8965  * \warning This function requires the enhanced NBC/NXC firmware.
8966  */
8967 inline unsigned int FindFirstFile(string & fname, byte & handle);
8968 
8969 /**
8970  * Continue searching for files.
8971  * This function lets you continue iterating through files stored on the NXT.
8972  *
8973  * \param fname On output this contains the name of the next file found that
8974  * matches the pattern used when the search began by calling \ref FindFirstFile.
8975  * \param handle The search handle input to and output from the function call.
8976  * \return The function call result. See \ref LoaderErrors.
8977  * \warning This function requires the enhanced NBC/NXC firmware.
8978  */
8979 inline unsigned int FindNextFile(string & fname, byte & handle);
8980 
8981 #endif
8982 
8983 /**
8984  * Calculate the size of a variable.
8985  * Calculate the number of bytes required to store the contents of the
8986  * variable passed into the function.
8987  *
8988  * \param value The variable.
8989  * \return The number of bytes occupied by the variable.
8990  */
8991 inline unsigned int SizeOf(variant & value);
8992 
8993 /**
8994  * Read a value from a file.
8995  * Read a value from the file associated with the specified handle.
8996  * The handle parameter must be a variable. The value parameter must be a
8997  * variable. The type of the value parameter determines the number of bytes of
8998  * data read.
8999  *
9000  * \param handle The file handle.
9001  * \param value The variable to store the data read from the file.
9002  * \return The function call result. See \ref LoaderErrors.
9003  */
9004 inline unsigned int Read(byte handle, variant & value);
9005 
9006 /**
9007  * Read a value from a file plus line ending.
9008  * Read a value from the file associated with the specified handle.
9009  * The handle parameter must be a variable. The value parameter must be a
9010  * variable. The type of the value parameter determines the number of bytes
9011  * of data read. The ReadLn function reads two additional bytes from the
9012  * file which it assumes are a carriage return and line feed pair.
9013  *
9014  * \param handle The file handle.
9015  * \param value The variable to store the data read from the file.
9016  * \return The function call result. See \ref LoaderErrors.
9017  */
9018 inline unsigned int ReadLn(byte handle, variant & value);
9019 
9020 /**
9021  * Read bytes from a file.
9022  * Read the specified number of bytes from the file associated with the
9023  * specified handle. The handle parameter must be a variable. The length
9024  * parameter must be a variable. The buf parameter must be an array or a
9025  * string variable. The actual number of bytes read is returned in the
9026  * length parameter.
9027  *
9028  * \param handle The file handle.
9029  * \param length The number of bytes to read. Returns the number of bytes actually read.
9030  * \param buf The byte array where the data is stored on output.
9031  * \return The function call result. See \ref LoaderErrors.
9032  */
9033 inline unsigned int ReadBytes(byte handle, unsigned int & length, byte & buf[]);
9034 
9035 /**
9036  * Read a string from a file plus line ending.
9037  * Read a string from the file associated with the specified handle.
9038  * The handle parameter must be a variable. The output parameter must be a
9039  * variable. Appends bytes to the output variable until a line ending (CRLF)
9040  * is reached. The line ending is also read but it is not appended to the
9041  * output parameter.
9042  *
9043  * \param handle The file handle.
9044  * \param output The variable to store the string read from the file.
9045  * \return The function call result. See \ref LoaderErrors.
9046  */
9047 inline unsigned int ReadLnString(byte handle, string & output);
9048 
9049 /**
9050  * Write value to file.
9051  * Write a value to the file associated with the specified handle.
9052  * The handle parameter must be a variable. The value parameter must be a
9053  * constant, a constant expression, or a variable. The type of the value
9054  * parameter determines the number of bytes of data written.
9055  *
9056  * \param handle The file handle.
9057  * \param value The value to write to the file.
9058  * \return The function call result. See \ref LoaderErrors.
9059  */
9060 inline unsigned int Write(byte handle, const variant & value);
9061 
9062 /**
9063  * Write bytes to file.
9064  * Write the contents of the data array to the file associated with the
9065  * specified handle. The handle parameter must be a variable. The cnt
9066  * parameter must be a variable. The data parameter must be a byte array. The
9067  * actual number of bytes written is returned in the cnt parameter.
9068  *
9069  * \param handle The file handle.
9070  * \param buf The byte array or string containing the data to write.
9071  * \param cnt The number of bytes actually written to the file.
9072  * \return The function call result. See \ref LoaderErrors.
9073  */
9074 inline unsigned int WriteBytes(byte handle, const byte & buf[], unsigned int & cnt);
9075 
9076 /**
9077  * Write bytes to a file with limit.
9078  * Write the specified number of bytes to the file associated with the
9079  * specified handle. The handle parameter must be a variable. The len
9080  * parameter must be a variable. The buf parameter must be a byte array or a
9081  * string variable or string constant. The actual number of bytes written is
9082  * returned in the len parameter.
9083  *
9084  * \param handle The file handle.
9085  * \param len The maximum number of bytes to write on input.  Returns the
9086  * actual number of bytes written.
9087  * \param buf The byte array or string containing the data to write.
9088  * \return The function call result. See \ref LoaderErrors.
9089  */
9090 inline unsigned int WriteBytesEx(byte handle, unsigned int & len, const byte & buf[]);
9091 
9092 /**
9093  * Write a value and new line to a file.
9094  * Write a value to the file associated with the specified handle. The
9095  * handle parameter must be a variable. The value parameter must be a constant,
9096  * a constant expression, or a variable. The type of the value parameter
9097  * determines the number of bytes of data written. This function also
9098  * writes a carriage return and a line feed to the file following the numeric
9099  * data.
9100  *
9101  * \param handle The file handle.
9102  * \param value The value to write to the file.
9103  * \return The function call result. See \ref LoaderErrors.
9104  */
9105 inline unsigned int WriteLn(byte handle, const variant & value);
9106 
9107 /**
9108  * Write string and new line to a file.
9109  * Write the string to the file associated with the specified handle. The
9110  * handle parameter must be a variable. The count parameter must be a variable.
9111  * The str parameter must be a string variable or string constant. This
9112  * function also writes a carriage return and a line feed to the file following
9113  * the string data. The total number of bytes written is returned in the
9114  * cnt parameter.
9115  *
9116  * \param handle The file handle.
9117  * \param str The string to write to the file.
9118  * \param cnt The number of bytes actually written to the file.
9119  * \return The function call result. See \ref LoaderErrors.
9120  */
9121 inline unsigned int WriteLnString(byte handle, const string & str, unsigned int & cnt);
9122 
9123 /**
9124  * Write string to a file.
9125  * Write the string to the file associated with the specified handle. The
9126  * handle parameter must be a variable. The count parameter must be a variable.
9127  * The str parameter must be a string variable or string constant. The actual
9128  * number of bytes written is returned in the cnt parameter.
9129  *
9130  * \param handle The file handle.
9131  * \param str The string to write to the file.
9132  * \param cnt The number of bytes actually written to the file.
9133  * \return The function call result. See \ref LoaderErrors.
9134  */
9135 inline unsigned int WriteString(byte handle, const string & str, unsigned int & cnt);
9136 
9137 /**
9138  * Open file for reading.
9139  * This function lets you open an existing file for reading using the values
9140  * specified via the \ref FileOpenType structure.
9141  *
9142  * The number of bytes that can be read from the file is returned via the
9143  * Length member.
9144  *
9145  * \param args The FileOpenType structure containing the needed parameters.
9146  */
9147 inline void SysFileOpenRead(FileOpenType & args);
9148 
9149 /**
9150  * Open and create file for writing.
9151  * This function lets you create a file that you can write to using the values
9152  * specified via the \ref FileOpenType structure.
9153  *
9154  * The desired maximum file capacity in bytes is specified via the Length
9155  * member.
9156  *
9157  * \param args The FileOpenType structure containing the needed parameters.
9158  */
9159 inline void SysFileOpenWrite(FileOpenType & args);
9160 
9161 /**
9162  * Open file for writing at end of file.
9163  * This function lets you open an existing file that you can write to using
9164  * the values specified via the \ref FileOpenType structure.
9165  *
9166  * The available length remaining in the file is returned via the Length
9167  * member.
9168  *
9169  * \param args The FileOpenType structure containing the needed parameters.
9170  */
9171 inline void SysFileOpenAppend(FileOpenType & args);
9172 
9173 /**
9174  * Read from file.
9175  * This function lets you read from a file using the values specified via the
9176  * \ref FileReadWriteType structure.
9177  *
9178  * \param args The FileReadWriteType structure containing the needed
9179  * parameters.
9180  */
9181 inline void SysFileRead(FileReadWriteType & args);
9182 
9183 /**
9184  * File write.
9185  * This function lets you write to a file using the values specified via the
9186  * \ref FileReadWriteType structure.
9187  *
9188  * \param args The FileReadWriteType structure containing the needed
9189  * parameters.
9190  */
9191 inline void SysFileWrite(FileReadWriteType & args);
9192 
9193 /**
9194  * Close file handle.
9195  * This function lets you close a file using the values specified via the \ref
9196  * FileCloseType structure.
9197  *
9198  * \param args The FileCloseType structure containing the needed parameters.
9199  */
9200 inline void SysFileClose(FileCloseType & args);
9201 
9202 /**
9203  * File resolve handle.
9204  * This function lets you resolve the handle of a file using the values
9205  * specified via the \ref FileResolveHandleType structure.  This will find a
9206  * previously opened file handle.
9207  *
9208  * \param args The FileResolveHandleType structure containing the needed
9209  * parameters.
9210  */
9211 inline void SysFileResolveHandle(FileResolveHandleType & args);
9212 
9213 /**
9214  * Rename file.
9215  * This function lets you rename a file using the values specified via the
9216  * \ref FileRenameType structure.
9217  *
9218  * \param args The FileRenameType structure containing the needed parameters.
9219  */
9220 inline void SysFileRename(FileRenameType & args);
9221 
9222 /**
9223  * Delete file.
9224  * This function lets you delete a file using the values specified via the
9225  * \ref FileDeleteType structure.
9226  *
9227  * \param args The FileDeleteType structure containing the needed parameters.
9228  */
9229 inline void SysFileDelete(FileDeleteType & args);
9230 
9231 #ifdef __ENHANCED_FIRMWARE
9232 /**
9233  * Execute any Loader module command.
9234  * This function lets you directly execute the Loader module's primary
9235  * function using the values specified via the \ref LoaderExecuteFunctionType
9236  * structure.
9237  *
9238  * \param args The LoaderExecuteFunctionType structure containing the needed
9239  * parameters.
9240  *
9241  * \warning This function requires the extended firmware.
9242  */
9243 inline void SysLoaderExecuteFunction(LoaderExecuteFunctionType & args);
9244 
9245 /**
9246  * Start finding files.
9247  * This function lets you begin iterating through files stored on the NXT.
9248  *
9249  * \param args The FileFindType structure containing the needed parameters.
9250  *
9251  * \warning This function requires the extended firmware.
9252  */
9253 inline void SysFileFindFirst(FileFindType & args);
9254 
9255 /**
9256  * Continue finding files.
9257  * This function lets you continue iterating through files stored on the NXT.
9258  *
9259  * \param args The FileFindType structure containing the needed parameters.
9260  *
9261  * \warning This function requires the extended firmware.
9262  */
9263 inline void SysFileFindNext(FileFindType & args);
9264 
9265 /**
9266  * Open and create linear file for writing.
9267  * This function lets you create a linear file that you can write to using the
9268  * values specified via the \ref FileOpenType structure.
9269  *
9270  * \param args The FileOpenType structure containing the needed parameters.
9271  *
9272  * \warning This function requires the extended firmware.
9273  */
9274 inline void SysFileOpenWriteLinear(FileOpenType & args);
9275 
9276 /**
9277  * Open and create non-linear file for writing.
9278  * This function lets you create a non-linear linear file that you can write
9279  * to using the values specified via the \ref FileOpenType structure.
9280  *
9281  * \param args The FileOpenType structure containing the needed parameters.
9282  *
9283  * \warning This function requires the extended firmware.
9284  */
9285 inline void SysFileOpenWriteNonLinear(FileOpenType & args);
9286 
9287 /**
9288  * Open linear file for reading.
9289  * This function lets you open an existing linear file for reading using the
9290  * values specified via the \ref FileOpenType structure.
9291  *
9292  * \param args The FileOpenType structure containing the needed parameters.
9293  *
9294  * \warning This function requires the extended firmware.
9295  */
9296 inline void SysFileOpenReadLinear(FileOpenType & args);
9297 
9298 #if __FIRMWARE_VERSION > 107
9299 /**
9300  * Seek to file position.
9301  * This function lets you seek to a specific file position using the
9302  * values specified via the \ref FileSeekType structure.
9303  *
9304  * \param args The FileSeekType structure containing the needed parameters.
9305  *
9306  * \warning This function requires the extended firmware.
9307  */
9308 inline void SysFileSeek(FileSeekType & args);
9309 
9310 /**
9311  * Resize a file.
9312  * This function lets you resize a file using the
9313  * values specified via the \ref FileResizeType structure.
9314  *
9315  * \param args The FileResizeType structure containing the needed parameters.
9316  *
9317  * \warning This function requires the extended firmware.
9318  * It has not yet been implemented at the firmware level.
9319  */
9320 inline void SysFileResize(FileResizeType & args);
9321 
9322 /**
9323  * Return the file position.
9324  * This function returns the current file position in the open file
9325  * specified via the \ref FileTellType structure.
9326  *
9327  * \param args The FileTellType structure containing the needed parameters.
9328  *
9329  * \warning This function requires the extended firmware.
9330  */
9331 inline void SysFileTell(FileTellType & args);
9332 
9333 #endif
9334 #endif
9335 #if __FIRMWARE_VERSION > 107
9336 /**
9337  * List files.
9338  * This function lets you retrieve a list of files on the NXT using the
9339  * values specified via the \ref ListFilesType structure.
9340  *
9341  * \param args The ListFilesType structure containing the needed parameters.
9342  */
9343 inline void SysListFiles(ListFilesType & args);
9344 
9345 #endif
9346 
9347 #else
9348 
9349 #define FreeMemory() asm { GetFreeMemory(__RETVAL__) }
9350 
9351 #define CreateFile(_fname, _fsize, _handle) asm { __createFile(_fname, _fsize, _handle, __RETVAL__) }
9352 #define OpenFileAppend(_fname, _fsize, _handle) asm { __openFileAppend(_fname, _fsize, _handle, __RETVAL__) }
9353 #define OpenFileRead(_fname, _fsize, _handle) asm { __openFileRead(_fname, _fsize, _handle, __RETVAL__) }
9354 #define CloseFile(_handle) asm { __closeFile(_handle, __RETVAL__) }
9355 #define ResolveHandle(_fname, _handle, _writeable) asm { __resolveHandle(_fname, _handle, _writeable, __RETVAL__) }
9356 #define RenameFile(_oldname, _newname) asm { __renameFile(_oldname, _newname, __RETVAL__) }
9357 #define DeleteFile(_fname) asm { __deleteFile(_fname, __RETVAL__) }
9358 #define ResizeFile(_fname, _newsize) asm { __fileResize(_fname, _newsize, __RETVAL__) }
9359 
9360 #ifdef __ENHANCED_FIRMWARE
9361 #define CreateFileLinear(_fname, _fsize, _handle) asm { __createFileLinear(_fname, _fsize, _handle, __RETVAL__) }
9362 #define CreateFileNonLinear(_fname, _fsize, _handle) asm { __createFileNonLinear(_fname, _fsize, _handle, __RETVAL__) }
9363 #define OpenFileReadLinear(_fname, _fsize, _handle) asm { __openFileReadLinear(_fname, _fsize, _handle, __RETVAL__) }
9364 #define FindFirstFile(_fname, _handle) asm { __findFirstFile(_fname, _handle, __RETVAL__) }
9365 #define FindNextFile(_fname, _handle) asm { __findNextFile(_fname, _handle, __RETVAL__) }
9366 #endif
9367 
9368 #define SizeOf(_n) asm { __sizeOF(_n, __RETVAL__) }
9369 #define Read(_handle, _n) asm { __readValue(_handle, _n, __RETVAL__) }
9370 #define ReadLn(_handle, _n) asm { __readLnValue(_handle, _n, __RETVAL__) }
9371 #define ReadBytes(_handle, _len, _buf) asm { __readBytes(_handle, _len, _buf, __RETVAL__) }
9372 #define ReadLnString(_handle, _output) asm { __readLnString(_handle, _output, __RETVAL__) }
9373 
9374 #define Write(_handle, _n) asm { __writeValue(_handle, _n, __RETVAL__) }
9375 #define WriteLn(_handle, _n) asm { __writeLnValue(_handle, _n, __RETVAL__) }
9376 #define WriteString(_handle, _str, _cnt) asm { __writeString(_handle, _str, _cnt, __RETVAL__) }
9377 #define WriteLnString(_handle, _str, _cnt) asm { __writeLnString(_handle, _str, _cnt, __RETVAL__) }
9378 #define WriteBytes(_handle, _buf, _cnt) asm { __writeBytes(_handle, _buf, _cnt, __RETVAL__) }
9379 #define WriteBytesEx(_handle, _len, _buf) asm { __writeBytesEx(_handle, _len, _buf, __RETVAL__) }
9380 
9381 #define SysFileOpenRead(_args) asm { \
9382   compchktype _args, FileOpenType \
9383   syscall FileOpenRead, _args \
9384 }
9385 #define SysFileOpenWrite(_args) asm { \
9386   compchktype _args, FileOpenType \
9387   syscall FileOpenWrite, _args \
9388 }
9389 #define SysFileOpenAppend(_args) asm { \
9390   compchktype _args, FileOpenType \
9391   syscall FileOpenAppend, _args \
9392 }
9393 #define SysFileRead(_args) asm { \
9394   compchktype _args, FileReadWriteType \
9395   syscall FileRead, _args \
9396 }
9397 #define SysFileWrite(_args) asm { \
9398   compchktype _args, FileReadWriteType \
9399   syscall FileWrite, _args \
9400 }
9401 #define SysFileClose(_args) asm { \
9402   compchktype _args, FileCloseType \
9403   syscall FileClose, _args \
9404 }
9405 #define SysFileResolveHandle(_args) asm { \
9406   compchktype _args, FileResolveHandleType \
9407   syscall FileResolveHandle, _args \
9408 }
9409 #define SysFileRename(_args) asm { \
9410   compchktype _args, FileRenameType \
9411   syscall FileRename, _args \
9412 }
9413 #define SysFileDelete(_args) asm { \
9414   compchktype _args, FileDeleteType \
9415   syscall FileDelete, _args \
9416 }
9417 
9418 #ifdef __ENHANCED_FIRMWARE
9419 #define SysLoaderExecuteFunction(_args) asm { \
9420   compchktype _args, LoaderExecuteFunctionType \
9421   syscall LoaderExecuteFunction, _args \
9422 }
9423 #define SysFileFindFirst(_args) asm { \
9424   compchktype _args, FileFindType \
9425   syscall FileFindFirst, _args \
9426 }
9427 #define SysFileFindNext(_args) asm { \
9428   compchktype _args, FileFindType \
9429   syscall FileFindNext, _args \
9430 }
9431 #define SysFileOpenWriteLinear(_args) asm { \
9432   compchktype _args, FileOpenType \
9433   syscall FileOpenWriteLinear, _args \
9434 }
9435 #define SysFileOpenWriteNonLinear(_args) asm { \
9436   compchktype _args, FileOpenType \
9437   syscall FileOpenWriteNonLinear, _args \
9438 }
9439 #define SysFileOpenReadLinear(_args) asm { \
9440   compchktype _args, FileOpenType \
9441   syscall FileOpenReadLinear, _args \
9442 }
9443 #if __FIRMWARE_VERSION > 107
9444 #define SysFileSeek(_args) asm { \
9445   compchktype _args, FileSeekType \
9446   syscall FileSeek, _args \
9447 }
9448 #define SysFileResize(_args) asm { \
9449   compchktype _args, FileResizeType \
9450   syscall FileResize, _args \
9451 }
9452 #define SysFileTell(_args) asm { \
9453   compchktype _args, FileTellType \
9454   syscall FileTell, _args \
9455 }
9456 #endif
9457 #endif
9458 #if __FIRMWARE_VERSION > 107
9459 #define SysListFiles(_args) asm { \
9460   compchktype _args, ListFilesType \
9461   syscall ListFiles, _args \
9462 }
9463 #endif
9464 
9465 #endif
9466 
9467 /** @} */ // end of LoaderModuleFunctions group
9468 /** @} */ // end of LoaderModule group
9469 /** @} */ // end of NXTFirmwareModules group
9470 
9471 
9472 /** @addtogroup ThirdPartyDevices
9473  * @{
9474  */
9475 
9476 ///////////////////////////////////////////////////////////////////////////////
9477 //////////////////////////////// HiTechnic API ////////////////////////////////
9478 ///////////////////////////////////////////////////////////////////////////////
9479 
9480 
9481 /** @addtogroup HiTechnicAPI
9482  * @{
9483  */
9484 
9485 /**
9486  * Read HiTechnic Gyro sensor.
9487  * Read the HiTechnic Gyro sensor on the specified port. The offset value
9488  * should be calculated by averaging several readings with an offset of zero
9489  * while the sensor is perfectly still.
9490  *
9491  * \param port The sensor port. See \ref InPorts.
9492  * \param offset The zero offset.
9493  * \return The Gyro sensor reading.
9494  */
9495 inline int SensorHTGyro(const byte & port, int offset = 0) {
9496   asm {
9497     getin __RETVAL__, port, RawValueField
9498     sub __RETVAL__, __RETVAL__, 600
9499     sub __RETVAL__, __RETVAL__, offset
9500   }
9501 }
9502 
9503 /**
9504  * Read HiTechnic Magnet sensor.
9505  * Read the HiTechnic Magnet sensor on the specified port. The offset value
9506  * should be calculated by averaging several readings with an offset of zero
9507  * while the sensor is perfectly still.
9508  *
9509  * \param port The sensor port. See \ref InPorts.
9510  * \param offset The zero offset.
9511  * \return The Magnet sensor reading.
9512  */
9513 inline int SensorHTMagnet(const byte & port, int offset = 0) {
9514   asm {
9515     getin __RETVAL__, port, RawValueField
9516     sub __RETVAL__, __RETVAL__, 600
9517     sub __RETVAL__, __RETVAL__, offset
9518   }
9519 }
9520 
9521 /**
9522  * Read HiTechnic EOPD sensor.
9523  * Read the HiTechnic EOPD sensor on the specified port.
9524  *
9525  * \param port The sensor port. See \ref InPorts.
9526  * \return The EOPD sensor reading.
9527  */
SensorHTEOPD(const byte & port)9528 inline int SensorHTEOPD(const byte & port) {
9529   asm {
9530     getin __RETVAL__, port, RawValueField
9531     sub __RETVAL__, 1023, __RETVAL__
9532   }
9533 }
9534 
9535 /**
9536  * Set sensor as HiTechnic EOPD.
9537  * Configure the sensor on the specified port as a HiTechnic EOPD sensor.
9538  *
9539  * \param port The sensor port. See \ref InPorts.
9540  * \param bStandard Configure in standard or long-range mode.
9541  */
SetSensorHTEOPD(const byte & port,bool bStandard)9542 inline void SetSensorHTEOPD(const byte & port, bool bStandard) {
9543   SetSensorType(port, bStandard ? SENSOR_TYPE_LIGHT_INACTIVE : SENSOR_TYPE_LIGHT_ACTIVE);
9544   SetSensorMode(port, SENSOR_MODE_RAW);
9545   ResetSensor(port);
9546 }
9547 
9548 /**
9549  * Set sensor as HiTechnic Gyro.
9550  * Configure the sensor on the specified port as a HiTechnic Gyro sensor.
9551  *
9552  * \param port The sensor port. See \ref InPorts.
9553  */
SetSensorHTGyro(const byte & port)9554 inline void SetSensorHTGyro(const byte & port) {
9555   SetSensorType(port, SENSOR_TYPE_LIGHT_INACTIVE);
9556   SetSensorMode(port, SENSOR_MODE_RAW);
9557   ResetSensor(port);
9558 }
9559 
9560 /**
9561  * Set sensor as HiTechnic Magnet.
9562  * Configure the sensor on the specified port as a HiTechnic Magnet sensor.
9563  *
9564  * \param port The sensor port. See \ref InPorts.
9565  */
SetSensorHTMagnet(const byte & port)9566 inline void SetSensorHTMagnet(const byte & port) {
9567   SetSensorType(port, SENSOR_TYPE_LIGHT_INACTIVE);
9568   SetSensorMode(port, SENSOR_MODE_RAW);
9569   ResetSensor(port);
9570 }
9571 
9572 #ifdef __DOXYGEN_DOCS
9573 
9574 /**
9575  * Read HiTechnic color sensor color number.
9576  * Read the color number from the HiTechnic Color sensor on the specified
9577  * port. The port must be configured as a Lowspeed port before using this
9578  * function.
9579  *
9580  * \param port The sensor port. See \ref InPorts.
9581  * \return The color number.
9582  */
9583 inline int SensorHTColorNum(const byte & port);
9584 
9585 /**
9586  * Read HiTechnic compass.
9587  * Read the compass heading value of the HiTechnic Compass sensor on the
9588  * specified port. The port must be configured as a Lowspeed port before
9589  * using this function.
9590  *
9591  * \param port The sensor port. See \ref InPorts.
9592  * \return The compass heading.
9593  */
9594 inline int SensorHTCompass(const byte & port);
9595 
9596 /**
9597  * Read HiTechnic IRSeeker direction.
9598  * Read the direction value of the HiTechnic IR Seeker on the specified
9599  * port. The port must be configured as a Lowspeed port before using this
9600  * function.
9601  *
9602  * \param port The sensor port. See \ref InPorts.
9603  * \return The IRSeeker direction.
9604  */
9605 inline int SensorHTIRSeekerDir(const byte & port);
9606 
9607 /**
9608  * Read HiTechnic IRSeeker2 register.
9609  * Read a register value from the HiTechnic IR Seeker2 on the specified
9610  * port. The port must be configured as a Lowspeed port before using this
9611  * function.
9612  *
9613  * \param port The sensor port. See \ref InPorts.
9614  * \param reg The register address. See \ref HTIRSeeker2Constants.
9615  * \return The IRSeeker2 register value.
9616  */
9617 inline int SensorHTIRSeeker2Addr(const byte & port, const byte reg);
9618 
9619 /**
9620  * Read HiTechnic IRSeeker2 DC direction.
9621  * Read the DC direction value from the HiTechnic IR Seeker2 on the specified
9622  * port. The port must be configured as a Lowspeed port before using this
9623  * function.
9624  *
9625  * \param port The sensor port. See \ref InPorts.
9626  * \return The IRSeeker2 DC direction.
9627  */
9628 inline int SensorHTIRSeeker2DCDir(const byte & port);
9629 
9630 /**
9631  * Read HiTechnic IRSeeker2 AC direction.
9632  * Read the AC direction value from the HiTechnic IR Seeker2 on the specified
9633  * port. The port must be configured as a Lowspeed port before using this
9634  * function.
9635  *
9636  * \param port The sensor port. See \ref InPorts.
9637  * \return The IRSeeker2 AC direction.
9638  */
9639 inline int SensorHTIRSeeker2ACDir(const byte & port);
9640 
9641 /**
9642  * Set HiTechnic Color2 mode.
9643  * Set the mode of the HiTechnic Color2 sensor on the specified
9644  * port. The port must be configured as a Lowspeed port before using this
9645  * function.
9646  *
9647  * \param port The sensor port. See \ref InPorts.
9648  * \param mode The Color2 mode. See \ref HTColor2Constants.
9649  * \return The function call result. \ref NO_ERR or \ref CommandCommErrors.
9650  */
9651 inline char SetHTColor2Mode(const byte & port, byte mode);
9652 
9653 /**
9654  * Set HiTechnic IRSeeker2 mode.
9655  * Set the mode of the HiTechnic IRSeeker2 sensor on the specified
9656  * port. The port must be configured as a Lowspeed port before using this
9657  * function.
9658  *
9659  * \param port The sensor port. See \ref InPorts.
9660  * \param mode The IRSeeker2 mode. See \ref HTIRSeeker2Constants.
9661  * \return The function call result. \ref NO_ERR or \ref CommandCommErrors.
9662  */
9663 inline char SetHTIRSeeker2Mode(const byte & port, const byte mode);
9664 
9665 /**
9666  * Read HiTechnic acceleration values.
9667  * Read X, Y, and Z axis acceleration values from the HiTechnic Accelerometer
9668  * sensor. Returns a boolean value indicating whether or not the operation
9669  * completed successfully. The port must be configured as a Lowspeed port
9670  * before using this function.
9671  *
9672  * \param port The sensor port. See \ref InPorts.
9673  * \param x The output x-axis acceleration.
9674  * \param y The output y-axis acceleration.
9675  * \param z The output z-axis acceleration.
9676  * \return The function call result.
9677  */
9678 inline bool ReadSensorHTAccel(const byte port, int & x, int & y, int & z);
9679 
9680 /**
9681  * Read HiTechnic Color values.
9682  * Read color number, red, green, and blue values from the HiTechnic Color
9683  * sensor. Returns a boolean value indicating whether or not the operation
9684  * completed successfully. The port must be configured as a Lowspeed port
9685  * before using this function.
9686  *
9687  * \param port The sensor port. See \ref InPorts.
9688  * \param ColorNum The output color number.
9689  * \param Red The red color value.
9690  * \param Green The green color value.
9691  * \param Blue The blue color value.
9692  * \return The function call result.
9693  */
9694 inline bool ReadSensorHTColor(const byte port, byte & ColorNum, byte & Red, byte & Green, byte & Blue);
9695 
9696 /**
9697  * Read HiTechnic IRSeeker values.
9698  * Read direction, and five signal strength values from the HiTechnic
9699  * IRSeeker sensor. Returns a boolean value indicating whether or not the
9700  * operation completed successfully. The port must be configured as a
9701  * Lowspeed port before using this function.
9702  *
9703  * \param port The sensor port. See \ref InPorts.
9704  * \param dir The direction.
9705  * \param s1 The signal strength from sensor 1.
9706  * \param s3 The signal strength from sensor 3.
9707  * \param s5 The signal strength from sensor 5.
9708  * \param s7 The signal strength from sensor 7.
9709  * \param s9 The signal strength from sensor 9.
9710  * \return The function call result.
9711  */
9712 inline bool ReadSensorHTIRSeeker(const byte port, byte & dir, byte & s1, byte & s3, byte & s5, byte & s7, byte & s9);
9713 
9714 /**
9715  * Read HiTechnic Color normalized values.
9716  * Read the color index and the normalized red, green, and blue values from
9717  * the HiTechnic Color sensor. Returns a boolean value indicating whether or
9718  * not the operation completed successfully. The port must be configured as a
9719  * Lowspeed port before using this function.
9720  *
9721  * \param port The sensor port. See \ref InPorts.
9722  * \param ColorIdx The output color index.
9723  * \param Red The normalized red color value.
9724  * \param Green The normalized green color value.
9725  * \param Blue The normalized blue color value.
9726  * \return The function call result.
9727  */
9728 inline bool ReadSensorHTNormalizedColor(const byte port, byte & ColorIdx, byte & Red, byte & Green, byte & Blue);
9729 
9730 /**
9731  * Read HiTechnic Color raw values.
9732  * Read the raw red, green, and blue values from the HiTechnic Color sensor.
9733  * Returns a boolean value indicating whether or not the operation completed
9734  * successfully. The port must be configured as a Lowspeed port before using
9735  * this function.
9736  *
9737  * \param port The sensor port. See \ref InPorts.
9738  * \param Red The raw red color value.
9739  * \param Green The raw green color value.
9740  * \param Blue The raw blue color value.
9741  * \return The function call result.
9742  */
9743 inline bool ReadSensorHTRawColor(const byte port, unsigned int & Red, unsigned int & Green, unsigned int & Blue);
9744 
9745 /**
9746  * Read HiTechnic Color2 active values.
9747  * Read color number, red, green, and blue values from the HiTechnic Color2
9748  * sensor. Returns a boolean value indicating whether or not the operation
9749  * completed successfully. The port must be configured as a Lowspeed port
9750  * before using this function.
9751  *
9752  * \param port The sensor port. See \ref InPorts.
9753  * \param ColorNum The output color number.
9754  * \param Red The red color value.
9755  * \param Green The green color value.
9756  * \param Blue The blue color value.
9757  * \param White The white color value.
9758  * \return The function call result.
9759  */
9760 inline bool ReadSensorHTColor2Active(byte port, byte & ColorNum, byte & Red, byte & Green, byte & Blue, byte & White);
9761 
9762 /**
9763  * Read HiTechnic Color2 normalized active values.
9764  * Read the color index and the normalized red, green, and blue values from
9765  * the HiTechnic Color2 sensor. Returns a boolean value indicating whether or
9766  * not the operation completed successfully. The port must be configured as a
9767  * Lowspeed port before using this function.
9768  *
9769  * \param port The sensor port. See \ref InPorts.
9770  * \param ColorIdx The output color index.
9771  * \param Red The normalized red color value.
9772  * \param Green The normalized green color value.
9773  * \param Blue The normalized blue color value.
9774  * \return The function call result.
9775  */
9776 inline bool ReadSensorHTNormalizedColor2Active(const byte port, byte & ColorIdx, byte & Red, byte & Green, byte & Blue);
9777 
9778 /**
9779  * Read HiTechnic Color2 raw values.
9780  * Read the raw red, green, and blue values from the HiTechnic Color2 sensor.
9781  * Returns a boolean value indicating whether or not the operation completed
9782  * successfully. The port must be configured as a Lowspeed port before using
9783  * this function.
9784  *
9785  * \param port The sensor port. See \ref InPorts.
9786  * \param Red The raw red color value.
9787  * \param Green The raw green color value.
9788  * \param Blue The raw blue color value.
9789  * \param White The raw white color value.
9790  * \return The function call result.
9791  */
9792 inline bool ReadSensorHTRawColor2(const byte port, unsigned int & Red, unsigned int & Green, unsigned int & Blue, unsigned int & White);
9793 
9794 /**
9795  * Read HiTechnic IRReceiver Power Function bytes.
9796  * Read Power Function bytes from the HiTechnic IRReceiver sensor.
9797  * Returns a boolean value indicating whether or not the operation completed
9798  * successfully. The port must be configured as a Lowspeed port before using
9799  * this function.
9800  *
9801  * \param port The sensor port. See \ref InPorts.
9802  * \param pfdata Eight bytes of power function remote IR data.
9803  * \return The function call result.
9804  */
9805 inline bool ReadSensorHTIRReceiver(const byte port, char & pfdata[]);
9806 
9807 /**
9808  * Read HiTechnic IRReceiver Power Function value.
9809  * Read a Power Function byte from the HiTechnic IRReceiver sensor.
9810  * Returns a boolean value indicating whether or not the operation completed
9811  * successfully. The port must be configured as a Lowspeed port before using
9812  * this function.
9813  *
9814  * \param port The sensor port. See \ref InPorts.
9815  * \param offset The power function data offset. See \ref HTIRReceiverConstants.
9816  * \param pfchar A single byte of power function remote IR data.
9817  * \return The function call result.
9818  */
9819 inline bool ReadSensorHTIRReceiverEx(const byte port, const byte offset, char & pfchar);
9820 
9821 /**
9822  * Read HiTechnic IRSeeker2 AC values.
9823  * Read direction, and five signal strength values from the HiTechnic
9824  * IRSeeker2 sensor in AC mode. Returns a boolean value indicating whether or
9825  * not the operation completed successfully. The port must be configured as a
9826  * Lowspeed port before using this function.
9827  *
9828  * \param port The sensor port. See \ref InPorts.
9829  * \param dir The direction.
9830  * \param s1 The signal strength from sensor 1.
9831  * \param s3 The signal strength from sensor 3.
9832  * \param s5 The signal strength from sensor 5.
9833  * \param s7 The signal strength from sensor 7.
9834  * \param s9 The signal strength from sensor 9.
9835  * \return The function call result.
9836  */
9837 inline bool ReadSensorHTIRSeeker2AC(const byte port, byte & dir, byte & s1, byte & s3, byte & s5, byte & s7, byte & s9);
9838 
9839 /**
9840  * Read HiTechnic IRSeeker2 DC values.
9841  * Read direction, five signal strength, and average strength values from the
9842  * HiTechnic IRSeeker2 sensor. Returns a boolean value indicating whether or
9843  * not the operation completed successfully. The port must be configured as a
9844  * Lowspeed port before using this function.
9845  *
9846  * \param port The sensor port. See \ref InPorts.
9847  * \param dir The direction.
9848  * \param s1 The signal strength from sensor 1.
9849  * \param s3 The signal strength from sensor 3.
9850  * \param s5 The signal strength from sensor 5.
9851  * \param s7 The signal strength from sensor 7.
9852  * \param s9 The signal strength from sensor 9.
9853  * \param avg The average signal strength.
9854  * \return The function call result.
9855  */
9856 inline bool ReadSensorHTIRSeeker2DC(const byte port, byte & dir, byte & s1, byte & s3, byte & s5, byte & s7, byte & s9, byte & avg);
9857 
9858 /**
9859  * Reset HiTechnic Angle sensor.
9860  * Reset the HiTechnic Angle sensor on the specified
9861  * port. The port must be configured as a Lowspeed port before using this
9862  * function.
9863  *
9864  * \param port The sensor port. See \ref InPorts.
9865  * \param mode The Angle reset mode. See \ref HTAngleConstants.
9866  * \return The function call result. \ref NO_ERR or \ref CommandCommErrors.
9867  */
9868 inline char ResetSensorHTAngle(const byte port, const byte mode);
9869 
9870 /**
9871  * Read HiTechnic Angle sensor values.
9872  * Read values from the HiTechnic Angle sensor.
9873  * Returns a boolean value indicating whether or not the operation completed
9874  * successfully. The port must be configured as a Lowspeed port before using
9875  * this function.
9876  *
9877  * \param port The sensor port. See \ref NBCInputPortConstants.
9878  * \param Angle Current angle in degrees (0-359).
9879  * \param AccAngle Accumulated angle in degrees (-2147483648 to 2147483647).
9880  * \param RPM rotations per minute (-1000 to 1000).
9881  * \return The function call result.
9882  */
9883 inline bool ReadSensorHTAngle(const byte port, int & Angle, long & AccAngle, int & RPM);
9884 
9885 /**
9886  * Read HiTechnic touch multiplexer.
9887  * Read touch sensor values from the HiTechnic touch multiplexer device.
9888  *
9889  * \param port The sensor port. See \ref InPorts.
9890  * \param t1 The value of touch sensor 1.
9891  * \param t2 The value of touch sensor 2.
9892  * \param t3 The value of touch sensor 3.
9893  * \param t4 The value of touch sensor 4.
9894  */
9895 inline void ReadSensorHTTouchMultiplexer(const byte port, byte & t1, byte & t2, byte & t3, byte & t4);
9896 
9897 /**
9898  * HTIRTrain function.
9899  * Control an IR Train receiver set to the specified channel using the
9900  * HiTechnic iRLink device. Valid func values are \ref TRAIN_FUNC_STOP,
9901  * \ref TRAIN_FUNC_INCR_SPEED, \ref TRAIN_FUNC_DECR_SPEED, and \ref TRAIN_FUNC_TOGGLE_LIGHT.
9902  * Valid channel values are \ref TRAIN_CHANNEL_1 through \ref TRAIN_CHANNEL_3 and
9903  * \ref TRAIN_CHANNEL_ALL. The port must be configured as a Lowspeed port before
9904  * using this function.
9905  *
9906  * \param port The sensor port. See \ref InPorts.
9907  * \param channel The IR Train channel.  See \ref IRTrainChannels.
9908  * \param func The IR Train function. See \ref IRTrainFuncs
9909  * \return The function call result. \ref NO_ERR or \ref CommandCommErrors.
9910  */
9911 inline char HTIRTrain(const byte port, const byte channel, const byte func);
9912 
9913 /**
9914  * HTPFComboDirect function.
9915  * Execute a pair of Power Function motor commands on the specified channel
9916  * using the HiTechnic iRLink device. Commands for outa and outb are
9917  * \ref PF_CMD_STOP, \ref PF_CMD_REV, \ref PF_CMD_FWD, and \ref PF_CMD_BRAKE. Valid channels are
9918  * \ref PF_CHANNEL_1 through \ref PF_CHANNEL_4. The port must be configured as a
9919  * Lowspeed port before using this function.
9920  *
9921  * \param port The sensor port. See \ref InPorts.
9922  * \param channel The Power Function channel.  See \ref PFChannelConstants.
9923  * \param outa The Power Function command for output A. See \ref PFCmdConstants.
9924  * \param outb The Power Function command for output B. See \ref PFCmdConstants.
9925  * \return The function call result. \ref NO_ERR or \ref CommandCommErrors.
9926  */
9927 inline char HTPFComboDirect(const byte port, const byte channel, const byte outa, const byte outb);
9928 
9929 /**
9930  * HTPFComboPWM function.
9931  * Control the speed of both outputs on a Power Function receiver set to the
9932  * specified channel using the HiTechnic iRLink device. Valid output values
9933  * are \ref PF_PWM_FLOAT, \ref PF_PWM_FWD1, \ref PF_PWM_FWD2, \ref PF_PWM_FWD3, \ref PF_PWM_FWD4,
9934  * \ref PF_PWM_FWD5, \ref PF_PWM_FWD6, \ref PF_PWM_FWD7, \ref PF_PWM_BRAKE, \ref PF_PWM_REV7,
9935  * \ref PF_PWM_REV6, \ref PF_PWM_REV5, \ref PF_PWM_REV4, \ref PF_PWM_REV3, \ref PF_PWM_REV2, and
9936  * \ref PF_PWM_REV1. Valid channels are \ref PF_CHANNEL_1 through \ref PF_CHANNEL_4. The
9937  * port must be configured as a Lowspeed port before using this function.
9938  *
9939  * \param port The sensor port. See \ref InPorts.
9940  * \param channel The Power Function channel.  See \ref PFChannelConstants.
9941  * \param outa The Power Function PWM command for output A. See \ref PFPWMOptions.
9942  * \param outb The Power Function PWM command for output B. See \ref PFPWMOptions.
9943  * \return The function call result. \ref NO_ERR or \ref CommandCommErrors.
9944  */
9945 inline char HTPFComboPWM(const byte port, const byte channel, const byte outa, const byte outb);
9946 
9947 /**
9948  * HTPFRawOutput function.
9949  * Control a Power Function receiver set to the specified channel using the
9950  * HiTechnic iRLink device. Build the raw data stream using the 3 nibbles
9951  * (4 bit values). The port must be configured as a Lowspeed port before using
9952  * this function.
9953  *
9954  * \param port The sensor port. See \ref InPorts.
9955  * \param nibble0 The first raw data nibble.
9956  * \param nibble1 The second raw data nibble.
9957  * \param nibble2 The third raw data nibble.
9958  * \return The function call result. \ref NO_ERR or \ref CommandCommErrors.
9959  */
9960 inline char HTPFRawOutput(const byte port, const byte nibble0, const byte nibble1, const byte nibble2);
9961 
9962 /**
9963  * HTPFRepeat function.
9964  * Repeat sending the last Power Function command using the HiTechnic
9965  * IRLink device. Specify the number of times to repeat the command and the
9966  * number of milliseconds of delay between each repetition. The port must be
9967  * configured as a Lowspeed port before using this function.
9968  *
9969  * \param port The sensor port. See \ref InPorts.
9970  * \param count The number of times to repeat the command.
9971  * \param delay The number of milliseconds to delay between each repetition.
9972  * \return The function call result. \ref NO_ERR or \ref CommandCommErrors.
9973  */
9974 inline char HTPFRepeat(const byte port, const byte count, const unsigned int delay);
9975 
9976 /**
9977  * HTPFSingleOutputCST function.
9978  * Control a single output on a Power Function receiver set to the specified
9979  * channel using the HiTechnic iRLink device. Select the desired output
9980  * using \ref PF_OUT_A or \ref PF_OUT_B. Valid functions are \ref PF_CST_CLEAR1_CLEAR2,
9981  * \ref PF_CST_SET1_CLEAR2, \ref PF_CST_CLEAR1_SET2, \ref PF_CST_SET1_SET2,
9982  * \ref PF_CST_INCREMENT_PWM, \ref PF_CST_DECREMENT_PWM, \ref PF_CST_FULL_FWD,
9983  * \ref PF_CST_FULL_REV, and \ref PF_CST_TOGGLE_DIR. Valid channels are
9984  * \ref PF_CHANNEL_1 through \ref PF_CHANNEL_4. The port must be configured as a
9985  * Lowspeed port before using this function.
9986  *
9987  * \param port The sensor port. See \ref InPorts.
9988  * \param channel The Power Function channel.  See \ref PFChannelConstants.
9989  * \param out The Power Function output. See \ref PFOutputs.
9990  * \param func The Power Function CST function. See \ref PFCSTOptions.
9991  * \return The function call result. \ref NO_ERR or \ref CommandCommErrors.
9992  */
9993 inline char HTPFSingleOutputCST(const byte port, const byte channel, const byte out, const byte func);
9994 
9995 /**
9996  * HTPFSingleOutputPWM function.
9997  * Control the speed of a single output on a Power Function receiver set to
9998  * the specified channel using the HiTechnic iRLink device. Select the
9999  * desired output using \ref PF_OUT_A or \ref PF_OUT_B. Valid functions are
10000  * \ref PF_PWM_FLOAT, \ref PF_PWM_FWD1, \ref PF_PWM_FWD2, \ref PF_PWM_FWD3, \ref PF_PWM_FWD4,
10001  * \ref PF_PWM_FWD5, \ref PF_PWM_FWD6, \ref PF_PWM_FWD7, \ref PF_PWM_BRAKE, \ref PF_PWM_REV7,
10002  * \ref PF_PWM_REV6, \ref PF_PWM_REV5, \ref PF_PWM_REV4, \ref PF_PWM_REV3, \ref PF_PWM_REV2, and
10003  * \ref PF_PWM_REV1. Valid channels are \ref PF_CHANNEL_1 through \ref PF_CHANNEL_4. The
10004  * port must be configured as a Lowspeed port before using this function.
10005  *
10006  * \param port The sensor port. See \ref InPorts.
10007  * \param channel The Power Function channel.  See \ref PFChannelConstants.
10008  * \param out The Power Function output. See \ref PFOutputs.
10009  * \param func The Power Function PWM function. See \ref PFPWMOptions.
10010  * \return The function call result. \ref NO_ERR or \ref CommandCommErrors.
10011  */
10012 inline char HTPFSingleOutputPWM(const byte port, const byte channel, const byte out, const byte func);
10013 
10014 /**
10015  * HTPFSinglePin function.
10016  * Control a single pin on a Power Function receiver set to the specified
10017  * channel using the HiTechnic iRLink device. Select the desired output
10018  * using \ref PF_OUT_A or \ref PF_OUT_B.  Select the desired pin using \ref PF_PIN_C1 or
10019  * \ref PF_PIN_C2. Valid functions are \ref PF_FUNC_NOCHANGE, \ref PF_FUNC_CLEAR,
10020  * \ref PF_FUNC_SET, and \ref PF_FUNC_TOGGLE. Valid channels are \ref PF_CHANNEL_1 through
10021  * \ref PF_CHANNEL_4. Specify whether the mode by passing true (continuous) or
10022  * false (timeout) as the final parameter. The port must be configured as a
10023  * Lowspeed port before using this function.
10024  *
10025  * \param port The sensor port. See \ref InPorts.
10026  * \param channel The Power Function channel.  See \ref PFChannelConstants.
10027  * \param out The Power Function output. See \ref PFOutputs.
10028  * \param pin The Power Function pin. See \ref PFPinConstants.
10029  * \param func The Power Function single pin function. See \ref PFPinFuncs.
10030  * \param cont Control whether the mode is continuous or timeout.
10031  * \return The function call result. \ref NO_ERR or \ref CommandCommErrors.
10032  */
10033 inline char HTPFSinglePin(const byte port, const byte channel, const byte out, const byte pin, const byte func, bool cont);
10034 
10035 /**
10036  * HTPFTrain function.
10037  * Control both outputs on a Power Function receiver set to the specified
10038  * channel using the HiTechnic iRLink device as if it were an IR Train
10039  * receiver. Valid function values are \ref TRAIN_FUNC_STOP, \ref TRAIN_FUNC_INCR_SPEED,
10040  * \ref TRAIN_FUNC_DECR_SPEED, and \ref TRAIN_FUNC_TOGGLE_LIGHT. Valid channels are
10041  * \ref PF_CHANNEL_1 through \ref PF_CHANNEL_4. The port must be configured as a
10042  * Lowspeed port before using this function.
10043  *
10044  * \param port The sensor port. See \ref InPorts.
10045  * \param channel The Power Function channel.  See \ref PFChannelConstants.
10046  * \param func The Power Function train function. See \ref IRTrainFuncs.
10047  * \return The function call result. \ref NO_ERR or \ref CommandCommErrors.
10048  */
10049 inline char HTPFTrain(const byte port, const byte channel, const byte func);
10050 
10051 /**
10052  * HTRCXSetIRLinkPort function.
10053  * Set the global port in advance of using the HTRCX* and HTScout* API
10054  * functions for sending RCX and Scout messages over the HiTechnic iRLink
10055  * device. The port must be configured as a Lowspeed port before using any of
10056  * the HiTechnic RCX and Scout iRLink functions.
10057  *
10058  * \param port The sensor port. See \ref InPorts.
10059  */
10060 inline void HTRCXSetIRLinkPort(const byte port);
10061 
10062 /**
10063  * HTRCXBatteryLevel function.
10064  * Send the BatteryLevel command to an RCX to read the current battery level.
10065  *
10066  * \return The RCX battery level.
10067  */
10068 inline int HTRCXBatteryLevel(void);
10069 
10070 /**
10071  * HTRCXPoll function
10072  * Send the Poll command to an RCX to read a signed 2-byte value at the
10073  * specified source and value combination.
10074  *
10075  * \param src The RCX source.  See \ref RCXSourceConstants.
10076  * \param value The RCX value.
10077  * \return The value read from the specified port and value.
10078  */
10079 inline int HTRCXPoll(const byte src, const byte value);
10080 
10081 /**
10082  * HTRCXPollMemory function.
10083  * Send the PollMemory command to an RCX.
10084  *
10085  * \param address The RCX memory address.
10086  * \return The value read from the specified address.
10087  */
10088 inline int HTRCXPollMemory(const unsigned int address);
10089 
10090 /**
10091  * HTRCXAddToDatalog function.
10092  * Send the AddToDatalog command to an RCX.
10093  *
10094  * \param src The RCX source.  See \ref RCXSourceConstants.
10095  * \param value The RCX value.
10096  */
10097 inline void HTRCXAddToDatalog(const byte src, const unsigned int value);
10098 
10099 /**
10100  * HTRCXClearAllEvents function.
10101  * Send the ClearAllEvents command to an RCX.
10102  */
10103 inline void HTRCXClearAllEvents(void);
10104 
10105 /**
10106  * HTRCXClearCounter function.
10107  * Send the ClearCounter command to an RCX.
10108  *
10109  * \param counter The counter to clear.
10110  */
10111 inline void HTRCXClearCounter(const byte counter);
10112 
10113 /**
10114  * HTRCXClearMsg function.
10115  * Send the ClearMsg command to an RCX.
10116  */
10117 inline void HTRCXClearMsg(void);
10118 
10119 /**
10120  * HTRCXClearSensor function.
10121  * Send the ClearSensor command to an RCX.
10122  *
10123  * \param port The RCX port number.
10124  */
10125 inline void HTRCXClearSensor(const byte port);
10126 
10127 /**
10128  * HTRCXClearSound function.
10129  * Send the ClearSound command to an RCX.
10130  */
10131 inline void HTRCXClearSound(void);
10132 
10133 /**
10134  * HTRCXClearTimer function.
10135  * Send the ClearTimer command to an RCX.
10136  *
10137  * \param timer The timer to clear.
10138  */
10139 inline void HTRCXClearTimer(const byte timer);
10140 
10141 /**
10142  * HTRCXCreateDatalog function.
10143  * Send the CreateDatalog command to an RCX.
10144  *
10145  * \param size The new datalog size.
10146  */
10147 inline void HTRCXCreateDatalog(const unsigned int size);
10148 
10149 /**
10150  * HTRCXDecCounter function.
10151  * Send the DecCounter command to an RCX.
10152  *
10153  * \param counter The counter to decrement.
10154  */
10155 inline void HTRCXDecCounter(const byte counter);
10156 
10157 /**
10158  * HTRCXDeleteSub function.
10159  * Send the DeleteSub command to an RCX.
10160  *
10161  * \param s The subroutine number to delete.
10162  */
10163 inline void HTRCXDeleteSub(const byte s);
10164 
10165 /**
10166  * HTRCXDeleteSubs function.
10167  * Send the DeleteSubs command to an RCX.
10168  */
10169 inline void HTRCXDeleteSubs(void);
10170 
10171 /**
10172  * HTRCXDeleteTask function.
10173  * Send the DeleteTask command to an RCX.
10174  *
10175  * \param t The task number to delete.
10176  */
10177 inline void HTRCXDeleteTask(const byte t);
10178 
10179 /**
10180  * HTRCXDeleteTasks function.
10181  * Send the DeleteTasks command to an RCX.
10182  */
10183 inline void HTRCXDeleteTasks(void);
10184 
10185 /**
10186  * HTRCXDisableOutput function.
10187  * Send the DisableOutput command to an RCX.
10188  *
10189  * \param outputs The RCX output(s) to disable. See \ref RCXOutputConstants.
10190  */
10191 inline void HTRCXDisableOutput(const byte outputs);
10192 
10193 /**
10194  * HTRCXEnableOutput function.
10195  * Send the EnableOutput command to an RCX.
10196  *
10197  * \param outputs The RCX output(s) to enable. See \ref RCXOutputConstants.
10198  */
10199 inline void HTRCXEnableOutput(const byte outputs);
10200 
10201 /**
10202  * HTRCXEvent function.
10203  * Send the Event command to an RCX.
10204  *
10205  * \param src The RCX source.  See \ref RCXSourceConstants.
10206  * \param value The RCX value.
10207  */
10208 inline void HTRCXEvent(const byte src, const unsigned int value);
10209 
10210 /**
10211  * HTRCXFloat function.
10212  * Send commands to an RCX to float the specified outputs.
10213  *
10214  * \param outputs The RCX output(s) to float. See \ref RCXOutputConstants.
10215  */
10216 inline void HTRCXFloat(const byte outputs);
10217 
10218 /**
10219  * HTRCXFwd function.
10220  * Send commands to an RCX to set the specified outputs to the forward direction.
10221  *
10222  * \param outputs The RCX output(s) to set forward. See \ref RCXOutputConstants.
10223  */
10224 inline void HTRCXFwd(const byte outputs);
10225 
10226 /**
10227  * HTRCXIncCounter function.
10228  * Send the IncCounter command to an RCX.
10229  *
10230  * \param counter The counter to increment.
10231  */
10232 inline void HTRCXIncCounter(const byte counter);
10233 
10234 /**
10235  * HTRCXInvertOutput function.
10236  * Send the InvertOutput command to an RCX.
10237  *
10238  * \param outputs The RCX output(s) to invert. See \ref RCXOutputConstants.
10239  */
10240 inline void HTRCXInvertOutput(const byte outputs);
10241 
10242 /**
10243  * HTRCXMuteSound function.
10244  * Send the MuteSound command to an RCX.
10245  */
10246 inline void HTRCXMuteSound(void);
10247 
10248 /**
10249  * HTRCXObvertOutput function.
10250  * Send the ObvertOutput command to an RCX.
10251  *
10252  * \param outputs The RCX output(s) to obvert. See \ref RCXOutputConstants.
10253  */
10254 inline void HTRCXObvertOutput(const byte outputs);
10255 
10256 /**
10257  * HTRCXOff function.
10258  * Send commands to an RCX to turn off the specified outputs.
10259  *
10260  * \param outputs The RCX output(s) to turn off. See \ref RCXOutputConstants.
10261  */
10262 inline void HTRCXOff(const byte outputs);
10263 
10264 /**
10265  * HTRCXOn function.
10266  * Send commands to an RCX to turn on the specified outputs.
10267  *
10268  * \param outputs The RCX output(s) to turn on. See \ref RCXOutputConstants.
10269  */
10270 inline void HTRCXOn(const byte outputs);
10271 
10272 /**
10273  * HTRCXOnFor function.
10274  * Send commands to an RCX to turn on the specified outputs in the forward
10275  * direction for the specified duration.
10276  *
10277  * \param outputs The RCX output(s) to turn on. See \ref RCXOutputConstants.
10278  * \param ms The number of milliseconds to leave the outputs on
10279  */
10280 inline void HTRCXOnFor(const byte outputs, const unsigned int ms);
10281 
10282 /**
10283  * HTRCXOnFwd function.
10284  * Send commands to an RCX to turn on the specified outputs in the forward
10285  * direction.
10286  *
10287  * \param outputs The RCX output(s) to turn on in the forward direction. See \ref RCXOutputConstants.
10288  */
10289 inline void HTRCXOnFwd(const byte outputs);
10290 
10291 /**
10292  * HTRCXOnRev function.
10293  * Send commands to an RCX to turn on the specified outputs in the reverse direction.
10294  *
10295  * \param outputs The RCX output(s) to turn on in the reverse direction. See \ref RCXOutputConstants.
10296  */
10297 inline void HTRCXOnRev(const byte outputs);
10298 
10299 /**
10300  * HTRCXPBTurnOff function.
10301  * Send the PBTurnOff command to an RCX.
10302  */
10303 inline void HTRCXPBTurnOff(void);
10304 
10305 /**
10306  * HTRCXPing function.
10307  * Send the Ping command to an RCX.
10308  */
10309 inline void HTRCXPing(void);
10310 
10311 /**
10312  * HTRCXPlaySound function.
10313  * Send the PlaySound command to an RCX.
10314  *
10315  * \param snd The sound number to play.
10316  */
10317 inline void HTRCXPlaySound(const byte snd);
10318 
10319 /**
10320  * HTRCXPlayTone function.
10321  * Send the PlayTone command to an RCX.
10322  *
10323  * \param freq The frequency of the tone to play.
10324  * \param duration The duration of the tone to play.
10325  */
10326 inline void HTRCXPlayTone(const unsigned int freq, const byte duration);
10327 
10328 /**
10329  * HTRCXPlayToneVar function.
10330  * Send the PlayToneVar command to an RCX.
10331  *
10332  * \param varnum The variable containing the tone frequency to play.
10333  * \param duration The duration of the tone to play.
10334  */
10335 inline void HTRCXPlayToneVar(const byte varnum, const byte duration);
10336 
10337 /**
10338  * HTRCXRemote function.
10339  * Send the Remote command to an RCX.
10340  *
10341  * \param cmd The RCX IR remote command to send. See \ref RCXRemoteConstants.
10342  */
10343 inline void HTRCXRemote(unsigned int cmd);
10344 
10345 /**
10346  * HTRCXRev function.
10347  * Send commands to an RCX to set the specified outputs to the reverse direction.
10348  *
10349  * \param outputs The RCX output(s) to reverse direction. See \ref RCXOutputConstants.
10350  */
10351 inline void HTRCXRev(const byte outputs);
10352 
10353 /**
10354  * HTRCXSelectDisplay function.
10355  * Send the SelectDisplay command to an RCX.
10356  *
10357  * \param src The RCX source.  See \ref RCXSourceConstants.
10358  * \param value The RCX value.
10359  */
10360 inline void HTRCXSelectDisplay(const byte src, const unsigned int value);
10361 
10362 /**
10363  * HTRCXSelectProgram function.
10364  * Send the SelectProgram command to an RCX.
10365  *
10366  * \param prog The program number to select.
10367  */
10368 inline void HTRCXSelectProgram(const byte prog);
10369 
10370 /**
10371  * HTRCXSendSerial function.
10372  * Send the SendSerial command to an RCX.
10373  *
10374  * \param first The first byte address.
10375  * \param count The number of bytes to send.
10376  */
10377 inline void HTRCXSendSerial(const byte first, const byte count);
10378 
10379 /**
10380  * HTRCXSetDirection function.
10381  * Send the SetDirection command to an RCX to configure the direction of the specified outputs.
10382  *
10383  * \param outputs The RCX output(s) to set direction. See \ref RCXOutputConstants.
10384  * \param dir The RCX output direction. See \ref RCXOutputDirection.
10385  */
10386 inline void HTRCXSetDirection(const byte outputs, const byte dir);
10387 
10388 /**
10389  * HTRCXSetEvent function.
10390  * Send the SetEvent command to an RCX.
10391  *
10392  * \param evt The event number to set.
10393  * \param src The RCX source. See \ref RCXSourceConstants.
10394  * \param type The event type.
10395  */
10396 inline void HTRCXSetEvent(const byte evt, const byte src, const byte type);
10397 
10398 /**
10399  * HTRCXSetGlobalDirection function.
10400  * Send the SetGlobalDirection command to an RCX.
10401  *
10402  * \param outputs The RCX output(s) to set global direction. See \ref RCXOutputConstants.
10403  * \param dir The RCX output direction. See \ref RCXOutputDirection.
10404  */
10405 inline void HTRCXSetGlobalDirection(const byte outputs, const byte dir);
10406 
10407 /**
10408  * HTRCXSetGlobalOutput function.
10409  * Send the SetGlobalOutput command to an RCX.
10410  *
10411  * \param outputs The RCX output(s) to set global mode. See \ref RCXOutputConstants.
10412  * \param mode The RCX output mode. See \ref RCXOutputMode.
10413  */
10414 inline void HTRCXSetGlobalOutput(const byte outputs, const byte mode);
10415 
10416 /**
10417  * HTRCXSetMaxPower function.
10418  * Send the SetMaxPower command to an RCX.
10419  *
10420  * \param outputs The RCX output(s) to set max power. See \ref RCXOutputConstants.
10421  * \param pwrsrc The RCX source.  See \ref RCXSourceConstants.
10422  * \param pwrval The RCX value.
10423  */
10424 inline void HTRCXSetMaxPower(const byte outputs, const byte pwrsrc, const byte pwrval);
10425 
10426 /**
10427  * HTRCXSetMessage function.
10428  * Send the SetMessage command to an RCX.
10429  *
10430  * \param msg The numeric message to send.
10431  */
10432 inline void HTRCXSetMessage(const byte msg);
10433 
10434 /**
10435  * HTRCXSetOutput function.
10436  * Send the SetOutput command to an RCX to configure the mode of the specified outputs
10437  *
10438  * \param outputs The RCX output(s) to set mode. See \ref RCXOutputConstants.
10439  * \param mode The RCX output mode. See \ref RCXOutputMode.
10440  */
10441 inline void HTRCXSetOutput(const byte outputs, const byte mode);
10442 
10443 /**
10444  * HTRCXSetPower function.
10445  * Send the SetPower command to an RCX to configure the power level of the specified outputs.
10446  *
10447  * \param outputs The RCX output(s) to set power. See \ref RCXOutputConstants.
10448  * \param pwrsrc The RCX source.  See \ref RCXSourceConstants.
10449  * \param pwrval The RCX value.
10450  */
10451 inline void HTRCXSetPower(const byte outputs, const byte pwrsrc, const byte pwrval);
10452 
10453 /**
10454  * HTRCXSetPriority function.
10455  * Send the SetPriority command to an RCX.
10456  *
10457  * \param p The new task priority.
10458  */
10459 inline void HTRCXSetPriority(const byte p);
10460 
10461 /**
10462  * HTRCXSetSensorMode function.
10463  * Send the SetSensorMode command to an RCX.
10464  *
10465  * \param port The RCX sensor port.
10466  * \param mode The RCX sensor mode.
10467  */
10468 inline void HTRCXSetSensorMode(const byte port, const byte mode);
10469 
10470 /**
10471  * HTRCXSetSensorType function.
10472  * Send the SetSensorType command to an RCX.
10473  *
10474  * \param port The RCX sensor port.
10475  * \param type The RCX sensor type.
10476  */
10477 inline void HTRCXSetSensorType(const byte port, const byte type);
10478 
10479 /**
10480  * HTRCXSetSleepTime function.
10481  * Send the SetSleepTime command to an RCX.
10482  *
10483  * \param t The new sleep time value.
10484  */
10485 inline void HTRCXSetSleepTime(const byte t);
10486 
10487 /**
10488  * HTRCXSetTxPower function.
10489  * Send the SetTxPower command to an RCX.
10490  *
10491  * \param pwr The IR transmit power level.
10492  */
10493 inline void HTRCXSetTxPower(const byte pwr);
10494 
10495 /**
10496  * HTRCXSetWatch function.
10497  * Send the SetWatch command to an RCX.
10498  *
10499  * \param hours The new watch time hours value.
10500  * \param minutes The new watch time minutes value.
10501  */
10502 inline void HTRCXSetWatch(const byte hours, const byte minutes);
10503 
10504 /**
10505  * HTRCXStartTask function.
10506  * Send the StartTask command to an RCX.
10507  *
10508  * \param t The task number to start.
10509  */
10510 inline void HTRCXStartTask(const byte t);
10511 
10512 /**
10513  * HTRCXStopAllTasks function.
10514  * Send the StopAllTasks command to an RCX.
10515  */
10516 inline void HTRCXStopAllTasks(void);
10517 
10518 /**
10519  * HTRCXStopTask function.
10520  * Send the StopTask command to an RCX.
10521  *
10522  * \param t The task number to stop.
10523  */
10524 inline void HTRCXStopTask(const byte t);
10525 
10526 /**
10527  * HTRCXToggle function.
10528  * Send commands to an RCX to toggle the direction of the specified outputs.
10529  *
10530  * \param outputs The RCX output(s) to toggle. See \ref RCXOutputConstants.
10531  */
10532 inline void HTRCXToggle(const byte outputs);
10533 
10534 /**
10535  * HTRCXUnmuteSound function.
10536  * Send the UnmuteSound command to an RCX.
10537  */
10538 inline void HTRCXUnmuteSound(void);
10539 
10540 /**
10541  * HTScoutCalibrateSensor function.
10542  * Send the CalibrateSensor command to a Scout.
10543  */
10544 inline void HTScoutCalibrateSensor(void);
10545 
10546 /**
10547  * HTScoutMuteSound function.
10548  * Send the MuteSound command to a Scout.
10549  */
10550 inline void HTScoutMuteSound(void);
10551 
10552 /**
10553  * HTScoutSelectSounds function.
10554  * Send the SelectSounds command to a Scout.
10555  *
10556  * \param grp The Scout sound group to select.
10557  */
10558 inline void HTScoutSelectSounds(const byte grp);
10559 
10560 /**
10561  * HTScoutSendVLL function.
10562  * Send the SendVLL command to a Scout.
10563  *
10564  * \param src The Scout source.  See \ref RCXSourceConstants.
10565  * \param value The Scout value.
10566  */
10567 inline void HTScoutSendVLL(const byte src, const unsigned int value);
10568 
10569 /**
10570  * HTScoutSetEventFeedback function.
10571  * Send the SetEventFeedback command to a Scout.
10572  *
10573  * \param src The Scout source.  See \ref RCXSourceConstants.
10574  * \param value The Scout value.
10575  */
10576 inline void HTScoutSetEventFeedback(const byte src, const unsigned int value);
10577 
10578 /**
10579  * HTScoutSetLight function.
10580  * Send the SetLight command to a Scout.
10581  *
10582  * \param x Set the light on or off using this value. See \ref ScoutLightConstants.
10583  */
10584 inline void HTScoutSetLight(const byte x);
10585 
10586 /**
10587  * HTScoutSetScoutMode function.
10588  * Send the SetScoutMode command to a Scout.
10589  *
10590  * \param mode Set the scout mode. See \ref ScoutModeConstants.
10591 */
10592 inline void HTScoutSetScoutMode(const byte mode);
10593 
10594 /**
10595  * HTScoutSetSensorClickTime function.
10596  * Send the SetSensorClickTime command to a Scout.
10597  *
10598  * \param src The Scout source.  See \ref RCXSourceConstants.
10599  * \param value The Scout value.
10600  */
10601 inline void HTScoutSetSensorClickTime(const byte src, const unsigned int value);
10602 
10603 /**
10604  * HTScoutSetSensorHysteresis function.
10605  * Send the SetSensorHysteresis command to a Scout.
10606  *
10607  * \param src The Scout source.  See \ref RCXSourceConstants.
10608  * \param value The Scout value.
10609  */
10610 inline void HTScoutSetSensorHysteresis(const byte src, const unsigned int value);
10611 
10612 /**
10613  * HTScoutSetSensorLowerLimit function.
10614  * Send the SetSensorLowerLimit command to a Scout.
10615  *
10616  * \param src The Scout source.  See \ref RCXSourceConstants.
10617  * \param value The Scout value.
10618  */
10619 inline void HTScoutSetSensorLowerLimit(const byte src, const unsigned int value);
10620 
10621 /**
10622  * HTScoutSetSensorUpperLimit function.
10623  * Send the SetSensorUpperLimit command to a Scout.
10624  *
10625  * \param src The Scout source.  See \ref RCXSourceConstants.
10626  * \param value The Scout value.
10627  */
10628 inline void HTScoutSetSensorUpperLimit(const byte src, const unsigned int value);
10629 
10630 /**
10631  * HTScoutUnmuteSound function.
10632  * Send the UnmuteSound command to a Scout.
10633  */
10634 inline void HTScoutUnmuteSound(void);
10635 
10636 #else
10637 
10638 #define SensorHTCompass(_port) asm { ReadSensorHTCompass(_port, __RETVAL__) }
10639 #define ReadSensorHTAccel(_port, _x, _y, _z) asm { __ReadSensorHTAccel(_port, _x, _y, _z, __RETVAL__) }
10640 #define ReadSensorHTColor(_port, _ColorNum, _Red, _Green, _Blue) asm { __ReadSensorHTColor(_port, _ColorNum, _Red, _Green, _Blue, __RETVAL__) }
10641 #define ReadSensorHTRawColor(_port, _Red, _Green, _Blue) asm { __ReadSensorHTRawColor(_port, _Red, _Green, _Blue, __RETVAL__) }
10642 #define ReadSensorHTNormalizedColor(_port, _ColorIdx, _Red, _Green, _Blue) asm { __ReadSensorHTNormalizedColor(_port, _ColorIdx, _Red, _Green, _Blue, __RETVAL__) }
10643 #define ReadSensorHTIRSeeker(_port, _dir, _s1, _s3, _s5, _s7, _s9) asm { __ReadSensorHTIRSeeker(_port, _dir, _s1, _s3, _s5, _s7, _s9, __RETVAL__) }
10644 #define SensorHTIRSeekerDir(_port) asm { ReadSensorHTIRSeekerDir(_port, __RETVAL__) }
10645 #define SensorHTColorNum(_port) asm { ReadSensorHTColorNum(_port, __RETVAL__) }
10646 #define ReadSensorHTTouchMultiplexer(_p, _t1, _t2, _t3, _t4) asm { __ReadSensorHTTouchMultiplexer(_p, _t1, _t2, _t3, _t4) }
10647 #define SensorHTIRSeeker2Addr(_port, _reg) asm { ReadSensorHTIRSeeker2Addr(_port, _reg, __RETVAL__) }
10648 #define SensorHTIRSeeker2DCDir(_port) asm { ReadSensorHTIRSeeker2Addr(_port, HTIR2_REG_DCDIR, __RETVAL__) }
10649 #define SensorHTIRSeeker2ACDir(_port) asm { ReadSensorHTIRSeeker2Addr(_port, HTIR2_REG_ACDIR, __RETVAL__) }
10650 #define ReadSensorHTIRSeeker2DC(_port, _dir, _s1, _s3, _s5, _s7, _s9, _avg) asm { __ReadSensorHTIRSeeker2DC(_port, _dir, _s1, _s3, _s5, _s7, _s9, _avg, __RETVAL__) }
10651 #define ReadSensorHTIRSeeker2AC(_port, _dir, _s1, _s3, _s5, _s7, _s9) asm { __ReadSensorHTIRSeeker2AC(_port, _dir, _s1, _s3, _s5, _s7, _s9, __RETVAL__) }
10652 #define SetHTIRSeeker2Mode(_port, _mode) asm { __SetHTIRSeeker2Mode(_port, _mode, __RETVAL__) }
10653 
10654 #define SetHTColor2Mode(_port, _mode) asm { __SetHTColor2Mode(_port, _mode, __RETVAL__) }
10655 #define ReadSensorHTColor2Active(_port, _ColorNum, _Red, _Green, _Blue, _White) asm { __ReadSensorHTColor2Active(_port, _ColorNum, _Red, _Green, _Blue, _White, __RETVAL__) }
10656 #define ReadSensorHTNormalizedColor2Active(_port, _ColorIdx, _Red, _Green, _Blue) asm { __ReadSensorHTNormalizedColor2Active(_port, _ColorIdx, _Red, _Green, _Blue, __RETVAL__) }
10657 #define ReadSensorHTRawColor2(_port, _Red, _Green, _Blue, _White) asm { __ReadSensorHTRawColor2(_port, _Red, _Green, _Blue, _White, __RETVAL__) }
10658 #define ReadSensorHTIRReceiver(_port, _pfdata) asm { __ReadSensorHTIRReceiver(_port, _pfdata, __RETVAL__) }
10659 #define ReadSensorHTIRReceiverEx(_port, _reg, _pfchar) asm { __ReadSensorHTIRReceiverEx(_port, _reg, _pfchar, __RETVAL__) }
10660 #define ResetSensorHTAngle(_port, _mode) asm { __ResetSensorHTAngle(_port, _mode, __RETVAL__) }
10661 #define ReadSensorHTAngle(_port, _Angle, _AccAngle, _RPM) asm { __ReadSensorHTAngle(_port, _Angle, _AccAngle, _RPM, __RETVAL__) }
10662 
10663 
10664 #define HTPowerFunctionCommand(_port, _channel, _outa, _outb) asm { __HTPFComboDirect(_port, _channel, _outa, _outb, __RETVAL__) }
10665 #define HTPFComboDirect(_port, _channel, _outa, _outb) asm { __HTPFComboDirect(_port, _channel, _outa, _outb, __RETVAL__) }
10666 #define HTPFSinglePin(_port, _channel, _out, _pin, _func, _cont) asm { __HTPFSinglePin(_port, _channel, _out, _pin, _func, _cont, __RETVAL__) }
10667 #define HTPFSingleOutputCST(_port, _channel, _out, _func) asm { __HTPFSingleOutput(_port, _channel, _out, _func, TRUE, __RETVAL__) }
10668 #define HTPFSingleOutputPWM(_port, _channel, _out, _func) asm { __HTPFSingleOutput(_port, _channel, _out, _func, FALSE, __RETVAL__) }
10669 #define HTPFComboPWM(_port, _channel, _outa, _outb) asm { __HTPFComboPWM(_port, _channel, _outa, _outb, __RETVAL__) }
10670 #define HTPFTrain(_port, _channel, _func) asm { __HTIRTrain(_port, _channel, _func, TRUE, __RETVAL__) }
10671 #define HTIRTrain(_port, _channel, _func) asm { __HTIRTrain(_port, _channel, _func, FALSE, __RETVAL__) }
10672 #define HTPFRawOutput(_port, _nibble0, _nibble1, _nibble2) asm { __HTPFRawOutput(_port, _nibble0, _nibble1, _nibble2, __RETVAL__) }
10673 #define HTPFRepeat(_port, _count, _delay) asm { __HTPFRepeatLastCommand(_port, _count, _delay, __RETVAL__) }
10674 
10675 #define HTRCXSetIRLinkPort(_port) asm { __HTRCXSetIRLinkPort(_port) }
10676 #define HTRCXPoll(_src, _value) asm { __HTRCXPoll(_src, _value, __RETVAL__) }
10677 #define HTRCXBatteryLevel() asm { __HTRCXBatteryLevel(__RETVAL__) }
10678 #define HTRCXPing() asm { __HTRCXOpNoArgs(RCX_PingOp) }
10679 #define HTRCXDeleteTasks() asm { __HTRCXOpNoArgs(RCX_DeleteTasksOp) }
10680 #define HTRCXStopAllTasks() asm { __HTRCXOpNoArgs(RCX_StopAllTasksOp) }
10681 #define HTRCXPBTurnOff() asm { __HTRCXOpNoArgs(RCX_PBTurnOffOp) }
10682 #define HTRCXDeleteSubs() asm { __HTRCXOpNoArgs(RCX_DeleteSubsOp) }
10683 #define HTRCXClearSound() asm { __HTRCXOpNoArgs(RCX_ClearSoundOp) }
10684 #define HTRCXClearMsg() asm { __HTRCXOpNoArgs(RCX_ClearMsgOp) }
10685 #define HTRCXMuteSound() asm { __HTRCXOpNoArgs(RCX_MuteSoundOp) }
10686 #define HTRCXUnmuteSound() asm { __HTRCXOpNoArgs(RCX_UnmuteSoundOp) }
10687 #define HTRCXClearAllEvents() asm { __HTRCXOpNoArgs(RCX_ClearAllEventsOp) }
10688 #define HTRCXSetOutput(_outputs, _mode) asm { __HTRCXSetOutput(_outputs, _mode) }
10689 #define HTRCXSetDirection(_outputs, _dir) asm { __HTRCXSetDirection(_outputs, _dir) }
10690 #define HTRCXSetPower(_outputs, _pwrsrc, _pwrval) asm { __HTRCXSetPower(_outputs, _pwrsrc, _pwrval) }
10691 #define HTRCXOn(_outputs) asm { __HTRCXSetOutput(_outputs, RCX_OUT_ON) }
10692 #define HTRCXOff(_outputs) asm { __HTRCXSetOutput(_outputs, RCX_OUT_OFF) }
10693 #define HTRCXFloat(_outputs) asm { __HTRCXSetOutput(_outputs, RCX_OUT_FLOAT) }
10694 #define HTRCXToggle(_outputs) asm { __HTRCXSetDirection(_outputs, RCX_OUT_TOGGLE) }
10695 #define HTRCXFwd(_outputs) asm { __HTRCXSetDirection(_outputs, RCX_OUT_FWD) }
10696 #define HTRCXRev(_outputs) asm { __HTRCXSetDirection(_outputs, RCX_OUT_REV) }
10697 #define HTRCXOnFwd(_outputs) asm { __HTRCXOnFwd(_outputs) }
10698 #define HTRCXOnRev(_outputs) asm { __HTRCXOnRev(_outputs) }
10699 #define HTRCXOnFor(_outputs, _ms) asm { __HTRCXOnFor(_outputs, _ms) }
10700 #define HTRCXSetTxPower(_pwr) asm { __HTRCXSetTxPower(_pwr) }
10701 #define HTRCXPlaySound(_snd) asm { __HTRCXPlaySound(_snd) }
10702 #define HTRCXDeleteTask(_t) asm { __HTRCXDeleteTask(_t) }
10703 #define HTRCXStartTask(_t) asm { __HTRCXStartTask(_t) }
10704 #define HTRCXStopTask(_t) asm { __HTRCXStopTask(_t) }
10705 #define HTRCXSelectProgram(_prog) asm { __HTRCXSelectProgram(_prog) }
10706 #define HTRCXClearTimer(_timer) asm { __HTRCXClearTimer(_timer) }
10707 #define HTRCXSetSleepTime(_t) asm { __HTRCXSetSleepTime(_t) }
10708 #define HTRCXDeleteSub(_s) asm { __HTRCXDeleteSub(_s) }
10709 #define HTRCXClearSensor(_port) asm { __HTRCXClearSensor(_port) }
10710 #define HTRCXPlayToneVar(_varnum, _duration) asm { __HTRCXPlayToneVar(_varnum, _duration) }
10711 #define HTRCXSetWatch(_hours, _minutes) asm { __HTRCXSetWatch(_hours, _minutes) }
10712 #define HTRCXSetSensorType(_port, _type) asm { __HTRCXSetSensorType(_port, _type) }
10713 #define HTRCXSetSensorMode(_port, _mode) asm { __HTRCXSetSensorMode(_port, _mode) }
10714 #define HTRCXCreateDatalog(_size) asm { __HTRCXCreateDatalog(_size) }
10715 #define HTRCXAddToDatalog(_src, _value) asm { __HTRCXAddToDatalog(_src, _value) }
10716 #define HTRCXSendSerial(_first, _count) asm { __HTRCXSendSerial(_first, _count) }
10717 #define HTRCXRemote(_cmd) asm { __HTRCXRemote(_cmd) }
10718 #define HTRCXEvent(_src, _value) asm { __HTRCXEvent(_src, _value) }
10719 #define HTRCXPlayTone(_freq, _duration) asm { __HTRCXPlayTone(_freq, _duration) }
10720 #define HTRCXSelectDisplay(_src, _value) asm { __HTRCXSelectDisplay(_src, _value) }
10721 #define HTRCXPollMemory(_memaddress) asm { __HTRCXPollMemory(_memaddress, __RETVAL__) }
10722 #define HTRCXSetEvent(_evt, _src, _type) asm { __HTRCXSetEvent(_evt, _src, _type) }
10723 #define HTRCXSetGlobalOutput(_outputs, _mode) asm { __HTRCXSetGlobalOutput(_outputs, _mode) }
10724 #define HTRCXSetGlobalDirection(_outputs, _dir) asm { __HTRCXSetGlobalDirection(_outputs, _dir) }
10725 #define HTRCXSetMaxPower(_outputs, _pwrsrc, _pwrval) asm { __HTRCXSetMaxPower(_outputs, _pwrsrc, _pwrval) }
10726 #define HTRCXEnableOutput(_outputs) asm { __HTRCXSetGlobalOutput(_outputs, RCX_OUT_ON) }
10727 #define HTRCXDisableOutput(_outputs) asm { __HTRCXSetGlobalOutput(_outputs, RCX_OUT_OFF) }
10728 #define HTRCXInvertOutput(_outputs) asm { __HTRCXSetGlobalDirection(_outputs, RCX_OUT_REV) }
10729 #define HTRCXObvertOutput(_outputs) asm { __HTRCXSetGlobalDirection(_outputs, RCX_OUT_FWD) }
10730 #define HTRCXIncCounter(_counter) asm { __HTRCXIncCounter(_counter) }
10731 #define HTRCXDecCounter(_counter) asm { __HTRCXDecCounter(_counter) }
10732 #define HTRCXClearCounter(_counter) asm { __HTRCXClearCounter(_counter) }
10733 #define HTRCXSetPriority(_p) asm { __HTRCXSetPriority(_p) }
10734 #define HTRCXSetMessage(_msg) asm { __HTRCXSetMessage(_msg) }
10735 
10736 #define HTScoutCalibrateSensor() asm { __HTRCXOpNoArgs(RCX_LSCalibrateOp) }
10737 #define HTScoutMuteSound() asm { __HTScoutMuteSound() }
10738 #define HTScoutUnmuteSound() asm { __HTScoutUnmuteSound() }
10739 #define HTScoutSelectSounds(_grp) asm { __HTScoutSelectSounds(_grp) }
10740 #define HTScoutSetLight(_x) asm { __HTScoutSetLight(_x) }
10741 #define HTScoutSetSensorClickTime(_src, _value) asm { __HTScoutSetSensorClickTime(_src, _value) }
10742 #define HTScoutSetSensorHysteresis(_src, _value) asm { __HTScoutSetSensorHysteresis(_src, _value) }
10743 #define HTScoutSetSensorLowerLimit(_src, _value) asm { __HTScoutSetSensorLowerLimit(_src, _value) }
10744 #define HTScoutSetSensorUpperLimit(_src, _value) asm { __HTScoutSetSensorUpperLimit(_src, _value) }
10745 #define HTScoutSetEventFeedback(_src, _value) asm { __HTScoutSetEventFeedback(_src, _value) }
10746 #define HTScoutSendVLL(_src, _value) asm { __HTScoutSendVLL(_src, _value) }
10747 #define HTScoutSetScoutMode(_mode) asm { __HTScoutSetScoutMode(_mode) }
10748 
10749 #endif
10750 /** @} */ // end of HiTechnicAPI group
10751 
10752 
10753 ///////////////////////////////////////////////////////////////////////////////
10754 /////////////////////////////// MindSensors API ///////////////////////////////
10755 ///////////////////////////////////////////////////////////////////////////////
10756 
10757 
10758 /** @addtogroup MindSensorsAPI
10759  * @{
10760  */
10761 
10762 /**
10763  * Configure a mindsensors pressure sensor.
10764  * Configure the specified port for a mindsensors pressure sensor.
10765  *
10766  * \param port The port to configure. See \ref InPorts.
10767  */
SetSensorMSPressure(const byte & port)10768 inline void SetSensorMSPressure(const byte & port ) {
10769   SetSensorType(port, SENSOR_TYPE_LIGHT);
10770   SetSensorMode(port, SENSOR_MODE_RAW);
10771   ResetSensor(port);
10772 }
10773 
10774 /**
10775  * Configure a mindsensors DROD sensor.
10776  * Configure the specified port for a mindsensors DROD sensor.
10777  *
10778  * \param port The port to configure. See \ref InPorts.
10779  * \param bActive A flag indicating whether to configure the sensor in active
10780  * or inactive mode.
10781  */
SetSensorMSDROD(const byte & port,bool bActive)10782 inline void SetSensorMSDROD(const byte & port, bool bActive) {
10783   if (bActive)
10784     SetSensorType(port, SENSOR_TYPE_LIGHT_ACTIVE);
10785   else
10786     SetSensorType(port, SENSOR_TYPE_LIGHT_INACTIVE);
10787   SetSensorMode(port, SENSOR_MODE_PERCENT);
10788   ResetSensor(port);
10789 }
10790 
10791 
10792 /**
10793  * Configure a mindsensors SumoEyes sensor.
10794  * Configure the specified port for a mindsensors SumoEyes sensor.
10795  *
10796  * \param port The port to configure. See \ref InPorts.
10797  * \param bLong A flag indicating whether to configure the sensor in long range
10798  * or short range mode.
10799  */
SetSensorNXTSumoEyes(const byte & port,bool bLong)10800 inline void SetSensorNXTSumoEyes(const byte & port, bool bLong) {
10801   if (bLong)
10802     SetSensorType(port, SENSOR_TYPE_LIGHT_INACTIVE);
10803   else
10804     SetSensorType(port, SENSOR_TYPE_LIGHT_ACTIVE);
10805   SetSensorMode(port, SENSOR_MODE_PERCENT);
10806   ResetSensor(port);
10807   Wait(275);
10808 }
10809 
10810 /**
10811  * Read mindsensors pressure sensor.
10812  * Read the pressure sensor value of the mindsensors pressure sensor on the
10813  * specified port.
10814  *
10815  * \param port The sensor port. See \ref InPorts.
10816  * \return The pressure reading.
10817  */
SensorMSPressure(const byte & port)10818 inline int SensorMSPressure(const byte & port) {
10819   asm {
10820     getin __RETVAL__, port, RawValueField
10821     sub __RETVAL__, 1024, __RETVAL__
10822     div __RETVAL__, __RETVAL__, 25
10823   }
10824 }
10825 
10826 /**
10827  * Read mindsensors NXTSumoEyes obstacle zone.
10828  * Return the Mindsensors NXTSumoEyes sensor obstacle zone value.  The port
10829  * should be configured for the NXTSumoEyes device using \ref SetSensorNXTSumoEyes
10830  * before calling this function.
10831  *
10832  * \param port The sensor port. See \ref InPorts.
10833  * \return The mindsensors NXTSumoEyes obstacle zone value.  See \ref NXTSumoEyesConstants.
10834  */
SensorNXTSumoEyes(const byte & port)10835 char SensorNXTSumoEyes(const byte & port) {
10836   int value;
10837   asm {
10838     getin value, port, NormalizedValueField
10839     mul value, value, 100
10840     div value, value, 1023
10841   }
10842   if (value > 30 && value < 36)
10843     return NXTSE_ZONE_LEFT;
10844   if (value > 63 && value < 69)
10845     return NXTSE_ZONE_RIGHT;
10846   if (value > 74 && value <= 80)
10847     return NXTSE_ZONE_FRONT;
10848   return NXTSE_ZONE_NONE;
10849 }
10850 
10851 #ifdef __DOXYGEN_DOCS
10852 
10853 /**
10854  * Read mindsensors compass value.
10855  * Return the Mindsensors Compass sensor value.
10856  *
10857  * \param port The sensor port. See \ref InPorts.
10858  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
10859  * \return The mindsensors compass value
10860  */
10861 inline int SensorMSCompass(const byte & port, const byte i2caddr);
10862 
10863 /**
10864  * Read mindsensors DROD value.
10865  * Return the Mindsensors DROD sensor value.
10866  *
10867  * \param port The sensor port. See \ref InPorts.
10868  * \return The mindsensors DROD value
10869  */
10870 inline int SensorMSDROD(const byte & port);
10871 
10872 /**
10873  * Read mindsensors NXTSumoEyes raw value.
10874  * Return the Mindsensors NXTSumoEyes raw sensor value. The port
10875  * should be configured for the NXTSumoEyes device using \ref SetSensorNXTSumoEyes
10876  * before calling this function.
10877  *
10878  * \param port The sensor port. See \ref InPorts.
10879  * \return The mindsensors NXTSumoEyes raw value
10880  */
10881 inline int SensorNXTSumoEyesRaw(const byte & port);
10882 
10883 /**
10884  * Read mindsensors raw pressure value.
10885  * Return the Mindsensors pressure sensor raw value.
10886  *
10887  * \param port The sensor port. See \ref InPorts.
10888  * \return The mindsensors raw pressure value
10889  */
10890 inline int SensorMSPressureRaw(const byte & port);
10891 
10892 /**
10893  * Read mindsensors acceleration values.
10894  * Read X, Y, and Z axis acceleration values from the mindsensors Accelerometer
10895  * sensor. Returns a boolean value indicating whether or not the operation
10896  * completed successfully. The port must be configured as a Lowspeed port
10897  * before using this function.
10898  *
10899  * \param port The sensor port. See \ref InPorts.
10900  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
10901  * \param x The output x-axis acceleration.
10902  * \param y The output y-axis acceleration.
10903  * \param z The output z-axis acceleration.
10904  * \return The function call result.
10905  */
10906 inline bool ReadSensorMSAccel(const byte port, const byte i2caddr, int & x, int & y, int & z);
10907 
10908 /**
10909  * Read mindsensors playstation controller values.
10910  * Read playstation controller values from the mindsensors playstation
10911  * sensor. Returns a boolean value indicating whether or not the operation
10912  * completed successfully. The port must be configured as a Lowspeed port
10913  * before using this function.
10914  *
10915  * \param port The sensor port. See \ref InPorts.
10916  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
10917  * \param btnset1 The button set 1 values. See \ref MSPSPNXBtnSet1.
10918  * \param btnset2 The button set 2 values. See \ref MSPSPNXBtnSet2.
10919  * \param xleft The left joystick x value.
10920  * \param yleft The left joystick y value.
10921  * \param xright The right joystick x value.
10922  * \param yright The right joystick y value.
10923  * \return The function call result.
10924  */
10925 inline bool ReadSensorMSPlayStation(const byte port, const byte i2caddr, byte & btnset1, byte & btnset2, byte & xleft, byte & yleft, byte & xright, byte & yright);
10926 
10927 /**
10928  * Read mindsensors RTClock values.
10929  * Read real-time clock values from the Mindsensors RTClock sensor. Returns
10930  * a boolean value indicating whether or not the operation completed
10931  * successfully. The port must be configured as a Lowspeed port before using
10932  * this function.
10933  *
10934  * \param port The sensor port. See \ref InPorts.
10935  * \param sec The seconds.
10936  * \param min The minutes.
10937  * \param hrs The hours.
10938  * \param dow The day of week number.
10939  * \param date The day.
10940  * \param month The month.
10941  * \param year The year.
10942  * \return The function call result.
10943  */
10944 inline bool ReadSensorMSRTClock(const byte port, byte & sec, byte & min, byte & hrs, byte & dow, byte & date, byte & month, byte & year);
10945 
10946 /**
10947  * Read mindsensors tilt values.
10948  * Read X, Y, and Z axis tilt values from the mindsensors tilt
10949  * sensor. Returns a boolean value indicating whether or not the operation
10950  * completed successfully. The port must be configured as a Lowspeed port
10951  * before using this function.
10952  *
10953  * \param port The sensor port. See \ref InPorts.
10954  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
10955  * \param x The output x-axis tilt.
10956  * \param y The output y-axis tilt.
10957  * \param z The output z-axis tilt.
10958  * \return The function call result.
10959  */
10960 inline bool ReadSensorMSTilt(const byte & port, const byte & i2caddr, byte & x, byte & y, byte & z);
10961 
10962 /**
10963  * Send PFMate command.
10964  * Send a PFMate command to the power function IR receiver.
10965  * Returns a boolean value indicating whether or not the operation
10966  * completed successfully. The port must be configured as a Lowspeed port
10967  * before using this function.
10968  *
10969  * \param port The sensor port. See \ref NBCInputPortConstants.
10970  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
10971  * \param channel The power function IR receiver channel. See the \ref PFMateChannelConstants group.
10972  * \param motors The motor(s) to control. See the \ref PFMateMotorConstants group.
10973  * \param cmdA The power function command for motor A.
10974  * \param spdA The power function speed for motor A.
10975  * \param cmdB The power function command for motor B.
10976  * \param spdB The power function speed for motor B.
10977  * \return The function call result.
10978  */
10979 inline bool PFMateSend(const byte & port, const byte & i2caddr, const byte & channel, const byte & motors, const byte & cmdA, const byte & spdA, const byte & cmdB, const byte & spdB);
10980 
10981 /**
10982  * Send raw PFMate command.
10983  * Send a raw PFMate command to the power function IR receiver.
10984  * Returns a boolean value indicating whether or not the operation
10985  * completed successfully. The port must be configured as a Lowspeed port
10986  * before using this function.
10987  *
10988  * \param port The sensor port. See \ref NBCInputPortConstants.
10989  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
10990  * \param channel The power function IR receiver channel. See the \ref PFMateChannelConstants group.
10991  * \param b1 Raw byte 1.
10992  * \param b2 Raw byte 2.
10993  * \return The function call result.
10994  */
10995 inline bool PFMateSendRaw(const byte & port, const byte & i2caddr, const byte & channel, const byte & b1, const byte & b2);
10996 
10997 /**
10998  * Read a mindsensors device value.
10999  * Read a one, two, or four byte value from a mindsensors sensor. The value must be
11000  * stored with the least signficant byte (LSB) first (i.e., little endian). Returns a boolean value
11001  * indicating whether or not the operation completed successfully. The port
11002  * must be configured as a Lowspeed port before using this function.
11003  *
11004  * \param port The sensor port. See \ref InPorts.
11005  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11006  * \param reg The device register to read.
11007  * \param numbytes The number of bytes to read. Only 1, 2 or 4 byte values are supported.
11008  * \return The function call result.
11009  */
11010 inline int MSReadValue(const byte port, const byte i2caddr, const byte reg, const byte numbytes);
11011 
11012 /**
11013  * Turn on power to device.
11014  * Turn the power on for the mindsensors device on the specified port. The port
11015  * must be configured as a Lowspeed port before using this function.
11016  *
11017  * \param port The sensor port. See \ref InPorts.
11018  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11019  * \return The function call result.
11020  */
11021 inline char MSEnergize(const byte port, const byte i2caddr);
11022 
11023 /**
11024  * Turn off power to device.
11025  * Turn power off for the mindsensors device on the specified port. The port
11026  * must be configured as a Lowspeed port before using this function.
11027  *
11028  * \param port The sensor port. See \ref InPorts.
11029  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11030  * \return The function call result.
11031  */
11032 inline char MSDeenergize(const byte port, const byte i2caddr);
11033 
11034 /**
11035  * Turn on mindsensors ADPA mode.
11036  * Turn ADPA mode on for the mindsensors device on the specified port. The port
11037  * must be configured as a Lowspeed port before using this function.
11038  *
11039  * \param port The sensor port. See \ref InPorts.
11040  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11041  * \return The function call result.
11042  */
11043 inline char MSADPAOn(const byte port, const byte i2caddr);
11044 
11045 /**
11046  * Turn off mindsensors ADPA mode.
11047  * Turn ADPA mode off for the mindsensors device on the specified port. The port
11048  * must be configured as a Lowspeed port before using this function.
11049  *
11050  * \param port The sensor port. See \ref InPorts.
11051  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11052  * \return The function call result.
11053  */
11054 inline char MSADPAOff(const byte port, const byte i2caddr);
11055 
11056 /**
11057  * Configure DISTNx as GP2D12.
11058  * Configure the mindsensors DISTNx sensor as GP2D12. The port
11059  * must be configured as a Lowspeed port before using this function.
11060  *
11061  * \param port The sensor port. See \ref InPorts.
11062  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11063  * \return The function call result.
11064  */
11065 inline char DISTNxGP2D12(const byte port, const byte i2caddr);
11066 
11067 /**
11068  * Configure DISTNx as GP2D120.
11069  * Configure the mindsensors DISTNx sensor as GP2D120. The port
11070  * must be configured as a Lowspeed port before using this function.
11071  *
11072  * \param port The sensor port. See \ref InPorts.
11073  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11074  * \return The function call result.
11075  */
11076 inline char DISTNxGP2D120(const byte port, const byte i2caddr);
11077 
11078 /**
11079  * Configure DISTNx as GP2YA02.
11080  * Configure the mindsensors DISTNx sensor as GP2YA02. The port
11081  * must be configured as a Lowspeed port before using this function.
11082  *
11083  * \param port The sensor port. See \ref InPorts.
11084  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11085  * \return The function call result.
11086  */
11087 inline char DISTNxGP2YA02(const byte port, const byte i2caddr);
11088 
11089 /**
11090  * Configure DISTNx as GP2YA21.
11091  * Configure the mindsensors DISTNx sensor as GP2YA21. The port
11092  * must be configured as a Lowspeed port before using this function.
11093  *
11094  * \param port The sensor port. See \ref InPorts.
11095  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11096  * \return The function call result.
11097  */
11098 inline char DISTNxGP2YA21(const byte port, const byte i2caddr);
11099 
11100 /**
11101  * Read DISTNx distance value.
11102  * Read the mindsensors DISTNx sensor's distance value.
11103  * The port must be configured as a Lowspeed port before using this function.
11104  *
11105  * \param port The sensor port. See \ref InPorts.
11106  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11107  * \return The distance value.
11108  */
11109 inline int DISTNxDistance(const byte port, const byte i2caddr);
11110 
11111 /**
11112  * Read DISTNx maximum distance value.
11113  * Read the mindsensors DISTNx sensor's maximum distance value.
11114  * The port must be configured as a Lowspeed port before using this function.
11115  *
11116  * \param port The sensor port. See \ref InPorts.
11117  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11118  * \return The maximum distance value.
11119  */
11120 inline int DISTNxMaxDistance(const byte port, const byte i2caddr);
11121 
11122 /**
11123  * Read DISTNx minimum distance value.
11124  * Read the mindsensors DISTNx sensor's minimum distance value.
11125  * The port must be configured as a Lowspeed port before using this function.
11126  *
11127  * \param port The sensor port. See \ref InPorts.
11128  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11129  * \return The distance value.
11130  */
11131 inline int DISTNxMinDistance(const byte port, const byte i2caddr);
11132 
11133 /**
11134  * Read DISTNx module type value.
11135  * Read the mindsensors DISTNx sensor's module type value.
11136  * The port must be configured as a Lowspeed port before using this function.
11137  *
11138  * \param port The sensor port. See \ref InPorts.
11139  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11140  * \return The module type value.
11141  */
11142 inline byte DISTNxModuleType(const byte port, const byte i2caddr);
11143 
11144 /**
11145  * Read DISTNx num points value.
11146  * Read the mindsensors DISTNx sensor's num points value.
11147  * The port must be configured as a Lowspeed port before using this function.
11148  *
11149  * \param port The sensor port. See \ref InPorts.
11150  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11151  * \return The num points value.
11152  */
11153 inline byte DISTNxNumPoints(const byte port, const byte i2caddr);
11154 
11155 /**
11156  * Read DISTNx voltage value.
11157  * Read the mindsensors DISTNx sensor's voltage value.
11158  * The port must be configured as a Lowspeed port before using this function.
11159  *
11160  * \param port The sensor port. See \ref InPorts.
11161  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11162  * \return The voltage value.
11163  */
11164 inline int DISTNxVoltage(const byte port, const byte i2caddr);
11165 
11166 /**
11167  * Calibrate ACCL-Nx X-axis.
11168  * Calibrate the mindsensors ACCL-Nx sensor X-axis. The port
11169  * must be configured as a Lowspeed port before using this function.
11170  *
11171  * \param port The sensor port. See \ref InPorts.
11172  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11173  * \return The function call result.
11174  */
11175 inline char ACCLNxCalibrateX(const byte port, const byte i2caddr);
11176 
11177 /**
11178  * Stop calibrating ACCL-Nx X-axis.
11179  * Stop calibrating the mindsensors ACCL-Nx sensor X-axis. The port
11180  * must be configured as a Lowspeed port before using this function.
11181  *
11182  * \param port The sensor port. See \ref InPorts.
11183  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11184  * \return The function call result.
11185  */
11186 inline char ACCLNxCalibrateXEnd(const byte port, const byte i2caddr);
11187 
11188 /**
11189  * Calibrate ACCL-Nx Y-axis.
11190  * Calibrate the mindsensors ACCL-Nx sensor Y-axis. The port
11191  * must be configured as a Lowspeed port before using this function.
11192  *
11193  * \param port The sensor port. See \ref InPorts.
11194  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11195  * \return The function call result.
11196  */
11197 inline char ACCLNxCalibrateY(const byte port, const byte i2caddr);
11198 
11199 /**
11200  * Stop calibrating ACCL-Nx Y-axis.
11201  * Stop calibrating the mindsensors ACCL-Nx sensor Y-axis. The port
11202  * must be configured as a Lowspeed port before using this function.
11203  *
11204  * \param port The sensor port. See \ref InPorts.
11205  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11206  * \return The function call result.
11207  */
11208 inline char ACCLNxCalibrateYEnd(const byte port, const byte i2caddr);
11209 
11210 /**
11211  * Calibrate ACCL-Nx Z-axis.
11212  * Calibrate the mindsensors ACCL-Nx sensor Z-axis. The port
11213  * must be configured as a Lowspeed port before using this function.
11214  *
11215  * \param port The sensor port. See \ref InPorts.
11216  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11217  * \return The function call result.
11218  */
11219 inline char ACCLNxCalibrateZ(const byte port, const byte i2caddr);
11220 
11221 /**
11222  * Stop calibrating ACCL-Nx Z-axis.
11223  * Stop calibrating the mindsensors ACCL-Nx sensor Z-axis. The port
11224  * must be configured as a Lowspeed port before using this function.
11225  *
11226  * \param port The sensor port. See \ref InPorts.
11227  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11228  * \return The function call result.
11229  */
11230 inline char ACCLNxCalibrateZEnd(const byte port, const byte i2caddr);
11231 
11232 /**
11233  * Reset ACCL-Nx calibration.
11234  * Reset the mindsensors ACCL-Nx sensor calibration to factory settings. The port
11235  * must be configured as a Lowspeed port before using this function.
11236  *
11237  * \param port The sensor port. See \ref InPorts.
11238  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11239  * \return The function call result.
11240  */
11241 inline char ACCLNxResetCalibration(const byte port, const byte i2caddr);
11242 
11243 /**
11244  * Set ACCL-Nx sensitivity.
11245  * Reset the mindsensors ACCL-Nx sensor calibration to factory settings. The port
11246  * must be configured as a Lowspeed port before using this function.
11247  *
11248  * \param port The sensor port. See \ref InPorts.
11249  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11250  * \param slevel The sensitivity level. See \ref MSACCLNxSLevel.
11251  * \return The function call result.
11252  */
11253 inline char SetACCLNxSensitivity(const byte port, const byte i2caddr, byte slevel);
11254 
11255 /**
11256  * Read ACCL-Nx sensitivity value.
11257  * Read the mindsensors ACCL-Nx sensitivity value.
11258  * The port must be configured as a Lowspeed port before using this function.
11259  *
11260  * \param port The sensor port. See \ref InPorts.
11261  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11262  * \return The sensitivity value.
11263  */
11264 inline byte ACCLNxSensitivity(const byte port, const byte i2caddr);
11265 
11266 /**
11267  * Read ACCL-Nx X offset value.
11268  * Read the mindsensors ACCL-Nx sensor's X offset value.
11269  * The port must be configured as a Lowspeed port before using this function.
11270  *
11271  * \param port The sensor port. See \ref InPorts.
11272  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11273  * \return The X offset value.
11274  */
11275 inline int ACCLNxXOffset(const byte port, const byte i2caddr);
11276 
11277 /**
11278  * Read ACCL-Nx X range value.
11279  * Read the mindsensors ACCL-Nx sensor's X range value.
11280  * The port must be configured as a Lowspeed port before using this function.
11281  *
11282  * \param port The sensor port. See \ref InPorts.
11283  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11284  * \return The X range value.
11285  */
11286 inline int ACCLNxXRange(const byte port, const byte i2caddr);
11287 
11288 /**
11289  * Read ACCL-Nx Y offset value.
11290  * Read the mindsensors ACCL-Nx sensor's Y offset value.
11291  * The port must be configured as a Lowspeed port before using this function.
11292  *
11293  * \param port The sensor port. See \ref InPorts.
11294  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11295  * \return The Y offset value.
11296  */
11297 inline int ACCLNxYOffset(const byte port, const byte i2caddr);
11298 
11299 /**
11300  * Read ACCL-Nx Y range value.
11301  * Read the mindsensors ACCL-Nx sensor's Y range value.
11302  * The port must be configured as a Lowspeed port before using this function.
11303  *
11304  * \param port The sensor port. See \ref InPorts.
11305  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11306  * \return The Y range value.
11307  */
11308 inline int ACCLNxYRange(const byte port, const byte i2caddr);
11309 
11310 /**
11311  * Read ACCL-Nx Z offset value.
11312  * Read the mindsensors ACCL-Nx sensor's Z offset value.
11313  * The port must be configured as a Lowspeed port before using this function.
11314  *
11315  * \param port The sensor port. See \ref InPorts.
11316  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11317  * \return The Z offset value.
11318  */
11319 inline int ACCLNxZOffset(const byte port, const byte i2caddr);
11320 
11321 /**
11322  * Read ACCL-Nx Z range value.
11323  * Read the mindsensors ACCL-Nx sensor's Z range value.
11324  * The port must be configured as a Lowspeed port before using this function.
11325  *
11326  * \param port The sensor port. See \ref InPorts.
11327  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11328  * \return The Z range value.
11329  */
11330 inline int ACCLNxZRange(const byte port, const byte i2caddr);
11331 
11332 /**
11333  * Configure PSPNx in digital mode.
11334  * Configure the mindsensors PSPNx device in digital mode. The port
11335  * must be configured as a Lowspeed port before using this function.
11336  *
11337  * \param port The sensor port. See \ref InPorts.
11338  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11339  * \return The function call result.
11340  */
11341 inline char PSPNxDigital(const byte & port, const byte & i2caddr);
11342 
11343 /**
11344  * Configure PSPNx in analog mode.
11345  * Configure the mindsensors PSPNx device in analog mode. The port
11346  * must be configured as a Lowspeed port before using this function.
11347  *
11348  * \param port The sensor port. See \ref InPorts.
11349  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11350  * \return The function call result.
11351  */
11352 inline char PSPNxAnalog(const byte & port, const byte & i2caddr);
11353 
11354 /**
11355  * Read NXTServo servo position value.
11356  * Read the mindsensors NXTServo device's servo position value.
11357  * The port must be configured as a Lowspeed port before using this function.
11358  *
11359  * \param port The sensor port. See \ref NBCInputPortConstants.
11360  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11361  * \param servo The servo number. See \ref NXTServoNumbers group.
11362  * \return The specified servo's position value.
11363  */
11364 inline unsigned int NXTServoPosition(const byte & port, const byte & i2caddr, const byte servo);
11365 
11366 /**
11367  * Read NXTServo servo speed value.
11368  * Read the mindsensors NXTServo device's servo speed value.
11369  * The port must be configured as a Lowspeed port before using this function.
11370  *
11371  * \param port The sensor port. See \ref NBCInputPortConstants.
11372  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11373  * \param servo The servo number. See \ref NXTServoNumbers group.
11374  * \return The specified servo's speed value.
11375  */
11376 inline byte NXTServoSpeed(const byte & port, const byte & i2caddr, const byte servo);
11377 
11378 /**
11379  * Read NXTServo battery voltage value.
11380  * Read the mindsensors NXTServo device's battery voltage value.
11381  * The port must be configured as a Lowspeed port before using this function.
11382  *
11383  * \param port The sensor port. See \ref NBCInputPortConstants.
11384  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11385  * \result The battery level.
11386  */
11387 inline byte NXTServoBatteryVoltage(const byte & port, const byte & i2caddr);
11388 
11389 /**
11390  * Set NXTServo servo motor speed.
11391  * Set the speed of a servo motor controlled by the NXTServo device. The port
11392  * must be configured as a Lowspeed port before using this function.
11393  *
11394  * \param port The sensor port. See \ref NBCInputPortConstants.
11395  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11396  * \param servo The servo number. See \ref NXTServoNumbers group.
11397  * \param speed The servo speed. (0..255)
11398  * \return A status code indicating whether the operation completed successfully or not.
11399  * See \ref CommLSCheckStatusType for possible result values.
11400  */
11401 inline char SetNXTServoSpeed(const byte & port, const byte & i2caddr, const byte servo, const byte & speed);
11402 
11403 /**
11404  * Set NXTServo servo motor quick position.
11405  * Set the quick position of a servo motor controlled by the NXTServo device. The port
11406  * must be configured as a Lowspeed port before using this function.
11407  *
11408  * \param port The sensor port. See \ref NBCInputPortConstants.
11409  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11410  * \param servo The servo number. See \ref NXTServoNumbers group.
11411  * \param qpos The servo quick position. See \ref NXTServoQPos group.
11412  * \return A status code indicating whether the operation completed successfully or not.
11413  * See \ref CommLSCheckStatusType for possible result values.
11414  */
11415 inline char SetNXTServoQuickPosition(const byte & port, const byte & i2caddr, const byte servo, const byte & qpos);
11416 
11417 /**
11418  * Set NXTServo servo motor position.
11419  * Set the position of a servo motor controlled by the NXTServo device. The port
11420  * must be configured as a Lowspeed port before using this function.
11421  *
11422  * \param port The sensor port. See \ref NBCInputPortConstants.
11423  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11424  * \param servo The servo number. See \ref NXTServoNumbers group.
11425  * \param pos The servo position. See \ref NXTServoPos group.
11426  * \return A status code indicating whether the operation completed successfully or not.
11427  * See \ref CommLSCheckStatusType for possible result values.
11428  */
11429 inline char SetNXTServoPosition(const byte & port, const byte & i2caddr, const byte servo, const byte & pos);
11430 
11431 /**
11432  * Reset NXTServo properties.
11433  * Reset NXTServo device properties to factory defaults.
11434  * Initial position = 1500.  Initial speed = 0. The port
11435  * must be configured as a Lowspeed port before using this function.
11436  *
11437  * \param port The sensor port. See \ref NBCInputPortConstants.
11438  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11439  * \return A status code indicating whether the operation completed successfully or not.
11440  * See \ref CommLSCheckStatusType for possible result values.
11441  */
11442 inline char NXTServoReset(const byte & port, const byte & i2caddr);
11443 
11444 /**
11445  * Halt NXTServo macro.
11446  * Halt a macro executing on the NXTServo device. This command re-initializes
11447  * the macro environment.
11448  * The port must be configured as a Lowspeed port before using this function.
11449  *
11450  * \param port The sensor port. See \ref NBCInputPortConstants.
11451  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11452  * \return A status code indicating whether the operation completed successfully or not.
11453  * See \ref CommLSCheckStatusType for possible result values.
11454  */
11455 inline char NXTServoHaltMacro(const byte & port, const byte & i2caddr);
11456 
11457 /**
11458  * Resume NXTServo macro.
11459  * Resume a macro executing on the NXTServo device. This command resumes
11460  * executing a macro where it was paused last, using the same environment.
11461  * The port must be configured as a Lowspeed port before using this function.
11462  *
11463  * \param port The sensor port. See \ref NBCInputPortConstants.
11464  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11465  * \return A status code indicating whether the operation completed successfully or not.
11466  * See \ref CommLSCheckStatusType for possible result values.
11467  */
11468 inline char NXTServoResumeMacro(const byte & port, const byte & i2caddr);
11469 
11470 /**
11471  * Pause NXTServo macro.
11472  * Pause a macro executing on the NXTServo device. This command will pause the
11473  * currently executing macro, and save the environment for subsequent resumption.
11474  * The port must be configured as a Lowspeed port before using this function.
11475  *
11476  * \param port The sensor port. See \ref NBCInputPortConstants.
11477  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11478  * \return A status code indicating whether the operation completed successfully or not.
11479  * See \ref CommLSCheckStatusType for possible result values.
11480  */
11481 inline char NXTServoPauseMacro(const byte & port, const byte & i2caddr);
11482 
11483 /**
11484  * Initialize NXTServo servo properties.
11485  * Store the initial speed and position properties of the servo motor 'n'.
11486  * Current speed and position values of the nth servo is read from the
11487  * servo speed register and servo position register and written to permanent
11488  * memory.
11489  * The port must be configured as a Lowspeed port before using this function.
11490  *
11491  * \param port The sensor port. See \ref NBCInputPortConstants.
11492  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11493  * \param servo The servo number. See \ref NXTServoNumbers group.
11494  * \return A status code indicating whether the operation completed successfully or not.
11495  * See \ref CommLSCheckStatusType for possible result values.
11496  */
11497 inline char NXTServoInit(const byte & port, const byte & i2caddr, const byte servo);
11498 
11499 /**
11500  * Goto NXTServo macro address.
11501  * Run the macro found at the specified EEPROM macro address. This command
11502  * re-initializes the macro environment.
11503  * The port must be configured as a Lowspeed port before using this function.
11504  *
11505  * \param port The sensor port. See \ref NBCInputPortConstants.
11506  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11507  * \param macro The EEPROM macro address.
11508  * \return A status code indicating whether the operation completed successfully or not.
11509  * See \ref CommLSCheckStatusType for possible result values.
11510  */
11511 inline char NXTServoGotoMacroAddress(const byte & port, const byte & i2caddr, const byte & macro);
11512 
11513 /**
11514  * Edit NXTServo macro.
11515  * Put the NXTServo device into macro edit mode. This operation changes the
11516  * I2C address of the device to 0x40.  Macros are written to EEPROM addresses
11517  * between 0x21 and 0xFF. Use \ref NXTServoQuitEdit to return the device to
11518  * its normal operation mode.
11519  * The port must be configured as a Lowspeed port before using this function.
11520  *
11521  * \param port The sensor port. See \ref NBCInputPortConstants.
11522  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11523  * \return A status code indicating whether the operation completed successfully or not.
11524  * See \ref CommLSCheckStatusType for possible result values.
11525  */
11526 inline char NXTServoEditMacro(const byte & port, const byte & i2caddr);
11527 
11528 /**
11529  * Quit NXTServo macro edit mode.
11530  * Stop editing NXTServo device macro EEPROM memory. Use \ref NXTServoEditMacro
11531  * to start editing a macro.
11532  * The port must be configured as a Lowspeed port before using this function.
11533  *
11534  * \param port The sensor port. See \ref NBCInputPortConstants.
11535  * \return A status code indicating whether the operation completed successfully or not.
11536  * See \ref CommLSCheckStatusType for possible result values.
11537  */
11538 inline char NXTServoQuitEdit(const byte & port);
11539 
11540 /**
11541  * Set NXTHID into ASCII data mode.
11542  * Set the NXTHID device into ASCII data mode. Only printable characters can be
11543  * transmitted in this mode. The port
11544  * must be configured as a Lowspeed port before using this function.
11545  *
11546  * \param port The sensor port. See \ref NBCInputPortConstants.
11547  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11548  * \return A status code indicating whether the operation completed successfully or not.
11549  * See \ref CommLSCheckStatusType for possible Result values.
11550  */
11551 inline char NXTHIDAsciiMode(const byte & port, const byte & i2caddr);
11552 
11553 /**
11554  * Set NXTHID into direct data mode.
11555  * Set the NXTHID device into direct data mode. Any character can be transmitted
11556  * while in this mode.
11557  * The port must be configured as a Lowspeed port before using this function.
11558  *
11559  * \param port The sensor port. See \ref NBCInputPortConstants.
11560  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11561  * \return A status code indicating whether the operation completed successfully or not.
11562  * See \ref CommLSCheckStatusType for possible Result values.
11563  */
11564 inline char NXTHIDDirectMode(const byte & port, const byte & i2caddr);
11565 
11566 /**
11567  * Transmit NXTHID character.
11568  * Transmit a single character to a computer using the NXTHID device. The port
11569  * must be configured as a Lowspeed port before using this function.
11570  *
11571  * \param port The sensor port. See \ref NBCInputPortConstants.
11572  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11573  * \return A status code indicating whether the operation completed successfully or not.
11574  * See \ref CommLSCheckStatusType for possible Result values.
11575  */
11576 inline char NXTHIDTransmit(const byte & port, const byte & i2caddr);
11577 
11578 /**
11579  * Load NXTHID character.
11580  * Load a character into the NXTHID device.
11581  * The port must be configured as a Lowspeed port before using this function.
11582  *
11583  * \param port The sensor port. See \ref NBCInputPortConstants.
11584  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11585  * \param modifier The key modifier. See the \ref NXTHIDModifiers group.
11586  * \param character The character.
11587  * \return A status code indicating whether the operation completed successfully or not.
11588  * See \ref CommLSCheckStatusType for possible Result values.
11589  */
11590 inline char NXTHIDLoadCharacter(const byte & port, const byte & i2caddr, const byte & modifier, const byte & character);
11591 
11592 /**
11593  * Reset NXTPowerMeter counters.
11594  * Reset the NXTPowerMeter counters back to zero. The port
11595  * must be configured as a Lowspeed port before using this function.
11596  *
11597  * \param port The sensor port. See \ref InPorts.
11598  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11599  * \return A status code indicating whether the operation completed successfully or not.
11600  * See \ref CommLSCheckStatusType for possible Result values.
11601  */
11602 inline char NXTPowerMeterResetCounters(const byte & port, const byte & i2caddr);
11603 
11604 /**
11605  * Read NXTPowerMeter present current.
11606  * Read the mindsensors NXTPowerMeter device's present current value.
11607  * The port must be configured as a Lowspeed port before using this function.
11608  *
11609  * \param port The sensor port. See \ref InPorts.
11610  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11611  * \return The NXTPowerMeter present current.
11612  */
11613 inline int NXTPowerMeterPresentCurrent(const byte & port, const byte & i2caddr);
11614 
11615 /**
11616  * Read NXTPowerMeter present voltage.
11617  * Read the mindsensors NXTPowerMeter device's present voltage value.
11618  * The port must be configured as a Lowspeed port before using this function.
11619  *
11620  * \param port The sensor port. See \ref InPorts.
11621  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11622  * \return The NXTPowerMeter present voltage.
11623  */
11624 inline int NXTPowerMeterPresentVoltage(const byte & port, const byte & i2caddr);
11625 
11626 /**
11627  * Read NXTPowerMeter capacity used.
11628  * Read the mindsensors NXTPowerMeter device's capacity used since the last reset command.
11629  * The port must be configured as a Lowspeed port before using this function.
11630  *
11631  * \param port The sensor port. See \ref InPorts.
11632  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11633  * \return The NXTPowerMeter capacity used value.
11634  */
11635 inline int NXTPowerMeterCapacityUsed(const byte & port, const byte & i2caddr);
11636 
11637 /**
11638  * Read NXTPowerMeter present power.
11639  * Read the mindsensors NXTPowerMeter device's present power value.
11640  * The port must be configured as a Lowspeed port before using this function.
11641  *
11642  * \param port The sensor port. See \ref InPorts.
11643  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11644  * \return The NXTPowerMeter present power value.
11645  */
11646 inline int NXTPowerMeterPresentPower(const byte & port, const byte & i2caddr);
11647 
11648 /**
11649  * Read NXTPowerMeter total power consumed.
11650  * Read the mindsensors NXTPowerMeter device's total power consumed since the last reset command.
11651  * The port must be configured as a Lowspeed port before using this function.
11652  *
11653  * \param port The sensor port. See \ref InPorts.
11654  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11655  * \return The NXTPowerMeter total power consumed value.
11656  */
11657 inline long NXTPowerMeterTotalPowerConsumed(const byte & port, const byte & i2caddr);
11658 
11659 /**
11660  * Read NXTPowerMeter maximum current.
11661  * Read the mindsensors NXTPowerMeter device's maximum current value.
11662  * The port must be configured as a Lowspeed port before using this function.
11663  *
11664  * \param port The sensor port. See \ref InPorts.
11665  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11666  * \return The NXTPowerMeter maximum current value.
11667  */
11668 inline int NXTPowerMeterMaxCurrent(const byte & port, const byte & i2caddr);
11669 
11670 /**
11671  * Read NXTPowerMeter minimum current.
11672  * Read the mindsensors NXTPowerMeter device's minimum current value.
11673  * The port must be configured as a Lowspeed port before using this function.
11674  *
11675  * \param port The sensor port. See \ref InPorts.
11676  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11677  * \return The NXTPowerMeter minimum current value.
11678  */
11679 inline int NXTPowerMeterMinCurrent(const byte & port, const byte & i2caddr);
11680 
11681 /**
11682  * Read NXTPowerMeter maximum voltage.
11683  * Read the mindsensors NXTPowerMeter device's maximum voltage value.
11684  * The port must be configured as a Lowspeed port before using this function.
11685  *
11686  * \param port The sensor port. See \ref InPorts.
11687  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11688  * \return The NXTPowerMeter maximum voltage value.
11689  */
11690 inline int NXTPowerMeterMaxVoltage(const byte & port, const byte & i2caddr);
11691 
11692 /**
11693  * Read NXTPowerMeter minimum voltage.
11694  * Read the mindsensors NXTPowerMeter device's minimum voltage value.
11695  * The port must be configured as a Lowspeed port before using this function.
11696  *
11697  * \param port The sensor port. See \ref InPorts.
11698  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11699  * \return The NXTPowerMeter minimum voltage value.
11700  */
11701 inline int NXTPowerMeterMinVoltage(const byte & port, const byte & i2caddr);
11702 
11703 /**
11704  * Read NXTPowerMeter elapsed time.
11705  * Read the mindsensors NXTPowerMeter device's elapsed time since the last reset command.
11706  * The port must be configured as a Lowspeed port before using this function.
11707  *
11708  * \param port The sensor port. See \ref InPorts.
11709  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11710  * \return The NXTPowerMeter elapsed time value.
11711  */
11712 inline long NXTPowerMeterElapsedTime(const byte & port, const byte & i2caddr);
11713 
11714 /**
11715  * Read NXTPowerMeter error count.
11716  * Read the mindsensors NXTPowerMeter device's error count value.
11717  * The port must be configured as a Lowspeed port before using this function.
11718  *
11719  * \param port The sensor port. See \ref InPorts.
11720  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11721  * \return The NXTPowerMeter error count value.
11722  */
11723 inline int NXTPowerMeterErrorCount(const byte & port, const byte & i2caddr);
11724 
11725 /**
11726  * Powerdown NXTLineLeader device.
11727  * Put the NXTLineLeader to sleep so that it does not consume power when it is
11728  * not required. The device wakes up on its own when any I2C communication
11729  * happens or you can specifically wake it up by using the \ref NXTLineLeaderPowerUp
11730  * command.
11731  * The port must be configured as a Lowspeed port before using this function.
11732  *
11733  * \param port The sensor port. See \ref NBCInputPortConstants.
11734  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11735  * \return A status code indicating whether the operation completed successfully or not.
11736  * See \ref CommLSCheckStatusType for possible Result values.
11737  */
11738 inline char NXTLineLeaderPowerDown(const byte & port, const byte & i2caddr);
11739 
11740 /**
11741  * Powerup NXTLineLeader device.
11742  * Wake up the NXTLineLeader device so that it can be used. The device can be
11743  * put to sleep using the \ref NXTLineLeaderPowerDown command.
11744  * The port must be configured as a Lowspeed port before using this function.
11745  *
11746  * \param port The sensor port. See \ref NBCInputPortConstants.
11747  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11748  * \return A status code indicating whether the operation completed successfully or not.
11749  * See \ref CommLSCheckStatusType for possible Result values.
11750  */
11751 inline char NXTLineLeaderPowerUp(const byte & port, const byte & i2caddr);
11752 
11753 /**
11754  * Invert NXTLineLeader colors.
11755  * Invert color sensing so that the device can detect a white line on a
11756  * black background.
11757  * The port must be configured as a Lowspeed port before using this function.
11758  *
11759  * \param port The sensor port. See \ref NBCInputPortConstants.
11760  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11761  * \return A status code indicating whether the operation completed successfully or not.
11762  * See \ref CommLSCheckStatusType for possible Result values.
11763  */
11764 inline char NXTLineLeaderInvert(const byte & port, const byte & i2caddr);
11765 
11766 /**
11767  * Reset NXTLineLeader color inversion.
11768  * Reset the NXTLineLeader color detection back to its default state (black
11769  * line on a white background).
11770  * The port must be configured as a Lowspeed port before using this function.
11771  *
11772  * \param port The sensor port. See \ref NBCInputPortConstants.
11773  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11774  * \return A status code indicating whether the operation completed successfully or not.
11775  * See \ref CommLSCheckStatusType for possible Result values.
11776  */
11777 inline char NXTLineLeaderReset(const byte & port, const byte & i2caddr);
11778 
11779 /**
11780  * Take NXTLineLeader line snapshot.
11781  * Takes a snapshot of the line under the sensor and tracks that position in
11782  * subsequent tracking operations.  This function also will set color inversion
11783  * if it sees a white line on a black background.
11784  * The port must be configured as a Lowspeed port before using this function.
11785  *
11786  * \param port The sensor port. See \ref NBCInputPortConstants.
11787  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11788  * \return A status code indicating whether the operation completed successfully or not.
11789  * See \ref CommLSCheckStatusType for possible Result values.
11790  */
11791 inline char NXTLineLeaderSnapshot(const byte & port, const byte & i2caddr);
11792 
11793 /**
11794  * Calibrate NXTLineLeader white color.
11795  * Store calibration data for the white color.
11796  * The port must be configured as a Lowspeed port before using this function.
11797  *
11798  * \param port The sensor port. See \ref NBCInputPortConstants.
11799  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11800  * \return A status code indicating whether the operation completed successfully or not.
11801  * See \ref CommLSCheckStatusType for possible Result values.
11802  */
11803 inline char NXTLineLeaderCalibrateWhite(const byte & port, const byte & i2caddr);
11804 
11805 /**
11806  * Calibrate NXTLineLeader black color.
11807  * Store calibration data for the black color.
11808  * The port must be configured as a Lowspeed port before using this function.
11809  *
11810  * \param port The sensor port. See \ref NBCInputPortConstants.
11811  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11812  * \return A status code indicating whether the operation completed successfully or not.
11813  * See \ref CommLSCheckStatusType for possible Result values.
11814  */
11815 inline char NXTLineLeaderCalibrateBlack(const byte & port, const byte & i2caddr);
11816 
11817 /**
11818  * Read NXTLineLeader steering.
11819  * Read the mindsensors NXTLineLeader device's steering value. This is the power
11820  * returned by the sensor to correct your course.  Add this value to your left
11821  * motor and subtract it from your right motor.
11822  * The port must be configured as a Lowspeed port before using this function.
11823  *
11824  * \param port The sensor port. See \ref NBCInputPortConstants.
11825  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11826  * \return The NXTLineLeader steering value.
11827  */
11828 inline char NXTLineLeaderSteering(const byte & port, const byte & i2caddr);
11829 
11830 /**
11831  * Read NXTLineLeader average.
11832  * Read the mindsensors NXTLineLeader device's average value. The
11833  * average is a weighted average of the bits set to 1 based on the position.
11834  * The left most bit has a weight of 10, second bit has a weight of 20, and so
11835  * forth. When all 8 sensors are over a black surface the average will be 45.
11836  * The port must be configured as a Lowspeed port before using this function.
11837  *
11838  * \param port The sensor port. See \ref NBCInputPortConstants.
11839  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11840  * \return The NXTLineLeader average value.
11841  */
11842 inline char NXTLineLeaderAverage(const byte & port, const byte & i2caddr);
11843 
11844 /**
11845  * Read NXTLineLeader result.
11846  * Read the mindsensors NXTLineLeader device's result value. This is a single
11847  * byte showing the 8 sensor's readings. Each bit corresponding to the sensor
11848  * where the line is seen is set to 1, otherwise it is set to 0.
11849  * When all 8 sensors are over a black surface the result will be 255 (b11111111).
11850  * The port must be configured as a Lowspeed port before using this function.
11851  *
11852  * \param port The sensor port. See \ref NBCInputPortConstants.
11853  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11854  * \return The NXTLineLeader result value.
11855  */
11856 inline byte NXTLineLeaderResult(const byte & port, const byte & i2caddr);
11857 
11858 /**
11859  * Write NXTLineLeader setpoint.
11860  * Write a new setpoint value to the NXTLineLeader device. The Set Point is a
11861  * value you can ask sensor to maintain the average to. The default value is
11862  * 45, whereby the line is maintained in center of the sensor. If you need to
11863  * maintain line towards left of the sensor, set the Set Point to
11864  * a lower value (minimum: 10). If you need it to be towards on the right of the
11865  * sensor, set it to higher value (maximum: 80). Set point is also useful while
11866  * tracking an edge of dark and light areas.
11867  * The port must be configured as a Lowspeed port before using this function.
11868  *
11869  * \param port The sensor port. See \ref NBCInputPortConstants.
11870  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11871  * \param value The new setpoint value (10..80).
11872  * \return A status code indicating whether the operation completed successfully or not.
11873  * See \ref CommLSCheckStatusType for possible Result values.
11874  */
11875 inline char SetNXTLineLeaderSetpoint(const byte & port, const byte & i2caddr, const byte & value);
11876 
11877 /**
11878  * Write NXTLineLeader Kp value.
11879  * Write a Kp value to the NXTLineLeader device. This value divided by PID
11880  * Factor for Kp is the Proportional value for the PID control. Suggested value
11881  * is 25 with a divisor factor of 32 (which is also a factory default), start
11882  * with this value, and tune it to meet your needs. Value ranges
11883  * between 0 and 255.
11884  * The port must be configured as a Lowspeed port before using this function.
11885  *
11886  * \param port The sensor port. See \ref NBCInputPortConstants.
11887  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11888  * \param value The new Kp value (0..255).
11889  * \return A status code indicating whether the operation completed successfully or not.
11890  * See \ref CommLSCheckStatusType for possible Result values.
11891  */
11892 inline char SetNXTLineLeaderKpValue(const byte & port, const byte & i2caddr, const byte & value);
11893 
11894 /**
11895  * Write NXTLineLeader Ki value.
11896  * Write a Ki value to the NXTLineLeader device. This value divided by PID
11897  * Factor for Ki is the Integral value for the PID control. Suggested value
11898  * is 0 with a divisor factor of 32 (which is also a factory default), start
11899  * with this value, and tune it to meet your needs. Value ranges
11900  * between 0 and 255.
11901  * The port must be configured as a Lowspeed port before using this function.
11902  *
11903  * \param port The sensor port. See \ref NBCInputPortConstants.
11904  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11905  * \param value The new Ki value (0..255).
11906  * \return A status code indicating whether the operation completed successfully or not.
11907  * See \ref CommLSCheckStatusType for possible Result values.
11908  */
11909 inline char SetNXTLineLeaderKiValue(const byte & port, const byte & i2caddr, const byte & value);
11910 
11911 /**
11912  * Write NXTLineLeader Kd value.
11913  * Write a Kd value to the NXTLineLeader device. This value divided by PID
11914  * Factor for Kd is the Derivative value for the PID control. Suggested value
11915  * is 8 with a divisor factor of 32 (which is also a factory default), start
11916  * with this value, and tune it to meet your needs. Value ranges
11917  * between 0 and 255.
11918  * The port must be configured as a Lowspeed port before using this function.
11919  *
11920  * \param port The sensor port. See \ref NBCInputPortConstants.
11921  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11922  * \param value The new Kd value (0..255).
11923  * \return A status code indicating whether the operation completed successfully or not.
11924  * See \ref CommLSCheckStatusType for possible Result values.
11925  */
11926 inline char SetNXTLineLeaderKdValue(const byte & port, const byte & i2caddr, const byte & value);
11927 
11928 /**
11929  * Write NXTLineLeader Kp factor.
11930  * Write a Kp divisor factor to the NXTLineLeader device. Value ranges between
11931  * 1 and 255. Change this value if you need more granularities in Kp value.
11932  * The port must be configured as a Lowspeed port before using this function.
11933  *
11934  * \param port The sensor port. See \ref NBCInputPortConstants.
11935  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11936  * \param value The new Kp factor (1..255).
11937  * \return A status code indicating whether the operation completed successfully or not.
11938  * See \ref CommLSCheckStatusType for possible Result values.
11939  */
11940 inline char SetNXTLineLeaderKpFactor(const byte & port, const byte & i2caddr, const byte & value);
11941 
11942 /**
11943  * Write NXTLineLeader Ki factor.
11944  * Write a Ki divisor factor to the NXTLineLeader device. Value ranges between
11945  * 1 and 255. Change this value if you need more granularities in Ki value.
11946  * The port must be configured as a Lowspeed port before using this function.
11947  *
11948  * \param port The sensor port. See \ref NBCInputPortConstants.
11949  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11950  * \param value The new Ki factor (1..255).
11951  * \return A status code indicating whether the operation completed successfully or not.
11952  * See \ref CommLSCheckStatusType for possible Result values.
11953  */
11954 inline char SetNXTLineLeaderKiFactor(const byte & port, const byte & i2caddr, const byte & value);
11955 
11956 /**
11957  * Write NXTLineLeader Kd factor.
11958  * Write a Kd divisor factor to the NXTLineLeader device. Value ranges between
11959  * 1 and 255. Change this value if you need more granularities in Kd value.
11960  * The port must be configured as a Lowspeed port before using this function.
11961  *
11962  * \param port The sensor port. See \ref NBCInputPortConstants.
11963  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11964  * \param value The new Kd factor (1..255).
11965  * \return A status code indicating whether the operation completed successfully or not.
11966  * See \ref CommLSCheckStatusType for possible Result values.
11967  */
11968 inline char SetNXTLineLeaderKdFactor(const byte & port, const byte & i2caddr, const byte & value);
11969 
11970 /**
11971  * Configure NRLink in 2400 baud mode.
11972  * Configure the mindsensors NRLink device in 2400 baud mode. The port
11973  * must be configured as a Lowspeed port before using this function.
11974  *
11975  * \param port The sensor port. See \ref InPorts.
11976  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11977  * \return The function call result.
11978  */
11979 inline char NRLink2400(const byte port, const byte i2caddr);
11980 
11981 /**
11982  * Configure NRLink in 4800 baud mode.
11983  * Configure the mindsensors NRLink device in 4800 baud mode. The port
11984  * must be configured as a Lowspeed port before using this function.
11985  *
11986  * \param port The sensor port. See \ref InPorts.
11987  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11988  * \return The function call result.
11989  */
11990 inline char NRLink4800(const byte port, const byte i2caddr);
11991 
11992 /**
11993  * Flush NRLink buffers.
11994  * Flush the mindsensors NRLink device buffers. The port
11995  * must be configured as a Lowspeed port before using this function.
11996  *
11997  * \param port The sensor port. See \ref InPorts.
11998  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
11999  * \return The function call result.
12000  */
12001 inline char NRLinkFlush(const byte port, const byte i2caddr);
12002 
12003 /**
12004  * Configure NRLink in IR long mode.
12005  * Configure the mindsensors NRLink device in IR long mode. The port
12006  * must be configured as a Lowspeed port before using this function.
12007  *
12008  * \param port The sensor port. See \ref InPorts.
12009  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
12010  * \return The function call result.
12011  */
12012 inline char NRLinkIRLong(const byte port, const byte i2caddr);
12013 
12014 /**
12015  * Configure NRLink in IR short mode.
12016  * Configure the mindsensors NRLink device in IR short mode. The port
12017  * must be configured as a Lowspeed port before using this function.
12018  *
12019  * \param port The sensor port. See \ref InPorts.
12020  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
12021  * \return The function call result.
12022  */
12023 inline char NRLinkIRShort(const byte port, const byte i2caddr);
12024 
12025 /**
12026  * Configure NRLink in power function mode.
12027  * Configure the mindsensors NRLink device in power function mode. The port
12028  * must be configured as a Lowspeed port before using this function.
12029  *
12030  * \param port The sensor port. See \ref InPorts.
12031  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
12032  * \return The function call result.
12033  */
12034 inline char NRLinkSetPF(const byte port, const byte i2caddr);
12035 
12036 /**
12037  * Configure NRLink in RCX mode.
12038  * Configure the mindsensors NRLink device in RCX mode. The port
12039  * must be configured as a Lowspeed port before using this function.
12040  *
12041  * \param port The sensor port. See \ref InPorts.
12042  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
12043  * \return The function call result.
12044  */
12045 inline char NRLinkSetRCX(const byte port, const byte i2caddr);
12046 
12047 /**
12048  * Configure NRLink in IR train mode.
12049  * Configure the mindsensors NRLink device in IR train mode. The port
12050  * must be configured as a Lowspeed port before using this function.
12051  *
12052  * \param port The sensor port. See \ref InPorts.
12053  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
12054  * \return The function call result.
12055  */
12056 inline char NRLinkSetTrain(const byte port, const byte i2caddr);
12057 
12058 /**
12059  * Configure NRLink in raw IR transmit mode.
12060  * Configure the mindsensors NRLink device in raw IR transmit mode. The port
12061  * must be configured as a Lowspeed port before using this function.
12062  *
12063  * \param port The sensor port. See \ref InPorts.
12064  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
12065  * \return The function call result.
12066  */
12067 inline char NRLinkTxRaw(const byte port, const byte i2caddr);
12068 
12069 /**
12070  * Read NRLink status.
12071  * Read the status of the mindsensors NRLink device. The port
12072  * must be configured as a Lowspeed port before using this function.
12073  *
12074  * \param port The sensor port. See \ref InPorts.
12075  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
12076  * \return The mindsensors NRLink status.
12077  */
12078 inline byte NRLinkStatus(const byte port, const byte i2caddr);
12079 
12080 /**
12081  * Run NRLink macro.
12082  * Run the specified mindsensors NRLink device macro. The port
12083  * must be configured as a Lowspeed port before using this function.
12084  *
12085  * \param port The sensor port. See \ref InPorts.
12086  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
12087  * \param macro The address of the macro to execute.
12088  * \return The function call result.
12089  */
12090 inline char RunNRLinkMacro(const byte port, const byte i2caddr, const byte macro);
12091 
12092 /**
12093  * Write data to NRLink.
12094  * Write data to the mindsensors NRLink device on the specified port. The port
12095  * must be configured as a Lowspeed port before using this function.
12096  *
12097  * \param port The sensor port. See \ref InPorts.
12098  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
12099  * \param data A byte array containing the data to write.
12100  * \return The function call result.
12101  */
12102 inline char WriteNRLinkBytes(const byte port, const byte i2caddr, const byte data[]);
12103 
12104 /**
12105  * Read data from NRLink.
12106  * Read data from the mindsensors NRLink device on the specified port. The port
12107  * must be configured as a Lowspeed port before using this function.
12108  *
12109  * \param port The sensor port. See \ref InPorts.
12110  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
12111  * \param data A byte array that will contain the data read from the device on output.
12112  * \return The function call result.
12113  */
12114 inline bool ReadNRLinkBytes(const byte port, const byte i2caddr, byte & data[]);
12115 
12116 /**
12117  * MSIRTrain function.
12118  * Control an IR Train receiver set to the specified channel using the
12119  * mindsensors NRLink device. Valid function values are \ref TRAIN_FUNC_STOP,
12120  * \ref TRAIN_FUNC_INCR_SPEED, \ref TRAIN_FUNC_DECR_SPEED, and \ref TRAIN_FUNC_TOGGLE_LIGHT.
12121  * Valid channels are \ref TRAIN_CHANNEL_1 through \ref TRAIN_CHANNEL_3 and
12122  * \ref TRAIN_CHANNEL_ALL. The port must be configured as a Lowspeed port before
12123  * using this function.
12124  *
12125  * \param port The sensor port. See \ref InPorts.
12126  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
12127  * \param channel The IR Train channel.  See \ref IRTrainChannels.
12128  * \param func The IR Train function. See \ref IRTrainFuncs
12129  * \return The function call result. \ref NO_ERR or \ref CommandCommErrors.
12130  */
12131 inline char MSIRTrain(const byte port, const byte i2caddr, const byte channel, const byte func);
12132 
12133 /**
12134  * MSPFComboDirect function.
12135  * Execute a pair of Power Function motor commands on the specified channel
12136  * using the mindsensors NRLink device. Commands for outa and outb are
12137  * PF_CMD_STOP, PF_CMD_REV, PF_CMD_FWD, and \ref PF_CMD_BRAKE. Valid channels are
12138  * PF_CHANNEL_1 through PF_CHANNEL_4. The port must be configured as a
12139  * Lowspeed port before using this function.
12140  *
12141  * \param port The sensor port. See \ref InPorts.
12142  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
12143  * \param channel The Power Function channel.  See \ref PFChannelConstants.
12144  * \param outa The Power Function command for output A. See \ref PFCmdConstants.
12145  * \param outb The Power Function command for output B. See \ref PFCmdConstants.
12146  * \return The function call result. \ref NO_ERR or \ref CommandCommErrors.
12147  */
12148 inline char MSPFComboDirect(const byte port, const byte i2caddr, const byte channel, const byte outa, const byte outb);
12149 
12150 /**
12151  * MSPFComboPWM function.
12152  * Control the speed of both outputs on a Power Function receiver set to the
12153  * specified channel using the mindsensors NRLink device. Valid output values
12154  * are \ref PF_PWM_FLOAT, \ref PF_PWM_FWD1, \ref PF_PWM_FWD2, \ref PF_PWM_FWD3, \ref PF_PWM_FWD4,
12155  * \ref PF_PWM_FWD5, \ref PF_PWM_FWD6, \ref PF_PWM_FWD7, \ref PF_PWM_BRAKE, \ref PF_PWM_REV7,
12156  * \ref PF_PWM_REV6, \ref PF_PWM_REV5, \ref PF_PWM_REV4, \ref PF_PWM_REV3, \ref PF_PWM_REV2, and
12157  * \ref PF_PWM_REV1. Valid channels are \ref PF_CHANNEL_1 through \ref PF_CHANNEL_4. The
12158  * port must be configured as a Lowspeed port before using this function.
12159  *
12160  * \param port The sensor port. See \ref InPorts.
12161  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
12162  * \param channel The Power Function channel.  See \ref PFChannelConstants.
12163  * \param outa The Power Function PWM command for output A. See \ref PFPWMOptions.
12164  * \param outb The Power Function PWM command for output B. See \ref PFPWMOptions.
12165  * \return The function call result. \ref NO_ERR or \ref CommandCommErrors.
12166  */
12167 inline char MSPFComboPWM(const byte port, const byte i2caddr, const byte channel, const byte outa, const byte outb);
12168 
12169 /**
12170  * MSPFRawOutput function.
12171  * Control a Power Function receiver set to the specified channel using the
12172  * mindsensors NRLink device. Build the raw data stream using the 3 nibbles
12173  * (4 bit values). The port must be configured as a Lowspeed port before using
12174  * this function.
12175  *
12176  * \param port The sensor port. See \ref InPorts.
12177  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
12178  * \param nibble0 The first raw data nibble.
12179  * \param nibble1 The second raw data nibble.
12180  * \param nibble2 The third raw data nibble.
12181  * \return The function call result. \ref NO_ERR or \ref CommandCommErrors.
12182  */
12183 inline char MSPFRawOutput(const byte port, const byte i2caddr, const byte nibble0, const byte nibble1, const byte nibble2);
12184 
12185 /**
12186  * MSPFRepeat function.
12187  * Repeat sending the last Power Function command using the mindsensors
12188  * NRLink device. Specify the number of times to repeat the command and the
12189  * number of milliseconds of delay between each repetition. The port must be
12190  * configured as a Lowspeed port before using this function.
12191  *
12192  * \param port The sensor port. See \ref InPorts.
12193  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
12194  * \param count The number of times to repeat the command.
12195  * \param delay The number of milliseconds to delay between each repetition.
12196  * \return The function call result. \ref NO_ERR or \ref CommandCommErrors.
12197  */
12198 inline char MSPFRepeat(const byte port, const byte i2caddr, const byte count, const unsigned int delay);
12199 
12200 /**
12201  * MSPFSingleOutputCST function.
12202  * Control a single output on a Power Function receiver set to the specified
12203  * channel using the mindsensors NRLink device. Select the desired output
12204  * using \ref PF_OUT_A or \ref PF_OUT_B. Valid functions are \ref PF_CST_CLEAR1_CLEAR2,
12205  * \ref PF_CST_SET1_CLEAR2, \ref PF_CST_CLEAR1_SET2, \ref PF_CST_SET1_SET2,
12206  * \ref PF_CST_INCREMENT_PWM, \ref PF_CST_DECREMENT_PWM, \ref PF_CST_FULL_FWD,
12207  * \ref PF_CST_FULL_REV, and \ref PF_CST_TOGGLE_DIR. Valid channels are
12208  * \ref PF_CHANNEL_1 through \ref PF_CHANNEL_4. The port must be configured as a
12209  * Lowspeed port before using this function.
12210  *
12211  * \param port The sensor port. See \ref InPorts.
12212  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
12213  * \param channel The Power Function channel.  See \ref PFChannelConstants.
12214  * \param out The Power Function output. See \ref PFOutputs.
12215  * \param func The Power Function CST function. See \ref PFCSTOptions.
12216  * \return The function call result. \ref NO_ERR or \ref CommandCommErrors.
12217  */
12218 inline char MSPFSingleOutputCST(const byte port, const byte i2caddr, const byte channel, const byte out, const byte func);
12219 
12220 /**
12221  * MSPFSingleOutputPWM function.
12222  * Control the speed of a single output on a Power Function receiver set to
12223  * the specified channel using the mindsensors NRLink device. Select the
12224  * desired output using \ref PF_OUT_A or \ref PF_OUT_B. Valid functions are
12225  * \ref PF_PWM_FLOAT, \ref PF_PWM_FWD1, \ref PF_PWM_FWD2, \ref PF_PWM_FWD3, \ref PF_PWM_FWD4,
12226  * \ref PF_PWM_FWD5, \ref PF_PWM_FWD6, \ref PF_PWM_FWD7, \ref PF_PWM_BRAKE, \ref PF_PWM_REV7,
12227  * \ref PF_PWM_REV6, \ref PF_PWM_REV5, \ref PF_PWM_REV4, \ref PF_PWM_REV3, \ref PF_PWM_REV2, and
12228  * \ref PF_PWM_REV1. Valid channels are \ref PF_CHANNEL_1 through \ref PF_CHANNEL_4. The
12229  * port must be configured as a Lowspeed port before using this function.
12230  *
12231  * \param port The sensor port. See \ref InPorts.
12232  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
12233  * \param channel The Power Function channel.  See \ref PFChannelConstants.
12234  * \param out The Power Function output. See \ref PFOutputs.
12235  * \param func The Power Function PWM function. See \ref PFPWMOptions.
12236  * \return The function call result. \ref NO_ERR or \ref CommandCommErrors.
12237  */
12238 inline char MSPFSingleOutputPWM(const byte port, const byte i2caddr, const byte channel, const byte out, const byte func);
12239 
12240 /**
12241  * MSPFSinglePin function.
12242  * Control a single pin on a Power Function receiver set to the specified
12243  * channel using the mindsensors NRLink device. Select the desired output
12244  * using \ref PF_OUT_A or \ref PF_OUT_B.  Select the desired pin using \ref PF_PIN_C1 or
12245  * \ref PF_PIN_C2. Valid functions are \ref PF_FUNC_NOCHANGE, \ref PF_FUNC_CLEAR,
12246  * \ref PF_FUNC_SET, and \ref PF_FUNC_TOGGLE. Valid channels are \ref PF_CHANNEL_1 through
12247  * \ref PF_CHANNEL_4. Specify whether the mode by passing true (continuous) or
12248  * false (timeout) as the final parameter. The port must be configured as a
12249  * Lowspeed port before using this function.
12250  *
12251  * \param port The sensor port. See \ref InPorts.
12252  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
12253  * \param channel The Power Function channel.  See \ref PFChannelConstants.
12254  * \param out The Power Function output. See \ref PFOutputs.
12255  * \param pin The Power Function pin. See \ref PFPinConstants.
12256  * \param func The Power Function single pin function. See \ref PFPinFuncs.
12257  * \param cont Control whether the mode is continuous or timeout.
12258  * \return The function call result. \ref NO_ERR or \ref CommandCommErrors.
12259  */
12260 inline char MSPFSinglePin(const byte port, const byte i2caddr, const byte channel, const byte out, const byte pin, const byte func, bool cont);
12261 
12262 /**
12263  * MSPFTrain function.
12264  * Control both outputs on a Power Function receiver set to the specified
12265  * channel using the mindsensors NRLink device as if it were an IR Train
12266  * receiver. Valid function values are \ref TRAIN_FUNC_STOP, \ref TRAIN_FUNC_INCR_SPEED,
12267  * \ref TRAIN_FUNC_DECR_SPEED, and \ref TRAIN_FUNC_TOGGLE_LIGHT. Valid channels are
12268  * PF_CHANNEL_1 through PF_CHANNEL_4. The port must be configured as a
12269  * Lowspeed port before using this function.
12270  *
12271  * \param port The sensor port. See \ref InPorts.
12272  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
12273  * \param channel The Power Function channel.  See \ref PFChannelConstants.
12274  * \param func The Power Function train function. See \ref IRTrainFuncs.
12275  * \return The function call result. \ref NO_ERR or \ref CommandCommErrors.
12276  */
12277 inline char MSPFTrain(const byte port, const byte i2caddr, const byte channel, const byte func);
12278 
12279 /**
12280  * MSRCXSetIRLinkPort function.
12281  * Set the global port in advance of using the MSRCX* and MSScout* API
12282  * functions for sending RCX and Scout messages over the mindsensors NRLink
12283  * device. The port must be configured as a Lowspeed port before using any of
12284  * the mindsensors RCX and Scout NRLink functions.
12285  *
12286  * \param port The sensor port. See \ref InPorts.
12287  * \param i2caddr The sensor I2C address. See sensor documentation for this value.
12288  */
12289 inline void MSRCXSetNRLinkPort(const byte port, const byte i2caddr);
12290 
12291 /**
12292  * MSRCXBatteryLevel function.
12293  * Send the BatteryLevel command to an RCX to read the current battery level.
12294  *
12295  * \return The RCX battery level.
12296  */
12297 inline int MSRCXBatteryLevel(void);
12298 
12299 /**
12300  * MSRCXPoll function.
12301  * Send the Poll command to an RCX to read a signed 2-byte value at the
12302  * specified source and value combination.
12303  *
12304  * \param src The RCX source.  See \ref RCXSourceConstants.
12305  * \param value The RCX value.
12306  * \return The value read from the specified port and value.
12307  */
12308 inline int MSRCXPoll(const byte src, const byte value);
12309 
12310 /**
12311  * MSRCXPollMemory function.
12312  * Send the PollMemory command to an RCX.
12313  *
12314  * \param address The RCX memory address.
12315  * \return The value read from the specified address.
12316  */
12317 inline int MSRCXPollMemory(const unsigned int address);
12318 
12319 /**
12320  * MSRCXAbsVar function.
12321  * Send the AbsVar command to an RCX.
12322  *
12323  * \param varnum The variable number to change.
12324  * \param src The RCX source.  See \ref RCXSourceConstants.
12325  * \param value The RCX value.
12326  */
12327 inline void MSRCXAbsVar(const byte varnum, const byte byte src, const unsigned int value);
12328 
12329 /**
12330  * MSRCXAddToDatalog function.
12331  * Send the AddToDatalog command to an RCX.
12332  *
12333  * \param src The RCX source.  See \ref RCXSourceConstants.
12334  * \param value The RCX value.
12335  */
12336 inline void MSRCXAddToDatalog(const byte src, const unsigned int value);
12337 
12338 /**
12339  * MSRCXAndVar function.
12340  * Send the AndVar command to an RCX.
12341  *
12342  * \param varnum The variable number to change.
12343  * \param src The RCX source.  See \ref RCXSourceConstants.
12344  * \param value The RCX value.
12345  */
12346 inline void MSRCXAndVar(const byte varnum, const byte src, const unsigned int value);
12347 
12348 /**
12349  * MSRCXBoot function.
12350  * Send the Boot command to an RCX.
12351  */
12352 inline void MSRCXBoot(void);
12353 
12354 /**
12355  * MSRCXCalibrateEvent function.
12356  * Send the CalibrateEvent command to an RCX.
12357  *
12358  * \param evt The event number.
12359  * \param low The low threshold.
12360  * \param hi The high threshold.
12361  * \param hyst The hysterisis value.
12362  */
12363 inline void MSRCXCalibrateEvent(const byte evt, const byte low, const byte hi, const byte hyst);
12364 
12365 /**
12366  * MSRCXClearAllEvents function.
12367  * Send the ClearAllEvents command to an RCX.
12368  */
12369 inline void MSRCXClearAllEvents(void);
12370 
12371 /**
12372  * MSRCXClearCounter function.
12373  * Send the ClearCounter command to an RCX.
12374  *
12375  * \param counter The counter to clear.
12376  */
12377 inline void MSRCXClearCounter(const byte counter);
12378 
12379 /**
12380  * MSRCXClearMsg function.
12381  * Send the ClearMsg command to an RCX.
12382  */
12383 inline void MSRCXClearMsg(void);
12384 
12385 /**
12386  * MSRCXClearSensor function.
12387  * Send the ClearSensor command to an RCX.
12388  *
12389  * \param port The RCX port number.
12390  */
12391 inline void MSRCXClearSensor(const byte port);
12392 
12393 /**
12394  * MSRCXClearSound function.
12395  * Send the ClearSound command to an RCX.
12396  */
12397 inline void MSRCXClearSound(void);
12398 
12399 /**
12400  * MSRCXClearTimer function.
12401  * Send the ClearTimer command to an RCX.
12402  *
12403  * \param timer The timer to clear.
12404  */
12405 inline void MSRCXClearTimer(const byte timer);
12406 
12407 /**
12408  * MSRCXCreateDatalog function.
12409  * Send the CreateDatalog command to an RCX.
12410  *
12411  * \param size The new datalog size.
12412  */
12413 inline void MSRCXCreateDatalog(const unsigned int size);
12414 
12415 /**
12416  * MSRCXDecCounter function.
12417  * Send the DecCounter command to an RCX.
12418  *
12419  * \param counter The counter to decrement.
12420  */
12421 inline void MSRCXDecCounter(const byte counter);
12422 
12423 /**
12424  * MSRCXDeleteSub function.
12425  * Send the DeleteSub command to an RCX.
12426  *
12427  * \param s The subroutine number to delete.
12428  */
12429 inline void MSRCXDeleteSub(const byte s);
12430 
12431 /**
12432  * MSRCXDeleteSubs function.
12433  * Send the DeleteSubs command to an RCX.
12434  */
12435 inline void MSRCXDeleteSubs(void);
12436 
12437 /**
12438  * MSRCXDeleteTask function.
12439  * Send the DeleteTask command to an RCX.
12440  *
12441  * \param t The task number to delete.
12442  */
12443 inline void MSRCXDeleteTask(const byte t);
12444 
12445 /**
12446  * MSRCXDeleteTasks function.
12447  * Send the DeleteTasks command to an RCX.
12448  */
12449 inline void MSRCXDeleteTasks(void);
12450 
12451 /**
12452  * MSRCXDisableOutput function.
12453  * Send the DisableOutput command to an RCX.
12454  *
12455  * \param outputs The RCX output(s) to disable. See \ref RCXOutputConstants.
12456  */
12457 inline void MSRCXDisableOutput(const byte outputs);
12458 
12459 /**
12460  * MSRCXDivVar function.
12461  * Send the DivVar command to an RCX.
12462  *
12463  * \param varnum The variable number to change.
12464  * \param src The RCX source.  See \ref RCXSourceConstants.
12465  * \param value The RCX value.
12466  */
12467 inline void MSRCXDivVar(const byte varnum, const byte src, const unsigned int value);
12468 
12469 /**
12470  * MSRCXEnableOutput function.
12471  * Send the EnableOutput command to an RCX.
12472  *
12473  * \param outputs The RCX output(s) to enable. See \ref RCXOutputConstants.
12474  */
12475 inline void MSRCXEnableOutput(const byte outputs);
12476 
12477 /**
12478  * MSRCXEvent function.
12479  * Send the Event command to an RCX.
12480  *
12481  * \param src The RCX source.  See \ref RCXSourceConstants.
12482  * \param value The RCX value.
12483  */
12484 inline void MSRCXEvent(const byte src, const unsigned int value);
12485 
12486 /**
12487  * MSRCXFloat function.
12488  * Send commands to an RCX to float the specified outputs.
12489  *
12490  * \param outputs The RCX output(s) to float. See \ref RCXOutputConstants.
12491  */
12492 inline void MSRCXFloat(const byte outputs);
12493 
12494 /**
12495  * MSRCXFwd function.
12496  * Send commands to an RCX to set the specified outputs to the forward direction.
12497  *
12498  * \param outputs The RCX output(s) to set forward. See \ref RCXOutputConstants.
12499  */
12500 inline void MSRCXFwd(const byte outputs);
12501 
12502 /**
12503  * MSRCXIncCounter function.
12504  * Send the IncCounter command to an RCX.
12505  *
12506  * \param counter The counter to increment.
12507  */
12508 inline void MSRCXIncCounter(const byte counter);
12509 
12510 /**
12511  * MSRCXInvertOutput function.
12512  * Send the InvertOutput command to an RCX.
12513  *
12514  * \param outputs The RCX output(s) to invert. See \ref RCXOutputConstants.
12515  */
12516 inline void MSRCXInvertOutput(const byte outputs);
12517 
12518 /**
12519  * MSRCXMulVar function.
12520  * Send the MulVar command to an RCX.
12521  *
12522  * \param varnum The variable number to change.
12523  * \param src The RCX source.  See \ref RCXSourceConstants.
12524  * \param value The RCX value.
12525  */
12526 inline void MSRCXMulVar(const byte varnum, const byte src, unsigned int value);
12527 
12528 /**
12529  * MSRCXMuteSound function.
12530  * Send the MuteSound command to an RCX.
12531  */
12532 inline void MSRCXMuteSound(void);
12533 
12534 /**
12535  * MSRCXObvertOutput function.
12536  * Send the ObvertOutput command to an RCX.
12537  *
12538  * \param outputs The RCX output(s) to obvert. See \ref RCXOutputConstants.
12539  */
12540 inline void MSRCXObvertOutput(const byte outputs);
12541 
12542 /**
12543  * MSRCXOff function.
12544  * Send commands to an RCX to turn off the specified outputs.
12545  *
12546  * \param outputs The RCX output(s) to turn off. See \ref RCXOutputConstants.
12547  */
12548 inline void MSRCXOff(const byte outputs);
12549 
12550 /**
12551  * MSRCXOn function.
12552  * Send commands to an RCX to turn on the specified outputs.
12553  *
12554  * \param outputs The RCX output(s) to turn on. See \ref RCXOutputConstants.
12555  */
12556 inline void MSRCXOn(const byte outputs);
12557 
12558 /**
12559  * MSRCXOnFor function.
12560  * Send commands to an RCX to turn on the specified outputs in the forward
12561  * direction for the specified duration.
12562  *
12563  * \param outputs The RCX output(s) to turn on. See \ref RCXOutputConstants.
12564  * \param ms The number of milliseconds to leave the outputs on
12565  */
12566 inline void MSRCXOnFor(const byte outputs, const unsigned int ms);
12567 
12568 /**
12569  * MSRCXOnFwd function.
12570  * Send commands to an RCX to turn on the specified outputs in the forward
12571  * direction.
12572  *
12573  * \param outputs The RCX output(s) to turn on in the forward direction. See \ref RCXOutputConstants.
12574  */
12575 inline void MSRCXOnFwd(const byte outputs);
12576 
12577 /**
12578  * MSRCXOnRev function.
12579  * Send commands to an RCX to turn on the specified outputs in the reverse direction.
12580  *
12581  * \param outputs The RCX output(s) to turn on in the reverse direction. See \ref RCXOutputConstants.
12582  */
12583 inline void MSRCXOnRev(const byte outputs);
12584 
12585 /**
12586  * MSRCXOrVar function.
12587  * Send the OrVar command to an RCX.
12588  *
12589  * \param varnum The variable number to change.
12590  * \param src The RCX source.  See \ref RCXSourceConstants.
12591  * \param value The RCX value.
12592  */
12593 inline void MSRCXOrVar(const byte varnum, const byte src, const unsigned int value);
12594 
12595 /**
12596  * MSRCXPBTurnOff function.
12597  * Send the PBTurnOff command to an RCX.
12598  */
12599 inline void MSRCXPBTurnOff(void);
12600 
12601 /**
12602  * MSRCXPing function.
12603  * Send the Ping command to an RCX.
12604  */
12605 inline void MSRCXPing(void);
12606 
12607 /**
12608  * MSRCXPlaySound function.
12609  * Send the PlaySound command to an RCX.
12610  *
12611  * \param snd The sound number to play.
12612  */
12613 inline void MSRCXPlaySound(const byte snd);
12614 
12615 /**
12616  * MSRCXPlayTone function.
12617  * Send the PlayTone command to an RCX.
12618  *
12619  * \param freq The frequency of the tone to play.
12620  * \param duration The duration of the tone to play.
12621  */
12622 inline void MSRCXPlayTone(const unsigned int freq, const byte duration);
12623 
12624 /**
12625  * MSRCXPlayToneVar function.
12626  * Send the PlayToneVar command to an RCX.
12627  *
12628  * \param varnum The variable containing the tone frequency to play.
12629  * \param duration The duration of the tone to play.
12630  */
12631 inline void MSRCXPlayToneVar(const byte varnum, const byte duration);
12632 
12633 /**
12634  * MSRCXRemote function.
12635  * Send the Remote command to an RCX.
12636  *
12637  * \param cmd The RCX IR remote command to send. See \ref RCXRemoteConstants.
12638  */
12639 inline void MSRCXRemote(unsigned int cmd);
12640 
12641 /**
12642  * MSRCXReset function.
12643  * Send the Reset command to an RCX.
12644  */
12645 inline void MSRCXReset(void);
12646 
12647 /**
12648  * MSRCXRev function.
12649  * Send commands to an RCX to set the specified outputs to the reverse direction.
12650  *
12651  * \param outputs The RCX output(s) to reverse direction. See \ref RCXOutputConstants.
12652  */
12653 inline void MSRCXRev(const byte outputs);
12654 
12655 /**
12656  * MSRCXSelectDisplay function.
12657  * Send the SelectDisplay command to an RCX.
12658  *
12659  * \param src The RCX source.  See \ref RCXSourceConstants.
12660  * \param value The RCX value.
12661  */
12662 inline void MSRCXSelectDisplay(const byte src, const unsigned int value);
12663 
12664 /**
12665  * MSRCXSelectProgram function.
12666  * Send the SelectProgram command to an RCX.
12667  *
12668  * \param prog The program number to select.
12669  */
12670 inline void MSRCXSelectProgram(const byte prog);
12671 
12672 /**
12673  * MSRCXSendSerial function.
12674  * Send the SendSerial command to an RCX.
12675  *
12676  * \param first The first byte address.
12677  * \param count The number of bytes to send.
12678  */
12679 inline void MSRCXSendSerial(const byte first, const byte count);
12680 
12681 /**
12682  * MSRCXSet function.
12683  * Send the Set command to an RCX.
12684  *
12685  * \param dstsrc The RCX destination source.  See \ref RCXSourceConstants.
12686  * \param dstval The RCX destination value.
12687  * \param src The RCX source.  See \ref RCXSourceConstants.
12688  * \param value The RCX value.
12689  */
12690 inline void MSRCXSet(const byte dstsrc, const byte dstval, const byte src, unsigned int value);
12691 
12692 /**
12693  * MSRCXSetDirection function.
12694  * Send the SetDirection command to an RCX to configure the direction of the specified outputs.
12695  *
12696  * \param outputs The RCX output(s) to set direction. See \ref RCXOutputConstants.
12697  * \param dir The RCX output direction. See \ref RCXOutputDirection.
12698  */
12699 inline void MSRCXSetDirection(const byte outputs, const byte dir);
12700 
12701 /**
12702  * MSRCXSetEvent function.
12703  * Send the SetEvent command to an RCX.
12704  *
12705  * \param evt The event number to set.
12706  * \param src The RCX source. See \ref RCXSourceConstants.
12707  * \param type The event type.
12708  */
12709 inline void MSRCXSetEvent(const byte evt, const byte src, const byte type);
12710 
12711 /**
12712  * MSRCXSetGlobalDirection function.
12713  * Send the SetGlobalDirection command to an RCX.
12714  *
12715  * \param outputs The RCX output(s) to set global direction. See \ref RCXOutputConstants.
12716  * \param dir The RCX output direction. See \ref RCXOutputDirection.
12717  */
12718 inline void MSRCXSetGlobalDirection(const byte outputs, const byte dir);
12719 
12720 /**
12721  * MSRCXSetGlobalOutput function.
12722  * Send the SetGlobalOutput command to an RCX.
12723  *
12724  * \param outputs The RCX output(s) to set global mode. See \ref RCXOutputConstants.
12725  * \param mode The RCX output mode. See \ref RCXOutputMode.
12726  */
12727 inline void MSRCXSetGlobalOutput(const byte outputs, const byte mode);
12728 
12729 /**
12730  * MSRCXSetMaxPower function.
12731  * Send the SetMaxPower command to an RCX.
12732  *
12733  * \param outputs The RCX output(s) to set max power. See \ref RCXOutputConstants.
12734  * \param pwrsrc The RCX source.  See \ref RCXSourceConstants.
12735  * \param pwrval The RCX value.
12736  */
12737 inline void MSRCXSetMaxPower(const byte outputs, const byte pwrsrc, const byte pwrval);
12738 
12739 /**
12740  * MSRCXSetMessage function.
12741  * Send the SetMessage command to an RCX.
12742  *
12743  * \param msg The numeric message to send.
12744  */
12745 inline void MSRCXSetMessage(const byte msg);
12746 
12747 /**
12748  * MSRCXSetOutput function.
12749  * Send the SetOutput command to an RCX to configure the mode of the specified outputs
12750  *
12751  * \param outputs The RCX output(s) to set mode. See \ref RCXOutputConstants.
12752  * \param mode The RCX output mode. See \ref RCXOutputMode.
12753  */
12754 inline void MSRCXSetOutput(const byte outputs, const byte mode);
12755 
12756 /**
12757  * MSRCXSetPower function.
12758  * Send the SetPower command to an RCX to configure the power level of the specified outputs.
12759  *
12760  * \param outputs The RCX output(s) to set power. See \ref RCXOutputConstants.
12761  * \param pwrsrc The RCX source.  See \ref RCXSourceConstants.
12762  * \param pwrval The RCX value.
12763  */
12764 inline void MSRCXSetPower(const byte outputs, const byte pwrsrc, const byte pwrval);
12765 
12766 /**
12767  * MSRCXSetPriority function.
12768  * Send the SetPriority command to an RCX.
12769  *
12770  * \param p The new task priority.
12771  */
12772 inline void MSRCXSetPriority(const byte p);
12773 
12774 /**
12775  * MSRCXSetSensorMode function.
12776  * Send the SetSensorMode command to an RCX.
12777  *
12778  * \param port The RCX sensor port.
12779  * \param mode The RCX sensor mode.
12780  */
12781 inline void MSRCXSetSensorMode(const byte port, const byte mode);
12782 
12783 /**
12784  * MSRCXSetSensorType function.
12785  * Send the SetSensorType command to an RCX.
12786  *
12787  * \param port The RCX sensor port.
12788  * \param type The RCX sensor type.
12789  */
12790 inline void MSRCXSetSensorType(const byte port, const byte type);
12791 
12792 /**
12793  * MSRCXSetSleepTime function.
12794  * Send the SetSleepTime command to an RCX.
12795  *
12796  * \param t The new sleep time value.
12797  */
12798 inline void MSRCXSetSleepTime(const byte t);
12799 
12800 /**
12801  * MSRCXSetTxPower function.
12802  * Send the SetTxPower command to an RCX.
12803  *
12804  * \param pwr The IR transmit power level.
12805  */
12806 inline void MSRCXSetTxPower(const byte pwr);
12807 
12808 /**
12809  * MSRCXSetUserDisplay function.
12810  * Send the SetUserDisplay command to an RCX.
12811  *
12812  * \param src The RCX source.  See \ref RCXSourceConstants.
12813  * \param value The RCX value.
12814  * \param precision The number of digits of precision.
12815  */
12816 inline void MSRCXSetUserDisplay(const byte src, const unsigned int value, const byte precision);
12817 
12818 /**
12819  * MSRCXSetVar function.
12820  * Send the SetVar command to an RCX.
12821  *
12822  * \param varnum The variable number to change.
12823  * \param src The RCX source.  See \ref RCXSourceConstants.
12824  * \param value The RCX value.
12825  */
12826 inline void MSRCXSetVar(const byte varnum, const byte src, const unsigned int value);
12827 
12828 /**
12829  * MSRCXSetWatch function.
12830  * Send the SetWatch command to an RCX.
12831  *
12832  * \param hours The new watch time hours value.
12833  * \param minutes The new watch time minutes value.
12834  */
12835 inline void MSRCXSetWatch(const byte hours, const byte minutes);
12836 
12837 /**
12838  * MSRCXSgnVar function.
12839  * Send the SgnVar command to an RCX.
12840  *
12841  * \param varnum The variable number to change.
12842  * \param src The RCX source.  See \ref RCXSourceConstants.
12843  * \param value The RCX value.
12844  */
12845 inline void MSRCXSgnVar(const byte varnum, const byte src, const unsigned int value);
12846 
12847 /**
12848  * MSRCXStartTask function.
12849  * Send the StartTask command to an RCX.
12850  *
12851  * \param t The task number to start.
12852  */
12853 inline void MSRCXStartTask(const byte t);
12854 
12855 /**
12856  * MSRCXStopAllTasks function.
12857  * Send the StopAllTasks command to an RCX.
12858  */
12859 inline void MSRCXStopAllTasks(void);
12860 
12861 /**
12862  * MSRCXStopTask function.
12863  * Send the StopTask command to an RCX.
12864  *
12865  * \param t The task number to stop.
12866  */
12867 inline void MSRCXStopTask(const byte t);
12868 
12869 /**
12870  * MSRCXSubVar function.
12871  * Send the SubVar command to an RCX.
12872  *
12873  * \param varnum The variable number to change.
12874  * \param src The RCX source.  See \ref RCXSourceConstants.
12875  * \param value The RCX value.
12876  */
12877 inline void MSRCXSubVar(const byte varnum, const byte src, const unsigned int value);
12878 
12879 /**
12880  * MSRCXSumVar function.
12881  * Send the SumVar command to an RCX.
12882  *
12883  * \param varnum The variable number to change.
12884  * \param src The RCX source.  See \ref RCXSourceConstants.
12885  * \param value The RCX value.
12886  */
12887 inline void MSRCXSumVar(const byte varnum, const byte src, const unsigned int value);
12888 
12889 /**
12890  * MSRCXToggle function.
12891  * Send commands to an RCX to toggle the direction of the specified outputs.
12892  *
12893  * \param outputs The RCX output(s) to toggle. See \ref RCXOutputConstants.
12894  */
12895 inline void MSRCXToggle(const byte outputs);
12896 
12897 /**
12898  * MSRCXUnlock function.
12899  * Send the Unlock command to an RCX.
12900  */
12901 inline void MSRCXUnlock(void);
12902 
12903 /**
12904  * MSRCXUnmuteSound function.
12905  * Send the UnmuteSound command to an RCX.
12906  */
12907 inline void MSRCXUnmuteSound(void);
12908 
12909 /**
12910  * MSScoutCalibrateSensor function.
12911  * Send the CalibrateSensor command to a Scout.
12912  */
12913 inline void MSScoutCalibrateSensor(void);
12914 
12915 /**
12916  * MSScoutMuteSound function.
12917  * Send the MuteSound command to a Scout.
12918  */
12919 inline void MSScoutMuteSound(void);
12920 
12921 /**
12922  * MSScoutSelectSounds function.
12923  * Send the SelectSounds command to a Scout.
12924  *
12925  * \param grp The Scout sound group to select.
12926  */
12927 inline void MSScoutSelectSounds(const byte grp);
12928 
12929 /**
12930  * MSScoutSendVLL function.
12931  * Send the SendVLL command to a Scout.
12932  *
12933  * \param src The Scout source.  See \ref RCXSourceConstants.
12934  * \param value The Scout value.
12935  */
12936 inline void MSScoutSendVLL(const byte src, const unsigned int value);
12937 
12938 /**
12939  * MSScoutSetCounterLimit function.
12940  * Send the SetCounterLimit command to a Scout.
12941  *
12942  * \param ctr The counter for which to set the limit.
12943  * \param src The Scout source.  See \ref RCXSourceConstants.
12944  * \param value The Scout value.
12945  */
12946 inline void MSScoutSetCounterLimit(const byte ctr, const byte src, const unsigned int value);
12947 
12948 /**
12949  * MSScoutSetEventFeedback function.
12950  * Send the SetEventFeedback command to a Scout.
12951  *
12952  * \param src The Scout source.  See \ref RCXSourceConstants.
12953  * \param value The Scout value.
12954  */
12955 inline void MSScoutSetEventFeedback(const byte src, const unsigned int value);
12956 
12957 /**
12958  * MSScoutSetLight function.
12959  * Send the SetLight command to a Scout.
12960  *
12961  * \param x Set the light on or off using this value. See \ref ScoutLightConstants.
12962  */
12963 inline void MSScoutSetLight(const byte x);
12964 
12965 /**
12966  * MSScoutSetScoutMode function.
12967  * Send the SetScoutMode command to a Scout.
12968  *
12969  * \param mode Set the scout mode. See \ref ScoutModeConstants.
12970 */
12971 inline void MSScoutSetScoutMode(const byte mode);
12972 
12973 /**
12974  * MSScoutSetScoutRules function.
12975  * Send the SetScoutRules command to a Scout.
12976  *
12977  * \param m Scout motion rule. See \ref ScoutMotionRuleConstants.
12978  * \param t Scout touch rule. See \ref ScoutTouchRuleConstants.
12979  * \param l Scout light rule. See \ref ScoutLightRuleConstants.
12980  * \param tm Scout transmit rule. See \ref ScoutTransmitRuleConstants.
12981  * \param fx Scout special effects rule. See \ref ScoutSpecialEffectConstants.
12982  */
12983 inline void MSScoutSetScoutRules(const byte m, const byte t, const byte l, const byte tm, const byte fx);
12984 
12985 /**
12986  * MSScoutSetSensorClickTime function.
12987  * Send the SetSensorClickTime command to a Scout.
12988  *
12989  * \param src The Scout source.  See \ref RCXSourceConstants.
12990  * \param value The Scout value.
12991  */
12992 inline void MSScoutSetSensorClickTime(const byte src, const unsigned int value);
12993 
12994 /**
12995  * MSScoutSetSensorHysteresis function.
12996  * Send the SetSensorHysteresis command to a Scout.
12997  *
12998  * \param src The Scout source.  See \ref RCXSourceConstants.
12999  * \param value The Scout value.
13000  */
13001 inline void MSScoutSetSensorHysteresis(const byte src, const unsigned int value);
13002 
13003 /**
13004  * MSScoutSetSensorLowerLimit function.
13005  * Send the SetSensorLowerLimit command to a Scout.
13006  *
13007  * \param src The Scout source.  See \ref RCXSourceConstants.
13008  * \param value The Scout value.
13009  */
13010 inline void MSScoutSetSensorLowerLimit(const byte src, const unsigned int value);
13011 
13012 /**
13013  * MSScoutSetSensorUpperLimit function.
13014  * Send the SetSensorUpperLimit command to a Scout.
13015  *
13016  * \param src The Scout source.  See \ref RCXSourceConstants.
13017  * \param value The Scout value.
13018  */
13019 inline void MSScoutSetSensorUpperLimit(const byte src, const unsigned int value);
13020 
13021 /**
13022  * MSScoutSetTimerLimit function.
13023  * Send the SetTimerLimit command to a Scout.
13024  *
13025  * \param tmr The timer for which to set a limit.
13026  * \param src The Scout source.  See \ref RCXSourceConstants.
13027  * \param value The Scout value.
13028  */
13029 inline void MSScoutSetTimerLimit(const byte tmr, const byte src, const unsigned int value);
13030 
13031 /**
13032  * MSScoutUnmuteSound function.
13033  * Send the UnmuteSound command to a Scout.
13034  */
13035 inline void MSScoutUnmuteSound(void);
13036 
13037 #else
13038 
13039 #define SensorMSDROD(_p) asm { getin __RETVAL__, _p, NormalizedValueField }
13040 #define SensorNXTSumoEyesRaw(_p) asm { getin __RETVAL__, _p, NormalizedValueField }
13041 #define SensorMSPressureRaw(_p) asm { getin __RETVAL__, _p, RawValueField }
13042 #define SensorMSCompass(_port, _i2caddr) asm { ReadSensorMSCompass(_port, _i2caddr, __RETVAL__) }
13043 #define ReadSensorMSRTClock(_port, _sec, _min, _hrs, _dow, _date, _month, _year) asm { __ReadSensorMSRTClock(_port, _sec, _min, _hrs, _dow, _date, _month, _year, __RETVAL__) }
13044 #define ReadSensorMSTilt(_port, _i2caddr, _x, _y, _z) asm { __ReadSensorMSTilt(_port, _i2caddr, _x, _y, _z, __RETVAL__) }
13045 #define ReadSensorMSAccel(_port, _i2caddr, _x, _y, _z) asm { __ReadSensorMSAccel(_port, _i2caddr, _x, _y, _z, __RETVAL__) }
13046 
13047 #define MSReadValue(_port, _i2caddr, _reg, _bytes) asm { __MSReadValue(_port, _i2caddr, _reg, _bytes, __RETVAL__, __TMPBYTE__) }
13048 #define MSEnergize(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, MS_CMD_ENERGIZED, __RETVAL__) }
13049 #define MSDeenergize(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, MS_CMD_DEENERGIZED, __RETVAL__) }
13050 #define MSADPAOn(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, MS_CMD_ADPA_ON, __RETVAL__) }
13051 #define MSADPAOff(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, MS_CMD_ADPA_OFF, __RETVAL__) }
13052 
13053 #define DISTNxGP2D12(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, DIST_CMD_GP2D12, __RETVAL__) }
13054 #define DISTNxGP2D120(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, DIST_CMD_GP2D120, __RETVAL__) }
13055 #define DISTNxGP2YA21(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, DIST_CMD_GP2YA21, __RETVAL__) }
13056 #define DISTNxGP2YA02(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, DIST_CMD_GP2YA02, __RETVAL__) }
13057 #define DISTNxDistance(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, DIST_REG_DIST, 2, __RETVAL__, __TMPBYTE__) }
13058 #define DISTNxVoltage(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, DIST_REG_VOLT, 2, __RETVAL__, __TMPBYTE__) }
13059 #define DISTNxModuleType(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, DIST_REG_MODULE_TYPE, 1, __RETVAL__, __TMPBYTE__) }
13060 #define DISTNxNumPoints(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, DIST_REG_NUM_POINTS, 1, __RETVAL__, __TMPBYTE__) }
13061 #define DISTNxMinDistance(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, DIST_REG_DIST_MIN, 2, __RETVAL__, __TMPBYTE__) }
13062 #define DISTNxMaxDistance(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, DIST_REG_DIST_MAX, 2, __RETVAL__, __TMPBYTE__) }
13063 
13064 #define ACCLNxCalibrateX(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, ACCL_CMD_X_CAL, __RETVAL__) }
13065 #define ACCLNxCalibrateXEnd(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, ACCL_CMD_X_CAL_END, __RETVAL__) }
13066 #define ACCLNxCalibrateY(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, ACCL_CMD_Y_CAL, __RETVAL__) }
13067 #define ACCLNxCalibrateYEnd(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, ACCL_CMD_Y_CAL_END, __RETVAL__) }
13068 #define ACCLNxCalibrateZ(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, ACCL_CMD_Z_CAL, __RETVAL__) }
13069 #define ACCLNxCalibrateZEnd(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, ACCL_CMD_Z_CAL_END, __RETVAL__) }
13070 #define ACCLNxResetCalibration(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, ACCL_CMD_RESET_CAL, __RETVAL__) }
13071 #define SetACCLNxSensitivity(_port, _i2caddr, _slevel) asm { __I2CSendCmd(_port, _i2caddr, _slevel, __RETVAL__) }
13072 #define ACCLNxSensitivity(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, ACCL_REG_sENS_LVL, 1, __RETVAL__, __TMPBYTE__) }
13073 #define ACCLNxXOffset(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, ACCL_REG_X_OFFSET, 2, __RETVAL__, __TMPBYTE__) }
13074 #define ACCLNxXRange(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, ACCL_REG_X_RANGE, 2, __RETVAL__, __TMPBYTE__) }
13075 #define ACCLNxYOffset(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, ACCL_REG_Y_OFFSET, 2, __RETVAL__, __TMPBYTE__) }
13076 #define ACCLNxYRange(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, ACCL_REG_Y_RANGE, 2, __RETVAL__, __TMPBYTE__) }
13077 #define ACCLNxZOffset(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, ACCL_REG_Z_OFFSET, 2, __RETVAL__, __TMPBYTE__) }
13078 #define ACCLNxZRange(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, ACCL_REG_Z_RANGE, 2, __RETVAL__, __TMPBYTE__) }
13079 
13080 #define PFMateSend(_port, _i2caddr, _channel, _motors, _cmdA, _spdA, _cmdB, _spdB) asm { __PFMateSend(_port, _i2caddr, _channel, _motors, _cmdA, _spdA, _cmdB, _spdB, __RETVAL__) }
13081 #define PFMateSendRaw(_port, _i2caddr, _channel, _b1, _b2) asm { __PFMateSendRaw(_port, _i2caddr, _channel, _b1, _b2, __RETVAL__) }
13082 
13083 #define NXTServoPosition(_port, _i2caddr, _servo) asm { __MSReadValue(_port, _i2caddr, NXTSERVO_REG_S1_POS+(_servo*2), 2, __RETVAL__, __TMPBYTE__) }
13084 #define NXTServoSpeed(_port, _i2caddr, _servo) asm { __MSReadValue(_port, _i2caddr, NXTSERVO_REG_S1_SPEED+_servo, 1, __RETVAL__, __TMPBYTE__) }
13085 #define NXTServoBatteryVoltage(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, NXTSERVO_REG_VOLTAGE, 1, __RETVAL__, __TMPBYTE__) }
13086 #define SetNXTServoSpeed(_port, _i2caddr, _servo, _speed) asm { __MSWriteToRegister(_port, _i2caddr, NXTSERVO_REG_S1_SPEED+_servo, _speed, __RETVAL__) }
13087 #define SetNXTServoQuickPosition(_port, _i2caddr, _servo, _qpos) asm { __MSWriteToRegister(_port, _i2caddr, NXTSERVO_REG_S1_QPOS+_servo, _qpos, __RETVAL__) }
13088 #define SetNXTServoPosition(_port, _i2caddr, _servo, _pos) asm { __MSWriteLEIntToRegister(_port, _i2caddr, NXTSERVO_REG_S1_POS+(_servo*2), _pos, __RETVAL__) }
13089 #define NXTServoReset(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NXTSERVO_CMD_RESET, __RETVAL__) }
13090 #define NXTServoHaltMacro(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NXTSERVO_CMD_HALT, __RETVAL__) }
13091 #define NXTServoResumeMacro(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NXTSERVO_CMD_RESUME, __RETVAL__) }
13092 #define NXTServoPauseMacro(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NXTSERVO_CMD_PAUSE, __RETVAL__) }
13093 #define NXTServoInit(_port, _i2caddr, _servo) asm { __NXTServoInit(_port, _i2caddr, _servo, __RETVAL__) }
13094 #define NXTServoGotoMacroAddress(_port, _i2caddr, _macro) asm { __NXTServoGotoMacroAddress(_port, _i2caddr, _macro, __RETVAL__) }
13095 #define NXTServoEditMacro(_port, _i2caddr) asm { __NXTServoEditMacro(_port, _i2caddr, __RETVAL__) }
13096 #define NXTServoQuitEdit(_port) asm { __MSWriteToRegister(_port, MS_ADDR_NXTSERVO_EM, NXTSERVO_EM_REG_CMD, NXTSERVO_EM_CMD_QUIT, __RETVAL__) }
13097 
13098 #define NXTHIDAsciiMode(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NXTHID_CMD_ASCII, __RETVAL__) }
13099 #define NXTHIDDirectMode(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NXTHID_CMD_DIRECT, __RETVAL__) }
13100 #define NXTHIDTransmit(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NXTHID_CMD_TRANSMIT, __RETVAL__) }
13101 #define NXTHIDLoadCharacter(_port, _i2caddr, _modifier, _character) asm { __NXTHIDLoadCharacter(_port, _i2caddr, _modifier, _character, __RETVAL__) }
13102 
13103 #define NXTPowerMeterResetCounters(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NXTPM_CMD_RESET, __RETVAL__) }
13104 #define NXTPowerMeterPresentCurrent(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, NXTPM_REG_CURRENT, 2, __RETVAL__, __TMPBYTE__) }
13105 #define NXTPowerMeterPresentVoltage(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, NXTPM_REG_VOLTAGE, 2, __RETVAL__, __TMPBYTE__) }
13106 #define NXTPowerMeterCapacityUsed(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, NXTPM_REG_CAPACITY, 2, __RETVAL__, __TMPBYTE__) }
13107 #define NXTPowerMeterPresentPower(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, NXTPM_REG_POWER, 2, __RETVAL__, __TMPBYTE__) }
13108 #define NXTPowerMeterTotalPowerConsumed(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, NXTPM_REG_POWER, 4, __RETVAL__, __TMPBYTE__) }
13109 #define NXTPowerMeterMaxCurrent(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, NXTPM_REG_MAXCURRENT, 2, __RETVAL__, __TMPBYTE__) }
13110 #define NXTPowerMeterMinCurrent(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, NXTPM_REG_MINCURRENT, 2, __RETVAL__, __TMPBYTE__) }
13111 #define NXTPowerMeterMaxVoltage(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, NXTPM_REG_MAXVOLTAGE, 2, __RETVAL__, __TMPBYTE__) }
13112 #define NXTPowerMeterMinVoltage(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, NXTPM_REG_MINVOLTAGE, 2, __RETVAL__, __TMPBYTE__) }
13113 #define NXTPowerMeterElapsedTime(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, NXTPM_REG_TIME, 4, __RETVAL__, __TMPBYTE__) }
13114 #define NXTPowerMeterErrorCount(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, NXTPM_REG_ERRORCOUNT, 2, __RETVAL__, __TMPBYTE__) }
13115 
13116 #define NXTLineLeaderSteering(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, NXTLL_REG_STEERING, 1, __RETVAL__, __TMPBYTE__) }
13117 #define NXTLineLeaderAverage(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, NXTLL_REG_AVERAGE, 1, __RETVAL__, __TMPBYTE__) }
13118 #define NXTLineLeaderResult(_port, _i2caddr) asm { __MSReadValue(_port, _i2caddr, NXTLL_REG_RESULT, 1, __RETVAL__, __TMPBYTE__) }
13119 #define NXTLineLeaderPowerDown(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NXTLL_CMD_POWERDOWN, __RETVAL__) }
13120 #define NXTLineLeaderPowerUp(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NXTLL_CMD_POWERUP, __RETVAL__) }
13121 #define NXTLineLeaderInvert(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NXTLL_CMD_INVERT, __RETVAL__) }
13122 #define NXTLineLeaderReset(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NXTLL_CMD_RESET, __RETVAL__) }
13123 #define NXTLineLeaderSnapshot(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NXTLL_CMD_SNAPSHOT, __RETVAL__) }
13124 #define NXTLineLeaderCalibrateWhite(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NXTLL_CMD_WHITE, __RETVAL__) }
13125 #define NXTLineLeaderCalibrateBlack(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NXTLL_CMD_BLACK, __RETVAL__) }
13126 #define SetNXTLineLeaderSetpoint(_port, _i2caddr, _value) asm { __MSWriteToRegister(_port, _i2caddr, NXTLL_REG_SETPOINT, _value, __RETVAL__) }
13127 #define SetNXTLineLeaderKpValue(_port, _i2caddr, _value) asm { __MSWriteToRegister(_port, _i2caddr, NXTLL_REG_KP_VALUE, _value, __RETVAL__) }
13128 #define SetNXTLineLeaderKiValue(_port, _i2caddr, _value) asm { __MSWriteToRegister(_port, _i2caddr, NXTLL_REG_KI_VALUE, _value, __RETVAL__) }
13129 #define SetNXTLineLeaderKdValue(_port, _i2caddr, _value) asm { __MSWriteToRegister(_port, _i2caddr, NXTLL_REG_KD_VALUE, _value, __RETVAL__) }
13130 #define SetNXTLineLeaderKpFactor(_port, _i2caddr, _value) asm { __MSWriteToRegister(_port, _i2caddr, NXTLL_REG_KP_FACTOR, _value, __RETVAL__) }
13131 #define SetNXTLineLeaderKiFactor(_port, _i2caddr, _value) asm { __MSWriteToRegister(_port, _i2caddr, NXTLL_REG_KI_FACTOR, _value, __RETVAL__) }
13132 #define SetNXTLineLeaderKdFactor(_port, _i2caddr, _value) asm { __MSWriteToRegister(_port, _i2caddr, NXTLL_REG_KD_FACTOR, _value, __RETVAL__) }
13133 
13134 #define PSPNxDigital(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, PSP_CMD_DIGITAL, __RETVAL__) }
13135 #define PSPNxAnalog(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, PSP_CMD_ANALOG, __RETVAL__) }
13136 
13137 #define ReadSensorMSPlayStation(_port, _i2caddr, _b1, _b2, _xleft, _yleft, _xright, _yright) asm { __ReadSensorMSPlayStation(_port, _i2caddr, _b1, _b2, _xleft, _yleft, _xright, _yright, __RETVAL__) }
13138 
13139 #define NRLink2400(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NRLINK_CMD_2400, __RETVAL__) }
13140 #define NRLink4800(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NRLINK_CMD_4800, __RETVAL__) }
13141 #define NRLinkFlush(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NRLINK_CMD_FLUSH, __RETVAL__) }
13142 #define NRLinkIRLong(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NRLINK_CMD_IR_LONG, __RETVAL__) }
13143 #define NRLinkIRShort(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NRLINK_CMD_IR_SHORT, __RETVAL__) }
13144 #define NRLinkTxRaw(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NRLINK_CMD_TX_RAW, __RETVAL__) }
13145 #define NRLinkSetRCX(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NRLINK_CMD_SET_RCX, __RETVAL__) }
13146 #define NRLinkSetTrain(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NRLINK_CMD_SET_TRAIN, __RETVAL__) }
13147 #define NRLinkSetPF(_port, _i2caddr) asm { __I2CSendCmd(_port, _i2caddr, NRLINK_CMD_SET_PF, __RETVAL__) }
13148 
13149 #define RunNRLinkMacro(_port, _i2caddr, _macro) asm { __RunNRLinkMacro(_port, _i2caddr, _macro, __RETVAL__) }
13150 
13151 #define NRLinkStatus(_port, _i2caddr) asm { ReadNRLinkStatus(_port, _i2caddr, __RETVAL__, __TMPBYTE__) }
13152 
13153 #define WriteNRLinkBytes(_port, _i2caddr, _bytes) asm { __WriteNRLinkBytes(_port, _i2caddr, _bytes, __RETVAL__) }
13154 #define ReadNRLinkBytes(_port, _i2caddr, _bytes) asm { __ReadNRLinkBytes(_port, _i2caddr, _bytes, __RETVAL__) }
13155 
13156 #define MSPFComboDirect(_port, _i2caddr, _channel, _outa, _outb) asm { __MSPFComboDirect(_port, _i2caddr, _channel, _outa, _outb, __RETVAL__) }
13157 #define MSPFSinglePin(_port, _i2caddr, _channel, _out, _pin, _func, _cont) asm { __MSPFSinglePin(_port, _i2caddr, _channel, _out, _pin, _func, _cont, __RETVAL__) }
13158 #define MSPFSingleOutputCST(_port, _i2caddr, _channel, _out, _func) asm { __MSPFSingleOutput(_port, _i2caddr, _channel, _out, _func, TRUE, __RETVAL__) }
13159 #define MSPFSingleOutputPWM(_port, _i2caddr, _channel, _out, _func) asm { __MSPFSingleOutput(_port, _i2caddr, _channel, _out, _func, FALSE, __RETVAL__) }
13160 #define MSPFComboPWM(_port, _i2caddr, _channel, _outa, _outb) asm { __MSPFComboPWM(_port, _i2caddr, _channel, _outa, _outb, __RETVAL__) }
13161 #define MSPFTrain(_port, _i2caddr, _channel, _func) asm { __MSIRTrain(_port, _i2caddr, _channel, _func, TRUE, __RETVAL__) }
13162 #define MSIRTrain(_port, _i2caddr, _channel, _func) asm { __MSIRTrain(_port, _i2caddr, _channel, _func, FALSE, __RETVAL__) }
13163 #define MSPFRawOutput(_port, _i2caddr, _nibble0, _nibble1, _nibble2) asm { __MSPFRawOutput(_port, _i2caddr, _nibble0, _nibble1, _nibble2, __RETVAL__) }
13164 #define MSPFRepeat(_port, _i2caddr, _count, _delay) asm { __MSPFRepeatLastCommand(_port, _i2caddr, _count, _delay, __RETVAL__) }
13165 
13166 #define MSRCXSetNRLinkPort(_port, _i2caddr) asm { __MSRCXSetNRLink(_port, _i2caddr) }
13167 #define MSRCXPoll(_src, _value) asm { __MSRCXPoll(_src, _value, __RETVAL__) }
13168 #define MSRCXBatteryLevel() asm { __MSRCXBatteryLevel(__RETVAL__) }
13169 #define MSRCXPing() asm { __MSRCXOpNoArgs(RCX_PingOp) }
13170 #define MSRCXDeleteTasks() asm { __MSRCXOpNoArgs(RCX_DeleteTasksOp) }
13171 #define MSRCXStopAllTasks() asm { __MSRCXOpNoArgs(RCX_StopAllTasksOp) }
13172 #define MSRCXPBTurnOff() asm { __MSRCXOpNoArgs(RCX_PBTurnOffOp) }
13173 #define MSRCXDeleteSubs() asm { __MSRCXOpNoArgs(RCX_DeleteSubsOp) }
13174 #define MSRCXClearSound() asm { __MSRCXOpNoArgs(RCX_ClearSoundOp) }
13175 #define MSRCXClearMsg() asm { __MSRCXOpNoArgs(RCX_ClearMsgOp) }
13176 #define MSRCXMuteSound() asm { __MSRCXOpNoArgs(RCX_MuteSoundOp) }
13177 #define MSRCXUnmuteSound() asm { __MSRCXOpNoArgs(RCX_UnmuteSoundOp) }
13178 #define MSRCXClearAllEvents() asm { __MSRCXOpNoArgs(RCX_ClearAllEventsOp) }
13179 #define MSRCXSetOutput(_outputs, _mode) asm { __MSRCXSetOutput(_outputs, _mode) }
13180 #define MSRCXSetDirection(_outputs, _dir) asm { __MSRCXSetDirection(_outputs, _dir) }
13181 #define MSRCXSetPower(_outputs, _pwrsrc, _pwrval) asm { __MSRCXSetPower(_outputs, _pwrsrc, _pwrval) }
13182 #define MSRCXOn(_outputs) asm { __MSRCXSetOutput(_outputs, RCX_OUT_ON) }
13183 #define MSRCXOff(_outputs) asm { __MSRCXSetOutput(_outputs, RCX_OUT_OFF) }
13184 #define MSRCXFloat(_outputs) asm { __MSRCXSetOutput(_outputs, RCX_OUT_FLOAT) }
13185 #define MSRCXToggle(_outputs) asm { __MSRCXSetDirection(_outputs, RCX_OUT_TOGGLE) }
13186 #define MSRCXFwd(_outputs) asm { __MSRCXSetDirection(_outputs, RCX_OUT_FWD) }
13187 #define MSRCXRev(_outputs) asm { __MSRCXSetDirection(_outputs, RCX_OUT_REV) }
13188 #define MSRCXOnFwd(_outputs) asm { __MSRCXOnFwd(_outputs) }
13189 #define MSRCXOnRev(_outputs) asm { __MSRCXOnRev(_outputs) }
13190 #define MSRCXOnFor(_outputs, _ms) asm { __MSRCXOnFor(_outputs, _ms) }
13191 #define MSRCXSetTxPower(_pwr) asm { __MSRCXSetTxPower(_pwr) }
13192 #define MSRCXPlaySound(_snd) asm { __MSRCXPlaySound(_snd) }
13193 #define MSRCXDeleteTask(_t) asm { __MSRCXDeleteTask(_t) }
13194 #define MSRCXStartTask(_t) asm { __MSRCXStartTask(_t) }
13195 #define MSRCXStopTask(_t) asm { __MSRCXStopTask(_t) }
13196 #define MSRCXSelectProgram(_prog) asm { __MSRCXSelectProgram(_prog) }
13197 #define MSRCXClearTimer(_timer) asm { __MSRCXClearTimer(_timer) }
13198 #define MSRCXSetSleepTime(_t) asm { __MSRCXSetSleepTime(_t) }
13199 #define MSRCXDeleteSub(_s) asm { __MSRCXDeleteSub(_s) }
13200 #define MSRCXClearSensor(_port) asm { __MSRCXClearSensor(_port) }
13201 #define MSRCXPlayToneVar(_varnum, _duration) asm { __MSRCXPlayToneVar(_varnum, _duration) }
13202 #define MSRCXSetWatch(_hours, _minutes) asm { __MSRCXSetWatch(_hours, _minutes) }
13203 #define MSRCXSetSensorType(_port, _type) asm { __MSRCXSetSensorType(_port, _type) }
13204 #define MSRCXSetSensorMode(_port, _mode) asm { __MSRCXSetSensorMode(_port, _mode) }
13205 #define MSRCXCreateDatalog(_size) asm { __MSRCXCreateDatalog(_size) }
13206 #define MSRCXAddToDatalog(_src, _value) asm { __MSRCXAddToDatalog(_src, _value) }
13207 #define MSRCXSendSerial(_first, _count) asm { __MSRCXSendSerial(_first, _count) }
13208 #define MSRCXRemote(_cmd) asm { __MSRCXRemote(_cmd) }
13209 #define MSRCXEvent(_src, _value) asm { __MSRCXEvent(_src, _value) }
13210 #define MSRCXPlayTone(_freq, _duration) asm { __MSRCXPlayTone(_freq, _duration) }
13211 #define MSRCXSelectDisplay(_src, _value) asm { __MSRCXSelectDisplay(_src, _value) }
13212 #define MSRCXPollMemory(_memaddress) asm { __MSRCXPollMemory(_memaddress, __RETVAL__) }
13213 #define MSRCXSetEvent(_evt, _src, _type) asm { __MSRCXSetEvent(_evt, _src, _type) }
13214 #define MSRCXSetGlobalOutput(_outputs, _mode) asm { __MSRCXSetGlobalOutput(_outputs, _mode) }
13215 #define MSRCXSetGlobalDirection(_outputs, _dir) asm { __MSRCXSetGlobalDirection(_outputs, _dir) }
13216 #define MSRCXSetMaxPower(_outputs, _pwrsrc, _pwrval) asm { __MSRCXSetMaxPower(_outputs, _pwrsrc, _pwrval) }
13217 #define MSRCXEnableOutput(_outputs) asm { __MSRCXSetGlobalOutput(_outputs, RCX_OUT_ON) }
13218 #define MSRCXDisableOutput(_outputs) asm { __MSRCXSetGlobalOutput(_outputs, RCX_OUT_OFF) }
13219 #define MSRCXInvertOutput(_outputs) asm { __MSRCXSetGlobalDirection(_outputs, RCX_OUT_REV) }
13220 #define MSRCXObvertOutput(_outputs) asm { __MSRCXSetGlobalDirection(_outputs, RCX_OUT_FWD) }
13221 #define MSRCXCalibrateEvent(_evt, _low, _hi, _hyst) asm { __MSRCXCalibrateEvent(_evt, _low, _hi, _hyst) }
13222 #define MSRCXSetVar(_varnum, _src, _value) asm { __MSRCXVarOp(RCX_SetVarOp, _varnum, _src, _value) }
13223 #define MSRCXSumVar(_varnum, _src, _value) asm { __MSRCXVarOp(RCX_SumVarOp, _varnum, _src, _value) }
13224 #define MSRCXSubVar(_varnum, _src, _value) asm { __MSRCXVarOp(RCX_SubVarOp, _varnum, _src, _value) }
13225 #define MSRCXDivVar(_varnum, _src, _value) asm { __MSRCXVarOp(RCX_DivVarOp, _varnum, _src, _value) }
13226 #define MSRCXMulVar(_varnum, _src, _value) asm { __MSRCXVarOp(RCX_MulVarOp, _varnum, _src, _value) }
13227 #define MSRCXSgnVar(_varnum, _src, _value) asm { __MSRCXVarOp(RCX_SgnVarOp, _varnum, _src, _value) }
13228 #define MSRCXAbsVar(_varnum, _src, _value) asm { __MSRCXVarOp(RCX_AbsVarOp, _varnum, _src, _value) }
13229 #define MSRCXAndVar(_varnum, _src, _value) asm { __MSRCXVarOp(RCX_AndVarOp, _varnum, _src, _value) }
13230 #define MSRCXOrVar(_varnum, _src, _value) asm { __MSRCXVarOp(RCX_OrVarOp, _varnum, _src, _value) }
13231 #define MSRCXSet(_dstsrc, _dstval, _src, _value) asm { __MSRCXSet(_dstsrc, _dstval, _src, _value) }
13232 #define MSRCXUnlock() asm { __MSRCXUnlock() }
13233 #define MSRCXReset() asm { __MSRCXReset() }
13234 #define MSRCXBoot() asm { __MSRCXBoot() }
13235 #define MSRCXSetUserDisplay(_src, _value, _precision) asm { __MSRCXSetUserDisplay(_src, _value, _precision) }
13236 #define MSRCXIncCounter(_counter) asm { __MSRCXIncCounter(_counter) }
13237 #define MSRCXDecCounter(_counter) asm { __MSRCXDecCounter(_counter) }
13238 #define MSRCXClearCounter(_counter) asm { __MSRCXClearCounter(_counter) }
13239 #define MSRCXSetPriority(_p) asm { __MSRCXSetPriority(_p) }
13240 #define MSRCXSetMessage(_msg) asm { __MSRCXSetMessage(_msg) }
13241 
13242 #define MSScoutCalibrateSensor() asm { __MSRCXOpNoArgs(RCX_LSCalibrateOp) }
13243 #define MSScoutMuteSound() asm { __MSScoutMuteSound() }
13244 #define MSScoutUnmuteSound() asm { __MSScoutUnmuteSound() }
13245 #define MSScoutSelectSounds(_grp) asm { __MSScoutSelectSounds(_grp) }
13246 #define MSScoutSetLight(_x) asm { __MSScoutSetLight(_x) }
13247 #define MSScoutSetCounterLimit(_ctr, _src, _value) asm { __MSScoutSetCounterLimit(_ctr, _src, _value) }
13248 #define MSScoutSetTimerLimit(_tmr, _src, _value) asm { __MSScoutSetTimerLimit(_tmr, _src, _value) }
13249 #define MSScoutSetSensorClickTime(_src, _value) asm { __MSScoutSetSensorClickTime(_src, _value) }
13250 #define MSScoutSetSensorHysteresis(_src, _value) asm { __MSScoutSetSensorHysteresis(_src, _value) }
13251 #define MSScoutSetSensorLowerLimit(_src, _value) asm { __MSScoutSetSensorLowerLimit(_src, _value) }
13252 #define MSScoutSetSensorUpperLimit(_src, _value) asm { __MSScoutSetSensorUpperLimit(_src, _value) }
13253 #define MSScoutSetEventFeedback(_src, _value) asm { __MSScoutSetEventFeedback(_src, _value) }
13254 #define MSScoutSendVLL(_src, _value) asm { __MSScoutSendVLL(_src, _value) }
13255 #define MSScoutSetScoutRules(_m, _t, _l, _tm, _fx) asm { __MSScoutSetScoutRules(_m, _t, _l, _tm, _fx) }
13256 #define MSScoutSetScoutMode(_mode) asm { __MSScoutSetScoutMode(_mode) }
13257 
13258 #endif
13259 
13260 /** @} */ // end of MindSensorsAPI group
13261 
13262 ///////////////////////////////////////////////////////////////////////////////
13263 /////////////////////////////// Codatex API ///////////////////////////////////
13264 ///////////////////////////////////////////////////////////////////////////////
13265 
13266 
13267 /** @addtogroup CodatexAPI
13268  * @{
13269  */
13270 
13271 #ifdef __DOXYGEN_DOCS
13272 
13273 /**
13274  * RFIDInit function.
13275  * Initialize the Codatex RFID sensor.
13276  *
13277  * \param port The port to which the Codatex RFID sensor is attached. See the
13278  * \ref InPorts group. You may use a constant or a variable.
13279  * \return The boolean function call result.
13280  */
13281 inline bool RFIDInit(const byte & port);
13282 
13283 /**
13284  * RFIDMode function.
13285  * Configure the Codatex RFID sensor mode.
13286  *
13287  * \param port The port to which the Codatex RFID sensor is attached. See the
13288  * \ref InPorts group. You may use a constant or a variable.
13289  * \param mode The RFID sensor mode.  See the \ref CTRFIDModeConstants group.
13290  * \return The boolean function call result.
13291  */
13292 inline bool RFIDMode(const byte & port, const byte & mode);
13293 
13294 /**
13295  * RFIDStatus function.
13296  * Read the Codatex RFID sensor status.
13297  *
13298  * \param port The port to which the Codatex RFID sensor is attached. See the
13299  * \ref InPorts group. You may use a constant or a variable.
13300  * \return The RFID sensor status.
13301  */
13302 inline byte RFIDStatus(const byte & port);
13303 
13304 /**
13305  * RFIDRead function.
13306  * Read the Codatex RFID sensor value.
13307  *
13308  * \param port The port to which the Codatex RFID sensor is attached. See the
13309  * \ref InPorts group. You may use a constant or a variable.
13310  * \param output The five bytes of RFID data.
13311  * \return The boolean function call result.
13312  */
13313 inline bool RFIDRead(const byte & port, byte & output[]);
13314 
13315 /**
13316  * RFIDStop function.
13317  * Stop the Codatex RFID sensor.
13318  *
13319  * \param port The port to which the Codatex RFID sensor is attached. See the
13320  * \ref InPorts group. You may use a constant or a variable.
13321  * \return The boolean function call result.
13322  */
13323 inline bool RFIDStop(const byte & port);
13324 
13325 /**
13326  * RFIDReadSingle function.
13327  * Set the Codatex RFID sensor into single mode and read the RFID data.
13328  *
13329  * \param port The port to which the Codatex RFID sensor is attached. See the
13330  * \ref InPorts group. You may use a constant or a variable.
13331  * \param output The five bytes of RFID data.
13332  * \return The boolean function call result.
13333  */
13334 inline bool RFIDReadSingle(const byte & port, byte & output[]);
13335 
13336 /**
13337  * RFIDReadContinuous function.
13338  * Set the Codatex RFID sensor into continuous mode, if necessary, and read
13339  * the RFID data.
13340  *
13341  * \param port The port to which the Codatex RFID sensor is attached. See the
13342  * \ref InPorts group. You may use a constant or a variable.
13343  * \param output The five bytes of RFID data.
13344  * \return The boolean function call result.
13345  */
13346 inline bool RFIDReadContinuous(const byte & port, byte & output[]);
13347 
13348 #else
13349 
13350 #define RFIDInit(_port) asm { __RFIDInit(_port, __RETVAL__) }
13351 #define RFIDMode(_port, _mode) asm { __RFIDMode(_port, _mode, __RETVAL__) }
13352 #define RFIDStatus(_port) asm { __RFIDStatus(_port, __RETVAL__) }
13353 #define RFIDRead(_port, _output) asm { __RFIDRead(_port, _output, __RETVAL__) }
13354 #define RFIDStop(_port) asm { __RFIDStop(_port, __RETVAL__) }
13355 #define RFIDReadSingle(_port, _output) asm { __RFIDReadSingle(_port, _output, __RETVAL__) }
13356 #define RFIDReadContinuous(_port, _output) asm { __RFIDReadContinuous(_port, _output, __RETVAL__) }
13357 
13358 #endif
13359 
13360 /** @} */ // end of CodatexAPI group
13361 
13362 /** @} */ // end of ThirdPartyDevices group
13363 
13364 
13365 
13366 /** @addtogroup StandardCAPIFunctions
13367  * @{
13368  */
13369 
13370 ///////////////////////////////////////////////////////////////////////////////
13371 ////////////////////////////////// cmath API //////////////////////////////////
13372 ///////////////////////////////////////////////////////////////////////////////
13373 
13374 
13375 /** @defgroup cmathAPI cmath API
13376  * Standard C cmath API functions.
13377  * @{
13378  */
13379 #if __FIRMWARE_VERSION > 107
13380 
13381 /**
13382  * Compute square root.
13383  * Computes the square root of _X. Only constants or variables allowed
13384  * (no expressions).
13385  *
13386  * \deprecated Use sqrt() instead.
13387  * \param _X Floating point value.
13388  * \return Square root of _X.
13389  */
13390 #define Sqrt(_X) asm { sqrt __FLTRETVAL__, _X }
13391 
13392 /**
13393  * Compute square root.
13394  * Computes the square root of x.
13395  *
13396  * \param x Floating point value.
13397  * \return Square root of x.
13398  */
sqrt(float x)13399 inline float sqrt(float x) { asm { sqrt __FLTRETVAL__, x } }
13400 
13401 #ifdef __ENHANCED_FIRMWARE
13402 
13403 /**
13404  * Compute sine.
13405  * Computes the sine of _X. Only constants or variables allowed
13406  * (no expressions).
13407  *
13408  * \deprecated Use sin() instead.
13409  * \param _X Floating point value.
13410  * \return Sine of _X.
13411  */
13412 #define Sin(_X) asm { sin __FLTRETVAL__, _X }
13413 
13414 /**
13415  * Compute cosine.
13416  * Computes the cosine of _X. Only constants or variables allowed
13417  * (no expressions).
13418  *
13419  * \deprecated Use cos() instead.
13420  * \param _X Floating point value.
13421  * \return Cosine of _X.
13422  */
13423 #define Cos(_X) asm { cos __FLTRETVAL__, _X }
13424 
13425 /**
13426  * Compute arc sine.
13427  * Computes the arc sine of _X. Only constants or variables allowed
13428  * (no expressions).
13429  *
13430  * \deprecated Use asin() instead.
13431  * \param _X Floating point value.
13432  * \return Arc sine of _X.
13433  */
13434 #define Asin(_X) asm { asin __FLTRETVAL__, _X }
13435 
13436 /**
13437  * Compute arc cosine.
13438  * Computes the arc cosine of _X. Only constants or variables allowed
13439  * (no expressions).
13440  *
13441  * \deprecated Use acos() instead.
13442  * \param _X Floating point value.
13443  * \return Arc cosine of _X.
13444  */
13445 #define Acos(_X) asm { acos __FLTRETVAL__, _X }
13446 
13447 /**
13448  * Compute arc tangent.
13449  * Computes the arc tangent of _X. Only constants or variables allowed
13450  * (no expressions).
13451  *
13452  * \deprecated Use atan() instead.
13453  * \param _X Floating point value.
13454  * \return Arc tangent of _X.
13455  */
13456 #define Atan(_X) asm { atan __FLTRETVAL__, _X }
13457 
13458 /**
13459  * Round up value.
13460  * Computes the smallest integral value that is not less than _X.
13461  * Only constants or variables allowed (no expressions).
13462  *
13463  * \deprecated Use ceil() instead.
13464  * \param _X Floating point value.
13465  * \return The smallest integral value not less than _X.
13466  */
13467 #define Ceil(_X) asm { ceil __FLTRETVAL__, _X }
13468 
13469 /**
13470  * Compute exponential function .
13471  * Computes the base-e exponential function of _X, which is the e number
13472  * raised to the power _X. Only constants or variables allowed
13473  * (no expressions).
13474  *
13475  * \deprecated Use exp() instead.
13476  * \param _X Floating point value.
13477  * \return Exponential value of _X.
13478  */
13479 #define Exp(_X) asm { exp __FLTRETVAL__, _X }
13480 
13481 /**
13482  * Round down value.
13483  * Computes the largest integral value that is not greater than _X.
13484  * Only constants or variables allowed (no expressions).
13485  *
13486  * \deprecated Use floor() instead.
13487  * \param _X Floating point value.
13488  * \return The largest integral value not greater than _X.
13489  */
13490 #define Floor(_X) asm { floor __FLTRETVAL__, _X }
13491 
13492 /**
13493  * Compute tangent.
13494  * Computes the tangent of _X. Only constants or variables allowed
13495  * (no expressions).
13496  *
13497  * \deprecated Use tan() instead.
13498  * \param _X Floating point value.
13499  * \return Tangent of _X.
13500  */
13501 #define Tan(_X) asm { tan __FLTRETVAL__, _X }
13502 
13503 /**
13504  * Compute hyperbolic tangent.
13505  * Computes the hyperbolic tangent of _X. Only constants or variables allowed
13506  * (no expressions).
13507  *
13508  * \deprecated Use tanh() instead.
13509  * \param _X Floating point value.
13510  * \return Hyperbolic tangent of _X.
13511  */
13512 #define Tanh(_X) asm { tanh __FLTRETVAL__, _X }
13513 
13514 /**
13515  * Compute hyperbolic cosine.
13516  * Computes the hyperbolic cosine of _X. Only constants or variables allowed
13517  * (no expressions).
13518  *
13519  * \deprecated Use cosh() instead.
13520  * \param _X Floating point value.
13521  * \return Hyperbolic cosine of _X.
13522  */
13523 #define Cosh(_X) asm { cosh __FLTRETVAL__, _X }
13524 
13525 /**
13526  * Compute hyperbolic sine.
13527  * Computes the hyperbolic sine of _X. Only constants or variables allowed
13528  * (no expressions).
13529  *
13530  * \deprecated Use sinh() instead.
13531  * \param _X Floating point value.
13532  * \return Hyperbolic sine of _X.
13533  */
13534 #define Sinh(_X) asm { sinh __FLTRETVAL__, _X }
13535 
13536 /**
13537  * Compute natural logarithm.
13538  * Computes the natural logarithm of _X. The natural logarithm is the base-e
13539  * logarithm, the inverse of the natural exponential function (exp). For
13540  * base-10 logarithms, a specific function Log10() exists.
13541  * Only constants or variables allowed (no expressions).
13542  *
13543  * \deprecated Use log() instead.
13544  * \param _X Floating point value.
13545  * \return Natural logarithm of _X.
13546  */
13547 #define Log(_X) asm { log __FLTRETVAL__, _X }
13548 
13549 /**
13550  * Compute common logarithm.
13551  * Computes the common logarithm of _X. The common logarithm is the base-10
13552  * logarithm. For base-e logarithms, a specific function Log() exists.
13553  * Only constants or variables allowed (no expressions).
13554  *
13555  * \deprecated Use log10() instead.
13556  * \param _X Floating point value.
13557  * \return Common logarithm of _X.
13558  */
13559 #define Log10(_X) asm { log10 __FLTRETVAL__, _X }
13560 
13561 /**
13562  * Compute arc tangent with 2 parameters.
13563  * Computes the principal value of the arc tangent of _Y/_X, expressed in
13564  * radians. To compute the value, the function uses the sign of both arguments
13565  * to determine the quadrant.
13566  * Only constants or variables allowed (no expressions).
13567  *
13568  * \deprecated Use atan2() instead.
13569  * \param _Y Floating point value representing a y coordinate.
13570  * \param _X Floating point value representing an x coordinate.
13571  * \return Arc tangent of _Y/_X, in the interval [-pi,+pi] radians.
13572  */
13573 #define Atan2(_Y,_X) asm { atan2 __FLTRETVAL__, _Y, _X }
13574 
13575 /**
13576  * Raise to power.
13577  * Computes _Base raised to the power _Exponent.
13578  * Only constants or variables allowed (no expressions).
13579  *
13580  * \deprecated Use pow() instead.
13581  * \param _Base Floating point value.
13582  * \param _Exponent Floating point value.
13583  * \return The result of raising _Base to the power _Exponent.
13584  */
13585 #define Pow(_Base,_Exponent) asm { pow __FLTRETVAL__, _Base, _Exponent }
13586 
13587 /**
13588  * Compute integral part.
13589  * Computes the integral part of _X.
13590  * Only constants or variables allowed (no expressions).
13591  *
13592  * \deprecated Use trunc() instead.
13593  * \param _X Floating point value.
13594  * \return Integral part of _X.
13595  */
13596 #define Trunc(_X) asm { trunc __RETVAL__, _X }
13597 
13598 /**
13599  * Compute fractional part.
13600  * Computes the fractional part of _X.
13601  * Only constants or variables allowed (no expressions).
13602  *
13603  * \deprecated Use frac() instead.
13604  * \param _X Floating point value.
13605  * \return Fractional part of _X.
13606  */
13607 #define Frac(_X) asm { frac __FLTRETVAL__, _X }
13608 
13609 /**
13610  * Multiply and divide.
13611  * Multiplies two 32-bit values and then divides the 64-bit result by a third
13612  * 32-bit value.
13613  * Only constants or variables allowed (no expressions).
13614  *
13615  * \deprecated Use muldiv32() instead.
13616  * \param _A 32-bit long value.
13617  * \param _B 32-bit long value.
13618  * \param _C 32-bit long value.
13619  * \return The result of multiplying _A times _B and dividing by _C.
13620  */
13621 #define MulDiv32(_A,_B,_C) asm { muldiv __RETVAL__, _A, _B, _C }
13622 
13623 /**
13624  * Compute sine (degrees).
13625  * Computes the sine of _X. Only constants or variables allowed
13626  * (no expressions).
13627  *
13628  * \deprecated Use sind() instead.
13629  * \param _X Floating point value.
13630  * \return Sine of _X.
13631  */
13632 #define SinD(_X) asm { sind __FLTRETVAL__, _X }
13633 
13634 /**
13635  * Compute cosine (degrees).
13636  * Computes the cosine of _X. Only constants or variables allowed
13637  * (no expressions).
13638  *
13639  * \deprecated Use cosd() instead.
13640  * \param _X Floating point value.
13641  * \return Cosine of _X.
13642  */
13643 #define CosD(_X) asm { cosd __FLTRETVAL__, _X }
13644 
13645 /**
13646  * Compute arch sine (degrees).
13647  * Computes the arc sine of _X. Only constants or variables allowed
13648  * (no expressions).
13649  *
13650  * \deprecated Use asind() instead.
13651  * \param _X Floating point value.
13652  * \return Arc sine of _X.
13653  */
13654 #define AsinD(_X) asm { asind __FLTRETVAL__, _X }
13655 
13656 /**
13657  * Compute arc cosine (degrees).
13658  * Computes the arc cosine of _X. Only constants or variables allowed
13659  * (no expressions).
13660  *
13661  * \deprecated Use acosd() instead.
13662  * \param _X Floating point value.
13663  * \return Arc cosine of _X.
13664  */
13665 #define AcosD(_X) asm { acosd __FLTRETVAL__, _X }
13666 
13667 /**
13668  * Compute arc tangent (degrees).
13669  * Computes the arc tangent of _X. Only constants or variables allowed
13670  * (no expressions).
13671  *
13672  * \deprecated Use atand() instead.
13673  * \param _X Floating point value.
13674  * \return Arc tangent of _X.
13675  */
13676 #define AtanD(_X) asm { atand __FLTRETVAL__, _X }
13677 
13678 /**
13679  * Compute tangent (degrees).
13680  * Computes the sine of _X. Only constants or variables allowed
13681  * (no expressions).
13682  *
13683  * \deprecated Use tand() instead.
13684  * \param _X Floating point value.
13685  * \return Tangent of _X.
13686  */
13687 #define TanD(_X) asm { tand __FLTRETVAL__, _X }
13688 
13689 /**
13690  * Compute hyperbolic tangent (degrees).
13691  * Computes the hyperbolic tangent of _X. Only constants or variables allowed
13692  * (no expressions).
13693  *
13694  * \deprecated Use tanhd() instead.
13695  * \param _X Floating point value.
13696  * \return Hyperbolic tangent of _X.
13697  */
13698 #define TanhD(_X) asm { tanhd __FLTRETVAL__, _X }
13699 
13700 /**
13701  * Compute hyperbolic cosine (degrees).
13702  * Computes the hyperbolic cosine of _X. Only constants or variables allowed
13703  * (no expressions).
13704  *
13705  * \deprecated Use coshd() instead.
13706  * \param _X Floating point value.
13707  * \return Hyperbolic cosine of _X.
13708  */
13709 #define CoshD(_X) asm { coshd __FLTRETVAL__, _X }
13710 
13711 /**
13712  * Compute hyperbolic sine (degrees).
13713  * Computes the hyperbolic sine of _X. Only constants or variables allowed
13714  * (no expressions).
13715  *
13716  * \deprecated Use sinhd() instead.
13717  * \param _X Floating point value.
13718  * \return Hyperbolic sine of _X.
13719  */
13720 #define SinhD(_X) asm { sinhd __FLTRETVAL__, _X }
13721 
13722 /**
13723  * Compute arc tangent with two parameters (degrees).
13724  * Computes the arc tangent of _Y/_X. Only constants or variables allowed
13725  * (no expressions).
13726  *
13727  * \deprecated Use atan2d() instead.
13728  * \param _Y Floating point value.
13729  * \param _X Floating point value.
13730  * \return Arc tangent of _Y/_X, in the interval [-180,+180] degrees.
13731  */
13732 #define Atan2D(_Y,_X) asm { atan2d __FLTRETVAL__, _Y, _X }
13733 
13734 /**
13735  * Compute cosine.
13736  * Computes the cosine of an angle of x radians.
13737  *
13738  * \param x Floating point value representing an angle expressed in radians.
13739  * \return Cosine of x.
13740  *
13741  * \warning This function requires the enhanced NBC/NXC firmware.
13742  */
cos(float x)13743 inline float cos(float x) { asm { cos __FLTRETVAL__, x } }
13744 
13745 /**
13746  * Compute sine.
13747  * Computes the sine of an angle of x radians.
13748  *
13749  * \param x Floating point value representing an angle expressed in radians.
13750  * \return Sine of x.
13751  *
13752  * \warning This function requires the enhanced NBC/NXC firmware.
13753  */
sin(float x)13754 inline float sin(float x) { asm { sin __FLTRETVAL__, x } }
13755 
13756 /**
13757  * Compute tangent.
13758  * Computes the tangent of an angle of x radians.
13759  *
13760  * \param x Floating point value representing an angle expressed in radians.
13761  * \return Tangent of x.
13762  *
13763  * \warning This function requires the enhanced NBC/NXC firmware.
13764  */
tan(float x)13765 inline float tan(float x) { asm { tan __FLTRETVAL__, x } }
13766 
13767 /**
13768  * Compute arc cosine.
13769  * Computes the principal value of the arc cosine of x, expressed in radians.
13770  * In trigonometrics, arc cosine is the inverse operation of cosine.
13771  *
13772  * \param x Floating point value in the interval [-1,+1].
13773  * \return Arc cosine of x, in the interval [0,pi] radians.
13774  *
13775  * \warning This function requires the enhanced NBC/NXC firmware.
13776  */
acos(float x)13777 inline float acos(float x) { asm { acos __FLTRETVAL__, x } }
13778 
13779 /**
13780  * Compute arc sine.
13781  * Computes the principal value of the arc sine of x, expressed in radians.
13782  * In trigonometrics, arc sine is the inverse operation of sine.
13783  *
13784  * \param x Floating point value in the interval [-1,+1].
13785  * \return Arc sine of x, in the interval [-pi/2,+pi/2] radians.
13786  *
13787  * \warning This function requires the enhanced NBC/NXC firmware.
13788  */
asin(float x)13789 inline float asin(float x) { asm { asin __FLTRETVAL__, x } }
13790 
13791 /**
13792  * Compute arc tangent.
13793  * Computes the principal value of the arc tangent of x, expressed in radians.
13794  * In trigonometrics, arc tangent is the inverse operation of tangent. Notice
13795  * that because of the sign ambiguity, a function cannot determine with
13796  * certainty in which quadrant the angle falls only by its tangent value.
13797  * You can use atan2() if you need to determine the quadrant.
13798  *
13799  * \sa atan2()
13800  * \param x Floating point value.
13801  * \return Arc tangent of x, in the interval [-pi/2,+pi/2] radians.
13802  *
13803  * \warning This function requires the enhanced NBC/NXC firmware.
13804  */
atan(float x)13805 inline float atan(float x) { asm { atan __FLTRETVAL__, x } }
13806 
13807 /**
13808  * Compute arc tangent with 2 parameters.
13809  * Computes the principal value of the arc tangent of y/x, expressed in
13810  * radians. To compute the value, the function uses the sign of both arguments
13811  * to determine the quadrant.
13812  *
13813  * \sa atan()
13814  * \param y Floating point value representing a y coordinate.
13815  * \param x Floating point value representing an x coordinate.
13816  * \return Arc tangent of y/x, in the interval [-pi,+pi] radians.
13817  *
13818  * \warning This function requires the enhanced NBC/NXC firmware.
13819  */
atan2(float y,float x)13820 inline float atan2(float y, float x) { asm { atan2 __FLTRETVAL__, y, x } }
13821 
13822 /**
13823  * Compute hyperbolic cosine.
13824  * Computes the hyperbolic cosine of x, expressed in radians.
13825  *
13826  * \param x Floating point value.
13827  * \return Hyperbolic cosine of x.
13828  *
13829  * \warning This function requires the enhanced NBC/NXC firmware.
13830  */
cosh(float x)13831 inline float cosh(float x) { asm { cosh __FLTRETVAL__, x } }
13832 
13833 /**
13834  * Compute hyperbolic sine.
13835  * Computes the hyperbolic sine of x, expressed in radians.
13836  *
13837  * \param x Floating point value.
13838  * \return Hyperbolic sine of x.
13839  *
13840  * \warning This function requires the enhanced NBC/NXC firmware.
13841  */
sinh(float x)13842 inline float sinh(float x) { asm { sinh __FLTRETVAL__, x } }
13843 
13844 /**
13845  * Compute hyperbolic tangent.
13846  * Computes the hyperbolic tangent of x, expressed in radians.
13847  *
13848  * \param x Floating point value.
13849  * \return Hyperbolic tangent of x.
13850  *
13851  * \warning This function requires the enhanced NBC/NXC firmware.
13852  */
tanh(float x)13853 inline float tanh(float x) { asm { tanh __FLTRETVAL__, x } }
13854 
13855 /**
13856  * Compute exponential function.
13857  * Computes the base-e exponential function of x, which is the e number
13858  * raised to the power x.
13859  *
13860  * \param x Floating point value.
13861  * \return Exponential value of x.
13862  *
13863  * \warning This function requires the enhanced NBC/NXC firmware.
13864  */
exp(float x)13865 inline float exp(float x) { asm { exp __FLTRETVAL__, x } }
13866 
13867 /**
13868  * Compute natural logarithm.
13869  * Computes the natural logarithm of x. The natural logarithm is the base-e
13870  * logarithm, the inverse of the natural exponential function (exp). For
13871  * base-10 logarithms, a specific function log10() exists.
13872  *
13873  * \sa log10(), exp()
13874  * \param x Floating point value.
13875  * \return Natural logarithm of x.
13876  *
13877  * \warning This function requires the enhanced NBC/NXC firmware.
13878  */
log(float x)13879 inline float log(float x) { asm { log __FLTRETVAL__, x } }
13880 
13881 /**
13882  * Compute common logarithm.
13883  * Computes the common logarithm of x. The common logarithm is the base-10
13884  * logarithm. For base-e logarithms, a specific function log() exists.
13885  *
13886  * \sa log(), exp()
13887  * \param x Floating point value.
13888  * \return Common logarithm of x.
13889  *
13890  * \warning This function requires the enhanced NBC/NXC firmware.
13891  */
log10(float x)13892 inline float log10(float x) { asm { log10 __FLTRETVAL__, x } }
13893 
13894 /**
13895  * Compute integral part.
13896  * Computes the integral part of x.
13897  *
13898  * \param x Floating point value.
13899  * \return Integral part of x.
13900  *
13901  * \warning This function requires the enhanced NBC/NXC firmware.
13902  */
trunc(float x)13903 inline long trunc(float x) { asm { trunc __RETVAL__, x } }
13904 
13905 /**
13906  * Compute fractional part.
13907  * Computes the fractional part of x.
13908  *
13909  * \param x Floating point value.
13910  * \return Fractional part of x.
13911  *
13912  * \warning This function requires the enhanced NBC/NXC firmware.
13913  */
frac(float x)13914 inline float frac(float x) { asm { frac __FLTRETVAL__, x } }
13915 
13916 /**
13917  * Raise to power.
13918  * Computes base raised to the power exponent.
13919  *
13920  * \param base Floating point value.
13921  * \param exponent Floating point value.
13922  * \return The result of raising base to the power exponent.
13923  *
13924  * \warning This function requires the enhanced NBC/NXC firmware.
13925  */
pow(float base,float exponent)13926 inline float pow(float base, float exponent) { asm { pow __FLTRETVAL__, base, exponent } }
13927 
13928 /**
13929  * Round up value.
13930  * Computes the smallest integral value that is not less than x.
13931  *
13932  * \param x Floating point value.
13933  * \return The smallest integral value not less than x.
13934  *
13935  * \warning This function requires the enhanced NBC/NXC firmware.
13936  */
ceil(float x)13937 inline float ceil(float x) { asm { ceil __FLTRETVAL__, x } }
13938 
13939 /**
13940  * Round down value.
13941  * Computes the largest integral value that is not greater than x.
13942  *
13943  * \param x Floating point value.
13944  * \return The largest integral value not greater than x.
13945  *
13946  * \warning This function requires the enhanced NBC/NXC firmware.
13947  */
floor(float x)13948 inline float floor(float x) { asm { floor __FLTRETVAL__, x } }
13949 
13950 /**
13951  * Multiply and divide.
13952  * Multiplies two 32-bit values and then divides the 64-bit result by a third
13953  * 32-bit value.
13954  *
13955  * \param a 32-bit long value.
13956  * \param b 32-bit long value.
13957  * \param c 32-bit long value.
13958  * \return The result of multiplying a times b and dividing by c.
13959  *
13960  * \warning This function requires the enhanced NBC/NXC firmware.
13961  */
muldiv32(long a,long b,long c)13962 inline long muldiv32(long a, long b, long c) { asm { muldiv __RETVAL__, a, b, c } }
13963 
13964 // degree-based trig functions
13965 
13966 /**
13967  * Compute cosine (degrees).
13968  * Computes the cosine of an angle of x degrees.
13969  *
13970  * \param x Floating point value representing an angle expressed in degrees.
13971  * \return Cosine of x.
13972  *
13973  * \warning This function requires the enhanced NBC/NXC firmware.
13974  */
cosd(float x)13975 inline float cosd(float x) { asm { cosd __FLTRETVAL__, x } }
13976 
13977 /**
13978  * Compute sine (degrees).
13979  * Computes the sine of an angle of x degrees.
13980  *
13981  * \param x Floating point value representing an angle expressed in degrees.
13982  * \return Sine of x.
13983  *
13984  * \warning This function requires the enhanced NBC/NXC firmware.
13985  */
sind(float x)13986 inline float sind(float x) { asm { sind __FLTRETVAL__, x } }
13987 
13988 /**
13989  * Compute tangent (degrees).
13990  * Computes the tangent of an angle of x degrees.
13991  *
13992  * \param x Floating point value representing an angle expressed in degrees.
13993  * \return Tangent of x.
13994  *
13995  * \warning This function requires the enhanced NBC/NXC firmware.
13996  */
tand(float x)13997 inline float tand(float x) { asm { tand __FLTRETVAL__, x } }
13998 
13999 /**
14000  * Compute arc cosine (degrees).
14001  * Computes the principal value of the arc cosine of x, expressed in degrees.
14002  * In trigonometrics, arc cosine is the inverse operation of cosine.
14003  *
14004  * \param x Floating point value in the interval [-1,+1].
14005  * \return Arc cosine of x, in the interval [0,180] degrees.
14006  *
14007  * \warning This function requires the enhanced NBC/NXC firmware.
14008  */
acosd(float x)14009 inline float acosd(float x) { asm { acosd __FLTRETVAL__, x } }
14010 
14011 /**
14012  * Compute arc sine (degrees).
14013  * Computes the principal value of the arc sine of x, expressed in degrees.
14014  * In trigonometrics, arc sine is the inverse operation of sine.
14015  *
14016  * \param x Floating point value in the interval [-1,+1].
14017  * \return Arc sine of x, in the interval [-90,+90] degrees.
14018  *
14019  * \warning This function requires the enhanced NBC/NXC firmware.
14020  */
asind(float x)14021 inline float asind(float x) { asm { asind __FLTRETVAL__, x } }
14022 
14023 /**
14024  * Compute arc tangent (degrees).
14025  * Computes the principal value of the arc tangent of x, expressed in degrees.
14026  * In trigonometrics, arc tangent is the inverse operation of tangent. Notice
14027  * that because of the sign ambiguity, a function cannot determine with
14028  * certainty in which quadrant the angle falls only by its tangent value.
14029  * You can use atan2d if you need to determine the quadrant.
14030  *
14031  * \param x Floating point value.
14032  * \return Arc tangent of x, in the interval [-90,+90] degrees.
14033  *
14034  * \warning This function requires the enhanced NBC/NXC firmware.
14035  */
atand(float x)14036 inline float atand(float x) { asm { atand __FLTRETVAL__, x } }
14037 
14038 /**
14039  * Compute arc tangent with 2 parameters (degrees).
14040  * Computes the principal value of the arc tangent of y/x, expressed in
14041  * degrees. To compute the value, the function uses the sign of both arguments
14042  * to determine the quadrant.
14043  *
14044  * \param y Floating point value representing a y coordinate.
14045  * \param x Floating point value representing an x coordinate.
14046  * \return Arc tangent of y/x, in the interval [-180,+180] degrees.
14047  *
14048  * \warning This function requires the enhanced NBC/NXC firmware.
14049  */
atan2d(float y,float x)14050 inline float atan2d(float y, float x) { asm { atan2d __FLTRETVAL__, y, x } }
14051 
14052 /**
14053  * Compute hyperbolic cosine (degrees).
14054  * Computes the hyperbolic cosine of x, expressed in degrees.
14055  *
14056  * \param x Floating point value.
14057  * \return Hyperbolic cosine of x.
14058  *
14059  * \warning This function requires the enhanced NBC/NXC firmware.
14060  */
coshd(float x)14061 inline float coshd(float x) { asm { coshd __FLTRETVAL__, x } }
14062 
14063 /**
14064  * Compute hyperbolic sine (degrees).
14065  * Computes the hyperbolic sine of x, expressed in degrees.
14066  *
14067  * \param x Floating point value.
14068  * \return Hyperbolic sine of x.
14069  *
14070  * \warning This function requires the enhanced NBC/NXC firmware.
14071  */
sinhd(float x)14072 inline float sinhd(float x) { asm { sinhd __FLTRETVAL__, x } }
14073 
14074 /**
14075  * Compute hyperbolic tangent (degrees).
14076  * Computes the hyperbolic tangent of x, expressed in degrees.
14077  *
14078  * \param x Floating point value.
14079  * \return Hyperbolic tangent of x.
14080  *
14081  * \warning This function requires the enhanced NBC/NXC firmware.
14082  */
tanhd(float x)14083 inline float tanhd(float x) { asm { tanhd __FLTRETVAL__, x } }
14084 
14085 #endif
14086 
14087 #else
14088 
14089 // math functions written by Tamas Sorosy (www.sorosy.com)
14090 
14091 // X is any integer; Y is the sqrt value (0->max); if X<0, Y is the sqrt value of absolute X
14092 #define Sqrt(_X) asm { __SQRT(_X,__RETVAL__) }
14093 
14094 #endif
14095 
14096 #if (__FIRMWARE_VERSION <= 107) || !defined(__ENHANCED_FIRMWARE)
14097 
14098 // X is any integer in degrees; Y is 100* the sin value (-100->100)
14099 #define Sin(_X) asm { __SIN(_X,__RETVAL__) }
14100 
14101 // X is any integer in degrees; Y is 100* the cos value (-100->100)
14102 #define Cos(_X) asm { __COS(_X,__RETVAL__) }
14103 
14104 // X is 100* the sin value (-100->100); Y is -90->90; Y is 101 if X is outside -100->100 range
14105 #define Asin(_X) asm { __ASIN(_X,__RETVAL__) }
14106 
14107 // X is 100* the cos value (-100->100); Y is 0->180; Y is -11 if X is outside -100->100 range
14108 #define Acos(_X) asm { __ACOS(_X,__RETVAL__) }
14109 
14110 #endif
14111 
14112 /**
14113  * Convert from BCD to decimal
14114  * Return the decimal equivalent of the binary coded decimal value provided.
14115  *
14116  * \param bcd The value you want to convert from bcd to decimal.
14117  * \return The decimal equivalent of the binary coded decimal byte.
14118  */
bcd2dec(byte bcd)14119 inline byte bcd2dec(byte bcd) { asm { __bcd2dec(bcd, __URETVAL__) } }
14120 
14121 #ifdef __DOXYGEN_DOCS
14122 
14123 /**
14124  * Is the value NaN.
14125  * Returns true if the floating point value is NaN (not a number).
14126  *
14127  * \param value A floating point variable.
14128  * \return Whether the value is NaN.
14129  */
14130 inline bool isNAN(float value);
14131 
14132 /**
14133  * Sign value.
14134  * Return the sign of the value argument (-1, 0, or 1). Any scalar type can
14135  * be passed into this function.
14136  *
14137  * \param num The numeric value for which to calculate its sign value.
14138  * \return -1 if the parameter is negative, 0 if the parameter is zero, or 1 if
14139  * the parameter is positive.
14140  */
14141 inline char sign(variant num);
14142 
14143 #else
14144 
14145 #define isNAN(_x) ((_x) != (_x))
14146 
14147 #endif
14148 /** @} */ // end of cmathAPI group
14149 
14150 
14151 ///////////////////////////////////////////////////////////////////////////////
14152 ///////////////////////////////// cstdio API //////////////////////////////////
14153 ///////////////////////////////////////////////////////////////////////////////
14154 
14155 
14156 /** @defgroup cstdioAPI cstdio API
14157  * Standard C cstdio API functions.
14158  * @{
14159  */
14160 /**
14161  * Close file.
14162  * Close the file associated with the specified file handle. The loader
14163  * result code is returned as the value of the function call.
14164  *
14165  * \param handle The handle of the file to be closed.
14166  * \return The loader result code.
14167  */
fclose(byte handle)14168 inline int fclose(byte handle) { return CloseFile(handle); }
14169 
14170 /**
14171  * Remove file.
14172  * Delete the specified file. The loader result code is returned as the value
14173  * of the function call.
14174  *
14175  * \param filename The name of the file to be deleted.
14176  * \return The loader result code.
14177  */
remove(string filename)14178 inline int remove(string filename) { return DeleteFile(filename); }
14179 
14180 /**
14181  * Rename file.
14182  * Rename a file from the old filename to the new filename. The loader
14183  * result code is returned as the value of the function call.
14184  *
14185  * \param old The name of the file to be renamed.
14186  * \param new The new name for the file.
14187  * \return The loader result code.
14188  */
rename(string old,string new)14189 inline int rename(string old, string new) { return RenameFile(old, new); }
14190 
14191 /**
14192  * Get character from file.
14193  * Returns the character currently pointed to by the internal file position
14194  * indicator of the file specified by the handle. The internal file position
14195  * indicator is then advanced by one character to point to the next character.
14196  * The functions fgetc and getc are equivalent.
14197  *
14198  * \param handle The handle of the file from which the character is read.
14199  * \return The character read from the file.
14200  */
fgetc(byte handle)14201 inline char fgetc(byte handle) {
14202   char ch;
14203   asm {
14204     __readValue(handle, ch, __RETVAL__)
14205     mov __RETVAL__, ch
14206   }
14207 }
14208 
14209 /**
14210  * Get character from file.
14211  * Returns the character currently pointed to by the internal file position
14212  * indicator of the file specified by the handle. The internal file position
14213  * indicator is then advanced by one character to point to the next character.
14214  * The functions fgetc and getc are equivalent.
14215  *
14216  * \param _handle The handle of the file from which the character is read.
14217  * \return The character read from the file.
14218  */
14219 #define getc(_handle) fgetc(_handle)
14220 
14221 /**
14222  * Get string from file.
14223  * Reads characters from a file and stores them as a string into str until
14224  * (num-1) characters have been read or either a newline or a the End-of-File
14225  * is reached, whichever comes first. A newline character makes fgets stop
14226  * reading, but it is considered a valid character and therefore it is
14227  * included in the string copied to str. A null character is automatically
14228  * appended in str after the characters read to signal the end of the string.
14229  * Returns the string parameter.
14230  *
14231  * \param str The string where the characters are stored.
14232  * \param num The maximum number of characters to be read.
14233  * \param handle The handle of the file from which the characters are read.
14234  * \return The string read from the file.
14235  */
fgets(string & str,int num,byte handle)14236 inline string fgets(string & str, int num, byte handle) {
14237   asm { __readLnStringEx(handle, str, num, __RETVAL__) };
14238   return str;
14239 }
14240 
14241 /**
14242  * Check End-of-file indicator.
14243  * Checks whether the End-of-File indicator associated with the handle is
14244  * set, returning a value different from zero if it is.
14245  *
14246  * \param handle The handle of the file to check.
14247  * \return Currently always returns 0.
14248  */
feof(byte handle)14249 inline int feof(byte handle) { return 0; }
14250 
14251 unsigned long __fopen_default_size = 1024;
14252 
14253 /**
14254  * Set the default fopen file size.
14255  * Set the default size of a file created via a call to fopen.
14256  *
14257  * \param fsize The default new file size for fopen.
14258  */
set_fopen_size(unsigned long fsize)14259 inline void set_fopen_size(unsigned long fsize) { __fopen_default_size = fsize; }
14260 
14261 /**
14262  * Open file.
14263  * Opens the file whose name is specified in the parameter filename and
14264  * associates it with a file handle that can be identified in future
14265  * operations by the handle that is returned. The operations that are allowed
14266  * on the stream and how these are performed are defined by the mode parameter.
14267  *
14268  * \param filename The name of the file to be opened.
14269  * \param mode The file access mode. Valid values are "r" - opens an existing
14270  * file for reading, "w" - creates a new file and opens it for writing, and
14271  * "a" - opens an existing file for appending to the end of the file.
14272  * \return The handle to the opened file.
14273  */
fopen(string filename,const string mode)14274 byte fopen(string filename, const string mode) {
14275   byte handle;
14276   int result = LDR_ILLEGALHANDLE;
14277   unsigned long fsize;
14278   switch(mode) {
14279     case "r" :
14280       result = OpenFileRead(filename, fsize, handle);
14281       break;
14282     case "w" :
14283       fsize  = __fopen_default_size;
14284       result = CreateFile(filename, fsize, handle);
14285       break;
14286     case "a" :
14287       result = OpenFileAppend(filename, fsize, handle);
14288       break;
14289   }
14290   if (result != LDR_SUCCESS)
14291     handle = NULL;
14292   return handle;
14293 }
14294 
14295 /**
14296  * Flush file.
14297  * Writes any buffered data to the file. A zero value indicates success.
14298  *
14299  * \param handle The handle of the file to be flushed.
14300  * \return Currently always returns 0.
14301  */
fflush(byte handle)14302 inline int fflush(byte handle) { return 0; }
14303 
14304 #if defined(__ENHANCED_FIRMWARE) && (__FIRMWARE_VERSION > 107)
14305 /**
14306  * Get current position in file.
14307  * Returns the current value of the file position indicator of the specified
14308  * handle.
14309  *
14310  * \param handle The handle of the file.
14311  * \return The current file position in the open file.
14312  *
14313  * \warning This function requires the enhanced NBC/NXC firmware version 1.31+.
14314  */
ftell(byte handle)14315 inline unsigned long ftell(byte handle) {
14316   FileTellType ftt;
14317   ftt.FileHandle = handle;
14318   SysFileTell(ftt);
14319   return ftt.Position;
14320 }
14321 #endif
14322 
14323 /**
14324  * Write character to file.
14325  * Writes a character to the file and advances the position indicator.
14326  * The character is written at the current position of the file as indicated
14327  * by the internal position indicator, which is then advanced one character.
14328  * If there are no errors, the same character that has been written is
14329  * returned. If an error occurs, EOF is returned.
14330  *
14331  * \param ch The character to be written.
14332  * \param handle The handle of the file where the character is to be written.
14333  * \return The character written to the file.
14334  */
fputc(char ch,byte handle)14335 inline char fputc(char ch, byte handle) {
14336   if (Write(handle, ch) == LDR_SUCCESS)
14337     return ch;
14338   else
14339     return EOF;
14340 }
14341 
14342 /**
14343  * Write character to file.
14344  * Writes a character to the file and advances the position indicator.
14345  * The character is written at the current position of the file as indicated
14346  * by the internal position indicator, which is then advanced one character.
14347  * If there are no errors, the same character that has been written is
14348  * returned. If an error occurs, EOF is returned.
14349  *
14350  * \param _ch The character to be written.
14351  * \param _handle The handle of the file where the character is to be written.
14352  * \return The character written to the file.
14353  */
14354 #define putc(_ch, _handle) fputc(_ch, _handle)
14355 
14356 /**
14357  * Write string to file.
14358  * Writes the string to the file specified by the handle. The null terminating
14359  * character at the end of the string is not written to the file. If there are
14360  * no errors, a non-negative value is returned. If an error occurs, EOF is
14361  * returned.
14362  *
14363  * \param str The string of characters to be written.
14364  * \param handle The handle of the file where the string is to be written.
14365  * \return The number of characters written to the file.
14366  */
fputs(string str,byte handle)14367 inline int fputs(string str, byte handle) {
14368   int cnt;
14369   if (WriteString(handle, str, cnt) == LDR_SUCCESS)
14370     return cnt;
14371   else
14372     return EOF;
14373 }
14374 
14375 #ifdef __ENHANCED_FIRMWARE
14376 
14377 #ifdef __DOXYGEN_DOCS
14378 
14379 /**
14380  * Print formatted data to stdout.
14381  * Writes to the LCD at 0, LCD_LINE1 a sequence of data formatted as the
14382  * format argument specifies. After the format parameter, the function
14383  * expects one value argument.
14384  *
14385  * \param format A string specifying the desired format.
14386  * \param value A value to be formatted for writing to the LCD.
14387  *
14388  * \warning This function requires the enhanced NBC/NXC firmware.
14389  */
14390 inline void printf(string format, variant value);
14391 
14392 /**
14393  * Write formatted data to file.
14394  * Writes a sequence of data formatted as the format argument specifies to a
14395  * file. After the format parameter, the function expects one value
14396  * argument.
14397  *
14398  * \param handle The handle of the file to write to.
14399  * \param format A string specifying the desired format.
14400  * \param value A value to be formatted for writing to the file.
14401  *
14402  * \warning This function requires the enhanced NBC/NXC firmware.
14403  */
14404 inline void fprintf(byte handle, string format, variant value);
14405 
14406 /**
14407  * Write formatted data to string.
14408  * Writes a sequence of data formatted as the format argument specifies to a
14409  * string. After the format parameter, the function expects one value
14410  * argument.
14411  *
14412  * \param str The string to write to.
14413  * \param format A string specifying the desired format.
14414  * \param value A value to be formatted for writing to the string.
14415  *
14416  * \warning This function requires the enhanced NBC/NXC firmware.
14417  */
14418 inline void sprintf(string & str, string format, variant value);
14419 
14420 #else
14421 
14422 #define printf(_format, _value) { \
14423   string msg = FormatNum(_format, _value); \
14424   TextOut(0, LCD_LINE1, msg); \
14425 }
14426 #define fprintf(_handle, _format, _value) { \
14427   int cnt = fputs(FormatNum(_format, _value), _handle); \
14428 }
14429 #define sprintf(_str, _format, _value) { \
14430   _str = FormatNum(_format, _value); \
14431 }
14432 
14433 #endif
14434 
14435 #if __FIRMWARE_VERSION > 107
14436 
14437 /** @defgroup fseekConstants fseek origin constants
14438  * Constants for use in calls to fseek.
14439  * @{
14440  */
14441 #define SEEK_SET 0 /*!< Seek from the beginning of the file */
14442 #define SEEK_CUR 1 /*!< Seek from the current file position */
14443 #define SEEK_END 2 /*!< Seek from the end of the file */
14444 /** @} */ // end of fseekConstants group
14445 
14446 /**
14447  * Reposition file position indicator.
14448  * Sets the position indicator associated with the file to a new position
14449  * defined by adding offset to a reference position specified by origin.
14450  *
14451  * \param handle The handle of the file.
14452  * \param offset The number of bytes to offset from origin.
14453  * \param origin Position from where offset is added. It is specified by one
14454  * of the following constants: SEEK_SET - beginning of file, SEEK_CUR - current
14455  * position of the file pointer, or SEEK_END - end of file. \ref fseekConstants
14456  * \return A value of zero if successful or non-zero otherwise. See \ref LoaderErrors.
14457  *
14458  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
14459  */
fseek(byte handle,long offset,int origin)14460 inline int fseek(byte handle, long offset, int origin) {
14461   FileSeekType fst;
14462   fst.FileHandle = handle;
14463   fst.Origin = origin;
14464   fst.Length = offset;
14465   SysFileSeek(fst);
14466   return fst.Result;
14467 }
14468 
14469 /**
14470  * Set position indicator to the beginning.
14471  * Sets the position indicator associated with stream to the beginning of
14472  * the file.
14473  *
14474  * \param handle The handle of the file.
14475  *
14476  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
14477  */
rewind(byte handle)14478 inline void rewind(byte handle) { fseek(handle, 0, SEEK_SET); }
14479 
14480 /**
14481  * Get character from stdin.
14482  * Returns the next character from the standard input (stdin).
14483  * It is equivalent to getc with stdin as its argument. On the NXT this means
14484  * wait for a button press and return the value of the button pressed.
14485  *
14486  * \return The pressed button. See \ref ButtonNameConstants.
14487  *
14488  */
getchar()14489 inline int getchar() {
14490   int result = -1;
14491   while (true) {
14492     if (ButtonPressed(BTN1, false))
14493       result = BTN1;
14494     else if (ButtonPressed(BTN2, false))
14495       result = BTN2;
14496     else if (ButtonPressed(BTN3, false))
14497       result = BTN3;
14498     else if (ButtonPressed(BTN4, false))
14499       result = BTN4;
14500     if (result != -1)
14501       break;
14502     else
14503       Yield();
14504   }
14505   while(ButtonPressed(result, false));
14506   return result;
14507 }
14508 
14509 
14510 #endif
14511 #endif
14512 
14513 /*
14514   size_t fread(ptr, size, count, FILE*); // read blocks of data from file; returns number of blocks read
14515   size_t fwrite(ptr, size, count, FILE*); // write blocks of data to stream; returns number of blocks written
14516   int putchar(int character); // write character to stdout
14517 */
14518 
14519 
14520 
14521 /** @} */ // end of cstdioAPI group
14522 
14523 
14524 ///////////////////////////////////////////////////////////////////////////////
14525 //////////////////////////////// cstdlib API //////////////////////////////////
14526 ///////////////////////////////////////////////////////////////////////////////
14527 
14528 
14529 /** @defgroup cstdlibAPI cstdlib API
14530  * Standard C cstdlib API functions and types.
14531  * @{
14532  */
14533 
14534 /** @defgroup cstdlibAPITypes cstdlib API types
14535  * Standard C cstdlib API types.
14536  * @{
14537  */
14538 
14539 /**
14540  * Parameters for the RandomNumber system call.
14541  * This structure is used when calling the \ref SysRandomNumber system call
14542  * function.
14543  * \sa SysRandomNumber()
14544  */
14545 struct RandomNumberType {
14546   int Result; /*!< The random number. */
14547 };
14548 
14549 /**
14550  * Output type of the div function.
14551  * div_t structure.
14552  * Structure used to represent the value of an integral division performed
14553  * by div. It has two members of the same type, defined in either order as:
14554  * int quot; int rem;.
14555  * \sa div()
14556  */
14557 struct div_t {
14558   int quot;  /*!< Represents the quotient of the integral division operation
14559                   performed by div, which is the integer of lesser magnitude
14560                   that is nearest to the algebraic quotient. */
14561   int rem;   /*!< Represents the remainder of the integral division operation
14562                   performed by div, which is the integer resulting from
14563                   subtracting quot to the numerator of the operation. */
14564 };
14565 
14566 /**
14567  * Output type of the ldiv function.
14568  * Structure used to represent the value of an integral division performed
14569  * by ldiv. It has two members of the same type, defined in either order as:
14570  * long quot; long rem;.
14571  * \sa ldiv()
14572  */
14573 struct ldiv_t {
14574   long quot;  /*!< Represents the quotient of the integral division operation
14575                   performed by div, which is the integer of lesser magnitude
14576                   that is nearest to the algebraic quotient. */
14577   long rem;   /*!< Represents the remainder of the integral division operation
14578                   performed by div, which is the integer resulting from
14579                   subtracting quot to the numerator of the operation. */
14580 };
14581 
14582 /** @} */ // end of cstdlibAPITypes group
14583 
14584 #ifdef __DOXYGEN_DOCS
14585 
14586 /**
14587  * Abort current process.
14588  * Aborts the process with an abnormal program termination.
14589  * The function never returns to its caller.
14590  */
14591 inline void abort();
14592 
14593 /**
14594  * Absolute value.
14595  * Return the absolute value of the value argument. Any scalar type can
14596  * be passed into this function.
14597  *
14598  * \param num The numeric value.
14599  * \return The absolute value of num. The return type matches the input type.
14600  */
14601 inline variant abs(variant num);
14602 
14603 /**
14604  * Generate random number.
14605  * Returns a pseudo-random integral number in the range 0 to \ref RAND_MAX.
14606  *
14607  * \return An integer value between 0 and RAND_MAX.
14608  */
14609 inline unsigned int rand();
14610 
14611 /**
14612  * Generate random number.
14613  * Return a signed or unsigned 16-bit random number. If the optional argument n
14614  * is not provided the function will return a signed value.  Otherwise the
14615  * returned value will range between 0 and n (exclusive).
14616  *
14617  * \param n The maximum unsigned value desired (optional).
14618  * \return A random number
14619  */
14620 inline int Random(unsigned int n = 0);
14621 
14622 /**
14623  * Draw a random number.
14624  * This function lets you obtain a random number via the \ref RandomNumberType
14625  * structure.
14626  *
14627  * \param args The RandomNumberType structure receiving results.
14628  */
14629 inline void SysRandomNumber(RandomNumberType & args);
14630 
14631 #else
14632 
14633 #define abort() Stop(true)
14634 #define rand() Random(RAND_MAX)
14635 
14636 #define SysRandomNumber(_args) asm { \
14637   compchktype _args, RandomNumberType \
14638   syscall RandomNumber, _args \
14639 }
14640 
14641 #endif
14642 
14643 /**
14644  * Convert string to integer.
14645  * Parses the string str interpreting its content as an integral number,
14646  * which is returned as an int value.
14647  *
14648  * The function first discards as many whitespace characters as necessary
14649  * until the first non-whitespace character is found. Then, starting from
14650  * this character, takes an optional initial plus or minus sign followed by as
14651  * many numerical digits as possible, and interprets them as a numerical value.
14652  *
14653  * The string can contain additional characters after those that form the
14654  * integral number, which are ignored and have no effect on the behavior of
14655  * this function.
14656  *
14657  * If the first sequence of non-whitespace characters in str does not form a
14658  * valid integral number, or if no such sequence exists
14659  * because either str is empty or contains only whitespace characters, no
14660  * conversion is performed.
14661  *
14662  * \param str String beginning with the representation of an integral number.
14663  * \return On success, the function returns the converted integral number
14664  * as an int value. If no valid conversion could be performed a zero value
14665  * is returned.
14666  */
atoi(const string & str)14667 inline int atoi(const string & str) { return StrToNum(str); }
14668 
14669 /**
14670  * Convert string to long integer.
14671  * Parses the string str interpreting its content as an integral number,
14672  * which is returned as a long int value.
14673  *
14674  * The function first discards as many whitespace characters as necessary
14675  * until the first non-whitespace character is found. Then, starting from
14676  * this character, takes an optional initial plus or minus sign followed by as
14677  * many numerical digits as possible, and interprets them as a numerical value.
14678  *
14679  * The string can contain additional characters after those that form the
14680  * integral number, which are ignored and have no effect on the behavior of
14681  * this function.
14682  *
14683  * If the first sequence of non-whitespace characters in str does not form a
14684  * valid integral number, or if no such sequence exists
14685  * because either str is empty or contains only whitespace characters, no
14686  * conversion is performed.
14687  *
14688  * \param str String beginning with the representation of an integral number.
14689  * \return On success, the function returns the converted integral number
14690  * as a long int value. If no valid conversion could be performed a zero value
14691  * is returned.
14692  */
atol(const string & str)14693 inline long atol(const string & str) { return StrToNum(str); }
14694 
14695 /**
14696  * Absolute value.
14697  * Return the absolute value of parameter n.
14698  *
14699  * \param n Integral value.
14700  * \return The absolute value of n.
14701  */
labs(long n)14702 inline long labs(long n) { return abs(n); }
14703 
14704 #if __FIRMWARE_VERSION > 107
14705 /**
14706  * Convert string to float.
14707  * Parses the string str interpreting its content as a floating point number
14708  * and returns its value as a float.
14709  *
14710  * The function first discards as many whitespace characters as necessary until
14711  * the first non-whitespace character is found. Then, starting from this
14712  * character, takes as many characters as possible that are valid following a
14713  * syntax resembling that of floating point literals, and interprets them as a
14714  * numerical value. The rest of the string after the last valid character is
14715  * ignored and has no effect on the behavior of this function.
14716  *
14717  * A valid floating point number for atof is formed by a succession of:
14718  * - An optional plus or minus sign
14719  * - A sequence of digits, optionally containing a decimal-point character
14720  * - An optional exponent part, which itself consists on an 'e' or 'E'
14721  * character followed by an optional sign and a sequence of digits.
14722  *
14723  * If the first sequence of non-whitespace characters in str does not form a
14724  * valid floating-point number as just defined, or if no such sequence exists
14725  * because either str is empty or contains only whitespace characters, no
14726  * conversion is performed.
14727  *
14728  * \param str String beginning with the representation of a floating-point number.
14729  * \return On success, the function returns the converted floating point number
14730  * as a float value. If no valid conversion could be performed a zero value
14731  * (0.0) is returned.
14732  */
atof(const string & str)14733 inline float atof(const string & str) {
14734   float result;
14735   asm { strtonum result, __TMPWORD__, str, NA, NA }
14736   return result;
14737 }
14738 
14739 /**
14740  * Convert string to float.
14741  * Parses the string str interpreting its content as a floating point number
14742  * and returns its value as a float.
14743  *
14744  * The function first discards as many whitespace characters as necessary until
14745  * the first non-whitespace character is found. Then, starting from this
14746  * character, takes as many characters as possible that are valid following a
14747  * syntax resembling that of floating point literals, and interprets them as a
14748  * numerical value. A string containing the rest of the string after the last
14749  * valid character is stored in endptr.
14750  *
14751  * A valid floating point number for atof is formed by a succession of:
14752  * - An optional plus or minus sign
14753  * - A sequence of digits, optionally containing a decimal-point character
14754  * - An optional exponent part, which itself consists on an 'e' or 'E'
14755  * character followed by an optional sign and a sequence of digits.
14756  *
14757  * If the first sequence of non-whitespace characters in str does not form a
14758  * valid floating-point number as just defined, or if no such sequence exists
14759  * because either str is empty or contains only whitespace characters, no
14760  * conversion is performed.
14761  *
14762  * \param str String beginning with the representation of a floating-point number.
14763  * \param endptr Reference to a string, whose value is set by the function to
14764  * the remaining characters in str after the numerical value.
14765  * \return On success, the function returns the converted floating point number
14766  * as a float value. If no valid conversion could be performed a zero value
14767  * (0.0) is returned.
14768  */
strtod(const string & str,string & endptr)14769 inline float strtod(const string & str, string & endptr) {
14770   float result;
14771   int offsetpast;
14772   asm {
14773     strtonum result, offsetpast, str, NA, NA
14774     strsubset endptr, str, offsetpast, NA
14775   }
14776   return result;
14777 }
14778 #endif
14779 
14780 /**
14781  * Convert string to long integer.
14782  * Parses the C string str interpreting its content as an integral number of
14783  * the specified base, which is returned as a long int value.
14784  *
14785  * The function first discards as many whitespace characters as necessary
14786  * until the first non-whitespace character is found. Then, starting from this
14787  * character, takes as many characters as possible that are valid following a
14788  * syntax that depends on the base parameter, and interprets them as a
14789  * numerical value. A string containing the rest of the characters following the
14790  * integer representation in str is stored in endptr.
14791  *
14792  * If the first sequence of non-whitespace characters in str does not form a
14793  * valid integral number, or if no such sequence exists
14794  * because either str is empty or contains only whitespace characters, no
14795  * conversion is performed.
14796  *
14797  * \param str String beginning with the representation of an integral number.
14798  * \param endptr Reference to a string, whose value is set by the function to
14799  * the remaining characters in str after the numerical value.
14800  * \param base Optional and ignored if specified.
14801  * \return On success, the function returns the converted integral number
14802  * as a long int value. If no valid conversion could be performed a zero value
14803  * is returned.
14804  * \warning Only base = 10 is currently supported.
14805  */
14806 inline long strtol(const string & str, string & endptr, int base = 10) {
14807   long result;
14808   int offsetpast;
14809   asm {
14810     strtonum result, offsetpast, str, NA, NA
14811     strsubset endptr, str, offsetpast, NA
14812   }
14813   return result;
14814 }
14815 
14816 /**
14817  * Convert string to unsigned long integer.
14818  * Parses the C string str interpreting its content as an unsigned integral
14819  * number of the specified base, which is returned as an unsigned long int value.
14820  *
14821  * The function first discards as many whitespace characters as necessary
14822  * until the first non-whitespace character is found. Then, starting from this
14823  * character, takes as many characters as possible that are valid following a
14824  * syntax that depends on the base parameter, and interprets them as a
14825  * numerical value. A string containing the rest of the characters following the
14826  * integer representation in str is stored in endptr.
14827  *
14828  * If the first sequence of non-whitespace characters in str does not form a
14829  * valid integral number, or if no such sequence exists
14830  * because either str is empty or contains only whitespace characters, no
14831  * conversion is performed.
14832  *
14833  * \param str String containing the representation of an unsigned integral number.
14834  * \param endptr Reference to a string, whose value is set by the function to
14835  * the remaining characters in str after the numerical value.
14836  * \param base Optional and ignored if specified.
14837  * \return On success, the function returns the converted integral number
14838  * as an unsigned long int value. If no valid conversion could be performed a
14839  * zero value is returned.
14840  * \warning Only base = 10 is currently supported.
14841  */
14842 inline long strtoul(const string & str, string & endptr, int base = 10) {
14843   unsigned long result;
14844   int offsetpast;
14845   asm {
14846     strtonum result, offsetpast, str, NA, NA
14847     strsubset endptr, str, offsetpast, NA
14848   }
14849   return result;
14850 }
14851 
14852 /**
14853  * Integral division.
14854  * Returns the integral quotient and remainder of the division of numerator by
14855  * denominator as a structure of type div_t, which has two members:
14856  * quot and rem.
14857  *
14858  * \param numer Numerator.
14859  * \param denom Denominator.
14860  * \return The result is returned by value in a structure defined in cstdlib,
14861  * which has two members. For div_t, these are, in either order:
14862  * int quot; int rem.
14863  */
div(int numer,int denom)14864 inline div_t div(int numer, int denom) {
14865   div_t result;
14866   result.quot = numer / denom;
14867   result.rem  = numer % denom;
14868   return result;
14869 }
14870 
14871 /**
14872  * Integral division.
14873  * Returns the integral quotient and remainder of the division of numerator by
14874  * denominator as a structure of type ldiv_t, which has two members:
14875  * quot and rem.
14876  *
14877  * \param numer Numerator.
14878  * \param denom Denominator.
14879  * \return The result is returned by value in a structure defined in cstdlib,
14880  * which has two members. For ldiv_t, these are, in either order:
14881  * long quot; long rem.
14882  */
ldiv(long numer,long denom)14883 inline ldiv_t ldiv(long numer, long denom) {
14884   ldiv_t result;
14885   result.quot = numer / denom;
14886   result.rem  = numer % denom;
14887   return result;
14888 }
14889 
14890 /** @} */ // end of cstdlibAPI group
14891 
14892 
14893 ///////////////////////////////////////////////////////////////////////////////
14894 //////////////////////////////// cstring API //////////////////////////////////
14895 ///////////////////////////////////////////////////////////////////////////////
14896 
14897 
14898 /** @defgroup cstringAPI cstring API
14899  * Standard C cstring API functions.
14900  * @{
14901  */
14902 
14903 #ifdef __DOXYGEN_DOCS
14904 
14905 /**
14906  * Convert string to number.
14907  * Return the numeric value specified by the string passed to the function.
14908  * If the content of the string is not a numeric value then this function
14909  * returns zero. The input string parameter
14910  * may be a variable, constant, or expression.
14911  *
14912  * \param str String beginning with the representation of a number.
14913  * \param str A string.
14914  * \return A number.
14915  */
14916 inline variant StrToNum(string str);
14917 
14918 /**
14919  * Get string length.
14920  * Return the length of the specified string. The length of a string does
14921  * not include the null terminator at the end of the string. The input
14922  * string parameter may be a variable, constant, or expression.
14923  *
14924  * \param str A string.
14925  * \return The length of the string.
14926  */
14927 inline unsigned int StrLen(string str);
14928 
14929 /**
14930  * Extract a character from a string.
14931  * Return the numeric value of the character in the specified string at the
14932  * specified index. The input string parameter
14933  * may be a variable, constant, or expression.
14934  *
14935  * \param str A string.
14936  * \param idx The index of the character to retrieve.
14937  * \return The numeric value of the character at the specified index.
14938  */
14939 inline byte StrIndex(string str, unsigned int idx);
14940 
14941 /**
14942  * Convert number to string.
14943  * Return the string representation of the specified numeric value.
14944  *
14945  * \param num A number.
14946  * \return The string representation of the parameter num.
14947  */
14948 inline string NumToStr(variant num);
14949 
14950 /**
14951  * Concatenate strings.
14952  * Return a string which is the result of concatenating all of the
14953  * string arguments together. This function accepts
14954  * any number of parameters which may be string variables, constants,
14955  * or expressions.
14956  *
14957  * \param str1 The first string.
14958  * \param str2 The second string.
14959  * \param strN The Nth string.
14960  * \return The concatenated string.
14961  */
14962 inline string StrCat(string str1, string str2, string strN);
14963 
14964 /**
14965  * Extract a portion of a string.
14966  * Return a sub-string from the specified input string starting at idx and
14967  * including the specified number of characters. The input string parameter
14968  * may be a variable, constant, or expression.
14969  *
14970  * \param str A string.
14971  * \param idx The starting point of the sub-string.
14972  * \param len The length of the sub-string.
14973  * \return The sub-string extracted from parameter str.
14974  */
14975 inline string SubStr(string str, unsigned int idx, unsigned int len);
14976 
14977 /**
14978  * Flatten a number to a string.
14979  * Return a string containing the byte representation of the specified value.
14980  *
14981  * \param num A number.
14982  * \return A string containing the byte representation of the parameter num.
14983  */
14984 inline string Flatten(variant num);
14985 
14986 /**
14987  * Replace a portion of a string.
14988  * Return a string with the part of the string replaced (starting at the
14989  * specified index) with the contents of the new string value provided in
14990  * the third argument. The input string parameters
14991  * may be variables, constants, or expressions.
14992  *
14993  * \param str A string.
14994  * \param idx The starting point for the replace operation.
14995  * \param strnew The replacement string.
14996  * \return The modified string.
14997  */
14998 inline string StrReplace(string str, unsigned int idx, string strnew);
14999 
15000 /**
15001  * Format a number.
15002  * Return the formatted string using the format and value. Use a standard
15003  * numeric sprintf format specifier within the format string. The input string
15004  * parameter may be a variable, constant, or expression.
15005  *
15006  * \param fmt The string format containing a sprintf numeric format specifier.
15007  * \param num A number.
15008  * \return A string containing the formatted numeric value.
15009  *
15010  * \warning This function requires the enhanced NBC/NXC firmware.
15011  */
15012 inline string FormatNum(string fmt, variant num);
15013 
15014 /**
15015  * Flatten any data to a string.
15016  * Return a string containing the byte representation of the specified value.
15017  *
15018  * \sa UnflattenVar
15019  * \param x Any NXC datatype.
15020  * \return A string containing the byte representation of the parameter x.
15021  */
15022 inline string FlattenVar(variant x);
15023 
15024 /**
15025  * Unflatten a string into a data type.
15026  * Convert a string containing the byte representation of the specified
15027  * variable back into the original variable type.
15028  *
15029  * \sa FlattenVar, Flatten
15030  * \param str A string containing flattened data.
15031  * \param x A variable reference where the unflattened data is stored.
15032  * \return A boolean value indicating whether the operation succeeded or not.
15033  */
15034 inline int UnflattenVar(string str, variant & x);
15035 
15036 #else
15037 
15038 #define FlattenVar(_value) asm { flatten __STRRETVAL__, _value }
15039 #define UnflattenVar(_str, _value) asm { \
15040   unflatten _value, __RETVAL__, _str, _value \
15041   not __RETVAL__, __RETVAL__ \
15042 }
15043 
15044 
15045 #endif
15046 
15047 /**
15048  * Find substring position.
15049  * Returns the index value of the first character in a specified substring
15050  * that occurs in a given string.  Pos searches for Substr within S and
15051  * returns an integer value that is the index of the first character of
15052  * Substr within S. Pos is case-sensitive. If Substr is not found, Pos
15053  * returns negative one.
15054  *
15055  * \param Substr A substring to search for in another string.
15056  * \param S A string that might contain the specified substring.
15057  * \return The position of the substring in the specified string or -1 if it is
15058  * not found.
15059  */
Pos(string Substr,string S)15060 inline int Pos(string Substr, string S) { asm { __doPos(Substr, S, __RETVAL__) } }
15061 
15062 /**
15063  * Convert a byte array to a string.
15064  * Convert the specified array to a string by appending a null terminator to
15065  * the end of the array elements. The array must be a one-dimensional array
15066  * of byte.
15067  *
15068  * \sa StrToByteArray, ByteArrayToStrEx
15069  * \param data A byte array.
15070  * \return A string containing data and a null terminator byte.
15071  */
ByteArrayToStr(byte data[])15072 inline string ByteArrayToStr(byte data[]) { asm { arrtostr __STRBUFFER__, data } }
15073 
15074 /**
15075  * Convert a byte array to a string.
15076  * Convert the specified array to a string by appending a null terminator to
15077  * the end of the array elements. The array must be a one-dimensional array
15078  * of byte.
15079  *
15080  * \sa StrToByteArray, ByteArrayToStr
15081  * \param data A byte array.
15082  * \param str A string variable reference which, on output, will contain
15083  * data and a null terminator byte.
15084  */
ByteArrayToStrEx(byte data[],string & str)15085 inline void ByteArrayToStrEx(byte data[], string & str) { asm { arrtostr str, data } }
15086 
15087 /**
15088  * Convert a string to a byte array.
15089  * Convert the specified string to an array of byte by removing the null
15090  * terminator at the end of the string. The output array variable must be a
15091  * one-dimensional array of byte.
15092  *
15093  * \sa ByteArrayToStr, ByteArrayToStrEx
15094  * \param str A string
15095  * \param data A byte array reference which, on output, will contain str
15096  * without its null terminator.
15097  */
StrToByteArray(string str,byte & data[])15098 inline void StrToByteArray(string str, byte & data[]) { asm { strtoarr data, str } }
15099 
15100 /**
15101  * Copy a portion of a string.
15102  * Returns a substring of a string.
15103  *
15104  * \param str A string
15105  * \param idx The starting index of the substring.
15106  * \param len The length of the substring.
15107  * \return The specified substring.
15108  */
Copy(string str,unsigned int idx,unsigned int len)15109 inline string Copy(string str, unsigned int idx, unsigned int len) {
15110   asm { strsubset __STRBUFFER__, str, idx, len  }
15111 }
15112 
15113 /**
15114  * Copy a portion from the middle of a string.
15115  * Returns the substring of a specified length that appears at a specified
15116  * position in a string.
15117  *
15118  * \param str A string
15119  * \param idx The starting index of the substring.
15120  * \param len The length of the substring.
15121  * \return The substring of a specified length that appears at a specified
15122  * position in a string.
15123  */
MidStr(string str,unsigned int idx,unsigned int len)15124 inline string MidStr(string str, unsigned int idx, unsigned int len) {
15125   asm { strsubset __STRBUFFER__, str, idx, len  }
15126 }
15127 
15128 /**
15129  * Copy a portion from the end of a string.
15130  * Returns the substring of a specified length that appears at the end of a string.
15131  *
15132  * \param str A string
15133  * \param size The size or length of the substring.
15134  * \return The substring of a specified length that appears at the end of a string.
15135  */
RightStr(string str,unsigned int size)15136 inline string RightStr(string str, unsigned int size) {
15137   unsigned int idx;
15138   asm {
15139     strlen idx, str
15140     sub idx, idx, size
15141     strsubset __STRBUFFER__, str, idx, size
15142   }
15143 }
15144 
15145 /**
15146  * Copy a portion from the start of a string.
15147  * Returns the substring of a specified length that appears at the start of a string.
15148  *
15149  * \param str A string
15150  * \param size The size or length of the substring.
15151  * \return The substring of a specified length that appears at the start of a string.
15152  */
LeftStr(string str,unsigned int size)15153 inline string LeftStr(string str, unsigned int size) {
15154   asm { strsubset __STRBUFFER__, str, 0, size  }
15155 }
15156 
15157 // cstring functions
15158 
15159 /**
15160  * Get string length.
15161  * Return the length of the specified string. The length of a string does
15162  * not include the null terminator at the end of the string.
15163  *
15164  * \param str A string.
15165  * \return The length of the string.
15166  */
strlen(const string & str)15167 inline int strlen(const string & str) { asm { strlen __RETVAL__, str } }
15168 
15169 /**
15170  * Concatenate strings.
15171  * Appends a copy of the source string to the destination string. The
15172  * terminating null character in destination is overwritten by the first
15173  * character of source, and a new null-character is appended at the end of
15174  * the new string formed by the concatenation of both in destination. The
15175  * destination string is returned.
15176  *
15177  * \param dest The destination string.
15178  * \param src The string to be appended.
15179  * \return The destination string.
15180  */
strcat(string & dest,const string & src)15181 inline string strcat(string & dest, const string & src) {
15182   asm {
15183     strcat __STRBUFFER__, dest, src
15184     mov dest, __STRBUFFER__
15185   }
15186 }
15187 
15188 /**
15189  * Append characters from string.
15190  * Appends the first num characters of source to destination, plus a
15191  * terminating null-character. If the length of the string in source is less
15192  * than num, only the content up to the terminating null-character is copied.
15193  * The destination string is returned.
15194  *
15195  * \param dest The destination string.
15196  * \param src The string to be appended.
15197  * \param num The maximum number of characters to be appended.
15198  * \return The destination string.
15199  */
strncat(string & dest,const string & src,unsigned int num)15200 inline string strncat(string & dest, const string & src, unsigned int num) {
15201   asm {
15202     strsubset __STRRETVAL__, src, 0, num
15203     strcat __STRBUFFER__, dest, __STRRETVAL__
15204     mov dest, __STRBUFFER__
15205   }
15206 }
15207 
15208 /**
15209  * Copy string.
15210  * Copies the string pointed by source into the array pointed by destination,
15211  * including the terminating null character. The destination string is returned.
15212  *
15213  * \param dest The destination string.
15214  * \param src The string to be appended.
15215  * \return The destination string.
15216  */
strcpy(string & dest,const string & src)15217 inline string strcpy(string & dest, const string & src) {
15218   asm {
15219     mov __STRBUFFER__, src
15220     mov dest, __STRBUFFER__
15221   }
15222 }
15223 
15224 /**
15225  * Copy characters from string.
15226  * Copies the first num characters of source to destination. The destination
15227  * string is returned.
15228  *
15229  * \param dest The destination string.
15230  * \param src The string to be appended.
15231  * \param num The maximum number of characters to be appended.
15232  * \return The destination string.
15233  */
strncpy(string & dest,const string & src,unsigned int num)15234 inline string strncpy(string & dest, const string & src, unsigned int num) {
15235   asm {
15236     strsubset dest, src, 0, num
15237     mov __STRBUFFER__, dest
15238   }
15239 }
15240 
15241 /**
15242  * Compare two strings.
15243  * Compares the string str1 to the string str2.
15244  *
15245  * \param str1 A string to be compared.
15246  * \param str2 A string to be compared.
15247  * \return Returns an integral value indicating the relationship between the
15248  * strings. A zero value indicates that both strings are equal. A value
15249  * greater than zero indicates that the first character that does not match
15250  * has a greater value in str1 than in str2. A value less than zero indicates
15251  * the opposite.
15252  */
strcmp(const string & str1,const string & str2)15253 inline int strcmp(const string & str1, const string & str2) {
15254   int result = -1;
15255   if (str1 == str2)
15256     result = 0;
15257   else if (str1 > str2)
15258     result = 1;
15259   return result;
15260 }
15261 
15262 /**
15263  * Compare characters of two strings.
15264  * Compares up to num characters of the string str1 to those of the string str2.
15265  *
15266  * \param str1 A string to be compared.
15267  * \param str2 A string to be compared.
15268  * \param num The maximum number of characters to be compared.
15269  * \return Returns an integral value indicating the relationship between the
15270  * strings. A zero value indicates that the characters compared in both
15271  * strings are all equal. A value greater than zero indicates that the first
15272  * character that does not match has a greater value in str1 than in str2. A
15273  * value less than zero indicates the opposite.
15274  */
strncmp(const string & str1,const string & str2,unsigned int num)15275 inline int strncmp(const string & str1, const string & str2, unsigned int num) {
15276   string sub1, sub2;
15277   asm {
15278     strsubset sub1, str1, 0, num
15279     strsubset sub2, str2, 0, num
15280   }
15281   int result = -1;
15282   if (sub1 == sub2)
15283     result = 0;
15284   else if (sub1 > sub2)
15285     result = 1;
15286   return result;
15287 }
15288 
15289 #ifdef __DOXYGEN_DOCS
15290 
15291 /**
15292  * Copy memory.
15293  * Copies memory contents from the source to the destination. The num
15294  * argument is ignored.
15295  *
15296  * \param dest The destination variable.
15297  * \param src The source variable.
15298  * \param num The number of bytes to copy (ignored).
15299  */
15300 inline void memcpy(variant dest, variant src, byte num);
15301 
15302 /**
15303  * Move memory.
15304  * Moves memory contents from the source to the destination. The num
15305  * argument is ignored.
15306  *
15307  * \param dest The destination variable.
15308  * \param src The source variable.
15309  * \param num The number of bytes to copy (ignored).
15310  */
15311 inline void memmove(variant dest, variant src, byte num);
15312 
15313 /**
15314  * Compare two blocks of memory.
15315  * Compares the variant ptr1 to the variant ptr2. Returns an integral value
15316  * indicating the relationship between the variables. The num argument is
15317  * ignored.
15318  *
15319  * \param ptr1 A variable to be compared.
15320  * \param ptr2 A variable to be compared.
15321  * \param num The number of bytes to compare (ignored).
15322  */
15323 inline char memcmp(variant ptr1, variant ptr2, byte num);
15324 
15325 /**
15326  * Get the absolute address of a variable.
15327  * Get the absolute address of a variable and return it to the calling routine
15328  * as an unsigned long value.
15329  *
15330  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
15331  *
15332  * \param data A variable whose address you wish to get.
15333  * \return The absolute address of the variable.
15334  */
15335 inline unsigned long addressOf(variant data);
15336 
15337 /**
15338  * Get the relative address of a variable.
15339  * Get the relative address of a variable and return it to the calling routine
15340  * as an unsigned long value.  The relative address is an offset from the
15341  * Command module's MemoryPool address.
15342  *
15343  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
15344  *
15345  * \param data A variable whose address you wish to get.
15346  * \return The relative address of the variable.
15347  */
15348 inline unsigned long reladdressOf(variant data);
15349 
15350 /**
15351  * Get the absolute or relative address of a variable.
15352  * Get the absolute or relative address of a variable and return it to the
15353  * calling routine as an unsigned long value. The relative address is an
15354  * offset from the Command module's MemoryPool address.
15355  *
15356  * \warning This function requires the enhanced NBC/NXC firmware version 1.28+.
15357  *
15358  * \param data A variable whose address you wish to get.
15359  * \param relative A boolean flag indicating whether you want to get the
15360  * relative or absolute address.
15361  * \return The absolute or relative address of the variable.
15362  */
15363 inline unsigned long addressOfEx(variant data, bool relative);
15364 
15365 #else
15366 
15367 #define memcpy(_dest, _src, _num) asm { mov _dest, _src }
15368 #define memmove(_dest, _src, _num) asm { mov _dest, _src }
15369 #define memcmp(_ptr1, _ptr2, _num) ( (_ptr1 == _ptr2) ? 0 : ( (_ptr1 > _ptr2) ? 1 : -1 ) )
15370 
15371 #define addressOf(_data) asm { addrof __URETVAL__, _data, 0 }
15372 #define reladdressOf(_data) asm { addrof __URETVAL__, _data, 1 }
15373 #define addressOfEx(_data, _rel) asm { addrof __URETVAL__, _data, _rel }
15374 
15375 #endif
15376 
15377 /*
15378 void * memchr (void * ptr, int value, size_t num ); // Locate character in block of memory
15379 char * strchr (       char * str, int character ); // Locate first occurrence of character in string
15380 size_t strcspn ( const char * str1, const char * str2 ); // Get span until character in string
15381 char * strpbrk ( const char *, const char * ); // Locate character in string
15382 char * strrchr ( const char *, int ); // Locate last occurrence of character in string
15383 size_t strspn ( const char * str1, const char * str2 ); // Get span of character set in string
15384 char * strtok ( char * str, const char * delimiters ); // Split string into tokens
15385 char * strstr ( const char *, const char * ); // Locate substring
15386 
15387 void * memset ( void * ptr, byte value, size_t num ); // Fill block of memory (something like replace)
15388 */
15389 
15390 
15391 
15392 /** @} */ // end of cstringAPI group
15393 
15394 
15395 ///////////////////////////////////////////////////////////////////////////////
15396 ///////////////////////////////// ctype API ///////////////////////////////////
15397 ///////////////////////////////////////////////////////////////////////////////
15398 
15399 
15400 /** @defgroup ctypeAPI ctype API
15401  * Standard C ctype API functions.
15402  * @{
15403  */
15404 /**
15405  * Check if character is uppercase letter.
15406  * Checks if parameter c is an uppercase alphabetic letter.
15407  *
15408  * \param c Character to be checked.
15409  * \return Returns a non-zero value (true) if c is an uppercase alphabetic
15410  * letter, otherwise it returns 0 (false).
15411  */
isupper(int c)15412 inline int isupper(int c) { return ((c >= 'A') && (c <= 'Z')); }
15413 
15414 /**
15415  * Check if character is lowercase letter.
15416  * Checks if parameter c is an lowercase alphabetic letter.
15417  *
15418  * \param c Character to be checked.
15419  * \return Returns a non-zero value (true) if c is an lowercase alphabetic
15420  * letter, otherwise it returns 0 (false).
15421  */
islower(int c)15422 inline int islower(int c) { return ((c >= 'a') && (c <= 'z')); }
15423 
15424 /**
15425  * Check if character is alphabetic.
15426  * Checks if parameter c is either an uppercase or lowercase letter.
15427  *
15428  * \param c Character to be checked.
15429  * \return Returns a non-zero value (true) if c is an alphabetic letter,
15430  * otherwise it returns 0 (false).
15431  */
isalpha(int c)15432 inline int isalpha(int c) { return isupper(c) || islower(c); }
15433 
15434 /**
15435  * Check if character is decimal digit.
15436  * Checks if parameter c is a decimal digit character.
15437  *
15438  * \param c Character to be checked.
15439  * \return Returns a non-zero value (true) if c is a decimal digit, otherwise
15440  * it returns 0 (false).
15441  */
isdigit(int c)15442 inline int isdigit(int c) { return ((c >= '0') && (c <= '9')); }
15443 
15444 /**
15445  * Check if character is alphanumeric.
15446  * Checks if parameter c is either a decimal digit or an uppercase or
15447  * lowercase letter. The result is true if either isalpha or isdigit would
15448  * also return true.
15449  *
15450  * \param c Character to be checked.
15451  * \return Returns a non-zero value (true) if c is either a digit or a
15452  * letter, otherwise it returns 0 (false).
15453  */
isalnum(int c)15454 inline int isalnum(int c) { return isalpha(c) || isdigit(c); }
15455 
15456 /**
15457  * Check if character is a white-space.
15458  * Checks if parameter c is a white-space character.
15459  *
15460  * \param c Character to be checked.
15461  * \return Returns a non-zero value (true) if c is a white-space character,
15462  * otherwise it returns 0 (false).
15463  */
isspace(int c)15464 inline int isspace(int c) { return (c == 0x20) || ((c >= 0x09) && (c <= 0x0d)); }
15465 
15466 /**
15467  * Check if character is a control character.
15468  * Checks if parameter c is a control character.
15469  *
15470  * \param c Character to be checked.
15471  * \return Returns a non-zero value (true) if c is a control character,
15472  * otherwise it returns 0 (false).
15473  */
iscntrl(int c)15474 inline int iscntrl(int c) { return (c <= 0x1f) || (c == 0x7f); }
15475 
15476 /**
15477  * Check if character is printable.
15478  * Checks if parameter c is a printable character (i.e., not a control
15479  * character).
15480  *
15481  * \param c Character to be checked.
15482  * \return Returns a non-zero value (true) if c is a printable character,
15483  * otherwise it returns 0 (false).
15484  */
isprint(int c)15485 inline int isprint(int c) { return !iscntrl(c); }
15486 
15487 /**
15488  * Check if character has graphical representation.
15489  * Checks if parameter c is a character with a graphical representation.
15490  *
15491  * \param c Character to be checked.
15492  * \return Returns a non-zero value (true) if c has a graphical representation,
15493  * otherwise it returns 0 (false).
15494  */
isgraph(int c)15495 inline int isgraph(int c) { return (c != 0x20) && isprint(c); }
15496 
15497 /**
15498  * Check if character is a punctuation.
15499  * Checks if parameter c is a punctuation character.
15500  *
15501  * \param c Character to be checked.
15502  * \return Returns a non-zero value (true) if c is a punctuation character,
15503  * otherwise it returns 0 (false).
15504  */
ispunct(int c)15505 inline int ispunct(int c) { return isgraph(c) && !isalnum(c); }
15506 
15507 /**
15508  * Check if character is hexadecimal digit.
15509  * Checks if parameter c is a hexadecimal digit character.
15510  *
15511  * \param c Character to be checked.
15512  * \return Returns a non-zero value (true) if c is a hexadecimal digit
15513  * character, otherwise it returns 0 (false).
15514  */
isxdigit(int c)15515 inline int isxdigit(int c) {  return isdigit(c) || ((c >= 'A') && (c <= 'F')) || ((c >= 'a') && (c <= 'f')); }
15516 
15517 /**
15518  * Convert lowercase letter to uppercase.
15519  * Converts parameter c to its uppercase equivalent if c is a lowercase
15520  * letter and has an uppercase equivalent. If no such conversion is possible,
15521  * the value returned is c unchanged.
15522  *
15523  * \param c Lowercase letter character to be converted.
15524  * \return The uppercase equivalent to c, if such value exists, or c
15525  * (unchanged) otherwise..
15526  */
toupper(int c)15527 inline int toupper(int c) { if (islower(c)) c -= 32; return c; }
15528 
15529 /**
15530  * Convert uppercase letter to lowercase.
15531  * Converts parameter c to its lowercase equivalent if c is an uppercase
15532  * letter and has a lowercase equivalent. If no such conversion is possible,
15533  * the value returned is c unchanged.
15534  *
15535  * \param c Uppercase letter character to be converted.
15536  * \return The lowercase equivalent to c, if such value exists, or c
15537  * (unchanged) otherwise..
15538  */
tolower(int c)15539 inline int tolower(int c) { if (isupper(c)) c += 32; return c; }
15540 
15541 
15542 /** @} */ // end of ctypeAPI group
15543 
15544 /** @} */ // end of StandardCAPIFunctions group
15545 
15546 
15547 /** @addtogroup RICMacros
15548  * @{
15549  */
15550 /**
15551  * Set the value of an element in an RIC data array.
15552  * \param _data The RIC data array
15553  * \param _idx The array index to update
15554  * \param _newval The new value to write into the RIC data array
15555  */
15556 #define RICSetValue(_data, _idx, _newval) _data[(_idx)] = (_newval)&0xFF; _data[(_idx)+1] = (_newval)>>8
15557 /** @} */ // end of RICMacros group
15558 
15559 /** @addtogroup GraphicsLibrary
15560  * @{
15561  */
15562 //------------------------------------------------------------------------------
15563 // File          : nbcGL.nbc
15564 // Description   : Data and subroutines for a very simple 3D engine.
15565 // Programmed by : Arno van der Vegt, legoasimo@gmail.com
15566 //------------------------------------------------------------------------------
15567 
15568 /**
15569  * Initialize graphics library.
15570  * Setup all the necessary data for the graphics library to function. Call this
15571  * function before any other graphics library routine.
15572  */
glInit()15573 inline void glInit() { asm { __glInit() } }
15574 
15575 /**
15576  * Set graphics library options.
15577  * Adjust graphic library settings for circle size and cull mode.
15578  *
15579  * \param glType The setting type.  See \ref GLConstantsSettings.
15580  * \param glValue The setting value. For culling modes see \ref GLConstantsCullMode.
15581  */
glSet(int glType,int glValue)15582 inline void glSet(int glType, int glValue) { asm { __glSet(glType, glValue) } }
15583 
15584 /**
15585  * Begin defining an object.
15586  * Start the process of defining a graphics library object using low level
15587  * functions such as \ref glBegin, \ref glAddVertex, and \ref glEnd.
15588  *
15589  * \return The object index of the new object being created.
15590  */
glBeginObject()15591 inline int glBeginObject() { asm { __glBeginObject(__RETVAL__) } }
15592 
15593 /**
15594  * Stop defining an object.
15595  * Finish the process of defining a graphics library object.  Call this function
15596  * after you have completed the object definition.
15597  */
glEndObject()15598 inline void glEndObject() { asm { __glEndObject() } }
15599 
15600 /**
15601  * Perform an object action.
15602  * Execute the specified action on the specified object.
15603  *
15604  * \param glObjectId The object id.
15605  * \param glAction The action to perform on the object. See \ref GLConstantsActions.
15606  * \param glValue The setting value.
15607  */
glObjectAction(int glObjectId,int glAction,int glValue)15608 inline void glObjectAction(int glObjectId, int glAction, int glValue) {
15609   asm { __glObjectAction(glObjectId, glAction, glValue) }
15610 }
15611 
15612 /**
15613  * Add a vertex to an object.
15614  * Add a vertex to an object currently being defined.  This function should
15615  * only be used between \ref glBegin and \ref glEnd which are themselves
15616  * nested within a \ref glBeginObject and \ref glEndObject pair.
15617  *
15618  * \param glX The X axis coordinate.
15619  * \param glY The Y axis coordinate.
15620  * \param glZ The Z axis coordinate.
15621  */
glAddVertex(int glX,int glY,int glZ)15622 inline void glAddVertex(int glX, int glY, int glZ) {
15623   asm { __glAddVertex(glX, glY, glZ) }
15624 }
15625 
15626 /**
15627  * Begin a new polygon for the current object.
15628  * Start defining a polygon surface for the current graphics object using
15629  * the specified begin mode.
15630  *
15631  * \param glBeginMode The desired mode.  See \ref GLConstantsBeginModes.
15632  */
glBegin(int glBeginMode)15633 inline void glBegin(int glBeginMode) { asm { __glBegin(glBeginMode) } }
15634 
15635 /**
15636  * Finish a polygon for the current object.
15637  * Stop defining a polgyon surface for the current graphics object.
15638  */
glEnd()15639 inline void glEnd() { asm { __glEnd() } }
15640 
15641 /**
15642  * Begin a new render.
15643  * Start the process of rendering the existing graphic objects.
15644  */
glBeginRender()15645 inline void glBeginRender() { asm { __glBeginRender() } }
15646 
15647 /**
15648  * Call a graphic object.
15649  * Tell the graphics library that you want it to include the specified
15650  * object in the render.
15651  *
15652  * \param glObjectId The desired object id.
15653  */
glCallObject(int glObjectId)15654 inline void glCallObject(int glObjectId) { asm { __glCallObject(glObjectId) } }
15655 
15656 /**
15657  * Finish the current render.
15658  * Rotate the vertex list, clear the screen, and draw the rendered objects
15659  * to the LCD.
15660  */
glFinishRender()15661 inline void glFinishRender() { asm { __glFinishRender() } }
15662 
15663 /**
15664  * Set the X axis angle.
15665  * Set the X axis angle to the specified value.
15666  *
15667  * \param glValue The new X axis angle.
15668  */
glSetAngleX(int glValue)15669 inline void glSetAngleX(int glValue) { asm { __glSetAngleX(glValue) } }
15670 
15671 /**
15672  * Add to the X axis angle.
15673  * Add the specified value to the existing X axis angle.
15674  *
15675  * \param glValue The value to add to the X axis angle.
15676  */
glAddToAngleX(int glValue)15677 inline void glAddToAngleX(int glValue) { asm { __glAddToAngleX(glValue) } }
15678 
15679 /**
15680  * Set the Y axis angle.
15681  * Set the Y axis angle to the specified value.
15682  *
15683  * \param glValue The new Y axis angle.
15684  */
glSetAngleY(int glValue)15685 inline void glSetAngleY(int glValue) { asm { __glSetAngleY(glValue) } }
15686 
15687 /**
15688  * Add to the Y axis angle.
15689  * Add the specified value to the existing Y axis angle.
15690  *
15691  * \param glValue The value to add to the Y axis angle.
15692  */
glAddToAngleY(int glValue)15693 inline void glAddToAngleY(int glValue) { asm { __glAddToAngleY(glValue) } }
15694 
15695 /**
15696  * Set the Z axis angle.
15697  * Set the Z axis angle to the specified value.
15698  *
15699  * \param glValue The new Z axis angle.
15700  */
glSetAngleZ(int glValue)15701 inline void glSetAngleZ(int glValue) { asm { __glSetAngleZ(glValue) } }
15702 
15703 /**
15704  * Add to the Z axis angle.
15705  * Add the specified value to the existing Z axis angle.
15706  *
15707  * \param glValue The value to add to the Z axis angle.
15708  */
glAddToAngleZ(int glValue)15709 inline void glAddToAngleZ(int glValue) { asm { __glAddToAngleZ(glValue) } }
15710 
15711 /**
15712  * Table-based sine scaled by 32768.
15713  * Return the sine of the specified angle in degrees.  The result is scaled
15714  * by 32768.
15715  *
15716  * \param glAngle The angle in degrees.
15717  * \return The sine value scaled by 32768.
15718  */
glSin32768(int glAngle)15719 inline int glSin32768(int glAngle) { asm { __glSin32768(__RETVAL__, glAngle) } }
15720 
15721 /**
15722  * Table-based cosine scaled by 32768.
15723  * Return the cosine of the specified angle in degrees.  The result is scaled
15724  * by 32768.
15725  *
15726  * \param glAngle The angle in degrees.
15727  * \return The cosine value scaled by 32768.
15728  */
glCos32768(int glAngle)15729 inline int glCos32768(int glAngle) { asm { __glCos32768(__RETVAL__, glAngle) } }
15730 
15731 /**
15732  * Create a 3D box.
15733  * Define a 3D box using the specified begin mode for all faces. The center
15734  * of the box is at the origin of the XYZ axis with width, height, and depth
15735  * specified via the glSizeX, glSizeY, and glSizeZ parameters.
15736  *
15737  * \param glMode The begin mode for each surface.  See \ref GLConstantsBeginModes.
15738  * \param glSizeX The X axis size (width).
15739  * \param glSizeY The Y axis size (height).
15740  * \param glSizeZ The Z axis size (depth).
15741  */
glBox(int glMode,int glSizeX,int glSizeY,int glSizeZ)15742 inline int glBox(int glMode, int glSizeX, int glSizeY, int glSizeZ) {
15743   asm { __glBox(glMode, glSizeX, glSizeY, glSizeZ, __RETVAL__) }
15744 }
15745 
15746 /**
15747  * Create a 3D cube.
15748  * Define a 3D cube using the specified begin mode for all faces. The center
15749  * of the box is at the origin of the XYZ axis with equal width, height, and depth
15750  * specified via the glSize parameter.
15751  *
15752  * \param glMode The begin mode for each surface.  See \ref GLConstantsBeginModes.
15753  * \param glSize The cube's width, height, and depth.
15754  */
glCube(int glMode,int glSize)15755 inline int glCube(int glMode, int glSize) {
15756   asm { __glBox(glMode, glSize, glSize, glSize, __RETVAL__) }
15757 }
15758 
15759 /**
15760  * Create a 3D pyramid.
15761  * Define a 3D pyramid using the specified begin mode for all faces. The center
15762  * of the pyramid is at the origin of the XYZ axis with width, height, and depth
15763  * specified via the glSizeX, glSizeY, and glSizeZ parameters.
15764  *
15765  * \param glMode The begin mode for each surface.  See \ref GLConstantsBeginModes.
15766  * \param glSizeX The X axis size (width).
15767  * \param glSizeY The Y axis size (height).
15768  * \param glSizeZ The Z axis size (depth).
15769  */
glPyramid(int glMode,int glSizeX,int glSizeY,int glSizeZ)15770 inline int glPyramid(int glMode, int glSizeX, int glSizeY, int glSizeZ) {
15771   asm { __glPyramid(glMode, glSizeX, glSizeY, glSizeZ, __RETVAL__) }
15772 }
15773 
15774 /** @} */ // end of GraphicsLibrary group
15775 
15776 #if defined(__ENHANCED_FIRMWARE) && (__FIRMWARE_VERSION > 107)
15777 /** @addtogroup NXTFirmwareModules
15778  * @{
15779  */
15780 /** @addtogroup OutputModule
15781  * @{
15782  */
15783 /** @addtogroup OutputModuleFunctions
15784  * @{
15785  */
15786 
15787 /**
15788  * Enable absolute position regulation with PID factors.
15789  * Enable absolute position regulation on the specified output.  Motor is kept
15790  * regulated as long as this is enabled.
15791  * Optionally specify proportional, integral, and derivative factors.
15792  *
15793  * \param output Desired output port. Can be a constant or a variable, see
15794  * \ref OutputPortConstants.
15795  * \param p Proportional factor used by the firmware's PID motor control
15796  * algorithm. See \ref PIDConstants. Default value is \ref PID_3.
15797  * \param i Integral factor used by the firmware's PID motor control
15798  * algorithm. See \ref PIDConstants. Default value is \ref PID_1.
15799  * \param d Derivative factor used by the firmware's PID motor control
15800  * algorithm. See \ref PIDConstants. Default value is \ref PID_1.
15801  */
15802 inline void PosRegEnable(byte output, byte p = PID_3, byte i = PID_1, byte d = PID_1)
15803 {
15804     SetOutput(output,
15805 	       OutputModeField, OUT_MODE_MOTORON+OUT_MODE_BRAKE+OUT_MODE_REGULATED,
15806 	       RegModeField, OUT_REGMODE_POS,
15807 	       RunStateField, OUT_RUNSTATE_RUNNING,
15808 	       PowerField, 0,
15809 	       TurnRatioField, 0,
15810 	       RegPValueField, p, RegIValueField, i, RegDValueField, d,
15811 	       UpdateFlagsField, UF_UPDATE_MODE+UF_UPDATE_SPEED+UF_UPDATE_PID_VALUES+UF_UPDATE_RESET_COUNT);
15812     Wait(MS_2);
15813 }
15814 
15815 /**
15816  * Change the current value for set angle.
15817  * Make the absolute position regulation going toward the new provided angle.
15818  * Returns immediately, but keep regulating.
15819  *
15820  * \param output Desired output port. Can be a constant or a variable, see
15821  * \ref OutputPortConstants.
15822  * \param angle New set position, in degree. The 0 angle corresponds to the
15823  * position of the motor when absolute position regulation was first enabled.
15824  * Can be negative. Can be greater than 360 degree to make several turns.
15825  */
PosRegSetAngle(byte output,long angle)15826 inline void PosRegSetAngle(byte output, long angle)
15827 {
15828     SetOutput(output,
15829 	       TachoLimitField, angle,
15830 	       UpdateFlagsField, UF_UPDATE_TACHO_LIMIT);
15831 }
15832 
15833 /**
15834  * Add to the current value for set angle.
15835  * Add an offset to the current set position. Returns immediately, but keep
15836  * regulating.
15837  *
15838  * \param output Desired output port. Can be a constant or a variable, see
15839  * \ref OutputPortConstants.
15840  * \param angle_add Value to add to the current set position, in degree. Can
15841  * be negative. Can be greater than 360 degree to make several turns.
15842  */
PosRegAddAngle(byte output,long angle_add)15843 inline void PosRegAddAngle(byte output, long angle_add)
15844 {
15845     long current_angle = GetOutput(output, TachoLimitField);
15846     SetOutput(output,
15847 	       TachoLimitField, current_angle + angle_add,
15848 	       UpdateFlagsField, UF_UPDATE_TACHO_LIMIT);
15849 }
15850 
15851 /**
15852  * Set maximum limits.
15853  * Set maximum speed and acceleration.
15854  *
15855  * \param output Desired output port. Can be a constant or a variable, see
15856  * \ref OutputPortConstants.
15857  * \param max_speed Maximum speed, or 0 to disable speed limiting.
15858  * \param max_acceleration Maximum acceleration, or 0 to disable acceleration
15859  * limiting. The max_speed parameter should not be 0 if this is not 0.
15860  */
PosRegSetMax(byte output,byte max_speed,byte max_acceleration)15861 inline void PosRegSetMax(byte output, byte max_speed, byte max_acceleration)
15862 {
15863     SetOutput(output,
15864 	       MaxSpeedField, max_speed,
15865 	       MaxAccelerationField, max_acceleration,
15866 	       UpdateFlagsField, UF_UPDATE_PID_VALUES);
15867     Wait(MS_2);
15868 }
15869 
15870 /** @} */ // end of OutputModuleFunctions group
15871 /** @} */ // end of OutputModule group
15872 /** @} */ // end of NXTFirmwareModules group
15873 #endif
15874 
15875 #endif // NXCDEFS_H
15876