Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __DFLEX_H__
00013 #define __DFLEX_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 DFLEXDAT "DFLEX.dat"
00042
00043
00044 int dflexlow = 0;
00045 int dflexhigh = 1023;
00046 bool DFLEX_calibrated = false;
00047
00048
00049 int DFLEXvalRaw(tSensors link);
00050 int DFLEXvalNorm(tSensors link);
00051
00052 void DFLEXcalLow(tSensors link);
00053 void DFLEXcalLow(int lowval);
00054 void DFLEXcalHigh(tSensors link);
00055 void DFLEXcalHigh(int highval);
00056
00057 void _DFLEXcheckSensor(tSensors link);
00058 void _DFLEXwriteCalVals(int lowval, int highval);
00059 void _DFLEXreadCalVals(int &lowval, int &highval);
00060
00061
00062
00063
00064
00065
00066
00067 int DFLEXvalRaw(tSensors link) {
00068 _DFLEXcheckSensor(link);
00069
00070 return SensorRaw[link];
00071 }
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 int DFLEXvalNorm(tSensors link) {
00082 long currval = 0;
00083
00084 _DFLEXcheckSensor(link);
00085
00086 if (!DFLEX_calibrated) {
00087 _DFLEXreadCalVals(dflexlow, dflexhigh);
00088 }
00089
00090 currval = DFLEXvalRaw(link);
00091
00092 if (currval <= dflexlow)
00093 return 0;
00094 else if (currval >= dflexhigh)
00095 return 100;
00096
00097 return ((currval - dflexlow) * 100) / (dflexhigh - dflexlow);
00098 }
00099
00100
00101
00102
00103
00104
00105 void DFLEXcalLow(tSensors link) {
00106 _DFLEXcheckSensor(link);
00107
00108 dflexlow = SensorRaw[link];
00109 _DFLEXwriteCalVals(dflexlow, dflexhigh);
00110 }
00111
00112
00113
00114
00115
00116
00117 void DFLEXcalLow(int lowval) {
00118 dflexlow = lowval;
00119 _DFLEXwriteCalVals(dflexlow, dflexhigh);
00120 }
00121
00122
00123
00124
00125
00126
00127 void DFLEXcalHigh(tSensors link) {
00128 _DFLEXcheckSensor(link);
00129
00130 dflexhigh = SensorRaw[link];
00131 _DFLEXwriteCalVals(dflexlow, dflexhigh);
00132 }
00133
00134
00135
00136
00137
00138
00139 void DFLEXcalHigh(int highval) {
00140 dflexhigh = highval;
00141 _DFLEXwriteCalVals(dflexlow, dflexhigh);
00142 }
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 void _DFLEXcheckSensor(tSensors link) {
00153 if (SensorMode[link] != modeRaw)
00154 SensorMode[link] = modeRaw;
00155 if (SensorType[link] != sensorAnalogInactive)
00156 SensorType[link] = sensorAnalogInactive;
00157 }
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 void _DFLEXwriteCalVals(int lowval, int highval) {
00168 TFileHandle hFileHandle;
00169 TFileIOResult nIoResult;
00170 short nFileSize = 4;
00171
00172
00173 Delete(DFLEXDAT, nIoResult);
00174 OpenWrite(hFileHandle, nIoResult, DFLEXDAT, nFileSize);
00175 if (nIoResult != ioRsltSuccess) {
00176 Close(hFileHandle, nIoResult);
00177 eraseDisplay();
00178 nxtDisplayTextLine(3, "W:can't cal file");
00179 PlaySound(soundException);
00180 while(bSoundActive);
00181 wait1Msec(5000);
00182 StopAllTasks();
00183 }
00184
00185
00186 WriteShort(hFileHandle, nIoResult, lowval);
00187 if (nIoResult != ioRsltSuccess) {
00188 eraseDisplay();
00189 nxtDisplayTextLine(3, "can't write lowval");
00190 PlaySound(soundException);
00191 while(bSoundActive);
00192 wait1Msec(5000);
00193 StopAllTasks();
00194 }
00195
00196
00197 WriteShort(hFileHandle, nIoResult, highval);
00198 if (nIoResult != ioRsltSuccess) {
00199 eraseDisplay();
00200 nxtDisplayTextLine(3, "can't write highval");
00201 PlaySound(soundException);
00202 while(bSoundActive);
00203 wait1Msec(5000);
00204 StopAllTasks();
00205 }
00206
00207
00208 Close(hFileHandle, nIoResult);
00209 if (nIoResult != ioRsltSuccess) {
00210 eraseDisplay();
00211 nxtDisplayTextLine(3, "Can't close");
00212 PlaySound(soundException);
00213 while(bSoundActive);
00214 wait1Msec(5000);
00215 StopAllTasks();
00216 }
00217 }
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227 void _DFLEXreadCalVals(int &lowval, int &highval) {
00228 TFileHandle hFileHandle;
00229 TFileIOResult nIoResult;
00230 short nFileSize;
00231
00232 short lv = 0;
00233 short hv = 0;
00234
00235
00236 DFLEX_calibrated = true;
00237 OpenRead(hFileHandle, nIoResult, DFLEXDAT, nFileSize);
00238 if (nIoResult != ioRsltSuccess) {
00239 Close(hFileHandle, nIoResult);
00240 return;
00241 }
00242
00243
00244 ReadShort(hFileHandle, nIoResult, lv);
00245 if (nIoResult != ioRsltSuccess) {
00246 Close(hFileHandle, nIoResult);
00247 return;
00248 }
00249
00250
00251 ReadShort(hFileHandle, nIoResult, hv);
00252 if (nIoResult != ioRsltSuccess) {
00253 Close(hFileHandle, nIoResult);
00254 return;
00255 }
00256
00257
00258 lowval = lv;
00259 highval = hv;
00260 Close(hFileHandle, nIoResult);
00261 }
00262
00263 #endif // __DFLEX_H__
00264
00265
00266
00267
00268
00269