download ad.cpp
Language: C++
LOC: 307
Project Info
RDOS operating system(rdos)
Server: SourceForge
Type: cvs
SourceForge\r\rdos\rdos\bur\
   ad.cpp
   ad.def
   BOOT.ASM
   bur2bin.asm
   burload.cpp
   burload.def
   CFG2ROM.ASM
   CLEAN.BAT
   DEMO.CFG
   FLASH.ASM
   LCD.ASM
   MK.BAT
   SDRAM.ASM
   SHUTDOWN.ASM
   TEST.ASM
   TEST.DEF
   YMODEM.CPP
   YMODEM.H
   ZFX86.ASM

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
#include "rdos.h"
#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include "adcdev.h"
#include "tempdev.h"
#include "lightdev.h"
#include "datetime.h"
#include "secsamp.h"
#include "minsamp.h"
#include "hoursamp.h"
#include "daysamp.h"
#include "datetime.h"
#include "bitdev.h"
#include "videodev.h"
#include "keyboard.h"


#define FALSE	0
#define TRUE	!FALSE

long double lv;
TSample lsmin, lsmax;

long double tv[3];
TSample tsmin[3], tsmax[3];

long double rv[4];
TSample rsmin[4], rsmax[4];

void UpdateTime()
{
	TDateTime CurrentTime;
	char str[80];

	sprintf(str,
			"%04d-%02d-%02d %02d.%02d.%02d",
			CurrentTime.GetYear(),
			CurrentTime.GetMonth(),
			CurrentTime.GetDay(),
			CurrentTime.GetHour(),
			CurrentTime.GetMin(),
			CurrentTime.GetSec());

	RdosSetCursorPosition(15, 0);
	RdosWriteString(str);
}

void UpdateLight(int all)
{
	char str[80];
	TDateTime time;

	if (all)
		sprintf(str, "LJUS:  %7.3LfW/m2 (%7.3Lf, %7.3Lf)", lv, lsmin.GetMin(&time), lsmax.GetMax(&time));
	else
		sprintf(str, "LJUS:  %7.3LfW/m2", lv);

	RdosSetCursorPosition(0, 0);
	RdosWriteString(str);
}

void UpdateTemp(int index, int all)
{
	char par[20];
	char str[80];
	TDateTime time;

	switch (index)
	{
		case 0:
			strcpy(par, "TEMP:   ");
			break;

		case 1:
			strcpy(par, "TANK:   ");
			break;

		case 2:
			strcpy(par, "PANNA:  ");
			break;
	}

	if (all)
		sprintf(str, "%s %7.1LfC (%7.1Lf, %7.1Lf)", par, tv[index], tsmin[index].GetMin(&time), tsmax[index].GetMax(&time));
	else
		sprintf(str, "%s %7.1LfC", par, tv[index]);

	switch (index)
	{
		case 0:
			RdosSetCursorPosition(1, 0);
			break;

		case 1:
			RdosSetCursorPosition(2, 0);
			break;

		case 2:
			RdosSetCursorPosition(3, 0);
			break;
	}

	RdosWriteString(str);
}

void UpdateRaw(int index, int all)
{
	char par[20];
	char str[80];
	TDateTime time;

	switch (index)
	{
		case 0:
			strcpy(par, "CH0:     ");
			break;

		case 1:
			strcpy(par, "CH1:     ");
			break;

		case 2:
			strcpy(par, "CH2:     ");
			break;

		case 3:
			strcpy(par, "CH3:     ");
			break;
	}

	if (all)
		sprintf(str, "%s%7.3LfmV (%7.3Lf, %7.3Lf)", par, rv[index], rsmin[index].GetMin(&time), rsmax[index].GetMax(&time));
	else
		sprintf(str, "%s%7.3LfmV", par, rv[index]);

	switch (index)
	{
		case 0:
			RdosSetCursorPosition(4, 0);
			break;

		case 1:
			RdosSetCursorPosition(5, 0);
			break;

		case 2:
			RdosSetCursorPosition(6, 0);
			break;

		case 3:
			RdosSetCursorPosition(7, 0);
			break;
	}

	RdosWriteString(str);
}

void SecClear(TSample *sample)
{
	TDateTime time;

	if (sample->GetCount())
	{
		switch (sample->GetIndex())
		{
			case 7:
				UpdateTime();
				lv = sample->GetMean(&time);
				UpdateLight(FALSE);
				break;

			case 6:
				tv[0] = sample->GetMean(&time);
				UpdateTemp(0, FALSE);
				break;

			case 5:
				tv[1] = sample->GetMean(&time);
				UpdateTemp(1, FALSE);
				break;

			case 4:
				tv[2] = sample->GetMean(&time);
				UpdateTemp(2, FALSE);
				break;

			case 3:
				rv[0] = sample->GetMean(&time);
				UpdateRaw(0, FALSE);
				break;

			case 2:
				rv[1] = sample->GetMean(&time);
				UpdateRaw(1, FALSE);
				break;

			case 1:
				rv[2] = sample->GetMean(&time);
				UpdateRaw(2, FALSE);
				break;

			case 0:
				rv[3] = sample->GetMean(&time);
				UpdateRaw(3, FALSE);
				break;

		}
	}
}

