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