Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __LEGOUS_H__
00013 #define __LEGOUS_H__
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #pragma systemFile
00033
00034 #ifndef __COMMON_H__
00035 #include "common.h"
00036 #endif
00037
00038 #define LEGOUS_I2C_ADDR 0x10
00039 #define LEGOUS_REG_CMD 0x41
00040 #define LEGOUS_REG_DATA 0x42
00041
00042 #define LEGOUS_CMD_OFF 0x00
00043 #define LEGOUS_CMD_SSHOT 0x01
00044 #define LEGOUS_CMD_CONT 0x02
00045 #define LEGOUS_CMD_ECAPT 0x03
00046 #define LEGOUS_CMD_RST 0x04
00047
00048
00049 int USreadDist(tSensors link);
00050 bool USreadDistances(tSensors link, tByteArray &distances);
00051 bool _USsendCmd(tSensors link, ubyte command);
00052 bool USsetSingleMode(tSensors link);
00053 bool USsetContinuousMode(tSensors link);
00054 bool USsetOff(tSensors link);
00055 bool USsetEventCapture(tSensors link);
00056 bool USreset(tSensors link);
00057
00058 #ifdef __HTSMUX_SUPPORT__
00059 int USreadDist(tMUXSensor muxsensor);
00060
00061 tConfigParams LEGOUS_config = {HTSMUX_CHAN_I2C + HTSMUX_CHAN_9V + HTSMUX_CHAN_I2C_SLOW, 1, 0x02, 0x42};
00062 #endif // __HTSMUX_SUPPORT__
00063
00064 tByteArray LEGOUS_I2CRequest;
00065 tByteArray LEGOUS_I2CReply;
00066
00067
00068
00069
00070
00071
00072 #ifdef __HTSMUX_SUPPORT__
00073 int USreadDist(tMUXSensor muxsensor) {
00074
00075 if (HTSMUXSensorTypes[muxsensor] != HTSMUXSensorCustom)
00076 HTSMUXconfigChannel(muxsensor, LEGOUS_config);
00077
00078
00079 if (!HTSMUXreadPort(muxsensor, LEGOUS_I2CReply, 1, 0)) {
00080 return 255;
00081 }
00082
00083 return (int)LEGOUS_I2CReply[0];
00084 }
00085 #endif
00086
00087
00088
00089
00090
00091
00092
00093 int USreadDist(tSensors link) {
00094 memset(LEGOUS_I2CRequest, 0, sizeof(tByteArray));
00095
00096 LEGOUS_I2CRequest[0] = 2;
00097 LEGOUS_I2CRequest[1] = LEGOUS_I2C_ADDR;
00098 LEGOUS_I2CRequest[2] = LEGOUS_REG_DATA;
00099
00100 if (!writeI2C(link, LEGOUS_I2CRequest, 1))
00101 return -1;
00102
00103 if (!readI2C(link, LEGOUS_I2CReply, 1))
00104 return -1;
00105
00106 return LEGOUS_I2CReply[0];
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 bool USreadDistances(tSensors link, tByteArray &distances) {
00118 memset(LEGOUS_I2CRequest, 0, sizeof(tByteArray));
00119
00120 LEGOUS_I2CRequest[0] = 2;
00121 LEGOUS_I2CRequest[1] = LEGOUS_I2C_ADDR;
00122 LEGOUS_I2CRequest[2] = LEGOUS_REG_DATA;
00123
00124 if (!writeI2C(link, LEGOUS_I2CRequest, 8))
00125 return false;
00126
00127 if (!readI2C(link, LEGOUS_I2CReply, 8))
00128 return false;
00129
00130 memcpy(distances, LEGOUS_I2CReply, sizeof(tByteArray));
00131 return true;
00132 }
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 bool _USsendCmd(tSensors link, ubyte command) {
00144 memset(LEGOUS_I2CRequest, 0, sizeof(tByteArray));
00145
00146 LEGOUS_I2CRequest[0] = 3;
00147 LEGOUS_I2CRequest[1] = LEGOUS_I2C_ADDR;
00148 LEGOUS_I2CRequest[2] = LEGOUS_REG_CMD;
00149 LEGOUS_I2CRequest[3] = command;
00150
00151 return writeI2C(link, LEGOUS_I2CRequest, 0);
00152 }
00153
00154
00155
00156
00157
00158
00159
00160 bool USsetSingleMode(tSensors link) {
00161 return _USsendCmd(link, LEGOUS_CMD_SSHOT);
00162 }
00163
00164
00165
00166
00167
00168
00169
00170 bool USsetContinuousMode(tSensors link) {
00171 return _USsendCmd(link, LEGOUS_CMD_CONT);
00172 }
00173
00174
00175
00176
00177
00178
00179
00180 bool USsetOff(tSensors link){
00181 return _USsendCmd(link, LEGOUS_CMD_OFF);
00182 }
00183
00184
00185
00186
00187
00188
00189
00190 bool USsetEventCapture(tSensors link) {
00191 return _USsendCmd(link, LEGOUS_CMD_ECAPT);
00192 }
00193
00194
00195
00196
00197
00198
00199
00200 bool USreset(tSensors link) {
00201 return _USsendCmd(link, LEGOUS_CMD_RST);
00202 }
00203
00204 #endif // __LEGOSNR_H__
00205
00206
00207
00208
00209
00210