00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __HTCS_H__
00013 #define __HTCS_H__
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #pragma systemFile
00043
00044 #ifndef __COMMON_H__
00045 #include "common.h"
00046 #endif
00047
00048 #ifndef __LIGHT_COMMON_H__
00049 #include "light-common.h"
00050 #endif
00051
00052 #define HTCS_I2C_ADDR 0x02
00053 #define HTCS_CMD_REG 0x41
00054 #define HTCS_OFFSET 0x42
00055 #define HTCS_COLNUM_REG 0x00
00056 #define HTCS_RED_REG 0x01
00057 #define HTCS_GREEN_REG 0x02
00058 #define HTCS_BLUE_REG 0x03
00059 #define HTCS_RED_RAW_REG 0x04
00060 #define HTCS_GREEN_RAW_REG 0x05
00061 #define HTCS_BLUE_RAW_REG 0x06
00062 #define HTSC_COL_INDEX_REG 0x07
00063 #define HTSC_RED_NORM_REG 0x08
00064 #define HTSC_GREEN_NORM_REG 0x09
00065 #define HTSC_BLUE_NORM_REG 0x0A
00066
00067 #define HTCS_CAL_WHITE 0x43
00068
00069 int HTCSreadColor(tSensors link);
00070 bool HTCSreadRGB(tSensors link, int &red, int &green, int &blue);
00071 bool HTCSreadNormRGB(tSensors link, int &red, int &green, int &blue);
00072 bool HTCSreadRawRGB(tSensors link, int &red, int &green, int &blue);
00073 bool HTCScalWhite(tSensors link);
00074
00075 #ifdef __HTSMUX_SUPPORT__
00076 int HTCSreadColor(tMUXSensor muxsensor);
00077 bool HTCSreadRGB(tMUXSensor muxsensor, int &red, int &green, int &blue);
00078
00079 tConfigParams HTCS_config = {HTSMUX_CHAN_I2C, 4, 0x02, 0x42};
00080 #endif
00081
00082 tByteArray HTCS_I2CRequest;
00083 tByteArray HTCS_I2CReply;
00084
00085
00086
00087
00088
00089
00090 int HTCSreadColor(tSensors link) {
00091 memset(HTCS_I2CRequest, 0, sizeof(tByteArray));
00092
00093 HTCS_I2CRequest[0] = 2;
00094 HTCS_I2CRequest[1] = HTCS_I2C_ADDR;
00095 HTCS_I2CRequest[2] = HTCS_OFFSET + HTCS_COLNUM_REG;
00096
00097 if (!writeI2C(link, HTCS_I2CRequest, 1))
00098 return -1;
00099
00100 if (!readI2C(link, HTCS_I2CReply, 1))
00101 return -1;
00102
00103 return HTCS_I2CReply[0];
00104 }
00105
00106
00107
00108
00109
00110
00111
00112 #ifdef __HTSMUX_SUPPORT__
00113 int HTCSreadColor(tMUXSensor muxsensor) {
00114 memset(HTCS_I2CRequest, 0, sizeof(tByteArray));
00115
00116 if (HTSMUXSensorTypes[muxsensor] != HTSMUXSensorCustom)
00117 HTSMUXconfigChannel(muxsensor, HTCS_config);
00118
00119 if (!HTSMUXreadPort(muxsensor, HTCS_I2CReply, 1, HTCS_COLNUM_REG)) {
00120 return -1;
00121 }
00122
00123 return HTCS_I2CReply[0];
00124 }
00125 #endif // __HTSMUX_SUPPORT__
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 bool HTCSreadRGB(tSensors link, int &red, int &green, int &blue) {
00137 memset(HTCS_I2CRequest, 0, sizeof(tByteArray));
00138
00139 HTCS_I2CRequest[0] = 2;
00140 HTCS_I2CRequest[1] = HTCS_I2C_ADDR;
00141 HTCS_I2CRequest[2] = HTCS_OFFSET + HTCS_RED_REG;
00142
00143 if (!writeI2C(link, HTCS_I2CRequest, 3))
00144 return false;
00145
00146 if (!readI2C(link, HTCS_I2CReply, 3))
00147 return false;
00148
00149 red = HTCS_I2CReply[0];
00150 green = HTCS_I2CReply[1];
00151 blue = HTCS_I2CReply[2];
00152
00153 return true;
00154 }
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 #ifdef __HTSMUX_SUPPORT__
00166 bool HTCSreadRGB(tMUXSensor muxsensor, int &red, int &green, int &blue) {
00167 memset(HTCS_I2CRequest, 0, sizeof(tByteArray));
00168
00169 if (HTSMUXSensorTypes[muxsensor] != HTSMUXSensorCustom)
00170 HTSMUXconfigChannel(muxsensor, HTCS_config);
00171
00172 if (!HTSMUXreadPort(muxsensor, HTCS_I2CReply, 3, HTCS_RED_REG)) {
00173 return false;
00174 }
00175
00176 red = HTCS_I2CReply[0];
00177 green = HTCS_I2CReply[1];
00178 blue = HTCS_I2CReply[2];
00179
00180 return true;
00181 }
00182 #endif // __HTSMUX_SUPPORT__
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 bool HTCSreadHSV(tSensors link, float &hue, float &saturation, float &value) {
00194
00195 int red,green,blue;
00196 bool ret = HTCSreadRGB(link, red, green, blue);
00197 RGBtoHSV(red,green,blue, hue, saturation, value);
00198
00199 return ret;
00200 }
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 #ifdef __HTSMUX_SUPPORT__
00212 bool HTCSreadHSV(tMUXSensor muxsensor, float &hue, float &saturation, float &value) {
00213
00214 int red,green,blue;
00215
00216 bool ret = HTCSreadRGB(muxsensor, red, green, blue);
00217 RGBtoHSV(red,green,blue, hue, saturation, value);
00218
00219 return ret;
00220 }
00221 #endif // __HTSMUX_SUPPORT__
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234 bool HTCSreadNormRGB(tSensors link, int &red, int &green, int &blue) {
00235 memset(HTCS_I2CRequest, 0, sizeof(tByteArray));
00236
00237 HTCS_I2CRequest[0] = 2;
00238 HTCS_I2CRequest[1] = HTCS_I2C_ADDR;
00239 HTCS_I2CRequest[2] = HTCS_OFFSET + HTSC_RED_NORM_REG;
00240
00241 if (!writeI2C(link, HTCS_I2CRequest, 3))
00242 return false;
00243
00244 if (!readI2C(link, HTCS_I2CReply, 3))
00245 return false;
00246
00247 red = HTCS_I2CReply[0];
00248 green = HTCS_I2CReply[1];
00249 blue = HTCS_I2CReply[2];
00250
00251 return true;
00252 }
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263 bool HTCSreadRawRGB(tSensors link, int &red, int &green, int &blue) {
00264 memset(HTCS_I2CRequest, 0, sizeof(tByteArray));
00265
00266 HTCS_I2CRequest[0] = 2;
00267 HTCS_I2CRequest[1] = HTCS_I2C_ADDR;
00268 HTCS_I2CRequest[2] = HTCS_OFFSET + HTCS_RED_RAW_REG;
00269
00270 if (!writeI2C(link, HTCS_I2CRequest, 6))
00271 return false;
00272
00273 if (!readI2C(link, HTCS_I2CReply, 6))
00274 return false;
00275
00276 red = HTCS_I2CReply[0];
00277 green = HTCS_I2CReply[1];
00278 blue = HTCS_I2CReply[2];
00279
00280 return true;
00281 }
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291 int HTCSreadColorIndex(tSensors link) {
00292 memset(HTCS_I2CRequest, 0, sizeof(tByteArray));
00293
00294 HTCS_I2CRequest[0] = 2;
00295 HTCS_I2CRequest[1] = HTCS_I2C_ADDR;
00296 HTCS_I2CRequest[2] = HTCS_OFFSET + HTSC_COL_INDEX_REG;
00297
00298 if (!writeI2C(link, HTCS_I2CRequest, 1))
00299 return -1;
00300
00301 if (!readI2C(link, HTCS_I2CReply, 1))
00302 return -1;
00303
00304 return HTCS_I2CReply[0];
00305 }
00306
00307
00308
00309
00310
00311
00312 bool HTCScalWhite(tSensors link) {
00313 memset(HTCS_I2CRequest, 0, sizeof(tByteArray));
00314
00315 HTCS_I2CRequest[0] = 3;
00316 HTCS_I2CRequest[1] = HTCS_I2C_ADDR;
00317 HTCS_I2CRequest[2] = HTCS_CMD_REG;
00318 HTCS_I2CRequest[3] = HTCS_CAL_WHITE;
00319
00320 if (!writeI2C(link, HTCS_I2CRequest, 0))
00321 return false;
00322
00323 return true;
00324 }
00325
00326 #endif // __HTCS_H__
00327
00328
00329
00330
00331
00332