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