void RawProc(TSample *sample)
{
	char str[80];
	long double val;
	TDateTime time;

	if (sample->GetCount())
	{
		val = sample->GetMean(&time);

		switch (sample->GetIndex())
		{
			case 7:
				lsmin.Add(&time, val);
				lsmax.Add(&time, val);
				UpdateLight(TRUE);
				break;

			case 6:
				tsmin[0].Add(&time, val);
				tsmax[0].Add(&time, val);
				UpdateTemp(0, TRUE);
				break;

			case 5:
				tsmin[1].Add(&time, val);
				tsmax[1].Add(&time, val);
				UpdateTemp(1, TRUE);
				break;

			case 4:
				tsmin[2].Add(&time, val);
				tsmax[2].Add(&time, val);
				UpdateTemp(2, TRUE);
				break;

			case 3:
				rsmin[0].Add(&time, val);
				rsmax[0].Add(&time, val);
				UpdateRaw(0, TRUE);
				break;

			case 2:
				rsmin[1].Add(&time, val);
				rsmax[1].Add(&time, val);
				UpdateRaw(1, TRUE);
				break;

			case 1:
				rsmin[2].Add(&time, val);
				rsmax[2].Add(&time, val);
				UpdateRaw(2, TRUE);
				break;

			case 0:
				rsmin[3].Add(&time, val);
				rsmax[3].Add(&time, val);
				UpdateRaw(3, TRUE);
				break;

		}
	}
}

void Sample(TAdcDevice *adc, TDateTime *time, long double value)
{
	char str[80];
	int channel = adc->GetChannel();

	sprintf(str, "%7.1LfmV", value);
	RdosSetCursorPosition(0, 0);
	RdosWriteString(str);
}

void CreateChannel(TAdcDevice *dev)
{
	TSample *sec;
	TSample *min;
	TSample *hourmin, *hourmax;
	TSample *day;

	dev->DefineInterval(1193000 / 20);
	sec = new TSecSample(dev->GetChannel(), dev->GetUnit());
	sec->ExcludeSmallest(3);
	sec->ExcludeLargest(3);
	sec->BeforeClear = SecClear;
	dev->Define(sec);

	min = new TMinSample(dev->GetChannel(), dev->GetUnit());
	sec->DefineMean(min);
	min->BeforeClear = RawProc;
}

void KeyPress(TKeyboardDevice *Keyboard, int ExtKey, int KeyState, int VirtualKey, int ScanCode)
{
	char str[40];

	sprintf(str, "Key press info:");
	RdosSetCursorPosition(9, 0);
	RdosWriteString(str);

	sprintf(str, "ExtKey = %02hX, State = %04hX", ExtKey, KeyState);
	RdosSetCursorPosition(10, 0);
	RdosWriteString(str);

	sprintf(str, "VK = %02hX, ScanCode = %02hX", VirtualKey, ScanCode);
	RdosSetCursorPosition(11, 0);
	RdosWriteString(str);
}

void KeyRelease(TKeyboardDevice *Keyboard, int ExtKey, int KeyState, int VirtualKey, int ScanCode)
{
	char str[40];

	sprintf(str, "Key release info:");
	RdosSetCursorPosition(9, 0);
	RdosWriteString(str);

	sprintf(str, "ExtKey = %02hX, State = %04hX", ExtKey, KeyState);
	RdosSetCursorPosition(10, 0);
	RdosWriteString(str);

	sprintf(str, "VK = %02hX, ScanCode = %02hX", VirtualKey, ScanCode);
	RdosSetCursorPosition(11, 0);
	RdosWriteString(str);
}

void cdecl main()
{
	int channel;
	TWait Wait;
	TAdcDevice *adc;
	TTempDevice *temp;
	TLightDevice *light;
	TKeyboardDevice *Keyboard;

	RdosWaitMilli(250);

	Keyboard = new TKeyboardDevice(&Wait);
	Keyboard->OnKeyPress = KeyPress;
	Keyboard->OnKeyRelease = KeyRelease;

#ifndef TEST

	light = new TLightDevice(&Wait, 7);
	CreateChannel(light);

	temp = new TTempDevice(&Wait, 6);
	CreateChannel(temp);

	temp = new TTempDevice(&Wait, 5);
	CreateChannel(temp);

	temp = new TTempDevice(&Wait, 4);
	CreateChannel(temp);

	adc = new TAdcDevice(&Wait, 3);
	CreateChannel(adc);

	adc = new TAdcDevice(&Wait, 2);
	CreateChannel(adc);

	adc = new TAdcDevice(&Wait, 1);
	CreateChannel(adc);

	adc = new TAdcDevice(&Wait, 0);
	CreateChannel(adc);

#endif

	for (;;)
		Wait.WaitForever();

}

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us