-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtsk_ui.ks
495 lines (432 loc) · 12 KB
/
rtsk_ui.ks
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
////////////////////////////////////////////////////////////////////////////////
// RTSK USER INTERFACE
////////////////////////////////////////////////////////////////////////////////
// REGISTERED MODE NAMES
GLOBAL MODE_NAMES TO LEXICON().
// REGISTERED VERB NAMES
GLOBAL VERB_NAMES TO LEXICON().
VERB_NAMES:ADD( 0, "TRANSFER MODE").
VERB_NAMES:ADD(10, "TRANSFER MODE").
VERB_NAMES:ADD(20, "TRANSFER MODE").
VERB_NAMES:ADD(30, "TRANSFER MODE").
VERB_NAMES:ADD(40, "TRANSFER MODE").
VERB_NAMES:ADD(50, "TRANSFER MODE").
VERB_NAMES:ADD(60, "TRANSFER MODE").
VERB_NAMES:ADD(70, "TRANSFER MODE").
VERB_NAMES:ADD(80, "TRANSFER MODE").
VERB_NAMES:ADD(90, "TRANSFER MODE").
// LIST OF PREVIOUSLY KNOWN VALUES FOR PREVIOUSLY PRINTED VARIABLES
GLOBAL UI_PREVIOUS_VALUES TO LEXICON().
// SOME CONSTANTS USED FOR DATA OUTPUT
GLOBAL NUMBER TO 0.
GLOBAL SIGNED TO 1.
GLOBAL ONOFF TO 2.
GLOBAL TEXT TO 3.
////////////////////////////////////////////////////////////////////////////////
// UI HEADER TASK
////////////////////////////////////////////////////////////////////////////////
GLOBAL UI_HEADER_REFRESH TO FALSE.
ON MAJOR_MODE {
IF NOT UI_HEADER_REFRESH {
SET UI_HEADER_REFRESH TO TRUE.
TASK_SCHEDULE(0, TASK_UI_HEADER@).
}
PRESERVE.
}
ON MINOR_MODE {
IF NOT UI_HEADER_REFRESH {
SET UI_HEADER_REFRESH TO TRUE.
TASK_SCHEDULE(0, TASK_UI_HEADER@).
}
PRESERVE.
}
FUNCTION TASK_UI_HEADER { PARAMETER DT.
IF DT = INIT {
SET UI_HEADER_REFRESH TO TRUE.
}
// DRAW BASE HEADER
IF UI_HEADER_REFRESH {
SET UI_HEADER_REFRESH TO FALSE.
CLEARLINE(0).
// SOFTWARE MODE
PRINT "OP" AT (0,0).
PRINT MAJOR_MODE AT (2,0).
PRINT MINOR_MODE AT (3,0).
// CURRENT SOFTWARE MODE NAME
LOCAL MODE_ID IS MAJOR_MODE*10 + MINOR_MODE.
IF MODE_NAMES:HASKEY(MODE_ID) {
PRINT MODE_NAMES[MODE_ID] AT (5,0).
} ELSE {
PRINT "----- RTSK -----" AT (5,0).
}
// DRAW RESOURCES INFO
PRINT " 0.0R" AT (22,0).
PRINT " 0C" AT (29,0).
// DAYS ON ORBIT
PRINT "-" AT (39,0).
}
// PRINT RESOURCES
PRINT N2S(SHIP:MONOPROPELLANT,1,5) AT (22,0).
PRINT N2S(SHIP:ELECTRICCHARGE,0,5) AT (29,0).
// PRINT MISSION TIME
PRINT (FLOOR(MISSIONTIME/21600) + ""):PADLEFT(3):REPLACE(" ", "0") AT (36,0).
PRINT_TIME(MISSIONTIME,40,0).
// RE-SCHEDULE TASK
TASK_SCHEDULE(17, TASK_UI_HEADER@).
}
////////////////////////////////////////////////////////////////////////////////
// SYSTEMS SCREENS DRAWING TASK
////////////////////////////////////////////////////////////////////////////////
GLOBAL UI_SYSTEMS_SCREENS_REFRESH TO FALSE.
ON RCS {
IF NOT UI_SYSTEMS_SCREENS_REFRESH {
SET UI_SYSTEMS_SCREENS_REFRESH TO TRUE.
TASK_SCHEDULE(0, TASK_UI_SYSTEMS_SCREENS@).
}
PRESERVE.
}
ON SAS {
IF NOT UI_SYSTEMS_SCREENS_REFRESH {
SET UI_SYSTEMS_SCREENS_REFRESH TO TRUE.
TASK_SCHEDULE(0, TASK_UI_SYSTEMS_SCREENS@).
}
PRESERVE.
}
GLOBAL UI_SYSTEMS_SCREEN_PRIORITY TO 0.
FUNCTION TASK_UI_SYSTEMS_SCREENS { PARAMETER DT.
IF DT = INIT {
SET UI_SYSTEMS_SCREENS_REFRESH TO TRUE.
VERT_LINE(30, 3, 19).
}
IF UI_SYSTEMS_SCREENS_REFRESH {
SET UI_SYSTEMS_SCREENS_REFRESH TO FALSE.
}
UI_VARIABLE("CPU", "%", CPU_LOAD*100, 0,3, NUMBER, 32,0).
UI_VARIABLE("TSK", "", TASK_LIST:LENGTH+1, 0,2, NUMBER, 42,0). // +1 SO IT COUNTS CURRENT TASK TOO
UI_VARIABLE(" LF", "U", SHIP:LIQUIDFUEL, 1,7, NUMBER, 32,2).
UI_VARIABLE(" OX", "U", SHIP:OXIDIZER, 1,7, NUMBER, 32,3).
UI_VARIABLE(" R", "KM", SHIP:ALTITUDE/1000, 3,8, SIGNED, 32,5).
UI_VARIABLE(" AP", "KM", SHIP:APOAPSIS/1000, 3,8, SIGNED, 32,6).
UI_VARIABLE(" PE", "KM", SHIP:PERIAPSIS/1000, 3,8, SIGNED, 32,7).
UI_VARIABLE("T AP", "SEC", ETA:APOAPSIS, 0,7, SIGNED, 32,9).
UI_VARIABLE("T PE", "SEC", ETA:PERIAPSIS, 0,7, SIGNED, 32,10).
UI_VARIABLE("RCS", "", RCS, 0,3, ONOFF, 32,12).
UI_VARIABLE("SAS", "", SAS, 0,3, ONOFF, 41,12).
UI_VARIABLE("FCL", "", FUELCELLS, 0,3, ONOFF, 32,13).
// RE-SCHEDULE TASK
IF MODES_TASKLIST:HASKEY(MAJOR_MODE) {
IF UI_SYSTEMS_SCREEN_PRIORITY > 0 {
TASK_SCHEDULE(UI_SYSTEMS_SCREEN_PRIORITY, TASK_UI_SYSTEMS_SCREENS@).
} ELSE {
TASK_SCHEDULE(6, TASK_UI_SYSTEMS_SCREENS@).
}
} ELSE {
TASK_SCHEDULE(3, TASK_UI_SYSTEMS_SCREENS@).
}
}
////////////////////////////////////////////////////////////////////////////////
// UI INPUT QUASI-TASK
////////////////////////////////////////////////////////////////////////////////
GLOBAL UI_ENTERING TO FALSE.
GLOBAL UI_COMMAND TO -1.
GLOBAL UI_PARAMETER TO 0.
FUNCTION TASK_HANDLE_COMMAND { PARAMETER DT.
IF UI_COMMAND = 0 {
IF UI_PARAMETER = 99 { // SERVICE COMMAND: REFRESH SCREEN
// CLEAR SCREEN AND ALL KNOWN VALUES
CLEARSCREEN.
SET UI_PREVIOUS_VALUES TO LEXICON().
// REFRESH HEADER AND SCREENS
TASK_UI_HEADER(INIT).
TASK_UI_SYSTEMS_SCREENS(INIT).
} ELSE IF UI_PARAMETER = 98 { // SERVICE COMMAND: EVENT TEST
PUSH_EVENT("999 EVT TEST", HIGH).
} ELSE IF UI_PARAMETER = 97 { // TOGGLE OUTPUT
SET OUTPUT_PERMITTED TO NOT OUTPUT_PERMITTED.
} ELSE {
LOCAL MINOR IS MOD(FLOOR(UI_PARAMETER),10).
LOCAL MAJOR IS MOD(FLOOR(UI_PARAMETER/10),10).
TRANSFER_MODE(MAJOR, MINOR).
}
} ELSE {
IF MODES_COMMAND:HASKEY(MAJOR_MODE) {
MODES_COMMAND[MAJOR_MODE]:CALL(UI_COMMAND, UI_PARAMETER).
} ELSE {
IF MODES_COMMAND:HASKEY(0) {
MODES_COMMAND[0]:CALL(UI_COMMAND, UI_PARAMETER).
}
}
}
}
FUNCTION UI_INPUT_REDRAW {
IF UI_ENTERING {
PRINT "VERB" AT (2,2).
IF UI_COMMAND = -1 {
PRINT "?" AT (6,2).
} ELSE {
IF VERB_NAMES:HASKEY(MAJOR_MODE*10 + UI_COMMAND) {
LOCAL VERB_NAME IS " [" + VERB_NAMES[MAJOR_MODE*10 + UI_COMMAND] + "]".
PRINT VERB_NAME AT (6,2).
PRINT UI_PARAMETER AT (7+VERB_NAME:LENGTH,2).
} ELSE {
PRINT UI_COMMAND AT (6,2).
PRINT UI_PARAMETER AT (8,2).
}
}
} ELSE {
CLEARLINE(2).
}
}
FUNCTION UI_ENTER_DIGIT {
PARAMETER DIGIT.
IF UI_ENTERING {
IF UI_COMMAND = -1 {
SET UI_COMMAND TO DIGIT.
} ELSE {
IF UI_PARAMETER < 0 {
SET UI_PARAMETER TO UI_PARAMETER*10 - DIGIT.
} ELSE {
SET UI_PARAMETER TO UI_PARAMETER*10 + DIGIT.
}
}
UI_INPUT_REDRAW().
}
}
////////////////////////////////////////////////////////////////////////////////
// HANDLERS FOR THE KEYS
////////////////////////////////////////////////////////////////////////////////
ON AG20 { UI_ENTER_DIGIT(0). PRESERVE. }
ON AG21 { UI_ENTER_DIGIT(1). PRESERVE. }
ON AG22 { UI_ENTER_DIGIT(2). PRESERVE. }
ON AG23 { UI_ENTER_DIGIT(3). PRESERVE. }
ON AG24 { UI_ENTER_DIGIT(4). PRESERVE. }
ON AG25 { UI_ENTER_DIGIT(5). PRESERVE. }
ON AG26 { UI_ENTER_DIGIT(6). PRESERVE. }
ON AG27 { UI_ENTER_DIGIT(7). PRESERVE. }
ON AG28 { UI_ENTER_DIGIT(8). PRESERVE. }
ON AG29 { UI_ENTER_DIGIT(9). PRESERVE. }
ON AG30 { // PRO
IF UI_ENTERING {
SET UI_ENTERING TO FALSE.
UI_INPUT_REDRAW().
// HANDLE COMMAND IN MAIN LOOP
TASK_SCHEDULE(0, TASK_HANDLE_COMMAND@).
}
PRESERVE.
}
ON AG31 { // ACK
IF UI_ENTERING {
SET UI_PARAMETER TO -UI_PARAMETER.
UI_INPUT_REDRAW().
} ELSE {
SET EVENT_PENDING TO NOT EVENT_PENDING.
EVENT_REDRAW().
}
PRESERVE.
}
ON AG32 { // REFRESH
// CLEAR SCREEN AND ALL KNOWN VALUES
CLEARSCREEN.
SET UI_PREVIOUS_VALUES TO LEXICON().
// REFRESH HEADER AND SCREENS
TASK_UI_HEADER(INIT).
PRESERVE.
}
ON AG33 { // VERB
IF UI_ENTERING {
SET UI_ENTERING TO FALSE.
} ELSE {
SET UI_ENTERING TO TRUE.
SET UI_COMMAND TO -1.
SET UI_PARAMETER TO 0.
}
UI_INPUT_REDRAW().
PRESERVE.
}
////////////////////////////////////////////////////////////////////////////////
//
// PRINT A VARIABLE ON SCREEN
//
FUNCTION UI_VARIABLE {
PARAMETER NAME, UNITS, VALUE, N, NMAX, TYPE, X, Y.
LOCAL VALUE_NUM IS 0.
LOCAL VALUE_STR IS "".
IF TYPE = SIGNED {
SET VALUE_NUM TO ROUND(VALUE, N).
} ELSE IF TYPE = NUMBER {
SET VALUE_NUM TO ROUND(VALUE, N).
} ELSE IF TYPE = ONOFF {
IF VALUE {
SET VALUE_NUM TO 1.
} ELSE {
SET VALUE_NUM TO 0.
}
} ELSE {
SET VALUE_NUM TO VALUE.
}
// NEW VALUE
IF NOT UI_PREVIOUS_VALUES:HASKEY(NAME) {
// >> START
IF TYPE = SIGNED {
SET VALUE_STR TO N2S_SIGN(VALUE, N, NMAX).
} ELSE IF TYPE = NUMBER {
SET VALUE_STR TO N2S(VALUE, N, NMAX).
} ELSE IF TYPE = ONOFF {
IF VALUE {
SET VALUE_STR TO " ON".
} ELSE {
SET VALUE_STR TO "OFF".
}
} ELSE {
SET VALUE_STR TO VALUE:PADLEFT(NMAX):SUBSTRING(0, NMAX).
}
// << END
PRINT NAME AT (X, Y+3).
PRINT UNITS AT (X+NAME:LENGTH+1+VALUE_STR:LENGTH+1, Y+3).
IF TYPE = TEXT {
UI_PREVIOUS_VALUES:ADD(NAME, "").
} ELSE {
UI_PREVIOUS_VALUES:ADD(NAME, VALUE_NUM - 1).
}
}
// PRINT ONLY IF UPDATED
IF UI_PREVIOUS_VALUES[NAME] <> VALUE_NUM {
// >> START
IF TYPE = SIGNED {
SET VALUE_STR TO N2S_SIGN(VALUE, N, NMAX).
} ELSE IF TYPE = NUMBER {
SET VALUE_STR TO N2S(VALUE, N, NMAX).
} ELSE IF TYPE = ONOFF {
IF VALUE {
SET VALUE_STR TO " ON".
} ELSE {
SET VALUE_STR TO "OFF".
}
} ELSE {
SET VALUE_STR TO VALUE:PADLEFT(NMAX):SUBSTRING(0, NMAX).
}
// << END
PRINT VALUE_STR AT (X+NAME:LENGTH+1, Y+3).
SET UI_PREVIOUS_VALUES[NAME] TO VALUE_NUM.
}
}
//
// CONVERT NUMBER TO PADDED STRING WITH FIXED NUMBER OF FRACTIONAL DIGITS
//
FUNCTION N2S {
PARAMETER X,N,NMAX.
IF N = 0 {
IF X >= 0 {
LOCAL XI IS ROUND(X).
RETURN ("" + XI):PADLEFT(NMAX):SUBSTRING(0, NMAX).
} ELSE {
LOCAL XI IS -ROUND(X).
RETURN ("-" + XI):PADLEFT(NMAX):SUBSTRING(0, NMAX).
}
} ELSE {
IF X >= 0 {
LOCAL XI IS FLOOR(X).
LOCAL XF IS FLOOR((10^N)*(X - XI)).
RETURN (XI + "." + (XF + ""):PADLEFT(N):REPLACE(" ", "0")):PADLEFT(NMAX):SUBSTRING(0, NMAX).
} ELSE {
LOCAL XI IS FLOOR(-X).
LOCAL XF IS FLOOR((10^N)*(-X - XI)).
RETURN ("-" + XI + "." + (XF + ""):PADLEFT(N):REPLACE(" ", "0")):PADLEFT(NMAX):SUBSTRING(0, NMAX).
}
}
}
//
// CONVERT NUMBER TO PADDED STRING WITH FIXED NUMBER OF FRACTIONAL DIGITS AND EXPLICIT SIGN
//
FUNCTION N2S_SIGN {
PARAMETER X,N,NMAX.
IF N = 0 {
IF X >= 0 {
LOCAL XI IS ROUND(X).
RETURN "+" + ("" + XI):PADLEFT(NMAX-1):SUBSTRING(0, NMAX-1).
} ELSE {
LOCAL XI IS -ROUND(X).
RETURN "-" + ("" + XI):PADLEFT(NMAX-1):SUBSTRING(0, NMAX-1).
}
} ELSE {
IF X >= 0 {
LOCAL XI IS FLOOR(X).
LOCAL XF IS FLOOR((10^N)*(X - XI)).
RETURN "+" + (XI + "." + (XF + ""):PADLEFT(N):REPLACE(" ", "0")):PADLEFT(NMAX-1):SUBSTRING(0, NMAX-1).
} ELSE {
LOCAL XI IS FLOOR(-X).
LOCAL XF IS FLOOR((10^N)*(-X - XI)).
RETURN "-" + (XI + "." + (XF + ""):PADLEFT(N):REPLACE(" ", "0")):PADLEFT(NMAX-1):SUBSTRING(0, NMAX-1).
}
}
}
//
// PRINT TIME IN EXTENDED FORMAT
//
FUNCTION PRINT_TIME {
PARAMETER T, X, Y.
PRINT FORMAT_TIME(T) AT (X,Y).
}
//
// FORMAT A TIME STRING
//
FUNCTION FORMAT_TIME {
PARAMETER T.
// SPLIT INTO TIME FORMAT
LOCAL SECOND IS MOD(FLOOR(T),60).
LOCAL MINUTE IS MOD(FLOOR(T / 60),60).
LOCAL HOUR IS MOD(FLOOR(T / 3600),6).
LOCAL RESULT IS "".
// PRINT ALL DIGITS
IF HOUR < 10 {
SET RESULT TO RESULT + "0" + HOUR + ":".
} ELSE {
SET RESULT TO RESULT + HOUR + ":".
}
IF MINUTE < 10 {
SET RESULT TO RESULT + "0" + MINUTE + ":".
} ELSE {
SET RESULT TO RESULT + MINUTE + ":".
}
IF SECOND < 10 {
SET RESULT TO RESULT + "0" + SECOND.
} ELSE {
SET RESULT TO RESULT + SECOND.
}
RETURN RESULT.
}
//
// CLEARS A LINE
//
FUNCTION CLEARLINE {
PARAMETER Y.
PRINT " " AT (0,Y).
}
//
// CLEARS ONLY THE MM-RELATED AREA
//
FUNCTION CLEAR_MM {
LOCAL Y IS 3.
UNTIL Y > 20 {
PRINT " " AT (0,Y).
SET Y TO Y + 1.
}
}
// DRAWS A VERTICAL LINE
FUNCTION VERT_LINE {
PARAMETER X,Y1,Y2.
LOCAL I IS Y1.
UNTIL I = Y2+1 {
PRINT "|" AT (X,I).
SET I TO I + 1.
}
}
// DRAWS A HORIZONTAL LINE
FUNCTION HORIZ_LINE {
PARAMETER X1,X2,Y.
LOCAL I IS X1.
UNTIL I = X2+1 {
PRINT "-" AT (I,Y).
SET I TO I + 1.
}
}