Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __LEGOLS_H__
00013 #define __LEGOLS_H__
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #pragma systemFile
00036
00037 #ifndef __COMMON_H__
00038 #include "common.h"
00039 #endif
00040
00041 #define LEGOLSDAT "legols.dat"
00042
00043
00044 int lslow = 0;
00045 int lshigh = 1023;
00046 bool legols_calibrated = false;
00047
00048
00049 int LSvalRaw(tSensors link);
00050 int LSvalNorm(tSensors link);
00051 void LScalLow(tSensors link);
00052 void LScalLow(int lowval);
00053 void LScalHigh(tSensors link);
00054 void LScalHigh(int highval);
00055 void LSsetActive(tSensors link);
00056 void LSsetInactive(tSensors link);
00057
00058 #ifdef __HTSMUX_SUPPORT__
00059 int LSvalNorm(tMUXSensor muxsensor);
00060 void LScalLow(tMUXSensor muxsensor);
00061 int LSvalRaw(tMUXSensor muxsensor);
00062 void LScalHigh(tMUXSensor muxsensor);
00063 void LSsetActive(tMUXSensor muxsensor);
00064 void LSsetInactive(tMUXSensor muxsensor);
00065 #endif // __HTSMUX_SUPPORT__
00066
00067 void _LScheckSensor(tSensors link);
00068 void _LSwriteCalVals(int lowval, int highval);
00069 void _LSreadCalVals(int &lowval, int &highval);
00070
00071
00072
00073
00074
00075
00076
00077 int LSvalRaw(tSensors link) {
00078 _LScheckSensor(link);
00079
00080 return SensorRaw[link];
00081 }
00082
00083
00084
00085
00086
00087
00088
00089 #ifdef __HTSMUX_SUPPORT__
00090 int LSvalRaw(tMUXSensor muxsensor) {
00091 return 1023 - HTSMUXreadAnalogue(muxsensor);
00092 }
00093 #endif // __HTSMUX_SUPPORT__
00094
00095
00096
00097
00098
00099
00100 int LSvalNorm(tSensors link) {
00101 long currval = 0;
00102
00103 _LScheckSensor(link);
00104
00105 if (!legols_calibrated) {
00106 _LSreadCalVals(lslow, lshigh);
00107 }
00108
00109 currval = LSvalRaw(link);
00110
00111 if (currval <= lslow)
00112 return 0;
00113 else if (currval >= lshigh)
00114 return 100;
00115
00116 return ((currval - lslow) * 100) / (lshigh - lslow);
00117 }
00118
00119
00120
00121
00122
00123
00124
00125 #ifdef __HTSMUX_SUPPORT__
00126 int LSvalNorm(tMUXSensor muxsensor) {
00127 long currval = 0;
00128
00129 if (!legols_calibrated) {
00130 _LSreadCalVals(lslow, lshigh);
00131 }
00132
00133 currval = LSvalRaw(muxsensor);
00134
00135 if (currval <= lslow)
00136 return 0;
00137 else if (currval >= lshigh)
00138 return 100;
00139
00140 return ((currval - lslow) * 100) / (lshigh - lslow);
00141 }
00142 #endif // __HTSMUX_SUPPORT__
00143
00144
00145
00146
00147
00148 void LScalLow(tSensors link) {
00149 _LScheckSensor(link);
00150
00151 lslow = SensorRaw[link];
00152 _LSwriteCalVals(lslow, lshigh);
00153 }
00154
00155
00156
00157
00158
00159
00160 #ifdef __HTSMUX_SUPPORT__
00161 void LScalLow(tMUXSensor muxsensor) {
00162 lslow = LSvalRaw(muxsensor);
00163 _LSwriteCalVals(lslow, lshigh);
00164 }
00165 #endif // __HTSMUX_SUPPORT__
00166
00167
00168
00169
00170
00171
00172 void LScalLow(int lowval) {
00173 lslow = lowval;
00174 _LSwriteCalVals(lslow, lshigh);
00175 }
00176
00177
00178
00179
00180
00181
00182 void LScalHigh(tSensors link) {
00183 _LScheckSensor(link);
00184
00185 lshigh = SensorRaw[link];
00186 _LSwriteCalVals(lslow, lshigh);
00187 }
00188
00189
00190
00191
00192
00193
00194 #ifdef __HTSMUX_SUPPORT__
00195 void LScalHigh(tMUXSensor muxsensor) {
00196 lshigh = LSvalRaw(muxsensor);
00197 _LSwriteCalVals(lslow, lshigh);
00198 }
00199 #endif // __HTSMUX_SUPPORT__
00200
00201
00202
00203
00204
00205
00206 void LScalHigh(int highval) {
00207 lshigh = highval;
00208 _LSwriteCalVals(lslow, lshigh);
00209 }
00210
00211
00212
00213
00214
00215
00216 void LSsetActive(tSensors link) {
00217 SensorType[link] = sensorLightActive;
00218 SensorMode[link] = modeRaw;
00219 wait1Msec(5);
00220 }
00221
00222
00223
00224
00225
00226
00227 #ifdef __HTSMUX_SUPPORT__
00228 void LSsetActive(tMUXSensor muxsensor) {
00229 HTSMUXsetAnalogueActive(muxsensor);
00230 }
00231 #endif // __HTSMUX_SUPPORT__
00232
00233
00234
00235
00236
00237
00238 void LSsetInactive(tSensors link) {
00239 SensorType[link] = sensorLightInactive;
00240 SensorMode[link] = modeRaw;
00241 wait1Msec(5);
00242 }
00243
00244
00245
00246
00247
00248
00249 #ifdef __HTSMUX_SUPPORT__
00250 void LSsetInactive(tMUXSensor muxsensor) {
00251 HTSMUXsetAnalogueInactive(muxsensor);
00252 }
00253 #endif // __HTSMUX_SUPPORT__
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263 void _LScheckSensor(tSensors link) {
00264 if (SensorMode[link] != modeRaw &&
00265 ((SensorType[link] != sensorLightActive) ||
00266 (SensorType[link] != sensorLightInactive))) {
00267 LSsetInactive(link);
00268 }
00269 }
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279 void _LSwriteCalVals(int lowval, int highval) {
00280 TFileHandle hFileHandle;
00281 TFileIOResult nIoResult;
00282 short nFileSize = 4;
00283
00284
00285 Delete(LEGOLSDAT, nIoResult);
00286 OpenWrite(hFileHandle, nIoResult, LEGOLSDAT, nFileSize);
00287 if (nIoResult != ioRsltSuccess) {
00288 Close(hFileHandle, nIoResult);
00289 eraseDisplay();
00290 nxtDisplayTextLine(3, "W:can't cal file");
00291 PlaySound(soundException);
00292 while(bSoundActive);
00293 wait1Msec(5000);
00294 StopAllTasks();
00295 }
00296
00297
00298 WriteShort(hFileHandle, nIoResult, lowval);
00299 if (nIoResult != ioRsltSuccess) {
00300 eraseDisplay();
00301 nxtDisplayTextLine(3, "can't write lowval");
00302 PlaySound(soundException);
00303 while(bSoundActive);
00304 wait1Msec(5000);
00305 StopAllTasks();
00306 }
00307
00308
00309 WriteShort(hFileHandle, nIoResult, highval);
00310 if (nIoResult != ioRsltSuccess) {
00311 eraseDisplay();
00312 nxtDisplayTextLine(3, "can't write highval");
00313 PlaySound(soundException);
00314 while(bSoundActive);
00315 wait1Msec(5000);
00316 StopAllTasks();
00317 }
00318
00319
00320 Close(hFileHandle, nIoResult);
00321 if (nIoResult != ioRsltSuccess) {
00322 eraseDisplay();
00323 nxtDisplayTextLine(3, "Can't close");
00324 PlaySound(soundException);
00325 while(bSoundActive);
00326 wait1Msec(5000);
00327 StopAllTasks();
00328 }
00329 }
00330
00331
00332
00333
00334
00335
00336
00337
00338 void _LSreadCalVals(int &lowval, int &highval) {
00339 TFileHandle hFileHandle;
00340 TFileIOResult nIoResult;
00341 short nFileSize;
00342
00343 short lv = 0;
00344 short hv = 0;
00345
00346
00347 legols_calibrated = true;
00348 OpenRead(hFileHandle, nIoResult, LEGOLSDAT, nFileSize);
00349 if (nIoResult != ioRsltSuccess) {
00350 Close(hFileHandle, nIoResult);
00351 return;
00352 }
00353
00354
00355 ReadShort(hFileHandle, nIoResult, lv);
00356 if (nIoResult != ioRsltSuccess) {
00357 Close(hFileHandle, nIoResult);
00358 return;
00359 }
00360
00361
00362 ReadShort(hFileHandle, nIoResult, hv);
00363 if (nIoResult != ioRsltSuccess) {
00364 Close(hFileHandle, nIoResult);
00365 return;
00366 }
00367
00368
00369 lowval = lv;
00370 highval = hv;
00371 Close(hFileHandle, nIoResult);
00372 }
00373
00374 #endif // __LEGOLS_H__
00375
00376
00377
00378
00379
00380