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