From 1f6e1a647e42439391b1b8bdc7fe197bc37e7541 Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Fri, 2 Apr 2021 22:19:29 +0800 Subject: [PATCH] add stl & more efficient scope --- lib.nas | 2 + nasal_builtin.h | 177 ++-- nasal_codegen.h | 4 +- nasal_gc.h | 52 +- nasal_vm.h | 23 +- {test => stl}/lib.nas | 2 + stl/list.nas | 73 ++ {test => stl}/queue.nas | 0 stl/sort.nas | 27 + {test => stl}/stack.nas | 0 test/ai.nas | 331 ------- test/auto_crash.nas | 59 +- test/bfs.nas | 16 +- test/bp.nas | 2 +- test/class.nas | 6 +- test/efb.nas | 2044 --------------------------------------- test/fib.nas | 13 +- test/multiplayer.nas | 643 ------------ test/neo4j.nas | 162 ---- test/smartscreen.nas | 210 ---- 20 files changed, 256 insertions(+), 3590 deletions(-) rename {test => stl}/lib.nas (99%) create mode 100644 stl/list.nas rename {test => stl}/queue.nas (100%) create mode 100644 stl/sort.nas rename {test => stl}/stack.nas (100%) delete mode 100644 test/ai.nas delete mode 100644 test/efb.nas delete mode 100644 test/multiplayer.nas delete mode 100644 test/neo4j.nas delete mode 100644 test/smartscreen.nas diff --git a/lib.nas b/lib.nas index 2974927..a094a7a 100644 --- a/lib.nas +++ b/lib.nas @@ -155,3 +155,5 @@ var math= sqrt: func(x) {return __builtin_sqrt(x); }, atan2: func(x,y){return __builtin_atan2(x,y);} }; + +var D2R=math.pi/180; \ No newline at end of file diff --git a/nasal_builtin.h b/nasal_builtin.h index 90d98e8..4f2322b 100644 --- a/nasal_builtin.h +++ b/nasal_builtin.h @@ -12,58 +12,52 @@ std::unordered_map builtin_use_str; // used to find values that builtin function uses -#define builtin_find(name) \ -(\ - local_scope\ - ->ptr.scop\ - ->get_val\ - (builtin_use_str[name])\ -) +#define builtin_find(name) (local_scope[builtin_use_str[name]]) // declaration of builtin functions // to add new builtin function,declare it here and write the definition below -nasal_val* builtin_print(nasal_val*,nasal_gc&); -nasal_val* builtin_append(nasal_val*,nasal_gc&); -nasal_val* builtin_setsize(nasal_val*,nasal_gc&); -nasal_val* builtin_system(nasal_val*,nasal_gc&); -nasal_val* builtin_input(nasal_val*,nasal_gc&); -nasal_val* builtin_sleep(nasal_val*,nasal_gc&); -nasal_val* builtin_fin(nasal_val*,nasal_gc&); -nasal_val* builtin_fout(nasal_val*,nasal_gc&); -nasal_val* builtin_split(nasal_val*,nasal_gc&); -nasal_val* builtin_rand(nasal_val*,nasal_gc&); -nasal_val* builtin_id(nasal_val*,nasal_gc&); -nasal_val* builtin_int(nasal_val*,nasal_gc&); -nasal_val* builtin_num(nasal_val*,nasal_gc&); -nasal_val* builtin_pop(nasal_val*,nasal_gc&); -nasal_val* builtin_str(nasal_val*,nasal_gc&); -nasal_val* builtin_size(nasal_val*,nasal_gc&); -nasal_val* builtin_xor(nasal_val*,nasal_gc&); -nasal_val* builtin_and(nasal_val*,nasal_gc&); -nasal_val* builtin_or(nasal_val*,nasal_gc&); -nasal_val* builtin_nand(nasal_val*,nasal_gc&); -nasal_val* builtin_not(nasal_val*,nasal_gc&); -nasal_val* builtin_sin(nasal_val*,nasal_gc&); -nasal_val* builtin_cos(nasal_val*,nasal_gc&); -nasal_val* builtin_tan(nasal_val*,nasal_gc&); -nasal_val* builtin_exp(nasal_val*,nasal_gc&); -nasal_val* builtin_ln(nasal_val*,nasal_gc&); -nasal_val* builtin_sqrt(nasal_val*,nasal_gc&); -nasal_val* builtin_atan2(nasal_val*,nasal_gc&); -nasal_val* builtin_time(nasal_val*,nasal_gc&); -nasal_val* builtin_contains(nasal_val*,nasal_gc&); -nasal_val* builtin_delete(nasal_val*,nasal_gc&); -nasal_val* builtin_getkeys(nasal_val*,nasal_gc&); -nasal_val* builtin_import(nasal_val*,nasal_gc&); -nasal_val* builtin_die(nasal_val*,nasal_gc&); -nasal_val* builtin_type(nasal_val*,nasal_gc&); -nasal_val* builtin_substr(nasal_val*,nasal_gc&); -nasal_val* builtin_streq(nasal_val*,nasal_gc&); -nasal_val* builtin_left(nasal_val*,nasal_gc&); -nasal_val* builtin_right(nasal_val*,nasal_gc&); -nasal_val* builtin_cmp(nasal_val*,nasal_gc&); -nasal_val* builtin_chr(nasal_val*,nasal_gc&); +nasal_val* builtin_print(std::unordered_map&,nasal_gc&); +nasal_val* builtin_append(std::unordered_map&,nasal_gc&); +nasal_val* builtin_setsize(std::unordered_map&,nasal_gc&); +nasal_val* builtin_system(std::unordered_map&,nasal_gc&); +nasal_val* builtin_input(std::unordered_map&,nasal_gc&); +nasal_val* builtin_sleep(std::unordered_map&,nasal_gc&); +nasal_val* builtin_fin(std::unordered_map&,nasal_gc&); +nasal_val* builtin_fout(std::unordered_map&,nasal_gc&); +nasal_val* builtin_split(std::unordered_map&,nasal_gc&); +nasal_val* builtin_rand(std::unordered_map&,nasal_gc&); +nasal_val* builtin_id(std::unordered_map&,nasal_gc&); +nasal_val* builtin_int(std::unordered_map&,nasal_gc&); +nasal_val* builtin_num(std::unordered_map&,nasal_gc&); +nasal_val* builtin_pop(std::unordered_map&,nasal_gc&); +nasal_val* builtin_str(std::unordered_map&,nasal_gc&); +nasal_val* builtin_size(std::unordered_map&,nasal_gc&); +nasal_val* builtin_xor(std::unordered_map&,nasal_gc&); +nasal_val* builtin_and(std::unordered_map&,nasal_gc&); +nasal_val* builtin_or(std::unordered_map&,nasal_gc&); +nasal_val* builtin_nand(std::unordered_map&,nasal_gc&); +nasal_val* builtin_not(std::unordered_map&,nasal_gc&); +nasal_val* builtin_sin(std::unordered_map&,nasal_gc&); +nasal_val* builtin_cos(std::unordered_map&,nasal_gc&); +nasal_val* builtin_tan(std::unordered_map&,nasal_gc&); +nasal_val* builtin_exp(std::unordered_map&,nasal_gc&); +nasal_val* builtin_ln(std::unordered_map&,nasal_gc&); +nasal_val* builtin_sqrt(std::unordered_map&,nasal_gc&); +nasal_val* builtin_atan2(std::unordered_map&,nasal_gc&); +nasal_val* builtin_time(std::unordered_map&,nasal_gc&); +nasal_val* builtin_contains(std::unordered_map&,nasal_gc&); +nasal_val* builtin_delete(std::unordered_map&,nasal_gc&); +nasal_val* builtin_getkeys(std::unordered_map&,nasal_gc&); +nasal_val* builtin_import(std::unordered_map&,nasal_gc&); +nasal_val* builtin_die(std::unordered_map&,nasal_gc&); +nasal_val* builtin_type(std::unordered_map&,nasal_gc&); +nasal_val* builtin_substr(std::unordered_map&,nasal_gc&); +nasal_val* builtin_streq(std::unordered_map&,nasal_gc&); +nasal_val* builtin_left(std::unordered_map&,nasal_gc&); +nasal_val* builtin_right(std::unordered_map&,nasal_gc&); +nasal_val* builtin_cmp(std::unordered_map&,nasal_gc&); +nasal_val* builtin_chr(std::unordered_map&,nasal_gc&); void builtin_err(std::string func_name,std::string info) { @@ -76,7 +70,7 @@ void builtin_err(std::string func_name,std::string info) struct FUNC_TABLE { std::string name; - nasal_val* (*func)(nasal_val* x,nasal_gc&); + nasal_val* (*func)(std::unordered_map&,nasal_gc&); } builtin_func[]= { {"__builtin_std_cout", builtin_print }, @@ -123,7 +117,7 @@ struct FUNC_TABLE {"", nullptr } }; -nasal_val* builtin_print(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_print(std::unordered_map& local_scope,nasal_gc& gc) { // get arguments nasal_val* vector_val_addr=builtin_find("elements"); @@ -146,7 +140,7 @@ nasal_val* builtin_print(nasal_val* local_scope,nasal_gc& gc) // generate return value return gc.nil_addr; } -nasal_val* builtin_append(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_append(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* vec_addr=builtin_find("vector"); nasal_val* elem_addr=builtin_find("elements"); @@ -162,7 +156,7 @@ nasal_val* builtin_append(nasal_val* local_scope,nasal_gc& gc) ref_vec.push_back(ref_elems[i]); return gc.nil_addr; } -nasal_val* builtin_setsize(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_setsize(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* vec_addr=builtin_find("vector"); nasal_val* size_addr=builtin_find("size"); @@ -193,7 +187,7 @@ nasal_val* builtin_setsize(nasal_val* local_scope,nasal_gc& gc) return gc.nil_addr; } -nasal_val* builtin_system(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_system(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* str_addr=builtin_find("str"); if(str_addr->type!=vm_str) @@ -205,14 +199,14 @@ nasal_val* builtin_system(nasal_val* local_scope,nasal_gc& gc) return gc.nil_addr; } -nasal_val* builtin_input(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_input(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* ret_addr=gc.gc_alloc(vm_str); std::cin>>*ret_addr->ptr.str; return ret_addr; } -nasal_val* builtin_sleep(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_sleep(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* val_addr=builtin_find("duration"); if(val_addr->type!=vm_num) @@ -225,7 +219,7 @@ nasal_val* builtin_sleep(nasal_val* local_scope,nasal_gc& gc) return gc.nil_addr; } -nasal_val* builtin_fin(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_fin(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* val_addr=builtin_find("filename"); if(val_addr->type!=vm_str) @@ -251,7 +245,7 @@ nasal_val* builtin_fin(nasal_val* local_scope,nasal_gc& gc) return ret_addr; } -nasal_val* builtin_fout(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_fout(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* val_addr=builtin_find("filename"); nasal_val* str_addr=builtin_find("str"); @@ -276,7 +270,7 @@ nasal_val* builtin_fout(nasal_val* local_scope,nasal_gc& gc) return gc.nil_addr; } -nasal_val* builtin_split(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_split(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* delimeter_val_addr=builtin_find("delimeter"); nasal_val* string_val_addr=builtin_find("string"); @@ -344,7 +338,7 @@ nasal_val* builtin_split(nasal_val* local_scope,nasal_gc& gc) } return ret_addr; } -nasal_val* builtin_rand(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_rand(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* val_addr=builtin_find("seed"); if(val_addr->type!=vm_num && val_addr->type!=vm_nil) @@ -364,7 +358,7 @@ nasal_val* builtin_rand(nasal_val* local_scope,nasal_gc& gc) ret_addr->ptr.num=num; return ret_addr; } -nasal_val* builtin_id(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_id(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* val_addr=builtin_find("thing"); nasal_val* ret_addr=gc.gc_alloc(vm_str); @@ -373,7 +367,7 @@ nasal_val* builtin_id(nasal_val* local_scope,nasal_gc& gc) *ret_addr->ptr.str=buf; return ret_addr; } -nasal_val* builtin_int(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_int(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* val_addr=builtin_find("value"); if(val_addr->type!=vm_num) @@ -386,7 +380,7 @@ nasal_val* builtin_int(nasal_val* local_scope,nasal_gc& gc) ret_addr->ptr.num=(double)number; return ret_addr; } -nasal_val* builtin_num(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_num(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* val_addr=builtin_find("value"); if(val_addr->type!=vm_str) @@ -398,7 +392,7 @@ nasal_val* builtin_num(nasal_val* local_scope,nasal_gc& gc) ret_addr->ptr.num=val_addr->to_number(); return ret_addr; } -nasal_val* builtin_pop(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_pop(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* val_addr=builtin_find("vector"); if(val_addr->type!=vm_vec) @@ -414,7 +408,7 @@ nasal_val* builtin_pop(nasal_val* local_scope,nasal_gc& gc) } return gc.nil_addr; } -nasal_val* builtin_str(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_str(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* val_addr=builtin_find("number"); if(val_addr->type!=vm_num) @@ -426,7 +420,7 @@ nasal_val* builtin_str(nasal_val* local_scope,nasal_gc& gc) *ret_addr->ptr.str=val_addr->to_string(); return ret_addr; } -nasal_val* builtin_size(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_size(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* val_addr=builtin_find("object"); nasal_val* ret_addr=gc.gc_alloc(vm_num); @@ -435,14 +429,13 @@ nasal_val* builtin_size(nasal_val* local_scope,nasal_gc& gc) case vm_nil: ret_addr->ptr.num=0; break; case vm_num: ret_addr->ptr.num=val_addr->ptr.num; break; case vm_func: ret_addr->ptr.num=0; break; - case vm_scop: ret_addr->ptr.num=val_addr->ptr.scop->elems.size();break; case vm_str: ret_addr->ptr.num=val_addr->ptr.str->length(); break; case vm_vec: ret_addr->ptr.num=val_addr->ptr.vec->elems.size(); break; case vm_hash: ret_addr->ptr.num=val_addr->ptr.hash->elems.size();break; } return ret_addr; } -nasal_val* builtin_xor(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_xor(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* a_addr=builtin_find("a"); nasal_val* b_addr=builtin_find("b"); @@ -462,7 +455,7 @@ nasal_val* builtin_xor(nasal_val* local_scope,nasal_gc& gc) ret_addr->ptr.num=(number_a^number_b); return ret_addr; } -nasal_val* builtin_and(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_and(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* a_addr=builtin_find("a"); nasal_val* b_addr=builtin_find("b"); @@ -482,7 +475,7 @@ nasal_val* builtin_and(nasal_val* local_scope,nasal_gc& gc) ret_addr->ptr.num=(number_a&number_b); return ret_addr; } -nasal_val* builtin_or(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_or(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* a_addr=builtin_find("a"); nasal_val* b_addr=builtin_find("b"); @@ -502,7 +495,7 @@ nasal_val* builtin_or(nasal_val* local_scope,nasal_gc& gc) ret_addr->ptr.num=(number_a|number_b); return ret_addr; } -nasal_val* builtin_nand(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_nand(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* a_addr=builtin_find("a"); nasal_val* b_addr=builtin_find("b"); @@ -522,7 +515,7 @@ nasal_val* builtin_nand(nasal_val* local_scope,nasal_gc& gc) ret_addr->ptr.num=(~(number_a&number_b)); return ret_addr; } -nasal_val* builtin_not(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_not(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* a_addr=builtin_find("a"); if(a_addr->type!=vm_num) @@ -535,7 +528,7 @@ nasal_val* builtin_not(nasal_val* local_scope,nasal_gc& gc) ret_addr->ptr.num=(~number); return ret_addr; } -nasal_val* builtin_sin(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_sin(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* val_addr=builtin_find("x"); if(val_addr->type!=vm_num) @@ -547,7 +540,7 @@ nasal_val* builtin_sin(nasal_val* local_scope,nasal_gc& gc) ret_addr->ptr.num=sin(val_addr->ptr.num); return ret_addr; } -nasal_val* builtin_cos(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_cos(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* val_addr=builtin_find("x"); if(val_addr->type!=vm_num) @@ -559,7 +552,7 @@ nasal_val* builtin_cos(nasal_val* local_scope,nasal_gc& gc) ret_addr->ptr.num=cos(val_addr->ptr.num); return ret_addr; } -nasal_val* builtin_tan(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_tan(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* val_addr=builtin_find("x"); if(val_addr->type!=vm_num) @@ -571,7 +564,7 @@ nasal_val* builtin_tan(nasal_val* local_scope,nasal_gc& gc) ret_addr->ptr.num=tan(val_addr->ptr.num); return ret_addr; } -nasal_val* builtin_exp(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_exp(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* val_addr=builtin_find("x"); if(val_addr->type!=vm_num) @@ -583,7 +576,7 @@ nasal_val* builtin_exp(nasal_val* local_scope,nasal_gc& gc) ret_addr->ptr.num=exp(val_addr->ptr.num); return ret_addr; } -nasal_val* builtin_ln(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_ln(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* val_addr=builtin_find("x"); if(val_addr->type!=vm_num) @@ -595,7 +588,7 @@ nasal_val* builtin_ln(nasal_val* local_scope,nasal_gc& gc) ret_addr->ptr.num=(log(val_addr->ptr.num)/log(2.7182818284590452354)); return ret_addr; } -nasal_val* builtin_sqrt(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_sqrt(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* val_addr=builtin_find("x"); if(val_addr->type!=vm_num) @@ -607,7 +600,7 @@ nasal_val* builtin_sqrt(nasal_val* local_scope,nasal_gc& gc) ret_addr->ptr.num=sqrt(val_addr->ptr.num); return ret_addr; } -nasal_val* builtin_atan2(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_atan2(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* x_val_addr=builtin_find("x"); nasal_val* y_val_addr=builtin_find("y"); @@ -625,7 +618,7 @@ nasal_val* builtin_atan2(nasal_val* local_scope,nasal_gc& gc) ret_addr->ptr.num=atan2(y_val_addr->ptr.num,x_val_addr->ptr.num); return ret_addr; } -nasal_val* builtin_time(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_time(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* val_addr=builtin_find("begin_time"); if(val_addr->type!=vm_num) @@ -638,7 +631,7 @@ nasal_val* builtin_time(nasal_val* local_scope,nasal_gc& gc) ret_addr->ptr.num=time(&begin_time); return ret_addr; } -nasal_val* builtin_contains(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_contains(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* hash_addr=builtin_find("hash"); nasal_val* key_addr=builtin_find("key"); @@ -656,7 +649,7 @@ nasal_val* builtin_contains(nasal_val* local_scope,nasal_gc& gc) ret_addr->ptr.num=hash_addr->ptr.hash->check_contain(*key_addr->ptr.str); return ret_addr; } -nasal_val* builtin_delete(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_delete(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* hash_addr=builtin_find("hash"); nasal_val* key_addr=builtin_find("key"); @@ -674,7 +667,7 @@ nasal_val* builtin_delete(nasal_val* local_scope,nasal_gc& gc) hash_addr->ptr.hash->elems.erase(*key_addr->ptr.str); return gc.nil_addr; } -nasal_val* builtin_getkeys(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_getkeys(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* hash_addr=builtin_find("hash"); if(hash_addr->type!=vm_hash) @@ -693,14 +686,14 @@ nasal_val* builtin_getkeys(nasal_val* local_scope,nasal_gc& gc) } return ret_addr; } -nasal_val* builtin_import(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_import(std::unordered_map& local_scope,nasal_gc& gc) { // this function is used in preprocessing. // this function will return nothing when running. builtin_err("import","cannot use import when running"); return nullptr; } -nasal_val* builtin_die(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_die(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* str_addr=builtin_find("str"); if(str_addr->type!=vm_str) @@ -708,10 +701,10 @@ nasal_val* builtin_die(nasal_val* local_scope,nasal_gc& gc) builtin_err("die","\"str\" must be string"); return nullptr; } - std::cout<<">> [vm] error: "<ptr.str<<'\n'; + std::cout<<">> [vm] error: "<<*str_addr->ptr.str<<'\n'; return nullptr; } -nasal_val* builtin_type(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_type(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* val_addr=builtin_find("object"); nasal_val* ret_addr=gc.gc_alloc(vm_str); @@ -726,7 +719,7 @@ nasal_val* builtin_type(nasal_val* local_scope,nasal_gc& gc) } return ret_addr; } -nasal_val* builtin_substr(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_substr(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* str_addr=builtin_find("str"); nasal_val* beg_addr=builtin_find("begin"); @@ -760,7 +753,7 @@ nasal_val* builtin_substr(nasal_val* local_scope,nasal_gc& gc) *ret_addr->ptr.str=str.substr(beg,len); return ret_addr; } -nasal_val* builtin_streq(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_streq(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* a_addr=builtin_find("a"); nasal_val* b_addr=builtin_find("b"); @@ -768,7 +761,7 @@ nasal_val* builtin_streq(nasal_val* local_scope,nasal_gc& gc) ret_addr->ptr.num=(a_addr->type!=vm_str || b_addr->type!=vm_str)?0:(*a_addr->ptr.str==*b_addr->ptr.str); return ret_addr; } -nasal_val* builtin_left(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_left(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* str_addr=builtin_find("string"); nasal_val* len_addr=builtin_find("length"); @@ -790,7 +783,7 @@ nasal_val* builtin_left(nasal_val* local_scope,nasal_gc& gc) *ret_addr->ptr.str=str.substr(0, len); return ret_addr; } -nasal_val* builtin_right(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_right(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* str_addr=builtin_find("string"); nasal_val* len_addr=builtin_find("length"); @@ -815,7 +808,7 @@ nasal_val* builtin_right(nasal_val* local_scope,nasal_gc& gc) *ret_addr->ptr.str=str.substr(srclen-len, srclen); return ret_addr; } -nasal_val* builtin_cmp(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_cmp(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* a_addr=builtin_find("a"); nasal_val* b_addr=builtin_find("b"); @@ -833,7 +826,7 @@ nasal_val* builtin_cmp(nasal_val* local_scope,nasal_gc& gc) ret_addr->ptr.num=strcmp(a_addr->ptr.str->data(),b_addr->ptr.str->data()); return ret_addr; } -nasal_val* builtin_chr(nasal_val* local_scope,nasal_gc& gc) +nasal_val* builtin_chr(std::unordered_map& local_scope,nasal_gc& gc) { nasal_val* code_addr=builtin_find("code"); if(code_addr->type!=vm_num) diff --git a/nasal_codegen.h b/nasal_codegen.h index e1a31ae..c7f61fe 100644 --- a/nasal_codegen.h +++ b/nasal_codegen.h @@ -395,7 +395,7 @@ void nasal_codegen::func_gen(nasal_ast& ast) } } exec_code[newfunc_label].num=exec_code.size()+1; - int ptr=exec_code.size(); + int jmp_ptr=exec_code.size(); gen(op_jmp,0); nasal_ast& block=ast.get_children()[1]; @@ -407,7 +407,7 @@ void nasal_codegen::func_gen(nasal_ast& ast) nil_gen(); gen(op_ret,0); } - exec_code[ptr].num=exec_code.size(); + exec_code[jmp_ptr].num=exec_code.size(); return; } diff --git a/nasal_gc.h b/nasal_gc.h index d62136d..8b690d1 100644 --- a/nasal_gc.h +++ b/nasal_gc.h @@ -6,7 +6,6 @@ enum nasal_type vm_nil=0, vm_num, vm_str, - vm_scop, vm_func, vm_vec, vm_hash @@ -48,14 +47,6 @@ struct nasal_func nasal_func(); }; -struct nasal_scop -{ - std::unordered_map elems; - - nasal_val* get_val(int); - nasal_val** get_mem(int); -}; - struct nasal_val { bool mark; @@ -67,7 +58,6 @@ struct nasal_val nasal_vec* vec; nasal_hash* hash; nasal_func* func; - nasal_scop* scop; }ptr; nasal_val(); @@ -232,20 +222,6 @@ nasal_func::nasal_func() return; } -/*functions of nasal_scop*/ -nasal_val* nasal_scop::get_val(int key) -{ - if(elems.count(key)) - return elems[key]; - return nullptr; -} -nasal_val** nasal_scop::get_mem(int key) -{ - if(elems.count(key)) - return &(elems[key]); - return nullptr; -} - /*functions of nasal_val*/ nasal_val::nasal_val() { @@ -264,7 +240,6 @@ nasal_val::nasal_val(int val_type) case vm_vec: ptr.vec=new nasal_vec; break; case vm_hash: ptr.hash=new nasal_hash; break; case vm_func: ptr.func=new nasal_func; break; - case vm_scop: ptr.scop=new nasal_scop; break; } return; } @@ -276,7 +251,6 @@ nasal_val::~nasal_val() case vm_vec: delete ptr.vec; break; case vm_hash: delete ptr.hash; break; case vm_func: delete ptr.func; break; - case vm_scop: delete ptr.scop; break; } type=vm_nil; return; @@ -289,7 +263,6 @@ void nasal_val::clear() case vm_vec: delete ptr.vec; break; case vm_hash: delete ptr.hash; break; case vm_func: delete ptr.func; break; - case vm_scop: delete ptr.scop; break; } type=vm_nil; return; @@ -304,7 +277,6 @@ void nasal_val::set_type(int val_type) case vm_vec: ptr.vec=new nasal_vec; break; case vm_hash: ptr.hash=new nasal_hash; break; case vm_func: ptr.func=new nasal_func; break; - case vm_scop: ptr.scop=new nasal_scop; break; } return; } @@ -329,14 +301,14 @@ struct nasal_gc nasal_val* zero_addr; // reserved address of nasal_val,type vm_num, 0 nasal_val* one_addr; // reserved address of nasal_val,type vm_num, 1 nasal_val* nil_addr; // reserved address of nasal_val,type vm_nil - nasal_val* global; // global scope address,type vm_scop nasal_val* val_stack[STACK_MAX_DEPTH]; nasal_val** stack_top; // stack top std::vector num_addrs; // reserved address for const vm_num - std::vector local; // local scope for function block std::vector slice_stack; // slice stack for vec[val,val,val:val] std::vector memory; // gc memory std::queue free_list; // gc free list + std::unordered_map global; + std::vector > local; void mark(); void sweep(); void gc_init(std::vector&); @@ -351,14 +323,16 @@ void nasal_gc::mark() zero_addr->mark=true; one_addr->mark=true; nil_addr->mark=true; - bfs.push(global); + for(auto i=global.begin();i!=global.end();++i) + bfs.push(i->second); int size=num_addrs.size(); for(int i=0;ibegin();j!=i->end();++j) + bfs.push(j->second); size=slice_stack.size(); for(int i=0;imark) bfs.push(*i); } - else if(tmp->type==vm_scop) - { - std::unordered_map& scop=tmp->ptr.scop->elems; - for(auto i=scop.begin();i!=scop.end();++i) - if(!i->second->mark) - bfs.push(i->second); - } } return; } @@ -442,9 +409,6 @@ void nasal_gc::gc_init(std::vector& nums) *val_stack=nil_addr; // the first space will not store any values,but gc checks - global=new nasal_val(vm_scop); // init global symbol table - memory.push_back(global); - num_addrs.clear(); // init constant numbers for(int i=0;iptr.scop->elems[exec_code[pc].num]=*stack_top--; + gc.global[exec_code[pc].num]=*stack_top--; return; } void nasal_vm::opr_loadl() { - gc.local.back()->ptr.scop->elems[exec_code[pc].num]=*stack_top--; + gc.local.back()[exec_code[pc].num]=*stack_top--; return; } void nasal_vm::opr_pnum() @@ -204,7 +204,7 @@ void nasal_vm::opr_newf() nasal_val* val=gc.gc_alloc(vm_func); val->ptr.func->entry=exec_code[pc].num; if(!gc.local.empty()) - val->ptr.func->closure=gc.local.back()->ptr.scop->elems; + val->ptr.func->closure=gc.local.back(); val->ptr.func->closure[me]=gc.nil_addr; *(++stack_top)=val; return; @@ -525,12 +525,12 @@ void nasal_vm::opr_feach() } void nasal_vm::opr_callg() { - *(++stack_top)=gc.global->ptr.scop->elems[exec_code[pc].num]; + *(++stack_top)=gc.global[exec_code[pc].num]; return; } void nasal_vm::opr_calll() { - *(++stack_top)=gc.local.back()->ptr.scop->elems[exec_code[pc].num]; + *(++stack_top)=gc.local.back()[exec_code[pc].num]; return; } void nasal_vm::opr_callv() @@ -633,14 +633,12 @@ void nasal_vm::opr_callf() return; } // push new local scope - nasal_val* closure=gc.gc_alloc(vm_scop); - gc.local.push_back(closure); + gc.local.push_back(func_addr->ptr.func->closure); // load parameters nasal_func& ref_func=*func_addr->ptr.func; std::vector& ref_para=ref_func.para; std::vector& ref_default=ref_func.default_para; - std::unordered_map& ref_closure=closure->ptr.scop->elems; - ref_closure=ref_func.closure; + std::unordered_map& ref_closure=gc.local.back(); if(para_addr->type==vm_vec) { @@ -677,7 +675,8 @@ void nasal_vm::opr_callf() die("callf: special call cannot use dynamic parameter"); return; } - for(int i=0;iptr.scop->elems[exec_code[pc].num]); + addr_stack.push(&gc.global[exec_code[pc].num]); return; } void nasal_vm::opr_mcalll() { - addr_stack.push(&gc.local.back()->ptr.scop->elems[exec_code[pc].num]); + addr_stack.push(&gc.local.back()[exec_code[pc].num]); return; } void nasal_vm::opr_mcallv() diff --git a/test/lib.nas b/stl/lib.nas similarity index 99% rename from test/lib.nas rename to stl/lib.nas index 2974927..a094a7a 100644 --- a/test/lib.nas +++ b/stl/lib.nas @@ -155,3 +155,5 @@ var math= sqrt: func(x) {return __builtin_sqrt(x); }, atan2: func(x,y){return __builtin_atan2(x,y);} }; + +var D2R=math.pi/180; \ No newline at end of file diff --git a/stl/list.nas b/stl/list.nas new file mode 100644 index 0000000..98109f6 --- /dev/null +++ b/stl/list.nas @@ -0,0 +1,73 @@ +# lib list.nas +# valkmjolnir 2021/3/31 +var list=func() +{ + var _={begin:nil,end:nil}; + return + { + push_back:func(elem) + { + var tmp={elem:elem,prev:nil,next:nil}; + if(_.end!=nil) + { + _.end.next=tmp; + tmp.prev=_.end; + _.end=tmp; + } + else + { + _.begin=tmp; + _.end=tmp; + } + return; + }, + push_front:func(elem) + { + var tmp={elem:elem,prev:nil,next:nil}; + if(_.begin!=nil) + { + _.begin.prev=tmp; + tmp.next=_.begin; + _.begin=tmp; + } + else + { + _.begin=tmp; + _.end=tmp; + } + return; + }, + pop_back:func() + { + if(_.end!=nil) + _.end=_.end.prev; + if(_.end==nil) + _.begin=nil; + else + _.end.next=nil; + return; + }, + pop_front:func() + { + if(_.begin!=nil) + _.begin=_.begin.next; + if(_.begin==nil) + _.end=nil; + else + _.begin.prev=nil; + return; + }, + front:func() + { + if(_.begin!=nil) + return _.begin.elem; + return nil; + }, + back:func() + { + if(_.end!=nil) + return _.end.elem; + return nil; + }, + }; +} \ No newline at end of file diff --git a/test/queue.nas b/stl/queue.nas similarity index 100% rename from test/queue.nas rename to stl/queue.nas diff --git a/stl/sort.nas b/stl/sort.nas new file mode 100644 index 0000000..0e5c3a1 --- /dev/null +++ b/stl/sort.nas @@ -0,0 +1,27 @@ +# lib sort.nas +# valkmjolnir 2021/4/2 +var sort=func(vec,left,right,cmp=func(a,b){return a<=b;}) +{ + if(left>=right) return nil; + var L=left; + var R=right; + var tmp=vec[L]; + while(left0? x:0; - }, - diffrelu_func:func(x) - { - return x>0; - }, - leaky_relu_func:func(k,x) - { - return x>0? x:k*x; - }, - diffleaky_relu_func:func(k,x) - { - return x>0? 1:k; - } -}; - -var matrix= -{ - new:func(col,row) - { - var new_mat= - { - col:col, - row:row, - mat:[] - }; - for(var i=0;i0.5) - mat.mat[i][j]=-rand(); - else - mat.mat[i][j]=rand(); - } - return; - }, - prt_mat:func(mat) - { - var prt_s='[\n'; - foreach(var i;mat.mat) - { - prt_s~='['; - foreach(var j;i) - prt_s~=(j~','); - prt_s~='],\n'; - } - prt_s~=']\n'; - print(prt_s); - return nil; - }, - mult_mat:func(mat1,mat2) - { - if(mat1.col!=mat2.row) - { - die("[error-mult] mat1\'s col does not match mat2\'s row."); - return nil; - } - var new_mat=me.new(mat2.col,mat1.row); - for(var i=0;i0.01) - { - error=0; - for(var i=0;i<4;i+=1) - { - me.forward(i); - error+=me.backward(i); - } - print(error); - } - return; - } -}; -var main=func() -{ - bp.init(); - bp.set_learning_rate(0.1); - bp.set_training_set(); - bp.set_expect_set(); - bp.training_process(); - return nil; -} - -main(); diff --git a/test/auto_crash.nas b/test/auto_crash.nas index 597e858..e13c864 100644 --- a/test/auto_crash.nas +++ b/test/auto_crash.nas @@ -1,5 +1,8 @@ -# Road check and auto pilot(??) by ValKmjolnir - +# Road check and auto pilot by ValKmjolnir +var dt=0.01; +var intergral=0; +var derivative=0; +var previous_error=0; var position_change = func(position_val,value){ if(position_val+value>180) position_val += value-360; @@ -10,12 +13,11 @@ var position_change = func(position_val,value){ return position_val; } var road_check_func = func(){ - + var lat = props.getNode("/position/latitude-deg",1).getValue(); var lon = props.getNode("/position/longitude-deg",1).getValue(); var position_info = geodinfo(lat,lon); var position_names = position_info[1].names; - # the friction_factor of freeway runway and road is 1 if((position_names[0]=="Freeway") or (position_names[0]=="Road")) { @@ -24,14 +26,14 @@ var road_check_func = func(){ var lon_change = 0; var left_range = 0; var right_range = 0; - + for(var i=0;i>-0.00005;i-=0.000001) { car_heading = props.getNode("/orientation/heading-deg",1).getValue(); - lat_change = math.sin(math.pi*car_heading/180); - lon_change = -math.cos(math.pi*car_heading/180); - lat = props.getNode("/position/latitude-deg",1).getValue()+0.0001*math.cos(math.pi*car_heading/180); - lon = props.getNode("/position/longitude-deg",1).getValue()+0.0001*math.sin(math.pi*car_heading/180); + lat_change = math.sin(D2R*car_heading); + lon_change = -math.cos(D2R*car_heading); + lat = props.getNode("/position/latitude-deg",1).getValue()+0.0001*math.cos(D2R*car_heading); + lon = props.getNode("/position/longitude-deg",1).getValue()+0.0001*math.sin(D2R*car_heading); var other_position_info = geodinfo(position_change(lat,i*lat_change),position_change(lon,i*lon_change)); var other_names = other_position_info[1].names; if((other_names[0]=="Freeway") or (other_names[0]=="Road")) @@ -42,10 +44,10 @@ var road_check_func = func(){ for(var i=0;i<0.00005;i+=0.000001) { car_heading = props.getNode("/orientation/heading-deg",1).getValue(); - lat_change = math.sin(math.pi*car_heading/180); - lon_change = -math.cos(math.pi*car_heading/180); - lat = props.getNode("/position/latitude-deg",1).getValue()+0.0001*math.cos(math.pi*car_heading/180); - lon = props.getNode("/position/longitude-deg",1).getValue()+0.0001*math.sin(math.pi*car_heading/180); + lat_change = math.sin(D2R*car_heading); + lon_change = -math.cos(D2R*car_heading); + lat = props.getNode("/position/latitude-deg",1).getValue()+0.0001*math.cos(D2R*car_heading); + lon = props.getNode("/position/longitude-deg",1).getValue()+0.0001*math.sin(D2R*car_heading); var other_position_info = geodinfo(position_change(lat,i*lat_change),position_change(lon,i*lon_change)); var other_names = other_position_info[1].names; if((other_names[0]=="Freeway") or (other_names[0]=="Road")) @@ -53,25 +55,26 @@ var road_check_func = func(){ else break; } - #if(left_range>right_range) - #{ - # setprop("/controls/flight/rudder",-(right_range-left_range)*(right_range-left_range)/10000); - # print("right ",right_range); - #} - #else if(left_range0) + props.getNode("/", 1).setValue("/controls/flight/rudder",Kp*error*error+Ki*intergral+Kd*derivative); + else + props.getNode("/", 1).setValue("/controls/flight/rudder",0); + previous_error=error; } }; -var road_check_timer = maketimer(0.1,road_check_func); + +var road_check_timer = maketimer(0.01,road_check_func); var toggle_auto_pilot = func(){ if(!road_check_timer.isRunning) { + intergral=0; road_check_timer.start(); props.getNode("/sim/messages/copilot",1).setValue("ze dong sheng teaan see tong yee tse yung. Auto Sheng Teaan System Activated!"); } @@ -80,4 +83,4 @@ var toggle_auto_pilot = func(){ road_check_timer.stop(); props.getNode("/sim/messages/copilot",1).setValue("ze dong sheng teaan see tong yee guan bee. Auto Sheng Teaan System is off."); } -} \ No newline at end of file +} diff --git a/test/bfs.nas b/test/bfs.nas index 81499fc..450cd27 100644 --- a/test/bfs.nas +++ b/test/bfs.nas @@ -1,5 +1,5 @@ -import("lib.nas"); -import("queue.nas"); +import("stl/lib.nas"); +import("stl/queue.nas"); rand(time(0)); @@ -26,13 +26,13 @@ var prt=func() var bfs=func(begin,end) { var move=[[1,0],[0,1],[-1,0],[0,-1]]; - var queue=new_queue(); - queue_push(queue,begin); + var que=queue(); + que.push(begin); map[begin[0]][begin[1]]=3; - while(!queue_empty(queue)) + while(!que.empty()) { - var vertex=queue_front(queue); - queue_pop(queue); + var vertex=que.front(); + que.pop(); foreach(var i;move) { var x=vertex[0]+i[0]; @@ -44,7 +44,7 @@ var bfs=func(begin,end) } if(0<=x and x<10 and 0<=y and y<10 and map[x][y]==0) { - queue_push(queue,[x,y]); + que.push([x,y]); map[x][y]=3; } } diff --git a/test/bp.nas b/test/bp.nas index 81c6594..67304b9 100644 --- a/test/bp.nas +++ b/test/bp.nas @@ -137,7 +137,7 @@ while(error>0.001) } cnt+=1; show+=1; - if(show==250) + if(show==300) { show=0; print('epoch ',cnt,':',error,'\r'); diff --git a/test/class.nas b/test/class.nas index 1f5e262..542c978 100644 --- a/test/class.nas +++ b/test/class.nas @@ -17,7 +17,11 @@ var student=func(name,age) var s=student('valk',24); s.print_info(); println(s.get_age(),' ',s.get_name()); -s.set_age(18); +s.set_age(20); s.set_name('aluo'); s.print_info(); +println(s.get_age(),' ',s.get_name()); +s.set_age(20); +s.set_name('Sidi Liang'); +s.print_info(); println(s.get_age(),' ',s.get_name()); \ No newline at end of file diff --git a/test/efb.nas b/test/efb.nas deleted file mode 100644 index 01c964d..0000000 --- a/test/efb.nas +++ /dev/null @@ -1,2044 +0,0 @@ -#// Wrappers for property I/O, for conveniently switching between two methods -var setProp = func(prop, value){ - #// setprop(prop, value); - props.getNode("/").setValue(prop, value); -} -var getProp = func(prop){ - #// getprop(prop); - props.getNode("/").getValue(prop); -} - -var ChartsList = -{ - 'KATL': - { - STAR: ["STAR_CANUK1_RNAV", "STAR_ERLIN9_RNAV", "STAR_FLCON7_RNAV", "STAR_HERKO6_RNAV", "STAR_HONIE8_RNAV", "STAR_LA_GRANGE2", "STAR_PECHY7_RNAV", "STAR_ROME4", "STAR_RPTOR1_RNAV", "STAR_SINCA5", "STAR_VIKNN_3RNAV", "STAR_WHINZ1"], - STARs: 12, - IAP: ["ILS_8L_Cat II - III", "ILS_PRM_8L", "ILS_PRM_8L_CAT II - III", "ILS_PRM_8R", "ILS_PRM_9L", "ILS-LOC_8L", "ILS-LOC_8R", "ILS-LOC_9L"], - IAPs: 8, - SID: ["SID_ATL5", "SID_BRAV6_RNAV", "SID_CADIT6_RNAV", "SID_COKEM5_RNAV", "SID_DAWGS5_RNAV", "SID_DOOLY5_RNAV", "SID_GEETK6_RNAV", "SID_JCKTS6_RNAV", "SID_JOGOR4_RNAV", "SID_MUNSN5_RNAV", "SID_NOVSS4_RNAV", "SID_NUGGT5_RNAV"], - SIDs: 12, - APT: "APT_0", - APTs: 1, - LOCATION: "ATLANTA USA", - NAME: "Hartsfield-Jackson" - }, - 'KLAX': - { - STAR: "REDEYE2", - STARs: 1, - IAP: ["06L-ILS", "06R-ILS", "07L-ILS", "07R-ILS"], - IAPs: 4, - SID: "SNGO6", - SIDs: 1, - APT: "APT_0", - APTs: 1, - LOCATION: "LOS ANGELES USA", - NAME: "Intntl" - }, - 'KIAH': - { - STAR: ["RIICE3_1", "RIICE_2"], - STARs: 2, - IAP: ["09-ILS", "15R-ILS"], - IAPs: 2, - SID: "", - SIDs: 0, - APT: "APT_0", - APTs: 1, - LOCATION: "HOUSTON USA", - NAME: "G. Bush Intctl" - }, - 'VABB': - { - STAR: "", - STARs: 0, - IAP: ["09-ILS-DME", "14-ILS-DME"], - IAPs: 2, - SID: "EKPOSxA", - SIDs: 1, - APT: "APT_0", - APTs: 1, - LOCATION: "MUMBAI IN", - NAME: "Chhatrapati Shivaji" - }, - 'KMEM': - { - STAR: "BEERT4", - STARs: 1, - IAP: "09-ILS_LOC", - IAPs: 1, - SID: "", - SIDs: 0, - APT: "APT_0", - APTs: 1, - LOCATION: "MEMPHIS USA", - NAME: "International" - }, - 'LFRB': - { - STAR: "STAR", - STARs: 1, - IAP: ["IAP_25L", "IAP_25L_RNAV", "ILS_Y_25L", "ILS_YZ_07R", "ILS_Z_25L", "NDB_25L", "RADAR", "RNAV_07R", "VFR_APP01", "VFR_LNDG_01"], - IAPs: 11, - SID: ["SID_07R", "SID_25L"], - SIDs: 2, - APT: ["APT_0", "APT_1"], - APTs: 2, - LOCATION: "BREST FR", - NAME: "Guipavas" - }, - 'LFRM': - { - STAR: ["VFR_APP01", "VFR_LND01"], - STARs: 2, - IAP: "", - IAPs: 0, - SID: "", - SIDs: 0, - APT: "APT_0", - APTs: 1, - LOCATION: "LE MANS FR", - NAME: "Arnage" - }, - 'LIME': - { - STAR: ["STAR_ASTIG_ODINA_1S", "STAR_ASTIG_ODINA_1T", "STAR_DIXER_GEN_IDONA_1S", "STAR_DIXER_GEN_IDONA_1T", "STAR_DORIN_LUSIL_OSKOR_1S", "STAR_DORIN_LUSIL_OSKOR_1T", "STAR_East", "STAR_West", "STAR_VOR_DME", "VOR_Y28", "VOR_Y28_2", "VOR_Z28"], - STARs: 12, - IAP: ["ILS-PAPA-28", "ILS-PAPA-28-CAT II", "ILS-SIERRA-28", "ILS-SIERRA-28-CAT II", "ILS-TANGO-28", "ILS-TANGO-28-CAT II", "ILS-X28", "ILS-Y28", "ILS-Z28"], - IAPs: 9, - SID: ["SID_10_BEKAN_DORIN_5S", "SID_10-28_BEKAN5T_DORIN5T_ORI5QT", "SID_10-28_Alternate", "SID_28_SRN5R_TZO5R_TZO5S", "SID_InitialClimb", "SID10_InitialClimb", "SID28_InitialClimb", "SID28_InitialClimb2", "DEP_North_East", "DEP_South", "DEP_West"], - SIDs: 12, - APT: ["APT_0", "APT_0_Small", "GROUND_East_Apron", "GROUND_North_Apron", "GROUND_West_Apron"], - APTs: 6, - LOCATION: "BERGAMO IT", - NAME: "Orio al Serio" - }, - 'LOWI': - { - STAR: ["26-RTT", "STAR", "VFR_East", "VFR_West_KTI", "West-NDB_KYI"], - STARs: 5, - IAP: ["LOC_26_RNAV", "LOC_DME_East", "LOC_DME_West", "NDB_East", "RNAV_08", "RNAV_26", "SPEC_LOC_DME_East"], - IAPs: 8, - SID: ["08-RTT", "General Departure", "SID_08", "SID0_RTT1W", "SID_08_SPECPERF_KPT1Z", "SID_08_SPECPERF_RTT2Z", "SID-26", "SID_26_MOGTI1H_RTT1Y", "SID_26_RNAV"], - SIDs: 9, - APT: ["APT_0", "APT_1"], - APTs: 2, - LOCATION: "INNSBRUCK AT", - NAME: "Kranebitten" - }, - 'WSSS': - { - STAR: ["BOBAG1A", "BOBAG1B", "LAVAX1A", "LAVAX1B"], - STARs: 4, - IAP: ["02C-VOR-DME", "02L-ILS", "02L-ILS-CATII", "20C-VOR-DME", "20R-ILS"], - IAPs: 5, - SID: "BOG1", - SIDs: 1, - APT: ["APT_0", "APT_1"], - APTs: 2, - LOCATION: "SINGAPORE SG", - NAME: "Changi" - }, -}; - -# used in page -var l=[]; -var r=[]; -for(var i=0;i<21;i+=1) -{ - append(l,""); - append(r,""); -} -var KCl0_0 = ""; -var KCl0_1 = ""; -var KCl0 = ""; -var KCl1 = ""; -var KCl2 = ""; -var KCl3 = ""; -var KCl4 = ""; -var KCr1 = ""; -var KCr2 = ""; -var KCr3 = ""; -var KCr4 = ""; -var KCr5 = ""; -var KCr6 = ""; -var ChartName = ["NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL", "NULL"]; -var ChartDisp = ["NULL", "NULL", "NULL"]; -var Keyboard_Helper = ""; -var Keyboard_Message = ""; -var Index_Max = 0; -var Index_Offset = 0; -var PageList = 0; - -# used in efb -var ZoomFact = 0; -var PanHFact = 0; -var PanVFact = 0; -var OriginApt = "NOT Set"; -var DestinationApt = "NOT Set"; -var ClosingFlightFlag = 0; -var lenght = 0; -var Temp_String = ""; -var Cnv_Fact = 0; -var VK_Key = ""; -var VK_Input_Mem = 0; -var VK_Output_Mem = 0; -var TMZ_Input_Lenght = 0; -var TMZ_Converted_ID = ""; -var TMZ_Converted_Name = ""; -var TMZ_Converted_OffSet = ""; -var TMZ_zulu_HH = ""; -var TMZ_Index = 0; -var TMZ_DB_Size = 0; -var Output_TMZ_Line = ""; -var TMZ_DATE = ""; -var TMZ_TIME = ""; -var Output_HH = 0; -var Output_MM = 0; -var CUT = ["NULL", "NULL", "NULL"]; -var Initial_FL = 0; -var Target_FL = 0; -var Initial_GS = 0; -var Target_GS = 0; -var DRC_String = ""; -var DRC_Input_Lenght = 0; - -# public vars -var helper = ""; -var keypress = ""; -var nochart = ""; -var AptName = "Unknown"; -var Chart_Pages = 1; -var DRC_Distance = 0; -var DRC_l3 = ""; -var DRC_r3 = ""; -var DRC_l5 = ""; -var DRC_r5 = ""; -var DRC_l7 = ""; -var DRC_r8 = ""; -var DRC_r9 = ""; -var DRC_r10 =""; - -# Chart Properties -ident = getProp("/sim/airport/closest-airport-id"); -#AptName = getProp("/instrumentation/efb/chart/icao"); - -if (ident != nil) -{ - setProp("instrumentation/efb/chart/icao", ident); - setProp("instrumentation/efb/chart/DEP_icao", getProp("/instrumentation/efb/chart/icao")); -} else setProp("/instrumentation/efb/chart/icao", ""); -setProp("/instrumentation/efb/chart/type", "APT"); -setProp("/instrumentation/efb/chart/newairport", 0); -setProp("/instrumentation/efb/FlightStatus", 0); # INACTIVE -nochart = 0; - -var page = { - update : func { - for(var i=0; i<21; i+=1) - setProp("/instrumentation/efb/display/line"~i~"-l", l[i]); - # r[0] haven't been used - for(var i=1; i<21; i+=1) - setProp("/instrumentation/efb/display/line"~i~"-r", r[i]); - setProp("/instrumentation/efb/display/input-helper", helper); - setProp("/instrumentation/efb/keypress", keypress); - return; - }, - clearpage : func { - for(var i=0; i<21; i+=1){ - l[i] = ""; - r[i] = ""; - } - helper = ""; - return; - }, - index : func { - for(var i=0; i<21; i+=1){ - l[i] = ""; - r[i] = ""; - } - return; - }, - index_TEST : func { - for(var i=0; i<21; i+=1) - l[i] = "< TEST_L"~i; - # r[0] haven't been used - for(var i=1; i<15; i+=1) - r[i] = "TEST >"; - for(var i=15; i<21; i+=1) - r[i] = "TEST_R"~i~" >"; - return; - }, - KCupdate : func { - setProp("/instrumentation/efb/display/lineAPT_NAME", KCl0); - setProp("/instrumentation/efb/display/lineAPT_LOCATION", KCl0_0); - setProp("/instrumentation/efb/display/lineAPT_PAGESHOW", KCl0_1); - setProp("/instrumentation/efb/display/lineSTAR", KCl1); - setProp("/instrumentation/efb/display/lineIAP", KCl2); - setProp("/instrumentation/efb/display/lineSID", KCl3); - setProp("/instrumentation/efb/display/lineAPT", KCl4); - - setProp("/instrumentation/efb/display/lineCHART1-r", KCr1); - setProp("/instrumentation/efb/display/lineCHART2-r", KCr2); - setProp("/instrumentation/efb/display/lineCHART3-r", KCr3); - - setProp("/instrumentation/efb/Keyboard/CHART_Input_Line", Keyboard_Helper); - setProp("/instrumentation/efb/Keyboard/CHART_Output_Line", Keyboard_Message); - }, - KCclearpage : func { - KCl0 = ""; - KCl0_0 = ""; - KCl0_1 = ""; - KCl1 = ""; - KCl2 = ""; - KCl3 = ""; - KCl4 = ""; - - KCr1 = ""; - KCr2 = ""; - KCr3 = ""; - - Keyboard_Helper = ""; - Keyboard_Message = ""; - helper = ""; - }, - DRCupdate : func { - setProp("/instrumentation/efb/display/DRC_l3", DRC_l3); - setProp("/instrumentation/efb/display/DRC_l5", DRC_l5); - setProp("/instrumentation/efb/display/DRC_r3", DRC_r3); - setProp("/instrumentation/efb/display/DRC_r5", DRC_r5); - setProp("/instrumentation/efb/display/DRC_l7", DRC_l7); - setProp("/instrumentation/efb/display/DRC_r8", DRC_r8); - setProp("/instrumentation/efb/display/DRC_r9", DRC_r9); - setProp("/instrumentation/efb/display/DRC_r10", DRC_r10); - }, - DRCclearpage : func { - DRC_l3 = ""; - DRC_l5 = ""; - DRC_r3 = ""; - DRC_r5 = ""; - DRC_l7 = ""; - DRC_r8 = ""; - DRC_r9 = ""; - DRC_r10 = ""; - }, - airportinfo : func { - var ClosestName = ""; - if (getProp("/instrumentation/gps/scratch/name") == nil) - ClosestName = ""; - else - ClosestName = getProp("/instrumentation/gps/scratch/name"); - l[2] = "Airport : " ~ getProp("/instrumentation/gps/scratch/ident") ~ " (" ~ ClosestName ~ ")"; - l[3] = "Latitude : " ~ sprintf("%3.4f", getProp("/instrumentation/gps/scratch/latitude-deg")); - l[4] = "Longitude : " ~ sprintf("%3.4f", getProp("/instrumentation/gps/scratch/longitude-deg")); - l[5] = "Elevation : " ~ sprintf("%3.4f", getProp("/instrumentation/gps/scratch/altitude-ft")) ~ " ft"; - setProp("/environment/metar[6]/station-id", getProp("/instrumentation/gps/scratch/ident")); - l[7] = "Runways : "; - l[8] = " "; - for (var n=0; n<12; n+=1) { - if (getProp("/instrumentation/gps/scratch/runways[" ~ n ~ "]/id") != nil) { - if (n <= 7) l[7] = l[7] ~ getProp("/instrumentation/gps/scratch/runways[" ~ n ~ "]/id") ~ " "; - else l[8] = l[8] ~ getProp("/instrumentation/gps/scratch/runways[" ~ n ~ "]/id") ~ " "; - } - l[10] = "Weather Source: NOAA/METAR"; - r[10] = substr(getProp("/environment/metar[6]/data"),0,16) ~ "z"; - l[11] = substr(getProp("/environment/metar[6]/data"),17,41); - if (size(getProp("/environment/metar[6]/data")) > 41) - l[12] = substr(getProp("/environment/metar[6]/data"), 58, 41); - l[13] = " Current Weather Situation"; - l[14] = "Temperature : " ~ sprintf("%3.2f", getProp("/environment/metar[6]/temperature-degc")) ~ " �C"; - r[14] = "Dewpoint : " ~ sprintf("%3.2f", getProp("/environment/metar[6]/dewpoint-degc")) ~ " �C"; - l[15] = "Wind Direction : " ~ sprintf("%3.0f", getProp("/environment/metar[6]/base-wind-dir-deg")) ~ " degs"; - r[15] = "Wind Speed : " ~ sprintf("%3.0f", getProp("/environment/metar[6]/base-wind-speed-kt")) ~ " Kt"; - l[16] = "Max Visibility : " ~ sprintf("%3.0f", getProp("/environment/metar[6]/max-visibility-m")) ~ " ft"; - r[16] = "Min Visibility : " ~ sprintf("%3.0f", getProp("/environment/metar[6]/min-visibility-m")) ~ " ft"; - l[17] = "Relative Humidity : " ~ sprintf("%3.2f", getProp("/environment/metar[6]/rel-humidity-norm")) ~ " %"; - l[18] = "Pressure : " ~ sprintf("%3.2f", getProp("/environment/metar[6]/pressure-inhg")) ~ " inHg"; - l[20] = "Weather Report subject to Station availability"; - } - }, - FlightMonitor : func { - if (getProp("/instrumentation/efb/FlightStatus") == 1) { - var FStatus = "ACTIVE"; - } else FStatus = "INACTIVE"; - if (getProp("/autopilot/route-manager/active") == 1) { - if (getProp("/autopilot/route-manager/departure/takeoff-time") != nil) { - var TOT = getProp("/autopilot/route-manager/departure/takeoff-time") ~ "z"; - } else TOT = "Unknown"; - if (getProp("/autopilot/route-manager/destination/touchdown-time") != nil) { - var TDT = getProp("/autopilot/route-manager/destination/touchdown-time") ~ "z"; - } else TDT = "Unknown"; - var OAPT = getProp("/autopilot/route-manager/departure/airport") ~ " " ~ getProp("/autopilot/route-manager/departure/runway"); - var DAPT = getProp("/autopilot/route-manager/destination/airport") ~ " " ~ getProp("/autopilot/route-manager/destination/runway"); - } else { - OAPT = "NOT Set"; - DAPT = "NOT Set"; - TOT = "Unknown"; - TDT = "Unknown"; - } - l[2] = "Aircraft: " ~ getProp("/sim/description") ~ " Seattle"; - l[3] = "Operator: " ~ substr(getProp("/sim/aircraft-operator"),0,3); - r[3] = "CallSign: " ~ substr(getProp("/sim/multiplay/callsign"), 0,6); - l[4] = "Flight No: " ~ "NOT Set"; # This will be set through CDU (To be done) - r[4] = "Flight Status: " ~ FStatus; - l[5] = "Origin APT: " ~ OAPT; - r[5] = "TO Time: " ~ TOT; - l[6] = "Destination APT: " ~ DAPT; - r[6] = "TD Time: " ~ TDT; - l[7] = "Date: " ~ substr(getProp("environment/metar/data"),0,10); - r[7] = "Time: " ~ getProp("/instrumentation/clock/indicated-short-string") ~ "z"; - l[9] = "Ind. ALT: " ~ sprintf("%3.2f", getProp("/Instrumentation/altimeter/indicated-altitude-ft")) ~ " ft"; - r[9] = "Press. ALT: " ~ sprintf("%3.2f", getProp("/Instrumentation/altimeter/pressure-alt-ft")) ~ " ft"; - l[10] = "Press. hPa: " ~ sprintf("%3.2f", getProp("/Instrumentation/altimeter/setting-hpa")); - r[10] = "Press. inHg: " ~ sprintf("%3.2f", getProp("/Instrumentation/altimeter/setting-inhg")); - l[11] = "Speed Knots: " ~ sprintf("%3.0f", getProp("/Instrumentation/airspeed/indicated-speed-kt")); - r[11] = "Speed Mach: " ~ sprintf("%3.0f", getProp("/Instrumentation/airspeed/indicated-mach")); - l[12] = "Temperature �C: " ~ sprintf("%3.2f", getProp("/environment/temperature-degc")); - r[12] = "Temperature �F: " ~ sprintf("%3.2f", getProp("/environment/temperature-degf")); - l[13] = "Wind Dir.: " ~ sprintf("%3.0f", getProp("/environment/metar/base-wind-dir-deg")) ~ " degs"; - r[13] = "Wind Speed: " ~ sprintf("%3.0f", getProp("/environment/base-wind-speed-kt")) ~ " kts"; - l[14] = "Total Fuel: " ~ sprintf("%3.2f", getProp("/consumables/fuel/total-fuel-gals")) ~ " gals"; - l[15] = "Gross Weight: " ~ sprintf("%3.2f", getProp("/yasim/gross-weight-lbs")) ~ " lbs"; - # warning: this line l[14] has been changed to l[15],be careful of bugs.But it must be at the right side - }, - gps : func { - l[1] = " GPS POSITION / SETTINGS"; - l[2] = "Latitude : " ~ sprintf("%3.2f", getProp("/instrumentation/gps/indicated-latitude-deg")) ~ " degs"; - r[2] = "Longitude : " ~ sprintf("%3.2f", getProp("/instrumentation/gps/indicated-longitude-deg")) ~ " degs"; - l[13] = "GPS Mode: " ~ getProp("/instrumentation/gps/mode"); - r[13] = "WayPoint ID: " ~ getProp("/instrumentation/gps/wp/wp[1]/ID"); - l[14] = "Leg Distance: " ~ sprintf("%3.2f", getProp("/instrumentation/gps/wp/leg-distance-nm")) ~ " Nm"; - l[15] = "Leg Magnetic Course : " ~ sprintf("%3.2f", getProp("/instrumentation/gps/wp/leg-mag-course-deg")) ~ " degs"; - l[16] = "Leg True Heading: " ~ sprintf("%3.2f", getProp("/instrumentation/gps/wp/leg-true-course-deg")) ~ " degs"; - }, - charts_keyboard : func { - setProp("/instrumentation/efb/chart/Status", "ON"); - setProp("/instrumentation/efb/chart/type", "APT"); - PageList = getProp("/instrumentation/efb/chart/PageList"); - - # Checks existence of Charts in the DB by chart's type ~ "-0"; example: "KSFO/type-0" - var Chart_Search = ""; - Chart_Search = sprintf("%s", getProp("/instrumentation/efb/chart/icao")); - - # HERE we need to launch the SEARCH into the ChartsList hash - #if (getProp("/instrumentation/efb/chartsDB/" ~ sprintf("%s", getProp("/instrumentation/efb/chart/icao")) ~ "/" ~ getProp("/instrumentation/efb/chart/type") ~ "-0") == nil ) { - # setProp("/instrumentation/efb/chart_Found", "NOT_FOUND"); - # nochart = 1; - #} else { - # setProp("/instrumentation/efb/chart_Found", "FOUND"); - # nochart = 0; - #} - - setProp("/instrumentation/efb/Keyboard/CHART_Input_Line", "Charts for " ~ sprintf("%s", getProp("/instrumentation/efb/chart/icao")) ~ ": " ~ getProp("/instrumentation/efb/chart_Found")); - if (nochart == 0) { - # gets the APT's Name & Location - setProp("/instrumentation/efb/chart/type", "NAME"); - KCl0 = getProp("/instrumentation/efb/chartsDB/" ~ sprintf("%s", getProp("/instrumentation/efb/chart/icao")) ~ "/" ~ getProp("/instrumentation/efb/chart/type")); - setProp("/instrumentation/efb/chart/type", "LOCATION"); - KCl0_0 = getProp("/instrumentation/efb/chartsDB/" ~ sprintf("%s", getProp("/instrumentation/efb/chart/icao")) ~ "/" ~ getProp("/instrumentation/efb/chart/type")); - - setProp("/instrumentation/efb/chart/type", "APT"); - # Gets the number of charts (by Type) in the Charts DB - STAR_Status = setProp("/instrumentation/efb/chart/NumSTARs", (getProp("/instrumentation/efb/chartsDB/" ~ sprintf("%s", getProp("/instrumentation/efb/chart/icao")) ~ "/" ~ "STARs"))); - IAP_Status = setProp("/instrumentation/efb/chart/NumIAPs", (getProp("/instrumentation/efb/chartsDB/" ~ sprintf("%s", getProp("/instrumentation/efb/chart/icao")) ~ "/" ~ "IAPs"))); - SID_Status = setProp("/instrumentation/efb/chart/NumSIDs", (getProp("/instrumentation/efb/chartsDB/" ~ sprintf("%s", getProp("/instrumentation/efb/chart/icao")) ~ "/" ~ "SIDs"))); - APT_Status = setProp("/instrumentation/efb/chart/NumAPTs", (getProp("/instrumentation/efb/chartsDB/" ~ sprintf("%s", getProp("/instrumentation/efb/chart/icao")) ~ "/" ~ "APTs"))); - - # Gets the Type of chart from Pilot's Selection - - if (getProp("/instrumentation/efb/VK_Chart_Type") != "") { - if (getProp("/instrumentation/efb/VK_Chart_Type") == "STAR") { - setProp("/instrumentation/efb/chart/type", "STAR"); - Keyboard_Message = getProp("/instrumentation/efb/chart/NumSTARs") ~ " " ~ getProp("/instrumentation/efb/chart/type") ~ " Charts for " ~ sprintf("%s", getProp("/instrumentation/efb/chart/icao")) ~ " Apt - Select a Chart"; - STAR_Status = 1; - } else STAR_STATUS = 0; - if (getProp("/instrumentation/efb/VK_Chart_Type") == "IAP") { - setProp("/instrumentation/efb/chart/type", "IAP"); - Keyboard_Message = getProp("/instrumentation/efb/chart/NumIAPs") ~ " " ~ getProp("/instrumentation/efb/chart/type") ~ " Charts for " ~ sprintf("%s", getProp("/instrumentation/efb/chart/icao")) ~ " Apt - Select a Chart"; - IAP_Status = 1; - } else IAP_Status = 0; - if (getProp("/instrumentation/efb/VK_Chart_Type") == "SID") { - setProp("/instrumentation/efb/chart/type", "SID"); - Keyboard_Message = getProp("/instrumentation/efb/chart/NumSIDs") ~ " " ~ getProp("/instrumentation/efb/chart/type") ~ " Charts for " ~ sprintf("%s", getProp("/instrumentation/efb/chart/icao")) ~ " Apt - Select a Chart"; - SID_Status = 1; - } else SID_Status = 0; - if (getProp("/instrumentation/efb/VK_Chart_Type") == "APT") { - setProp("/instrumentation/efb/chart/type", "APT"); - Keyboard_Message = getProp("/instrumentation/efb/chart/NumAPTs") ~ " " ~ getProp("/instrumentation/efb/chart/type") ~ " Charts for " ~ sprintf("%s", getProp("/instrumentation/efb/chart/icao")) ~ " Apt - Select a Chart"; - APT_Status = 1; - } else APT_Status = 0; - - setProp("/instrumentation/efb/VK_Chart_Type", getProp("/instrumentation/efb/chart/type")); - setProp("/instrumentation/efb/chartsDB", "ChartsDB/"); - - #setProp("/instrumentation/efb/chart/selected", getProp("/instrumentation/efb/chartsDB/" ~ sprintf("%s", getProp("/instrumentation/efb/chart/icao")) ~ "/" ~ getProp("/instrumentation/efb/chart/type") ~ "-1")); - - var lastn = getProp("/instrumentation/efb/chartsDB/" ~ sprintf("%s", getProp("/instrumentation/efb/chart/icao")) ~ "/" ~ getProp("/instrumentation/efb/chart/type") ~ "s") - 1; - if (lastn <= 0) lastn = 0; - - if ((STAR_Status == 0) and (IAP_Status == 0) and (SID_Status == 0) and (APT_Status == 0)) { - setProp("/instrumentation/efb/chart/Status", 0); - Keyboard_Message = "No Charts available for: " ~ sprintf("%s", getProp("/instrumentation/efb/chart/icao")) ~ " Apt"; - setProp("/instrumentation/efb/chart/Status", "OFF"); - } - - # Gets the available ICAO/Type charts in the Charts DB - for (var index = 0; index <= 29; index += 1) - ChartName[index] = ""; - - if (lastn > 0) { - for (var index = 0; index <= lastn; index += 1) { - setProp("/instrumentation/efb/chart/IDX", index); - setProp("/instrumentation/efb/chart/selected", (getProp("/instrumentation/efb/chartsDB/" ~ sprintf("%s", getProp("/instrumentation/efb/chart/icao")) ~ "/" ~ getProp("/instrumentation/efb/chart/type") ~ "-" ~ getProp("/instrumentation/efb/chart/IDX")))); - ChartName[index] = getProp("/instrumentation/efb/chart/selected"); - } - } else { - setProp("/instrumentation/efb/chart/selected", (getProp("/instrumentation/efb/chartsDB/" ~ sprintf("%s", getProp("/instrumentation/efb/chart/icao")) ~ "/" ~ getProp("/instrumentation/efb/chart/type") ~ "-0"))); - ChartName[0] = getProp("/instrumentation/efb/chart/selected"); - } - Keyboard_Helper = "Enter Airport ICAO"; - setProp("/instrumentation/efb/Keyboard/CHART_Input_Line", Keyboard_Helper); - setProp("/instrumentation/efb/Keyboard/CHART_Output_Line", Keyboard_Message); - - # Prints Charts values to Upper Input Display - if (getProp("/instrumentation/efb/chart/Status") == "ON") { - KCl1 = sprintf(getProp("/instrumentation/efb/chart/NumSTARs")); - KCl2 = sprintf(getProp ("/instrumentation/efb/chart/NumIAPs")); - KCl3 = sprintf(getProp ("/instrumentation/efb/chart/NumSIDs")); - KCl4 = sprintf(getProp ("/instrumentation/efb/chart/NumAPTs")); - - # Set Index Offset for proper Page Display (by 3 rows) - if (lastn <=2) Index_Max = 0; - elsif ((lastn > 2) and (lastn <= 5)) Index_Max = 3; - elsif ((lastn > 5) and (lastn <= 8)) Index_Max = 6; - elsif ((lastn > 8) and (lastn <=11)) Index_Max = 9; - elsif ((lastn > 11) and (lastn <=14)) Index_Max = 12; - elsif ((lastn > 14) and (lastn <=17)) Index_Max = 15; - elsif ((lastn > 17) and (lastn <=20)) Index_Max = 18; - elsif ((lastn > 20) and (lastn <=23)) Index_Max = 21; - elsif ((lastn > 23) and (lastn <=26)) Index_Max = 24; - elsif ((lastn > 26) and (lastn <=29)) Index_Max = 27; - - Chart_Pages = (Index_Max/3) + 1; - - # Displays Actual Chart Page/Total Pages - var Page_Show = "Page " ~ getProp("/instrumentation/efb/chart/PageList") ~ "/" ~ Chart_Pages; - setProp("instrumentation/efb/chart/PageShow", Page_Show); - KCl0_1 = getProp("/instrumentation/efb/chart/PageShow"); - - # Build 3 rows of Chart Names - for (var index = 0; index <= 2; index += 1) { - Index_Offset = ((getProp("/instrumentation/efb/chart/PageList") - 1) * 3); - Index_Offset = Index_Offset + index; - ChartDisp[index] = ChartName[Index_Offset]; - } - # Displays 3 Chart Names [MAX Lenght = 27 chars !], ready for Selection by the Pilot - setProp("instrumentation/efb/chart/Selection_0", ChartDisp[0]); - setProp("instrumentation/efb/chart/Selection_1", ChartDisp[1]); - setProp("instrumentation/efb/chart/Selection_2", ChartDisp[2]); - KCr1 = substr(getProp("instrumentation/efb/chart/Selection_0"), 0, 26); - KCr2 = substr(getProp("instrumentation/efb/chart/Selection_1"), 0, 26); - KCr3 = substr(getProp("instrumentation/efb/chart/Selection_2"), 0, 26); - } else { - KCl0 = ""; - KCl0_0 = ""; - KCl0_1 = ""; - KCl1 = ""; - KCl2 = ""; - KCl3 = ""; - KCl4 = ""; - - KCr1 = ""; - KCr2 = ""; - KCr3 = ""; - setProp("instrumentation/efb/chart/Selection_0", ""); - setProp("instrumentation/efb/chart/Selection_1", ""); - setProp("instrumentation/efb/chart/Selection_2", ""); - } - page.KCupdate(); - } - } # END of 'nochart == 0' Brace - } -}; - -var efb = { - init : func { - me.UPDATE_INTERVAL = 0.05; - me.loopid = 0; - # INITIALIZE - - setProp("/instrumentation/efb/page", "MENU"); - setProp("/sim/model/efb/page", "Displays/Main_Menu.jpg"); - - # Chart Section Stuff - - setProp("/instrumentation/efb/chart/type", "APT"); - setProp("/instrumentation/efb/chart/selected", "APT_0"); - setProp("/instrumentation/efb/VK_keypress", ""); - setProp("/instrumentation/efb/Keyboard/CHART_Input_Line", ""); - setProp("/instrumentation/efb/chart/rotation", 0); - setProp("/instrumentation/efb/diagram/rotation", 0); - - AptName = getProp("/instrumentation/efb/chart/icao"); - - # Various Stuff - - setProp("/instrumentation/efb/manual-page", 0); - - setProp("/instrumentation/efb/vnav_autogen/first", 0); - setProp("/instrumentation/efb/vnav_autogen/gen", 0); - TMZ_DB_Size = getProp("/instrumentation/efb/TimeZonesDB/TMZ_DB_Size") - 1; - setProp("/instrumentation/efb/chart/PageList", 1); - me.reset(); - }, - searchairport : func(query) { - setProp("/instrumentation/gps/scratch/query", query); - setProp("/instrumentation/gps/scratch/type", "airport"); - setProp("/instrumentation/gps/command", "search"); - setProp("/instrumentation/efb/selected-rwy/id", ""); - }, - searchcomms : func(query) { - setProp("/sim/gui/dialogs/scratch/airports/selected-airport/id", query); - #setProp("/sim/gui/dialogs/airports/scratch/type", "airport"); - setProp("/sim/gui/dialogs/scratch/airports/mode", "search"); - #setProp("/instrumentation/efb/selected-rwy/id", ""); - }, - searchcharts : func(chart) {setProp("/sim/model/efb/chart", "Charts/" ~ chart ~ ".jpg");}, - efbTimer : nil, - update : func { - var keypress = getProp("/instrumentation/efb/keypress"); - var currentPage = getProp("/instrumentation/efb/page"); - if (currentPage == "MENU") { - # Make sure we know the APT's ICAO - setProp("/instrumentation/gps/scratch/ident", getProp("/sim/airport/closest-airport-id")); - - if (getProp("/instrumentation/gps/scratch/ident") != nil) setProp("/instrumentation/efb/chart/icao", sprintf("%s", getProp("/instrumentation/gps/scratch/ident"))); - else setProp("/instrumentation/efb/chart/icao", ""); - - AptName = sprintf("%s", getProp("/instrumentation/efb/chart/icao")); - page.clearpage(); - page.index(); - - if (keypress == "MENU") { - setProp("/sim/model/efb/page", "Displays/Main_Menu.jpg"); - keypress = ""; - } - elsif (keypress == "l1") { - setProp("/instrumentation/efb/page", "CHARTS"); - setProp("/instrumentation/efb/chart/chartmenu", 0); - setProp("/instrumentation/efb/chart/zoom-in", 0); - ZoomFact = 0; - PanHFact = 0; - PanVFact = 0; - keypress = ""; - } - elsif (keypress == "r1") { - setProp("/sim/model/efb/page", "Displays/Video_1.jpg"); - setProp("/instrumentation/efb/page", "VIDEO"); - keypress = ""; - } - elsif (keypress == "l2") { - setProp("/sim/model/efb/page", "Displays/Performance_1.jpg"); - setProp("/instrumentation/efb/page", "PERFORMANCE"); - keypress = ""; - } - elsif (keypress == "r2") { - setProp("/sim/model/efb/page", "Displays/Documents_1.jpg"); - setProp("/instrumentation/efb/page", "DOCUMENTS"); - keypress = ""; - } - elsif (keypress == "l4") { - setProp("/sim/model/efb/page", "Displays/Airport_Info.jpg"); - setProp("/instrumentation/efb/page", "APT INFO"); - keypress = ""; - } - elsif (keypress == "l5") { - setProp("/instrumentation/efb/page", "Airport Charts"); - keypress = ""; - } - elsif (keypress == "l7") { - setProp("/sim/model/efb/page", "Displays/IDENT_1.jpg"); - setProp("/instrumentation/efb/page", "IDENT"); - keypress = ""; - } - elsif (keypress == "l8") { - setProp("/sim/model/efb/page", "Displays/System_1.jpg"); - setProp("/instrumentation/efb/page", "SYSTEMS"); - keypress = ""; - } - elsif (keypress == "r4") { - #//setProp("/instrumentation/efb/page", "Airport Diagram"); - keypress = ""; - } - elsif (keypress == "r5") { - setProp("/sim/model/efb/page", "Displays/PU_1.jpg"); - setProp("/instrumentation/efb/page", "UTILITIES"); - keypress = ""; - } - elsif (keypress == "r6") { - #//setProp("/instrumentation/efb/page", "Flight Fuel Planner"); - keypress = ""; - } - elsif (keypress == "r7") { - setProp("/sim/model/efb/page", "Displays/Monitor.jpg"); - setProp("/instrumentation/efb/page", "MONITOR"); - keypress = ""; - } - elsif (keypress == "r8") { - setProp("/instrumentation/efb/page", "INITIALIZE"); - keypress = ""; - } - #__________________________________________________________________________________________ - # CHART SECTION Parser --------------------------------------------------------------------| - #__________________________________________________________________________________________| - } elsif (currentPage == "CHARTS") { - page.clearpage(); - #setProp("/sim/model/efb/chart", "Displays/Help_1.jpg"); - setProp("/instrumentation/efb/diagram/rotation", 0); - setProp("/instrumentation/efb/diagram/chartmenu", 0); - setProp("/instrumentation/efb/chartsDB", "Charts/"); - #helper = ""; - # NOTE: this gives the Airport's name to be used on the bottom line of the Chart Display) has still to be checked: if RouteManager is not selected from the upper MENU, the property is not active... - AptName = getProp("/instrumentation/efb/chart/icao"); - - #_____________________________ - # Chart Selection at Airport | - #_____________________________| - - # Checks existence of Charts in the DB - - if(ChartsList[AptName] == nil){ - setProp("/instrumentation/efb/chart_Found", "NOT_FOUND"); - nochart = 1; - }else{ - setProp("/instrumentation/efb/chart_Found", "FOUND"); - nochart = 0; - } - if (nochart == 0){ - page.update(); - if (getProp("/instrumentation/efb/chart/type") == "APT"){ - l[0] = "AIRPORT MAP"; - } - else l[0] = ""; - - l[20] = AptName; - efb.searchcharts(AptName ~ "/" ~ getProp("/instrumentation/efb/chart/type") ~ "/" ~ getProp("/instrumentation/efb/chart/selected")); - #efb.searchcharts(AptName ~ "/" ~ getProp("/instrumentation/efb/chart/type") ~ "/" ~ getProp("instrumentation/efb/chart/selection2"); - setProp("/sim/model/efb/chart", getProp("/sim/model/efb/chart")); - setProp("/sim/model/efb/chart_BKUP", getProp("/sim/model/efb/chart")); - setProp("/sim/model/efb/Chart_2", getProp("/sim/model/efb/chart_BKUP")); - setProp("/sim/model/efb/Chart_4", getProp("/sim/model/efb/chart_BKUP")); - setProp("/sim/model/efb/Ovlay_1", "Displays/drawing.png"); - - if (getProp("/instrumentation/efb/chart/chartmenu") == 0) setProp("/sim/model/efb/Ovlay_1", "Displays/drawing.png"); - if (getProp("/instrumentation/efb/chart/chartmenu") == 1) setProp("/sim/model/efb/Ovlay_1", "Displays/drawing2.png"); - - } else { - setProp("/sim/model/efb/chart", "Displays/NoCharts.jpg"); - setProp("/sim/model/efb/Ovlay_1", "Displays/drawingNULL.png"); - helper = "Airport: " ~ AptName; - } - # Handles the Zoom-In and Zoom-Out EFB buttons on Charts Display; available ZoomFact is 2x and 4x only. - if ((ZoomFact >= 0) and (ZoomFact <= 4)) { - if ((keypress == "Zin") and (nochart == 0)) { - ZoomFact = ZoomFact + 2; - setProp("/instrumentation/efb/chart/zoom-in", ZoomFact); - keypress = ""; - } - elsif ((keypress == "Zout") and (nochart == 0) and (ZoomFact > 0)) { - ZoomFact = ZoomFact - 2; - setProp("/instrumentation/efb/chart/zoom-in", ZoomFact); - keypress = ""; - } - } - if (ZoomFact == 0) setProp("/instrumentation/efb/chart/zoom-in", 0); - # Handles the Pan-Right, Pan_Left, ScrollUP and ScrollDN EFB buttons on Charts Display; Pan Horizontal Factor is 100; Pan Vertical Factor is 100. - if ((ZoomFact == 2) or (ZoomFact == 4)) { - if ((keypress == "Move_R") and (nochart == 0)) { - PanHFact = PanHFact + 100; - setProp("/instrumentation/efb/chart/panH", PanHFact); - keypress = ""; - } - elsif ((keypress == "Move_L") and (nochart == 0)) { - PanHFact = PanHFact - 100; - setProp("/instrumentation/efb/chart/panH", PanHFact); - keypress = ""; - } - elsif ((keypress == "ScrollUP") and (nochart == 0)) { - PanVFact = PanVFact + 100; - setProp("/instrumentation/efb/chart/panV", PanVFact); - keypress = ""; - } - elsif ((keypress == "ScrollDN") and (nochart == 0)) { - PanVFact = PanVFact - 100; - setProp("/instrumentation/efb/chart/panV", PanVFact); - keypress = ""; - } - } elsif (ZoomFact == 0) { - setProp("/instrumentation/efb/chart/panH", -PanHFact); - setProp("/instrumentation/efb/chart/panV", -PanVFact); - } - # Handles Chart Rotation counter-clockwise - if ((keypress == "l2") and (nochart == 0) and (getProp("/instrumentation/efb/chart/chartmenu")) == 0) toggle("/instrumentation/efb/chart/rotation"); - # Toggles Overlay Menu On/OFF - if ((keypress == "r8") and (nochart == 0)) toggle("/instrumentation/efb/chart/chartmenu"); - # Calls Virtual Keyboard for Chart DB Selection by the Pilot - if (keypress == "l5") { - setProp("/instrumentation/efb/page", "CHARTS_KEYBOARD"); - setProp("/instrumentation/efb/chart/zoom-in", 0); - setProp("/instrumentation/efb/VKDRC_keypress", ""); - setProp("/instrumentation/efb/VK_Keyboard/Input_String", ""); - setProp("/instrumentation/efb/chart/Searchable", 0); - } - if (keypress == "MENU") { - setProp("/sim/model/efb/page", "Displays/Main_Menu.jpg"); - setProp("/instrumentation/efb/chart/zoom-in", 0); - ZoomFact = 0; - PanHFact = -PanHFact; - PanVFact = -PanVFact; - setProp("/instrumentation/efb/page", "MENU"); - keypress = ""; - } - #__________________________________________________________________________________________ - # AIRPORT INFO SECTION Parser -------------------------------------------------------------| - #__________________________________________________________________________________________| - } elsif (currentPage == "APT INFO") { - - page.clearpage(); - efb.searchairport(getProp("/sim/airport/closest-airport-id")); - efb.searchcomms(getProp("/sim/airport/closest-airport-id")); - page.airportinfo(); - page.update(); - - # if (keypress == "r6") { - # setProp("/instrumentation/efb/page", "Runway Information"); - # keypress = ""; - # } - if (keypress == "r8") { - setProp("/instrumentation/efb/page", "CHARTS"); - keypress = ""; - } - elsif (keypress == "MENU") { - setProp("/sim/model/efb/page", "Displays/Main_Menu.jpg"); - setProp("/instrumentation/efb/page", "MENU"); - keypress = ""; - } - #__________________________________________________________________________________________ - # MONITOR SECTION Parser ------------------------------------------------------------------| - #__________________________________________________________________________________________| - } elsif (currentPage == "MONITOR") { - page.clearpage(); - page.FlightMonitor(); - page.update(); - - if (keypress == "MENU") { - setProp("/sim/model/efb/page", "Displays/Main_Menu.jpg"); - setProp("/instrumentation/efb/page", "MENU"); - keypress = ""; - } - #__________________________________________________________________________________________ - # VIDEO SECTION Parser --------------------------------------------------------------------| - #__________________________________________________________________________________________| - } elsif (currentPage == "VIDEO") { - page.clearpage(); - if (keypress == "MENU") { - setProp("/sim/model/efb/page", "Displays/Main_Menu.jpg"); - setProp("/instrumentation/efb/page", "MENU"); - keypress = ""; - } - #__________________________________________________________________________________________ - # DOCUMENTS SECTION Parser ----------------------------------------------------------------| - #__________________________________________________________________________________________| - } elsif (currentPage == "DOCUMENTS") { - page.clearpage(); - - if (keypress == "l3") { - setProp("/instrumentation/efb/page", "NORM PROC MANUAL"); - keypress = ""; - } - elsif (keypress == "r2") { - setProp("/sim/model/efb/page", "Displays/Checklists_1.jpg"); - setProp("/instrumentation/efb/page", "CHECKLISTS"); - keypress = ""; - } - elsif (keypress == "MENU") { - setProp("/sim/model/efb/page", "Displays/Main_Menu.jpg"); - setProp("/instrumentation/efb/page", "MENU"); - keypress = ""; - } - #__________________________________________________________________________________________ - # PERFORMANCE SECTION Parser --------------------------------------------------------------| - #__________________________________________________________________________________________| - } elsif (currentPage == "PERFORMANCE") { - page.clearpage(); - - if (keypress == "MENU") { - setProp("/sim/model/efb/page", "Displays/Main_Menu.jpg"); - setProp("/instrumentation/efb/page", "MENU"); - keypress = ""; - } - #__________________________________________________________________________________________ - # CHECKLISTS SECTION Parser ---------------------------------------------------------------| - #__________________________________________________________________________________________| - } elsif (currentPage == "CHECKLISTS") { - page.clearpage(); - - if (keypress == "MENU") { - setProp("/sim/model/efb/page", "Displays/Main_Menu.jpg"); - setProp("/instrumentation/efb/page", "MENU"); - keypress = ""; - } - if (keypress == "l2") { - setProp("/sim/model/efb/page", "Displays/Checklists_1_1.jpg"); - setProp("/instrumentation/efb/page", "CHECKLISTS"); - keypress = ""; - } - if (keypress == "r2") { - setProp("/sim/model/efb/page", "Displays/Checklists_1_2.jpg"); - setProp("/instrumentation/efb/page", "CHECKLISTS"); - keypress = ""; - } - #__________________________________________________________________________________________ - # IDENT SECTION Parser -------------------------------------------------------------------| - #_________________________________________________________________________________________| - } elsif (currentPage == "IDENT") { - page.clearpage(); - - IDENTl3 = getProp("/sim/description"); - IDENTl4 = substr(getProp("/sim/aircraft-operator"),0,3) ~ " / " ~ substr(getProp("/sim/multiplay/callsign"), 0,6); # this is to ensure that too long 'operator' and 'callsign' data can fit into the EFB display - IDENTr4 = "VMEFB001"; # this is the EFb Seattle version's ID - IDENTl5 = substr(getProp("environment/metar/data"),0,10); - IDENTr5 = getProp("/instrumentation/clock/indicated-short-string") ~ "z"; - IDENTl8 = "AIRPORT MAP DATABASE Seattle Data APR1214-JUN3014"; # this is the DB version, which we will periodically update with better and new Charts - - setProp("/instrumentation/efb/display/IDENTline3-l", IDENTl3); - setProp("/instrumentation/efb/display/IDENTline4-l", IDENTl4); - setProp("/instrumentation/efb/display/IDENTline4-r", IDENTr4); - setProp("/instrumentation/efb/display/IDENTline5-l", IDENTl5); - setProp("/instrumentation/efb/display/IDENTline5-r", IDENTr5); - setProp("/instrumentation/efb/display/IDENTline8-l", IDENTl8); - - setProp("/instrumentation/efb/display/input-helper", helper); - setProp("/instrumentation/efb/keypress", keypress); - - if (keypress == "MENU") { - setProp("/sim/model/efb/page", "Displays/Main_Menu.jpg"); - setProp("/instrumentation/efb/page", "MENU"); - - IDENTl3 = ""; - IDENTl4 = ""; - IDENTr4 = ""; - IDENTl5 = ""; - IDENTr5 = ""; - IDENTl8 = ""; - setProp("/instrumentation/efb/display/IDENTline3-l", IDENTl3); - setProp("/instrumentation/efb/display/IDENTline4-l", IDENTl4); - setProp("/instrumentation/efb/display/IDENTline4-r", IDENTr4); - setProp("/instrumentation/efb/display/IDENTline5-l", IDENTl5); - setProp("/instrumentation/efb/display/IDENTline5-r", IDENTr5); - setProp("/instrumentation/efb/display/IDENTline8-l", IDENTl8); - - keypress = ""; - } - #__________________________________________________________________________________________ - # SYSTEM SECTION Parser ------------------------------------------------------------------| - #__________________________________________________________________________________________| - } elsif (currentPage == "SYSTEMS") { - page.clearpage(); - - if (keypress == "MENU") { - setProp("/sim/model/efb/page", "Displays/Main_Menu.jpg"); - setProp("/instrumentation/efb/page", "MENU"); - keypress = ""; - } - #__________________________________________________________________________________________ - # CHART SECTION Parser -------------------------------------------------------------------| - #__________________________________________________________________________________________| - } elsif (currentPage == "CHARTS_KEYBOARD") { - page.clearpage(); - page.update(); - page.charts_keyboard(); - - if (getProp("/instrumentation/efb/chart/Searchable") == 0) { - setProp("/instrumentation/efb/Keyboard/CHART_Input_Line", "Enter ICAO"); - } - - # Get the ICAO to be searched for; "Virtual Keyboard" Keys Parser (see EFB_Chart_Keyboard.xml) - - if ((getProp("/instrumentation/efb/VKDRC_keypress") != "") and (getProp("/instrumentation/efb/VKDRC_keypress") != "SYMB") and (getProp("/instrumentation/efb/VKDRC_keypress") != "SHIFT")) { - setProp("/instrumentation/efb/VK_Keyboard/Input_String", getProp("/instrumentation/efb/VK_Keyboard/Input_String") ~ getProp("/instrumentation/efb/VKDRC_keypress")); # Build the Input String - - if (getProp("/instrumentation/efb/VKDRC_keypress") == "CLEAR") { - - setProp("/instrumentation/efb/VK_Keyboard/Input_String", ""); # CLEARs the whole Input Field and other stuff - } - if (getProp("/instrumentation/efb/VKDRC_keypress") == "BKSP") { - Temp_String = getProp("/instrumentation/efb/VK_Keyboard/Input_String"); # BACKSPACEs the Input Field - lenght = size(Temp_String) - 1; - setProp("/instrumentation/efb/VK_Keyboard/Input_String", substr(Temp_String, 0, lenght)); - setProp("/instrumentation/efb/VKDRC_keypress", ""); - } - } - - setProp("/instrumentation/efb/VKDRC_keypress", ""); - - TMZ_String = getProp("/instrumentation/efb/VK_Keyboard/Input_String"); - TMZ_Input_Lenght = size(TMZ_String); - - if (TMZ_Input_Lenght <= 3) { - setProp("/instrumentation/efb/Keyboard/CHART_Input_Line", getProp("/instrumentation/efb/VK_Keyboard/Input_String")); # Print it to the Keyboard Input Field - - } else { - setProp("/instrumentation/efb/chart/Searchable", 1); - setProp("/instrumentation/efb/Keyboard/CHART_Input_Line", "Press [Search IDENT] to search for: " ~ getProp("/instrumentation/efb/VK_Keyboard/Input_String")); - } - if ((getProp("/instrumentation/efb/chart/Searchable") == 1) and (keypress == "l3")) { # do SEARCH CHART - setProp("/instrumentation/efb/chart/icao", getProp("/instrumentation/efb/VK_Keyboard/Input_String")); - page.charts_keyboard(); - setProp("/instrumentation/efb/VKDRC_keypress", ""); - setProp("/instrumentation/efb/chart/Searchable", 0); - setProp("/instrumentation/efb/VK_Keyboard/Input_String", ""); - } - - if ((keypress == "PGDN") and (getProp("/instrumentation/efb/chart/PageList") < Chart_Pages)) { - setProp("/instrumentation/efb/chart/SetPage", "INCREASE"); - setProp("/instrumentation/efb/chart/PageList", getProp("/instrumentation/efb/chart/PageList") + 1); - } - if ((keypress == "PGUP") and (getProp("/instrumentation/efb/chart/PageList") > 1)) { - setProp("/instrumentation/efb/chart/SetPage", "INCREASE"); - setProp("/instrumentation/efb/chart/PageList", getProp("/instrumentation/efb/chart/PageList") + 1); - } - - # Chart Selection - redirection to CHARTS...___________________________________________________________________________________ - - if (keypress == "r1") { - setProp("/instrumentation/efb/chart/selected", getProp("/instrumentation/efb/chart/Selection_0")); - keypress = "MENU"; - } - if (keypress == "r2") { - setProp("/instrumentation/efb/chart/selected", getProp("/instrumentation/efb/chart/Selection_1")); - keypress = "MENU"; - } - if (keypress == "r3") { - setProp("/instrumentation/efb/chart/selected", getProp("/instrumentation/efb/chart/Selection_2")); - keypress = "MENU"; - } - # _____________________________________________________________________________________________________________________________ - - if (keypress == "MENU") { - # setProp("/sim/model/efb/page", "Displays/Blank_Test.jpg"); - setProp("/instrumentation/efb/chart/Status", "OFF"); - setProp("/instrumentation/efb/VK_Chart_Type", "APT"); # This starts and re-starts the Chart_Keyboard with active ICAO/APT Chart displayed ! (see B777 EFB Manual) - setProp("/instrumentation/efb/VK_Keyboard/Input_String", ""); - setProp("/instrumentation/efb/page", "CHARTS"); - page.KCclearpage(); - page.KCupdate(); - keypress = ""; - } - - #__________________________________________________________________________________________ - # INITIALIZE SECTION Parser --------------------------------------------------------------| - #__________________________________________________________________________________________| - } elsif (currentPage == "INITIALIZE") { - page.clearpage(); - if (getProp("/instrumentation/efb/FlightStatus") == 0) { - if (getProp("/autopilot/route-manager/departure/airport") != "") - OriginApt = getProp("/autopilot/route-manager/departure/airport"); - else - OriginApt = "NOT Set"; - if (getProp("/autopilot/route-manager/destination/airport") != "") - DestinationApt = getProp("/autopilot/route-manager/destination/airport"); - else - DestinationApt = "NOT Set"; - if ((OriginApt != "NOT Set") and (DestinationApt != "NOT Set")) { - OriginApt = getProp("/autopilot/route-manager/departure/airport"); - DestinationApt = getProp("/autopilot/route-manager/destination/airport"); - setProp("/sim/model/efb/page", "Displays/Initialize_1.jpg"); - ClosingFlightFlag = 1; # Flight INITIABLE - } else { - setProp("/sim/model/efb/page", "Displays/Initialize_2.jpg"); - setProp("/instrumentation/efb/FlightStatus", 0); - ClosingFlightFlag = 0; # Flight NOT INITIABLE - } - } elsif ((getProp("/instrumentation/efb/FlightStatus") == 1) and (ClosingFlightFlag == 2)) { - setProp("/instrumentation/efb/FlightStatus", 1); # Flight ACTIVE and CLOSABLE - FlightStatus = 1; - setProp("/sim/model/efb/page", "Displays/Initialize_3.jpg"); - } - - INITl4 = OriginApt; - INITl5 = DestinationApt; - setProp("/instrumentation/efb/display/INITline4-l", INITl4); - setProp("/instrumentation/efb/display/INITline5-l", INITl5); - - if ((keypress == "r8") and (ClosingFlightFlag == 1)) { - setProp("/instrumentation/efb/FlightStatus", 1); # Flight INITIATED - ClosingFlightFlag = 2; # Flight CLOSABLE - keypress = ""; - } - if ((keypress == "r8") and (FlightStatus == 1)) { - setProp("/instrumentation/efb/FlightStatus", 0); # Flight NOT ACTIVE - setProp("/sim/model/efb/page", "Displays/Initialize_5.jpg"); - FlightStatus = 0; - ClosingFlightFlag = 0; # Flight CLOSED - keypress = ""; - } - if (keypress == "MENU") { - setProp("/sim/model/efb/page", "Displays/Main_Menu.jpg"); - setProp("/instrumentation/efb/page", "MENU"); - keypress = ""; - INITl4 = ""; - INITl5 = ""; - setProp("/instrumentation/efb/display/INITline4-l", INITl4); - setProp("/instrumentation/efb/display/INITline5-l", INITl5); - keypress = ""; - } - - #__________________________________________________________________________________________ - # PILOT UTILITIES SECTION Parser ----------------------------------------------------------| - #__________________________________________________________________________________________| - } elsif (currentPage == "UTILITIES") { - page.clearpage(); - setProp("/instrumentation/efb/Keyboard/Input_String", ""); - setProp("/instrumentation/efb/Keyboard/Input_Line", ""); - setProp("/instrumentation/efb/Keyboard/Input_Line2", ""); - setProp("/instrumentation/efb/Keyboard/Input_Line3", ""); - setProp("/instrumentation/efb/VK_keypress", ""); - - if (keypress == "l3") { - setProp("/instrumentation/efb/page", "UTILITIES_DESC_RATE"); - setProp("/sim/model/efb/page", "Displays/PU_DRC.jpg"); - setProp("/instrumentation/efb/Keyboard/Input_String", ""); - setProp("/instrumentation/efb/VK_keypress", ""); - setProp("/instrumentation/efb/Input_Unit", "NO_INPUT"); - setProp("/instrumentation/efb/DRC_Initial_FL", "300"); - setProp("/instrumentation/efb/DRC_Target_FL", "30"); - setProp("/instrumentation/efb/DRC_Initial_GS", "250"); - setProp("/instrumentation/efb/DRC_Target_GS", "200"); - setProp("/instrumentation/efb/DRC_Distance", "50"); - setProp("/instrumentation/efb/DRC_Initial_FL_MEM", getProp("/instrumentation/efb/DRC_Initial_FL")); - setProp("/instrumentation/efb/DRC_Target_FL_MEM", getProp("/instrumentation/efb/DRC_Target_FL")); - setProp("/instrumentation/efb/DRC_Initial_GS_MEM", getProp("/instrumentation/efb/DRC_Initial_GS")); - setProp("/instrumentation/efb/DRC_Target_GS_MEM", getProp("/instrumentation/efb/DRC_Target_GS")); - setProp("/instrumentation/efb/DRC_Distance_MEM", getProp("/instrumentation/efb/DRC_Distance")); - VK_Key = ""; - #setProp("/instrumentation/efb/VK_DRC_MarkerL", 1); - Initial_FL = 300; - Target_FL = 30; - Initial_GS = 250; - Target_GS = 200; - DRC_Distance = 50; - keypress = ""; - } - if (keypress == "l4") { - setProp("/instrumentation/efb/page", "GPS POSITION"); - } - if (keypress == "r1") { - setProp("/instrumentation/efb/page", "UTILITIES_CNV_SPD"); - setProp("/sim/model/efb/page", "Displays/PU_Cnv_Spd.jpg"); - setProp("/instrumentation/efb/VK_keypress", ""); - setProp("/instrumentation/efb/VK_IN_Marker", 1); - setProp("/instrumentation/efb/VK_OUT_Marker", 1); - VK_Input_Mem = 0; - VK_Output_Mem = 0; - } - if (keypress == "r2") { - setProp("/instrumentation/efb/page", "UTILITIES_CNV_LNG"); - setProp("/sim/model/efb/page", "Displays/PU_Cnv_Lng.jpg"); - setProp("/instrumentation/efb/VK_keypress", ""); - setProp("/instrumentation/efb/VK_IN_Marker", 1); - setProp("/instrumentation/efb/VK_OUT_Marker", 1); - VK_Input_Mem = 0; - VK_Output_Mem = 0; - } - if (keypress == "r3") { - setProp("/instrumentation/efb/page", "UTILITIES_CNV_WGT"); - setProp("/sim/model/efb/page", "Displays/PU_Cnv_Wgt.jpg"); - setProp("/instrumentation/efb/VK_keypress", ""); - setProp("/instrumentation/efb/VK_IN_Marker", 1); - setProp("/instrumentation/efb/VK_OUT_Marker", 1); - VK_Input_Mem = 0; - VK_Output_Mem = 0; - } - if (keypress == "r4") { - setProp("/instrumentation/efb/page", "UTILITIES_CNV_TMP"); - setProp("/sim/model/efb/page", "Displays/PU_Cnv_Tmp.jpg"); - setProp("/instrumentation/efb/VK_keypress", ""); - setProp("/instrumentation/efb/VK_IN_Marker", 1); - setProp("/instrumentation/efb/VK_OUT_Marker", 1); - VK_Input_Mem = 0; - VK_Output_Mem = 0; - } - if (keypress == "r5") { - setProp("/instrumentation/efb/page", "UTILITIES_CNV_VLM"); - setProp("/sim/model/efb/page", "Displays/PU_Cnv_Vlm.jpg"); - setProp("/instrumentation/efb/VK_keypress", ""); - setProp("/instrumentation/efb/VK_IN_Marker", 1); - setProp("/instrumentation/efb/VK_OUT_Marker", 1); - VK_Input_Mem = 0; - VK_Output_Mem = 0; - } - if (keypress == "r6") { - setProp("/instrumentation/efb/page", "UTILITIES_CNV_TMZ"); - setProp("/sim/model/efb/page", "Displays/PU_Cnv_Tmz.jpg"); - setProp("/instrumentation/efb/VK_keypress", ""); - setProp("/instrumentation/efb/VK_IN_Marker", 1); - setProp("/instrumentation/efb/VK_OUT_Marker", 1); - setProp("/instrumentation/efb/Keyboard/Input_String",""); - setProp("/instrumentation/efb/Keyboard/Input_HH", "--"); - setProp("/instrumentation/efb/Keyboard/Input_MM", "--"); - setProp("/instrumentation/efb/Keyboard/Output_HH", ""); - setProp("/instrumentation/efb/Keyboard/Output_MM", ""); - setProp("/instrumentation/efb/page/Cnv_Fact", "0"); - TMZ_String = ""; - TMZ_Index = 0; - - #Parsing for Month's names - - TMZ_DATE = substr(getProp("environment/metar/data"), 5, 5); - - if (substr(TMZ_DATE, 0, 2) == "01") TMZ_DATE = "JAN" ~ substr(TMZ_DATE, 2, 3); - if (substr(TMZ_DATE, 0, 2) == "02") TMZ_DATE = "FEB" ~ substr(TMZ_DATE, 2, 3); - if (substr(TMZ_DATE, 0, 2) == "03") TMZ_DATE = "MAR" ~ substr(TMZ_DATE, 2, 3); - if (substr(TMZ_DATE, 0, 2) == "04") TMZ_DATE = "APR" ~ substr(TMZ_DATE, 2, 3); - if (substr(TMZ_DATE, 0, 2) == "05") TMZ_DATE = "MAY" ~ substr(TMZ_DATE, 2, 3); - if (substr(TMZ_DATE, 0, 2) == "06") TMZ_DATE = "JUN" ~ substr(TMZ_DATE, 2, 3); - if (substr(TMZ_DATE, 0, 2) == "07") TMZ_DATE = "JUL" ~ substr(TMZ_DATE, 2, 3); - if (substr(TMZ_DATE, 0, 2) == "08") TMZ_DATE = "AUG" ~ substr(TMZ_DATE, 2, 3); - if (substr(TMZ_DATE, 0, 2) == "09") TMZ_DATE = "SEP" ~ substr(TMZ_DATE, 2, 3); - if (substr(TMZ_DATE, 0, 2) == "10") TMZ_DATE = "OCT" ~ substr(TMZ_DATE, 2, 3); - if (substr(TMZ_DATE, 0, 2) == "11") TMZ_DATE = "NOV" ~ substr(TMZ_DATE, 2, 3); - if (substr(TMZ_DATE, 0, 2) == "12") TMZ_DATE = "DEC" ~ substr(TMZ_DATE, 2, 3); - } - - if (keypress == "MENU") { - setProp("/sim/model/efb/page", "Displays/Main_Menu.jpg"); - setProp("/instrumentation/efb/page", "MENU"); - keypress = ""; - } - - #__________________________________________________________________________________________ - # PILOT UTILITIES - GPS POSITION ----------------------------------------------------------| - #__________________________________________________________________________________________| - } elsif (currentPage == "GPS POSITION") { - page.clearpage(); - page.gps(); - - if (keypress == "MENU") { - setProp("/sim/model/efb/page", "Displays/PU_1.jpg"); - setProp("/instrumentation/efb/page", "UTILITIES"); - keypress = ""; - } - - #__________________________________________________________________________________________ - # PILOT UTILITIES - SPEED CONVERSION Parser -----------------------------------------------| - #__________________________________________________________________________________________| - } elsif (currentPage == "UTILITIES_CNV_SPD") { - Input_Unit = getProp("/instrumentation/efb/VK_IN_Marker"); - Output_Unit = getProp("/instrumentation/efb/VK_OUT_Marker"); - - # Input keys Check - - if (getProp("/instrumentation/efb/VK_keypress") != "" or (Input_Unit != VK_Input_Mem) or (Output_Unit != VK_Output_Mem)) { - # Input Field Parser - if (getProp("/instrumentation/efb/VK_keypress") == "CLEAR") { - setProp("/instrumentation/efb/Keyboard/Input_String", ""); # CLEARs the whole Input Field - setProp("/instrumentation/efb/VK_keypress", ""); - } - if (getProp("/instrumentation/efb/VK_keypress") == "BKSP") { - Temp_String = getProp("/instrumentation/efb/Keyboard/Input_String"); # BACKSPACEs the Input Field - lenght = size(Temp_String) - 1; - setProp("/instrumentation/efb/Keyboard/Input_String", substr(Temp_String, 0, lenght)); - setProp("/instrumentation/efb/VK_keypress", ""); - } - if (getProp("/instrumentation/efb/VK_keypress") == "CHNGS") { - Temp_String = getProp("/instrumentation/efb/Keyboard/Input_String"); # CHANGEs SIGN to the Input Field - if (substr(Temp_String, 0, 1) == "-") { - lenght = size(Temp_String) - 1; - Temp_String = substr(Temp_String, 1, lenght); - } else { - Temp_String = "-" ~ Temp_String; - } - setProp("/instrumentation/efb/Keyboard/Input_String", Temp_String); - setProp("/instrumentation/efb/VK_keypress", ""); - } - - # Input Field Display - - setProp("/instrumentation/efb/Keyboard/Input_String", getProp("/instrumentation/efb/Keyboard/Input_String") ~ getProp("/instrumentation/efb/VK_keypress")); # Build the Input String - setProp("/instrumentation/efb/Keyboard/Input_Line", getProp("/instrumentation/efb/Keyboard/Input_String")); # Print it to the Keyboard Input Field - - # ---------------> Conversion Table Selection - # ---------------> Input Unit 1 () FT/M ---> Output Unit: FT/M, KM/H, KT, MTS, MPH - if (Input_Unit == 1) { - if (Output_Unit == 1) Cnv_Fact = 1; - elsif (Output_Unit == 2) Cnv_Fact = 0.018288; - elsif (Output_Unit == 3) Cnv_Fact = 0.0098747; - elsif (Output_Unit == 4) Cnv_Fact = 0.0050800; - elsif (Output_Unit == 5) { - if (getProp("/instrumentation/efb/VK_keypress") == "CLEAR") { - setProp("/instrumentation/efb/Keyboard/Input_String", ""); # CLEARs the whole Input Field - setProp("/instrumentation/efb/VK_keypress", ""); - } - elsif (getProp("/instrumentation/efb/VK_keypress") == "BKSP") { - Temp_String = getProp("/instrumentation/efb/Keyboard/Input_String"); # BACKSPACEs the Input Field - lenght = size(Temp_String) - 1; - setProp("/instrumentation/efb/Keyboard/Input_String", substr(Temp_String, 0, lenght)); - setProp("/instrumentation/efb/VK_keypress", ""); - } - elsif (getProp("/instrumentation/efb/VK_keypress") == "CHNGS") { - Temp_String = getProp("/instrumentation/efb/Keyboard/Input_String"); # CHANGEs SIGN to the Input Field - if (substr(Temp_String, 0, 1) == "-") { - lenght = size(Temp_String) - 1; - Temp_String = substr(Temp_String, 1, lenght); - } else { - Temp_String = "-" ~ Temp_String; - } - setProp("/instrumentation/efb/Keyboard/Input_String", Temp_String); - setProp("/instrumentation/efb/VK_keypress", ""); - } - Cnv_Fact = 0.011364; - } - } - # ---------------> Input Unit 2 () KM/H ---> Output Unit: FT/M, KM/H, KT, MTS, MPH - elsif (Input_Unit == 2) { - if (Output_Unit == 1) Cnv_Fact = 54.68066; - elsif (Output_Unit == 2) Cnv_Fact = 1; - elsif (Output_Unit == 3) Cnv_Fact = 0.5399568; - elsif (Output_Unit == 4) Cnv_Fact = 0.2777778; - elsif (Output_Unit == 5) Cnv_Fact = 0.6213712; - } - # ---------------> Input Unit 3 () KT ---> Output Unit: FT/M, KM/H, KT, MTS, MPH - elsif (Input_Unit == 3) { - if (Output_Unit == 1) Cnv_Fact = 101.2686; - elsif (Output_Unit == 2) Cnv_Fact = 1.852000; - elsif (Output_Unit == 3) Cnv_Fact = 1; - elsif (Output_Unit == 4) Cnv_Fact = 0.5144444; - elsif (Output_Unit == 5) Cnv_Fact = 1.150779; - } - # ---------------> Input Unit 4 () MTS ---> Output Unit: FT/M, KM/H, KT, MTS, MPH - elsif (Input_Unit == 4) { - if (Output_Unit == 1) Cnv_Fact = 196.85; - elsif (Output_Unit == 2) Cnv_Fact = 3.6000; - elsif (Output_Unit == 3) Cnv_Fact = 1.9438; - elsif (Output_Unit == 4) Cnv_Fact = 1; - elsif (Output_Unit == 5) Cnv_Fact = 2.2369; - } - # ---------------> Input Unit 5 () MPH ---> Output Unit: FT/M, KM/H, KT, MTS, MPH - elsif (Input_Unit == 5) { - if (Output_Unit == 1) Cnv_Fact = 88.0002; - elsif (Output_Unit == 2) Cnv_Fact = 1.609344; - elsif (Output_Unit == 3) Cnv_Fact = 0.8689762; - elsif (Output_Unit == 4) Cnv_Fact = 0.4470400; - elsif (Output_Unit == 5) Cnv_Fact = 1; - } - VK_Input_Mem = Input_Unit; - VK_Output_Mem = Output_Unit; - - # Output Field Display - - if ((getProp("/instrumentation/efb/Keyboard/Input_Line") == "") or (getProp("/instrumentation/efb/Keyboard/Input_Line") == ".") or (getProp("/instrumentation/efb/Keyboard/Input_Line") == "-")) { - setProp("/instrumentation/efb/Keyboard/Output_Line", ""); - } else { - Output_Line = getProp("/instrumentation/efb/Keyboard/Input_Line"); - Output_Line = Output_Line * Cnv_Fact; # Build the Input String - setProp("/instrumentation/efb/Keyboard/Output_Line", Output_Line); # Print it to the Keyboard Output Field - } - setProp("/instrumentation/efb/VK_keypress", ""); - } - - if (keypress == "MENU") { - setProp("/sim/model/efb/page", "Displays/PU_1.jpg"); - setProp("/instrumentation/efb/page", "UTILITIES"); - setProp("/instrumentation/efb/Keyboard/Input_Line", ""); - setProp("/instrumentation/efb/Keyboard/Output_Line", ""); - keypress = ""; - } - - #__________________________________________________________________________________________ - # PILOT UTILITIES - LENGHT CONVERSION Parser ----------------------------------------------| - #__________________________________________________________________________________________| - } elsif (currentPage == "UTILITIES_CNV_LNG") { - - Input_Unit = getProp("/instrumentation/efb/VK_IN_Marker"); - Output_Unit = getProp("/instrumentation/efb/VK_OUT_Marker"); - - # Input keys Check - - if (getProp("/instrumentation/efb/VK_keypress") != "" or (Input_Unit != VK_Input_Mem) or (Output_Unit != VK_Output_Mem)) { - # Input Field Parser - - if (getProp("/instrumentation/efb/VK_keypress") == "CLEAR") { - setProp("/instrumentation/efb/Keyboard/Input_String", ""); # CLEARs the whole Input Field - setProp("/instrumentation/efb/VK_keypress", ""); - } - elsif (getProp("/instrumentation/efb/VK_keypress") == "BKSP") { - Temp_String = getProp("/instrumentation/efb/Keyboard/Input_String"); # BACKSPACEs the Input Field - lenght = size(Temp_String) - 1; - setProp("/instrumentation/efb/Keyboard/Input_String", substr(Temp_String, 0, lenght)); - setProp("/instrumentation/efb/VK_keypress", ""); - } - elsif (getProp("/instrumentation/efb/VK_keypress") == "CHNGS") { - Temp_String = getProp("/instrumentation/efb/Keyboard/Input_String"); # CHANGEs SIGN to the Input Field - if (substr(Temp_String, 0, 1) == "-") { - lenght = size(Temp_String) - 1; - Temp_String = substr(Temp_String, 1, lenght); - } else { - Temp_String = "-" ~ Temp_String; - } - setProp("/instrumentation/efb/Keyboard/Input_String", Temp_String); - setProp("/instrumentation/efb/VK_keypress", ""); - } - - # Input Field Display - - setProp("/instrumentation/efb/Keyboard/Input_String", getProp("/instrumentation/efb/Keyboard/Input_String") ~ getProp("/instrumentation/efb/VK_keypress")); # Build the Input String - setProp("/instrumentation/efb/Keyboard/Input_Line", getProp("/instrumentation/efb/Keyboard/Input_String")); # Print it to the Keyboard Input Field - - # ---------------> Conversion Table Selection - - # ---------------> Input Unit 1 () FEET ---> Output Unit: FEET, KILOMETERS, METERS, NAUTICAL MILES, STATUTE MILES - if (Input_Unit == 1) { - if (Output_Unit == 1) Cnv_Fact = 1; - elsif (Output_Unit == 2) Cnv_Fact = 0.0003048; - elsif (Output_Unit == 3) Cnv_Fact = 0.30480; - elsif (Output_Unit == 4) Cnv_Fact = 0.000164579; # International and US Nautical Miles, NOT UK Nautical Miles !! - elsif (Output_Unit == 5) Cnv_Fact = 0.000189394; # International Statute Miles - } - # ---------------> Input Unit 2 () KILOMETERS ---> Output Unit: FEET, KILOMETERS, METERS, NAUTICAL MILES, STATUTE MILES - elsif (Input_Unit == 2) { - if (Output_Unit == 1) Cnv_Fact = 3280.83989501; - elsif (Output_Unit == 2) Cnv_Fact = 1; - elsif (Output_Unit == 3) Cnv_Fact = 1000; - elsif (Output_Unit == 4) Cnv_Fact = 0.539956803456; # International and US Nautical Miles, NOT UK Nautical Miles !! - elsif (Output_Unit == 5) Cnv_Fact = 0.621371192237; # International Statute Miles - } - # ---------------> Input Unit 3 () METERS ---> Output Unit: FEET, KILOMETERS, METERS, NAUTICAL MILES, STATUTE MILES - elsif (Input_Unit == 3) { - if (Output_Unit == 1) Cnv_Fact = 3.28083989501; - elsif (Output_Unit == 2) Cnv_Fact = 0.001; - elsif (Output_Unit == 3) Cnv_Fact = 1; - elsif (Output_Unit == 4) Cnv_Fact = 0.000539956803456; # International and US Nautical Miles, NOT UK Nautical Miles !! - elsif (Output_Unit == 5) Cnv_Fact = 0.000621371192237; # International Statute Miles - } - # ---------------> Input Unit 4 () NAUTICAL MILES (INTERNATIONAL!) ---> Output Unit: FEET, KILOMETERS, METERS, NAUTICAL MILES, STATUTE MILES - elsif (Input_Unit == 4) { - if (Output_Unit == 1) Cnv_Fact = 6076.11548556; - elsif (Output_Unit == 2) Cnv_Fact = 1.852; - elsif (Output_Unit == 3) Cnv_Fact = 1852; - elsif (Output_Unit == 4) Cnv_Fact = 1; - elsif (Output_Unit == 5) Cnv_Fact = 1.15077944802; # International Statute Miles - } - # ---------------> Input Unit 5 () STATUTE MILES ---> Output Unit: FEET, KILOMETERS, METERS, NAUTICAL MILES, STATUTE MILES - elsif (Input_Unit == 5) { - if (Output_Unit == 1) Cnv_Fact = 5280; - elsif (Output_Unit == 2) Cnv_Fact = 1.609344; - elsif (Output_Unit == 3) Cnv_Fact = 1609.344; - elsif (Output_Unit == 4) Cnv_Fact = 0.868976241901; # International and US Nautical Miles, NOT UK Nautical Miles !! - elsif (Output_Unit == 5) Cnv_Fact = 1; - } - VK_Input_Mem = Input_Unit; - VK_Output_Mem = Output_Unit; - - # Output Field Display - if ((getProp("/instrumentation/efb/Keyboard/Input_Line") == "") or (getProp("/instrumentation/efb/Keyboard/Input_Line") == ".") or (getProp("/instrumentation/efb/Keyboard/Input_Line") == "-")) { - setProp("/instrumentation/efb/Keyboard/Output_Line", ""); - } else { - Output_Line = getProp("/instrumentation/efb/Keyboard/Input_Line"); - Output_Line = Output_Line * Cnv_Fact; # Build the Input String - setProp("/instrumentation/efb/Keyboard/Output_Line", Output_Line); # Print it to the Keyboard Output Field - } - setProp("/instrumentation/efb/VK_keypress", ""); - } - - if (keypress == "MENU") { - setProp("/sim/model/efb/page", "Displays/PU_1.jpg"); - setProp("/instrumentation/efb/page", "UTILITIES"); - setProp("/instrumentation/efb/Keyboard/Input_Line", ""); - setProp("/instrumentation/efb/Keyboard/Output_Line", ""); - keypress = ""; - } - - #__________________________________________________________________________________________ - # PILOT UTILITIES - WEIGHT CONVERSION Parser ----------------------------------------------| - #__________________________________________________________________________________________| - } elsif (currentPage == "UTILITIES_CNV_WGT") { - Input_Unit = getProp("/instrumentation/efb/VK_IN_Marker"); - Output_Unit = getProp("/instrumentation/efb/VK_OUT_Marker"); - - # Input keys Check - if (getProp("/instrumentation/efb/VK_keypress") != "" or (Input_Unit != VK_Input_Mem) or (Output_Unit != VK_Output_Mem)) { - # Input Field Parser - if (getProp("/instrumentation/efb/VK_keypress") == "CLEAR") { - setProp("/instrumentation/efb/Keyboard/Input_String", ""); # CLEARs the whole Input Field - setProp("/instrumentation/efb/VK_keypress", ""); - } - elsif (getProp("/instrumentation/efb/VK_keypress") == "BKSP") { - Temp_String = getProp("/instrumentation/efb/Keyboard/Input_String"); # BACKSPACEs the Input Field - lenght = size(Temp_String) - 1; - setProp("/instrumentation/efb/Keyboard/Input_String", substr(Temp_String, 0, lenght)); - setProp("/instrumentation/efb/VK_keypress", ""); - } - elsif (getProp("/instrumentation/efb/VK_keypress") == "CHNGS") { - Temp_String = getProp("/instrumentation/efb/Keyboard/Input_String"); # CHANGEs SIGN to the Input Field - if (substr(Temp_String, 0, 1) == "-") { - lenght = size(Temp_String) - 1; - Temp_String = substr(Temp_String, 1, lenght); - } else { - Temp_String = "-" ~ Temp_String; - } - setProp("/instrumentation/efb/Keyboard/Input_String", Temp_String); - setProp("/instrumentation/efb/VK_keypress", ""); - } - - # Input Field Display - setProp("/instrumentation/efb/Keyboard/Input_String", getProp("/instrumentation/efb/Keyboard/Input_String") ~ getProp("/instrumentation/efb/VK_keypress")); # Build the Input String - setProp("/instrumentation/efb/Keyboard/Input_Line2", getProp("/instrumentation/efb/Keyboard/Input_String")); # Print it to the Keyboard Input Field - - # ---------------> Conversion Table Selection - # ---------------> Input Unit 1 () KILOGRAMS ---> Output Unit: KILOGRAMS, POUNDS - if (Input_Unit == 1) { - if (Output_Unit == 1) Cnv_Fact = 1; - elsif (Output_Unit == 2) Cnv_Fact = 2.20462262185; - } - # ---------------> Input Unit 2 () POUNDS ---> Output Unit: KILOGRAMS, POUNDS - elsif (Input_Unit == 2) { - if (Output_Unit == 1) Cnv_Fact = 0.45359237; - elsif (Output_Unit == 2) Cnv_Fact = 1; - } - VK_Input_Mem = Input_Unit; - VK_Output_Mem = Output_Unit; - - # Output Field Display - if ((getProp("/instrumentation/efb/Keyboard/Input_Line2") == "") or (getProp("/instrumentation/efb/Keyboard/Input_Line2") == ".") or (getProp("/instrumentation/efb/Keyboard/Input_Line2") == "-")) { - setProp("/instrumentation/efb/Keyboard/Output_Line2", ""); - } else { - Output_Line2 = getProp("/instrumentation/efb/Keyboard/Input_Line2"); - Output_Line2 = Output_Line2 * Cnv_Fact; # Build the Input String - setProp("/instrumentation/efb/Keyboard/Output_Line2", Output_Line2); # Print it to the Keyboard Output Field - } - setProp("/instrumentation/efb/VK_keypress", ""); - } - - if (keypress == "MENU") { - setProp("/sim/model/efb/page", "Displays/PU_1.jpg"); - setProp("/instrumentation/efb/page", "UTILITIES"); - setProp("/instrumentation/efb/Keyboard/Input_Line2", ""); - setProp("/instrumentation/efb/Keyboard/Output_Line2", ""); - keypress = ""; - } - - #__________________________________________________________________________________________ - # PILOT UTILITIES - TEMPERATURE CONVERSION Parser -----------------------------------------| - #__________________________________________________________________________________________| - } elsif (currentPage == "UTILITIES_CNV_TMP") { - - Input_Unit = getProp("/instrumentation/efb/VK_IN_Marker"); - Output_Unit = getProp("/instrumentation/efb/VK_OUT_Marker"); - - # Input keys Check - if (getProp("/instrumentation/efb/VK_keypress") != "" or (Input_Unit != VK_Input_Mem) or (Output_Unit != VK_Output_Mem)) { - # Input Field Parser - if (getProp("/instrumentation/efb/VK_keypress") == "CLEAR") { - setProp("/instrumentation/efb/Keyboard/Input_String", ""); # CLEARs the whole Input Field - setProp("/instrumentation/efb/VK_keypress", ""); - } - elsif (getProp("/instrumentation/efb/VK_keypress") == "BKSP") { - Temp_String = getProp("/instrumentation/efb/Keyboard/Input_String"); # BACKSPACEs the Input Field - lenght = size(Temp_String) - 1; - setProp("/instrumentation/efb/Keyboard/Input_String", substr(Temp_String, 0, lenght)); - setProp("/instrumentation/efb/VK_keypress", ""); - } - elsif (getProp("/instrumentation/efb/VK_keypress") == "CHNGS") { - Temp_String = getProp("/instrumentation/efb/Keyboard/Input_String"); # CHANGEs SIGN to the Input Field - if (substr(Temp_String, 0, 1) == "-") { - lenght = size(Temp_String) - 1; - Temp_String = substr(Temp_String, 1, lenght); - } else { - Temp_String = "-" ~ Temp_String; - } - setProp("/instrumentation/efb/Keyboard/Input_String", Temp_String); - setProp("/instrumentation/efb/VK_keypress", ""); - } - # Input Field Display - setProp("/instrumentation/efb/Keyboard/Input_String", getProp("/instrumentation/efb/Keyboard/Input_String") ~ getProp("/instrumentation/efb/VK_keypress")); # Build the Input String - setProp("/instrumentation/efb/Keyboard/Input_Line2", getProp("/instrumentation/efb/Keyboard/Input_String")); # Print it to the Keyboard Input Field - - # Output Field Display - if ((getProp("/instrumentation/efb/Keyboard/Input_Line2") == "") or (getProp("/instrumentation/efb/Keyboard/Input_Line2") == ".") or (getProp("/instrumentation/efb/Keyboard/Input_Line2") == "-")) { - setProp("/instrumentation/efb/Keyboard/Output_Line2", ""); - } else { - Output_Line2 = getProp("/instrumentation/efb/Keyboard/Input_Line2"); - # ---------------> Conversion Table Selection - # ---------------> Input Unit 1 () CELSIUS (�C) ---> Output Unit: CELSIUS (�C), FAHRENHEIT (�F) - if (Input_Unit == 1) { - if (Output_Unit == 1) Cnv_Fact = Output_Line2; - elsif (Output_Unit == 2) Cnv_Fact = (Output_Line2*1.8) + 32; - } - # ---------------> Input Unit 2 () FAHRENHEIT (�F) ---> Output Unit: CELSIUS (�C), FAHRENHEIT (�F) - elsif (Input_Unit == 2) { - if (Output_Unit == 1) Cnv_Fact = (Output_Line2 - 32)/1.8; - elsif (Output_Unit == 2) Cnv_Fact = Output_Line2; - } - VK_Input_Mem = Input_Unit; - VK_Output_Mem = Output_Unit; - - Output_Line2 = Cnv_Fact; # Build the Input String - setProp("/instrumentation/efb/Keyboard/Output_Line2", Output_Line2); # Print it to the Keyboard Output Field - } - setProp("/instrumentation/efb/VK_keypress", ""); - } - if (keypress == "MENU") { - setProp("/sim/model/efb/page", "Displays/PU_1.jpg"); - setProp("/instrumentation/efb/page", "UTILITIES"); - setProp("/instrumentation/efb/Keyboard/Input_Line2", ""); - setProp("/instrumentation/efb/Keyboard/Output_Line2", ""); - keypress = ""; - } - #__________________________________________________________________________________________ - # PILOT UTILITIES - VOLUME CONVERSION Parser ----------------------------------------------| - #__________________________________________________________________________________________| - } elsif (currentPage == "UTILITIES_CNV_VLM") { - - Input_Unit = getProp("/instrumentation/efb/VK_IN_Marker"); - Output_Unit = getProp("/instrumentation/efb/VK_OUT_Marker"); - Output_TMZ_Line = ""; - # Input keys Check - if (getProp("/instrumentation/efb/VK_keypress") != "" or (Input_Unit != VK_Input_Mem) or (Output_Unit != VK_Output_Mem)) { - # Input Field Parser - if (getProp("/instrumentation/efb/VK_keypress") == "CLEAR") { - setProp("/instrumentation/efb/Keyboard/Input_String", ""); # CLEARs the whole Input Field - setProp("/instrumentation/efb/VK_keypress", ""); - } - elsif (getProp("/instrumentation/efb/VK_keypress") == "BKSP") { - Temp_String = getProp("/instrumentation/efb/Keyboard/Input_String"); # BACKSPACEs the Input Field - lenght = size(Temp_String) - 1; - setProp("/instrumentation/efb/Keyboard/Input_String", substr(Temp_String, 0, lenght)); - setProp("/instrumentation/efb/VK_keypress", ""); - } - elsif (getProp("/instrumentation/efb/VK_keypress") == "CHNGS") { - Temp_String = getProp("/instrumentation/efb/Keyboard/Input_String"); # CHANGEs SIGN to the Input Field - if (substr(Temp_String, 0, 1) == "-") { - lenght = size(Temp_String) - 1; - Temp_String = substr(Temp_String, 1, lenght); - } else { - Temp_String = "-" ~ Temp_String; - } - setProp("/instrumentation/efb/Keyboard/Input_String", Temp_String); - setProp("/instrumentation/efb/VK_keypress", ""); - } - # Input Field Display - setProp("/instrumentation/efb/Keyboard/Input_String", getProp("/instrumentation/efb/Keyboard/Input_String") ~ getProp("/instrumentation/efb/VK_keypress")); # Build the Input String - setProp("/instrumentation/efb/Keyboard/Input_Line3", getProp("/instrumentation/efb/Keyboard/Input_String")); # Print it to the Keyboard Input Field - - # ---------------> Conversion Table Selection - # ---------------> Input Unit 1 () IMPERIAL GALLONS ---> Output Unit: IMPERIAL GALLONS, US GALLONS, LITERS - if (Input_Unit == 1) { - if (Output_Unit == 1) Cnv_Fact = 1; - elsif (Output_Unit == 2) Cnv_Fact = 1.20095; - elsif (Output_Unit == 3) Cnv_Fact = 4.54609; - } - # ---------------> Input Unit 2 () US GALLONS ---> Output Unit: IMPERIAL GALLONS, US GALLONS, LITERS - elsif (Input_Unit == 2) { - if (Output_Unit == 1) Cnv_Fact = 0.832674; - elsif (Output_Unit == 2) Cnv_Fact = 1; - elsif (Output_Unit == 3) Cnv_Fact = 3.78541; - } - # ---------------> Input Unit 3 () LITERS ---> Output Unit: IMPERIAL GALLONS, US GALLONS, LITERS - elsif (Input_Unit == 3) { - if (Output_Unit == 1) Cnv_Fact = 0.219969; - elsif (Output_Unit == 2) Cnv_Fact = 0.264172; - elsif (Output_Unit == 3) Cnv_Fact = 1; - } - VK_Input_Mem = Input_Unit; - VK_Output_Mem = Output_Unit; - # Output Field Display - if ((getProp("/instrumentation/efb/Keyboard/Input_Line3") == "") or (getProp("/instrumentation/efb/Keyboard/Input_Line3") == ".") or (getProp("/instrumentation/efb/Keyboard/Input_Line3") == "-")) { - setProp("/instrumentation/efb/Keyboard/Output_Line3", ""); - } else { - Output_Line2 = getProp("/instrumentation/efb/Keyboard/Input_Line3"); - Output_Line2 = Output_Line2 * Cnv_Fact; # Build the Input String - setProp("/instrumentation/efb/Keyboard/Output_Line3", Output_Line2); # Print it to the Keyboard Output Field - } - setProp("/instrumentation/efb/VK_keypress", ""); - } - if (keypress == "MENU") { - setProp("/sim/model/efb/page", "Displays/PU_1.jpg"); - setProp("/instrumentation/efb/page", "UTILITIES"); - setProp("/instrumentation/efb/Keyboard/Input_Line3", ""); - setProp("/instrumentation/efb/Keyboard/Output_Line3", ""); - keypress = ""; - } - - #__________________________________________________________________________________________ - # PILOT UTILITIES - TIME ZONE CONVERSION Parser -------------------------------------------| - #__________________________________________________________________________________________| - } elsif (currentPage == "UTILITIES_CNV_TMZ") { - - TMZ_TIME = getProp("/instrumentation/clock/indicated-short-string") ~ "z"; - setProp("/instrumentation/efb/Keyboard/Current_DT_Line", TMZ_DATE ~ " " ~ TMZ_TIME); # Print Current Date & Time - setProp("/instrumentation/efb/Keyboard/Converted_Name_Line", "Use Keyboard to Input Time (HHMM)"); - # Input keys Check - - if (getProp("/instrumentation/efb/VK_keypress") != "") { - # Input Field Parser - if (getProp("/instrumentation/efb/VK_keypress") == "CLEAR") { - setProp("/instrumentation/efb/Keyboard/Input_String", ""); # CLEARs the whole Input Field and other stuff - setProp("/instrumentation/efb/Keyboard/Input_HH_Line", "--"); - setProp("/instrumentation/efb/Keyboard/Input_MM_Line", "--"); - setProp("/instrumentation/efb/Keyboard/Input_Zulu_Line", "--:--"); - setProp("/instrumentation/efb/Keyboard/Output_HH", ""); - setProp("/instrumentation/efb/Keyboard/Output_MM", ""); - setProp("/instrumentation/efb/Keyboard/Converted_ID_Line", ""); - setProp("/instrumentation/efb/Keyboard/Converted_Name_Line", "Use Keyboard to Input Time (HHMM)"); - setProp("/instrumentation/efb/Keyboard/Output_TMZ_Line", "--:--"); - setProp("/instrumentation/efb/Keyboard/Cnv_Fact", ""); - TMZ_index = 0; - Output_TMz_Line = "--:--"; - setProp("/instrumentation/efb/VK_keypress", ""); - } - elsif (getProp("/instrumentation/efb/VK_keypress") == "BKSP") { - Temp_String = getProp("/instrumentation/efb/Keyboard/Input_String"); # BACKSPACEs the Input Field - lenght = size(Temp_String) - 1; - setProp("/instrumentation/efb/Keyboard/Input_String", substr(Temp_String, 0, lenght)); - setProp("/instrumentation/efb/VK_keypress", ""); - } - elsif (getProp("/instrumentation/efb/VK_keypress") == "CHNGS") { - setProp("/instrumentation/efb/Keyboard/Input_String", getProp("/instrumentation/efb/Keyboard/Input_String")); # Bypasses CHANGEs SIGN - setProp("/instrumentation/efb/VK_keypress", ""); - } - - # Input Field Display - TMZ_String = getProp("/instrumentation/efb/Keyboard/Input_String"); - TMZ_Input_Lenght = size(TMZ_String); - - if (TMZ_Input_Lenght <= 3) { - setProp("/instrumentation/efb/Keyboard/Input_String", getProp("/instrumentation/efb/Keyboard/Input_String") ~ getProp("/instrumentation/efb/VK_keypress")); # Build the Input String - - if (TMZ_Input_Lenght > 1) { - setProp("/instrumentation/efb/Keyboard/Input_HH_Line", substr(getProp("/instrumentation/efb/Keyboard/Input_String"), 0, 2)); # IF 3rd digit, Print HH to the Keyboard Input Field - setProp("/instrumentation/efb/Keyboard/Output_HH", substr(getProp("/instrumentation/efb/Keyboard/Input_String"), 0, 2)); # Copy HH to Output_HH - setProp("/instrumentation/efb/Keyboard/Input_MM_Line", substr(getProp("/instrumentation/efb/Keyboard/Input_String"), 2, TMZ_Input_Lenght)); # IF 3rd digit, Print MM to the Keyboard Input Field - setProp("/instrumentation/efb/Keyboard/Output_MM", substr(getProp("/instrumentation/efb/Keyboard/Input_String"), 2, TMZ_Input_Lenght)); # Copy MM to Output_MM - setProp("/instrumentation/efb/Keyboard/Input_Zulu_Line", (getProp("/instrumentation/efb/Keyboard/Input_HH_Line") ~ ":" ~ getProp("/instrumentation/efb/Keyboard/Input_MM_Line"))); # IF 3rd digit, Print "zulu Time" to the Keyboard Output "zulu to be converted" Field (see EFB Manual) - } else { - setProp("/instrumentation/efb/Keyboard/Input_HH_Line", getProp("/instrumentation/efb/Keyboard/Input_String")); # Print Blank HH to the Keyboard Input Field - setProp("/instrumentation/efb/Keyboard/Input_MM_Line", "--"); # Print Blank HH to the Keyboard Input Field - setProp("/instrumentation/efb/Keyboard/Input_Zulu_Line", getProp("/instrumentation/efb/Keyboard/Input_HH_Line") ~ ":" ~ getProp("/instrumentation/efb/Keyboard/Input_MM_Line")); # Print Blank "zulu Time" to the Keyboard Output "zulu to be converted" Field (see EFB Manual) # Print "" MM to the Keyboard Input Field - setProp("/instrumentation/efb/Keyboard/Output_HH", ""); - setProp("/instrumentation/efb/Keyboard/Output_MM", ""); - } - - } # an 'else' clause should be set here, giving the Pilot an audible 'WARNING Beep', because we cannot accept more than 4 chars for Time Input! - } - setProp("/instrumentation/efb/VK_keypress", ""); # reset the VK keys to "" - - # ---------------> Output Unit: Input Time Conversion --> TIME ZONES Time - - if (TMZ_Input_Lenght > 1) { - # TMZ_Index = TMZ_Index; - if ((keypress == "r3") and (TMZ_Index > 0)) { - TMZ_Index = TMZ_Index - 1; - keypress = ""; - } # an 'else' clause should be set here, giving the Pilot an audible 'WARNING Beep', because he reached Bottom End of DB File! - if ((keypress == "r4") and (TMZ_Index < TMZ_DB_Size)) { - TMZ_Index = TMZ_Index + 1; - keypress = ""; - } # an 'else' clause should be set here, giving the Pilot an audible 'WARNING Beep', because he reached Top End of DB File! - #setProp("/instrumentation/efb/Keyboard/Output_HH", "12"); - #setProp("/instrumentation/efb/Keyboard/Output_MM", "54"); - if (keypress == "r5") { setProp("/instrumentation/efb/Keyboard/Cnv_Fact", "0"); # RESET ALL - setProp("/instrumentation/efb/Keyboard/Input_String", ""); - TMZ_String = ""; - TMZ_Index = 0; - TMZ_Input_Lenght = 0; - setProp("/instrumentation/efb/Keyboard/Current_DT_Line", ""); - setProp("/instrumentation/efb/Keyboard/Input_HH_Line", ""); - setProp("/instrumentation/efb/Keyboard/Input_MM_Line", ""); - setProp("/instrumentation/efb/Keyboard/Input_Zulu_Line", ""); - setProp("/instrumentation/efb/Keyboard/Output_HH", "0"); - setProp("/instrumentation/efb/Keyboard/Output_MM", "0"); - setProp("/instrumentation/efb/Keyboard/Converted_ID_Line", ""); - setProp("/instrumentation/efb/Keyboard/Converted_Name_Line", "Use Keyboard to Input Time (HHMM)"); - setProp("/instrumentation/efb/Keyboard/Output_TMZ_Line", ""); - setProp("/instrumentation/efb/Keyboard/Cnv_Fact", "0"); - TMZ_index = 0; - Output_TMz_Line = "--:--"; - } - if (getProp("/instrumentation/efb/Keyboard/Output_HH") != "0") { - TMZ_Converted_ID = getProp("/instrumentation/efb/TimeZonesDB/IDX[" ~ TMZ_Index ~ "]/ID"); - TMZ_Converted_Name = getProp("/instrumentation/efb/TimeZonesDB/IDX[" ~ TMZ_Index ~ "]/Name"); - TMZ_zulu_HH = getProp("/instrumentation/efb/Keyboard/Output_HH"); - TMZ_Converted_OffSet = getProp("/instrumentation/efb/TimeZonesDB/IDX[" ~ TMZ_Index ~ "]/OffSet"); - setProp("/instrumentation/efb/Keyboard/Converted_ID_Line", TMZ_Converted_ID); # Print Time Zone ID to the Keyboard Converted Time Field - setProp("/instrumentation/efb/Keyboard/Converted_Name_Line", TMZ_Converted_Name); # Print Time Zone Name to the Keyboard Converted Time Field - setProp("/instrumentation/efb/Keyboard/Cnv_Fact", (TMZ_zulu_HH + TMZ_Converted_OffSet)); - } else { - setProp("/instrumentation/efb/Keyboard/Cnv_Fact", 0); - } - # HH Corrections for Time Zone's Conversion Factors - if (getProp("/instrumentation/efb/Keyboard/Cnv_Fact") > 9) { - setProp("/instrumentation/efb/Keyboard/Cnv_Fact", getProp("/instrumentation/efb/Keyboard/Cnv_Fact")); # Print HH Converted Time to the Keyboard Converted Time Field - } elsif (((getProp("/instrumentation/efb/Keyboard/Cnv_Fact") >= 0) and (getProp("/instrumentation/efb/Keyboard/Cnv_Fact") <= 9))) { - setProp("/instrumentation/efb/Keyboard/Cnv_Fact", "0" ~ getProp("/instrumentation/efb/Keyboard/Cnv_Fact")); # Print H Converted Time to the Keyboard Converted Time Field - } elsif (getProp("/instrumentation/efb/Keyboard/Cnv_Fact") < 0) { - setProp("/instrumentation/efb/Keyboard/Cnv_Fact", (24 + getProp("/instrumentation/efb/Keyboard/Cnv_Fact"))); # Print (24 - HH) Converted Time to the Keyboard Converted Time Field - } - } else { - setProp("/instrumentation/efb/Keyboard/Cnv_Fact", "--"); - } - # Output Converted Time Field Display - if ((getProp("/instrumentation/efb/Keyboard/Input_HH_Line") == "") or (getProp("/instrumentation/efb/Keyboard/Input_HH_Line") == ".") or (getProp("/instrumentation/efb/Keyboard/Input_HH_Line") == "--")) { - setProp("/instrumentation/efb/Keyboard/Output_TMZ_Line", ""); - Output_TMz_Line = "--:--"; - } else { - Output_TMZ_Line = getProp("/instrumentation/efb/Keyboard/Cnv_Fact"); - Output_TMZ_Line = substr(Output_TMZ_Line, 0, 2) ~ ":" ~ getProp("/instrumentation/efb/Keyboard/Output_MM");# Build the Output String - } - setProp("/instrumentation/efb/Keyboard/Output_TMZ_Line", Output_TMZ_Line); # Print it to the Keyboard Output Converted Time Field - - if (keypress == "MENU") { - setProp("/sim/model/efb/page", "Displays/PU_1.jpg"); - setProp("/instrumentation/efb/page", "UTILITIES"); - setProp("/instrumentation/efb/Keyboard/Current_DT_Line", ""); - setProp("/instrumentation/efb/Keyboard/Input_HH_Line", ""); - setProp("/instrumentation/efb/Keyboard/Input_MM_Line", ""); - setProp("/instrumentation/efb/Keyboard/Input_Zulu_Line", ""); - setProp("/instrumentation/efb/Keyboard/Cnv_Fact", ""); - setProp("/instrumentation/efb/Keyboard/Output_HH", ""); - setProp("/instrumentation/efb/Keyboard/Output_MM", ""); - setProp("/instrumentation/efb/Keyboard/Converted_ID_Line", ""); - setProp("/instrumentation/efb/Keyboard/Converted_Name_Line", ""); - setProp("/instrumentation/efb/Keyboard/Output_TMZ_Line", ""); - setProp("/instrumentation/efb/Keyboard/Input_String", ""); - - keypress = ""; - } - - #__________________________________________________________________________________________ - # PILOT UTILITIES - DESCENT RATE Calculator ----------------------------------------------| - #_________________________________________________________________________________________| - } elsif (currentPage == "UTILITIES_DESC_RATE") { - - page.clearpage(); - # Input keys Check - if (keypress == "l2") { - setProp("/instrumentation/efb/Input_Unit", "Initial_FL"); - setProp("/instrumentation/efb/Keyboard/Input_String",""); - setProp("/instrumentation/efb/DRC_Initial_FL_MEM", getProp("/instrumentation/efb/DRC_Initial_FL")); - setProp("/instrumentation/efb/VK_DRC_MarkerL", 1); - setProp("/instrumentation/efb/VK_DRC_MarkerR", 0); - } - elsif (keypress == "r2") { - setProp("/instrumentation/efb/Input_Unit", "Target_FL"); - setProp("/instrumentation/efb/Keyboard/Input_String",""); - setProp("/instrumentation/efb/DRC_Target_FL_MEM", getProp("/instrumentation/efb/DRC_Target_FL")); - setProp("/instrumentation/efb/VK_DRC_MarkerR", 1); - setProp("/instrumentation/efb/VK_DRC_MarkerL", 0); - } - elsif (keypress == "l3") { - setProp("/instrumentation/efb/Input_Unit", "Initial_GS"); - setProp("/instrumentation/efb/Keyboard/Input_String",""); - setProp("/instrumentation/efb/DRC_Initial_GS_MEM", getProp("/instrumentation/efb/DRC_Initial_GS")); - setProp("/instrumentation/efb/VK_DRC_MarkerL", 2); - setProp("/instrumentation/efb/VK_DRC_MarkerR", 0); - } - elsif (keypress == "r3") { - setProp("/instrumentation/efb/Input_Unit", "Target_GS"); - setProp("/instrumentation/efb/Keyboard/Input_String",""); - setProp("/instrumentation/efb/DRC_Target_GS_MEM", getProp("/instrumentation/efb/DRC_Target_GS")); - setProp("/instrumentation/efb/VK_DRC_MarkerR", 2); - setProp("/instrumentation/efb/VK_DRC_MarkerL", 0); - } - elsif (keypress == "l4") { - setProp("/instrumentation/efb/Input_Unit", "Distance"); - setProp("/instrumentation/efb/Keyboard/Input_String",""); - setProp("/instrumentation/efb/DRC_Distance_MEM", getProp("/instrumentation/efb/DRC_Distance")); - setProp("/instrumentation/efb/VK_DRC_MarkerL", 3); - setProp("/instrumentation/efb/VK_DRC_MarkerR", 0); - } - - # Input keys Parser - if ((getProp("/instrumentation/efb/VK_keypress") != "") and (getProp("/instrumentation/efb/VK_keypress") != ".") and (getProp("/instrumentation/efb/VK_keypress") != "CHNGS") and (getProp("/instrumentation/efb/Input_Unit") != "NO_INPUT")) { - if (getProp("/instrumentation/efb/VK_keypress") == "CLEAR") { - setProp("/instrumentation/efb/Keyboard/Input_String", ""); # CLEARs the whole Input Field - VK_Key = "VOID"; - setProp("/instrumentation/efb/VK_keypress", ""); - } - elsif (getProp("/instrumentation/efb/VK_keypress") == "BKSP") { - Temp_String = getProp("/instrumentation/efb/Keyboard/Input_String"); # BACKSPACEs the Input Field - lenght = size(Temp_String) - 1; - if (lenght >= 1) { - setProp("/instrumentation/efb/Keyboard/Input_String", substr(Temp_String, 0, lenght)); - setProp("/instrumentation/efb/VK_keypress", ""); - } elsif (lenght <= 0) { - setProp("/instrumentation/efb/Keyboard/Input_String", ""); # CLEARs the whole Input Field - VK_Key = "VOID"; - } - } - DRC_String = getProp("/instrumentation/efb/Keyboard/Input_String"); - DRC_Input_Lenght = size(DRC_String); - - if (DRC_Input_Lenght < 3) { - if (VK_Key != "VOID") { - setProp("/instrumentation/efb/Keyboard/Input_String", getProp("/instrumentation/efb/Keyboard/Input_String") ~ getProp("/instrumentation/efb/VK_keypress")); # Build the Input String... - } - if ((getProp("/instrumentation/efb/Input_Unit") == "Initial_FL") and (VK_Key != "VOID")) { - setProp("/instrumentation/efb/DRC_Initial_FL", getProp("/instrumentation/efb/Keyboard/Input_String")); # ...For Initial FL - } elsif ((getProp("/instrumentation/efb/Input_Unit") == "Initial_FL") and (VK_Key == "VOID")) { - setProp("/instrumentation/efb/display/DRC_l3", "CLEAR"); - setProp("/instrumentation/efb/DRC_Initial_FL", getProp("/instrumentation/efb/DRC_Initial_FL_MEM")); - } - if ((getProp("/instrumentation/efb/Input_Unit") == "Target_FL") and (VK_Key != "VOID")) { - setProp("/instrumentation/efb/DRC_Target_FL", getProp("/instrumentation/efb/Keyboard/Input_String")); # ...For Target FL - } elsif ((getProp("/instrumentation/efb/Input_Unit") == "Target_FL") and (VK_Key == "VOID")) { - setProp("/instrumentation/efb/display/DRC_r3", "CLEAR"); - setProp("/instrumentation/efb/DRC_Target_FL", getProp("/instrumentation/efb/DRC_Target_FL_MEM")); - } - if ((getProp("/instrumentation/efb/Input_Unit") == "Initial_GS") and (VK_Key != "VOID")) { - setProp("/instrumentation/efb/DRC_Initial_GS", getProp("/instrumentation/efb/Keyboard/Input_String")); # ...For Initial GS - } elsif ((getProp("/instrumentation/efb/Input_Unit") == "Initial_GS") and (VK_Key == "VOID")) { - setProp("/instrumentation/efb/display/DRC_l5", "CLEAR"); - setProp("/instrumentation/efb/DRC_Initial_GS", getProp("/instrumentation/efb/DRC_Initial_GS_MEM")); - } - if ((getProp("/instrumentation/efb/Input_Unit") == "Target_GS") and (VK_Key != "VOID")) { - setProp("/instrumentation/efb/DRC_Target_GS", getProp("/instrumentation/efb/Keyboard/Input_String")); # ...For Target GS - } elsif ((getProp("/instrumentation/efb/Input_Unit") == "Target_GS") and (VK_Key == "VOID")) { - setProp("/instrumentation/efb/display/DRC_r5", "CLEAR"); - setProp("/instrumentation/efb/DRC_Target_GS", getProp("/instrumentation/efb/DRC_Target_GS_MEM")); - } - if ((getProp("/instrumentation/efb/Input_Unit") == "Distance") and (VK_Key != "VOID")) { - setProp("/instrumentation/efb/DRC_Distance", getProp("/instrumentation/efb/Keyboard/Input_String")); # ...For Distance - } elsif ((getProp("/instrumentation/efb/Input_Unit") == "Distance") and (VK_Key == "VOID")) { - setProp("/instrumentation/efb/display/DRC_l7", "CLEAR"); - setProp("/instrumentation/efb/DRC_Distance", getProp("/instrumentation/efb/DRC_Distance_MEM")); - } - } - } - setProp("/instrumentation/efb/VK_keypress", ""); # reset the VK keys to "" - VK_Key = ""; - - # Transfers Values to DRC variables as numbers - Initial_FL = num(getProp("/instrumentation/efb/DRC_Initial_FL")); - Target_FL = num(getProp("/instrumentation/efb/DRC_Target_FL")); - Initial_GS = num(getProp("/instrumentation/efb/DRC_Initial_GS")); - Target_GS = num(getProp("/instrumentation/efb/DRC_Target_GS")); - DRC_Distance = num(getProp("/instrumentation/efb/DRC_Distance")); - - # Calculates Formulas - # Formula: [Angle of Descent (ft/NM) = ALT Gradient/Distance] |||| [SPD Factor (ft/min) = SPD Gradient/60] |||| [Target Descent Rate (Fpm) = Angle of Descent * SPD Factor] - - var DRC_Angle = (Target_FL - Initial_FL)/DRC_Distance; - var DRC_AvgSpeed = (Initial_GS + Target_GS)/2; - var DRC_Fact = DRC_AvgSpeed/60; - var DRC_Output = DRC_Angle * DRC_Fact*100; - var DRC_Time = (Target_FL - Initial_FL)/(DRC_Output/100); - - # Prepares Output Strings - DRC_l3 = substr(getProp("/instrumentation/efb/DRC_Initial_FL"), 0, 3); - CUT = split(".", DRC_l3); - DRC_l3 = CUT[0]; - - DRC_r3 = substr(getProp("/instrumentation/efb/DRC_Target_FL"), 0, 3); - CUT = split(".", DRC_r3); - DRC_r3 = CUT[0]; - - DRC_l5 = substr(getProp("/instrumentation/efb/DRC_Initial_GS"), 0, 3); - CUT = split(".", DRC_l5); - DRC_l5 = CUT[0]; - - DRC_r5 = substr(getProp("/instrumentation/efb/DRC_Target_GS"), 0, 3); - CUT = split(".", DRC_r5); - DRC_r5 = CUT[0]; - - DRC_l7 = substr(getProp("/instrumentation/efb/DRC_Distance"), 0, 3); - CUT = split(".", DRC_l7); - DRC_l7 = CUT[0]; - - setProp("/instrumentation/efb/DRC_Output", "100"); - setProp("/instrumentation/efb/DRC_Output", DRC_Output); - DRC_r8 = substr(getProp("/instrumentation/efb/DRC_Output"), 0, 8); - CUT = split(".", DRC_r8); - DRC_r8 = CUT[0]; - - setProp("/instrumentation/efb/DRC_Angle", "100"); - setProp("/instrumentation/efb/DRC_Angle", DRC_Angle); - DRC_r9 = substr(getProp("/instrumentation/efb/DRC_Angle"), 0, 5); - # CUT = split(".", DRC_r9); - # DRC_r9 = CUT[0]; - - setProp("/instrumentation/efb/DRC_Time", "100"); - setProp("/instrumentation/efb/DRC_Time", DRC_Time); - DRC_r10 = substr(getProp("/instrumentation/efb/DRC_Time"), 0, 5); - #CUT = split(".", DRC_r10); - #DRC_r10 = CUT[0]; - - - page.DRCupdate(); # Displays Output - - if (keypress == "MENU") { - page.DRCclearpage(); - page.DRCupdate(); - setProp("/sim/model/efb/page", "Displays/PU_1.jpg"); - setProp("/instrumentation/efb/VK_DRC_MarkerR", 0); - setProp("/instrumentation/efb/VK_DRC_MarkerL", 0); - setProp("/instrumentation/efb/page", "UTILITIES"); - keypress = ""; - } - #__________________________________________________________________________________________ - # PILOT UTILITIES - NORMAL PROCEDURES MANUAL ----------------------------------------------| - #__________________________________________________________________________________________| - } elsif (currentPage == "NORM PROC MANUAL") { - page.clearpage(); - - if (keypress == "PGUP") { - setProp("/instrumentation/efb/manual-page", getProp("/instrumentation/efb/manual-page") - 0.20); - keypress = ""; - } - elsif (keypress == "ScrollUP") { - setProp("/instrumentation/efb/manual-page", getProp("/instrumentation/efb/manual-page") - 0.02); - keypress = ""; - } - elsif (keypress == "ScrollDN") { - setProp("/instrumentation/efb/manual-page", getProp("/instrumentation/efb/manual-page") + 0.02); - keypress = ""; - } - elsif (keypress == "PGDN") { - setProp("/instrumentation/efb/manual-page", getProp("/instrumentation/efb/manual-page") + 0.20); - keypress = ""; - } - elsif (keypress == "MENU") { - setProp("/sim/model/efb/page", "Displays/Documents_1.jpg"); - setProp("/instrumentation/efb/page", "DOCUMENTS"); - keypress = ""; - } - } - #___________________________________________________________________________________________ - #_______________________________END of Parsers & SubParsers_________________________________| - page.update(); - if ((getProp("/instrumentation/efb/page") == "Airport Charts") or (getProp("/instrumentation/efb/page") == "Airport Diagram") or (getProp("/instrumentation/efb/page") == "NORM PROC MANUAL")) setProp("/instrumentation/efb/text-color", 0); - else setProp("/instrumentation/efb/text-color", 1); - }, - reset : func { - if(!me.efbTimer) - me.efbTimer = maketimer(me.UPDATE_INTERVAL, func me.update()); - else - me.efbTimer.stop(); - me.loopid += 1; - #//me._loop_(me.loopid); - me.efbTimer.start(); - }, - #//_loop_ : func() { - #// id == me.loopid or return; - #// me.update(); - #//} -}; - -var toggle = func(property) { - if (getProp(property) == 1) - setProp(property, 0); - else - setProp(property, 1); -} -setlistener("sim/signals/fdm-initialized", func {efb.init();}); diff --git a/test/fib.nas b/test/fib.nas index 51e36b0..d06371a 100644 --- a/test/fib.nas +++ b/test/fib.nas @@ -5,15 +5,4 @@ var fib=func(x) return fib(x-1)+fib(x-2); } for(var i=0;i<31;i+=1) - print(fib(i),'\n'); - -var m=[0,1,1,2,3,5,8]; -setsize(m,32); -var fib=func(n) -{ - if(m[n]!=nil) return m[n]; - var t=fib(n-1)+fib(n-2); - m[n]=t; - return t; -} -print(fib(31),'\n'); \ No newline at end of file + print(fib(i),'\n'); \ No newline at end of file diff --git a/test/multiplayer.nas b/test/multiplayer.nas deleted file mode 100644 index 4d71d3a..0000000 --- a/test/multiplayer.nas +++ /dev/null @@ -1,643 +0,0 @@ -############################################################################### -## -## Nasal module for dual control over the multiplayer network. -## -## Copyright (C) 2007 - 2010 Anders Gidenstam (anders(at)gidenstam.org) -## This file is licensed under the GPL license version 2 or later. -## -############################################################################### -## MP properties -var lat_mpp = "position/latitude-deg"; -var lon_mpp = "position/longitude-deg"; -var alt_mpp = "position/altitude-ft"; -var heading_mpp = "orientation/true-heading-deg"; -var pitch_mpp = "orientation/pitch-deg"; -var roll_mpp = "orientation/roll-deg"; - -# Import components from the mp_broadcast module. -var Binary = mp_broadcast.Binary; -var MessageChannel = mp_broadcast.MessageChannel; - -############################################################################### -# Utility classes - -############################################################ -# Translate a property into another. -# Factor and offsets are only used for numeric values. -# src - source : property node -# dest - destination : property node -# factor - : double -# offset - : double -var Translator = {}; -Translator.new = func (src = nil, dest = nil, factor = 1, offset = 0) { - var obj = { parents : [Translator], - src : src, - dest : dest, - factor : factor, - offset : offset }; - if (obj.src == nil or obj.dest == nil) { - print("Translator["); - print(" ", debug.string(obj.src)); - print(" ", debug.string(obj.dest)); - print("]"); - fail(); - } - - return obj; -} -Translator.update = func () { - var v = me.src.getValue(); - if (is_num(v)) { - me.dest.setValue(me.factor * v + me.offset); - } else { - if (typeof(v) == "scalar") - me.dest.setValue(v); - } -} - -############################################################ -# Detects flanks on two insignals encoded in a property. -# - positive signal up/down flank -# - negative signal up/down flank -# n - source : property node -# on_positive_flank - action : func (v) -# on_negative_flank - action : func (v) -var EdgeTrigger = {}; -EdgeTrigger.new = func (n, on_positive_flank, on_negative_flank) { - var obj = { parents : [EdgeTrigger], - old : 0, - node : n, - pos_flank : on_positive_flank, - neg_flank : on_negative_flank }; - if (obj.node == nil) { - print("EdgeTrigger["); - print(" ", debug.string(obj.node)); - print("]"); - fail(); - } - return obj; -} -EdgeTrigger.update = func { - # NOTE: float MP properties get interpolated. - # This detector relies on that steady state is reached between - # flanks. - var val = me.node.getValue(); - if (!is_num(val)) return; - if (me.old == 1) { - if (val < me.old) { - me.pos_flank(0); - } - } elsif (me.old == 0) { - if (val > me.old) { - me.pos_flank(1); - } elsif (val < me.old) { - me.neg_flank(1); - } - } elsif (me.old == -1) { - if (val > me.old) { - me.neg_flank(0); - } - } - me.old = val; -} - -############################################################ -# StableTrigger: Triggers an action when a MPP property -# becomes stable (i.e. doesn't change for -# MIN_STABLE seconds). -# src - MP prop : property node -# action - action to take when the value becomes stable : [func(v)] -# An action is triggered when value has stabilized. -var StableTrigger = {}; -StableTrigger.new = func (src, action) { - var obj = { parents : [StableTrigger], - src : src, - action : action, - old : 0, - stable_since : 0, - wait : 0, - MIN_STABLE : 0.01 }; - # Error checking. - var bad = (obj.src == nil) or (action = nil); - - if (bad) { - print("StableTrigger["); - print(" ", debug.string(obj.src)); - print(" ", debug.string(obj.action)); - print("]"); - fail(); - } - - return obj; -} -StableTrigger.update = func () { - var v = me.src.getValue(); - if (!is_num(v)) return; - var t = getprop("/sim/time/elapsed-sec"); # NOTE: simulated time. - - if ((me.old == v) and - ((t - me.stable_since) > me.MIN_STABLE) and (me.wait == 1)) { - # Trigger action. - me.action(v); - - me.wait = 0; - } elsif (me.old == v) { - # Wait. This is either before the signal is stable or after the action. - } else { - me.stable_since = t; - me.wait = 1; - me.old = me.src.getValue(); - } -} - -############################################################ -# Selects the most recent value of two properties. -# src1 - : property node -# src2 - : property node -# dest - : property node -# threshold - : double -var MostRecentSelector = {}; -MostRecentSelector.new = func (src1, src2, dest, threshold) { - var obj = { parents : [MostRecentSelector], - old1 : 0, - old2 : 0, - src1 : src1, - src2 : src2, - dest : dest, - thres : threshold }; - if (obj.src1 == nil or obj.src2 == nil or obj.dest == nil) { - print("MostRecentSelector["); - print(" ", debug.string(obj.src1)); - print(" ", debug.string(obj.src2)); - print(" ", debug.string(obj.dest)); - print("]"); - } - - return obj; -} -MostRecentSelector.update = func { - var v1 = me.src1.getValue(); - var v2 = me.src2.getValue(); - if (!is_num(v1) and !is_num(v2)) return; - elsif (!is_num(v1)) me.dest.setValue(v2); - elsif (!is_num(v2)) me.dest.setValue(v1); - else { - if (abs (v2 - me.old2) > me.thres) { - me.old2 = v2; - me.dest.setValue(me.old2); - } - if (abs (v1 - me.old1) > me.thres) { - me.old1 = v1; - me.dest.setValue(me.old1); - } - } -} - -############################################################ -# Adds two input properties. -# src1 - : property node -# src2 - : property node -# dest - : property node -var Adder = {}; -Adder.new = func (src1, src2, dest) { - var obj = { parents : [DeltaAccumulator], - src1 : src1, - src2 : src2, - dest : dest }; - if (obj.src1 == nil or obj.src2 == nil or obj.dest == nil) { - print("Adder["); - print(" ", debug.string(obj.src1)); - print(" ", debug.string(obj.src2)); - print(" ", debug.string(obj.dest)); - print("]"); - fail(); - } - - return obj; -} -Adder.update = func () { - var v1 = me.src1.getValue(); - var v2 = me.src2.getValue(); - if (!is_num(v1) or !is_num(v2)) return; - me.dest.setValue(v1 + v2); -} - -############################################################ -# Adds the delta of src to dest. -# src - : property node -# dest - : property node -var DeltaAdder = {}; -DeltaAdder.new = func (src, dest) { - var obj = { parents : [DeltaAdder], - old : 0, - src : src, - dest : dest }; - if (obj.src == nil or obj.dest == nil) { - print("DeltaAdder[", debug.string(obj.src), ", ", - debug.string(obj.dest), "]"); - fail(); - } - - return obj; -} -DeltaAdder.update = func () { - var v = me.src.getValue(); - if (!is_num(v)) return; - me.dest.setValue((v - me.old) + me.dest.getValue()); - me.old = v; -} - -############################################################ -# Switch encoder: Encodes upto 32 boolean properties in one -# int property. -# inputs - list of property nodes -# dest - where the bitmask is stored : property node -var SwitchEncoder = {}; -SwitchEncoder.new = func (inputs, dest) { - var obj = { parents : [SwitchEncoder], - inputs : inputs, - dest : dest }; - # Error checking. - var bad = (obj.dest == nil); - foreach (var i; inputs) { - if (i == nil) { bad = 1; } - } - - if (bad) { - print("SwitchEncoder["); - foreach (var i; inputs) { - print(" ", debug.string(i)); - } - print(" ", debug.string(obj.dest)); - print("]"); - fail(); - } - - return obj; -} -SwitchEncoder.update = func () { - var v = 0; - var b = 1; - forindex (var i; me.inputs) { - if (me.inputs[i].getBoolValue()) { - v = v + b; - } - b *= 2; - } - me.dest.setIntValue(v); -} - -############################################################ -# Switch decoder: Decodes a bitmask in an int property. -# src - : property node -# actions - list of actions : [func(b)] -# Actions are triggered when their input bit change. -# Due to interpolation the decoder needs to wait for a -# stable input value. -var SwitchDecoder = {}; -SwitchDecoder.new = func (src, actions) { - var obj = { parents : [SwitchDecoder], - wait : 0, - old : 0, - old_stable : 0, - stable_since : 0, - reset : 1, - src : src, - actions : actions, - MIN_STABLE : 0.1 }; - # Error checking. - var bad = (obj.src == nil); - foreach (var a; obj.actions) { - if (a == nil) { bad = 1; } - } - - if (bad) { - print("SwitchDecoder["); - print(" ", debug.string(obj.src)); - foreach (var a; obj.actions) { - print(" ", debug.string(a)); - } - print("]"); - fail(); - } - - return obj; -} -SwitchDecoder.update = func () { - var t = getprop("/sim/time/elapsed-sec"); # NOTE: simulated time. - var v = me.src.getValue(); - if (!is_num(v)) return; - - if ((me.old == v) and ((t - me.stable_since) > me.MIN_STABLE) and - (me.wait == 1)) { - var ov = me.old_stable; -# Use this to improve. -# here's the boring version: var bittest = func(u, b) { while (b) { u = int(u / 2); b -= 1; } u != int(u / 2) * 2; } - forindex (var i; me.actions) { - var m = math.mod(v, 2); - var om = math.mod(ov, 2); - if ((m != om or me.reset)) { me.actions[i](m?1:0); } - v = (v - m)/2; - ov = (ov - om)/2; - } - me.old_stable = me.src.getValue(); - me.wait = 0; - me.reset = 0; - } elsif (me.old == v) { - # Wait. This is either before the bitmask is stable or after - # it has been processed. - } else { - me.stable_since = t; - me.wait = 1; - me.old = me.src.getValue(); - } -} - -############################################################ -# Time division multiplexing encoder: Transmits a list of -# properties over a MP enabled string property. -# inputs - input properties : [property node] -# dest - MP string prop : property node -# Note: TDM can have high latency so it is best used for -# non-time critical properties. -var TDMEncoder = {}; -TDMEncoder.new = func (inputs, dest) { - var obj = { parents : [TDMEncoder], - inputs : inputs, - channel : MessageChannel.new(dest, - func (msg) { - print("This should not happen!"); - }), - MIN_INT : 0.25, - last_time : 0, - next_item : 0, - old : [] }; - # Error checking. - var bad = (dest == nil) or (obj.channel == nil); - foreach (var i; inputs) { - if (i == nil) { bad = 1; } - } - - if (bad) { - print("TDMEncoder["); - foreach (var i; inputs) { - print(" ", debug.string(i)); - } - print(" ", debug.string(dest)); - print("]"); - } - - setsize(obj.old, size(obj.inputs)); - - return obj; -} -TDMEncoder.update = func () { - var t = getprop("/sim/time/elapsed-sec"); # NOTE: simulated time. - if (t > me.last_time + me.MIN_INT) { - var n = size(me.inputs); - while (1) { - var v = me.inputs[me.next_item].getValue(); - - if ((n <= 0) or (me.old[me.next_item] != v)) { - # Set the MP properties to send the next item. - me.channel.send(Binary.encodeByte(me.next_item) ~ - Binary.encodeDouble(v)); - - me.old[me.next_item] = v; - - me.last_time = t; - me.next_item += 1; - if (me.next_item >= size(me.inputs)) { me.next_item = 0; } - return; - } else { - # Search for changed property. - n -= 1; - me.next_item += 1; - if (me.next_item >= size(me.inputs)) { me.next_item = 0; } - } - } - } -} - -############################################################ -# Time division multiplexing decoder: Receives a list of -# properties over a MP enabled string property. -# src - MP string prop : property node -# actions - list of actions : [func(v)] -# An action is triggered when its value is received. -# Note: TDM can have high latency so it is best used for -# non-time critical properties. -var TDMDecoder = {}; -TDMDecoder.new = func (src, actions) { - var obj = { parents : [TDMDecoder], - actions : actions }; - obj.channel = MessageChannel.new(src, - func (msg) { - obj.process(msg); - }); - - # Error checking. - var bad = (src == nil) or (obj.channel == nil); - foreach (var a; actions) { - if (a == nil) { bad = 1; } - } - - if (bad) { - print("TDMDecoder["); - print(" ", debug.string(src)); - foreach (var a; actions) { - print(" ", debug.string(a)); - } - print("]"); - fail(); - } - - return obj; -} -TDMDecoder.process = func (msg) { - var v1 = Binary.decodeByte(msg); - var v2 = Binary.decodeDouble(substr(msg, 1)); - # Trigger action. - me.actions[v1](v2); -} -TDMDecoder.update = func { - me.channel.update(); -} - -############################################################################### -# Internal utility functions - -var is_num = func (v) { - return num(v) != nil; -} - -# fail causes a Nasal runtime error so we get a backtrace. -var fail = func { - error_detected_in_calling_context(); -} - -############################################################################### - -############################################################################### -# Copilot selection dialog. -# -# Usage: dual_control_tools.copilot_dialog.show(); -# -var COPILOT_DLG = 0; -var copilot_dialog = {}; -############################################################ -copilot_dialog.init = func (copilot_type, x = nil, y = nil) { - me.x = x; - me.y = y; - me.bg = [0, 0, 0, 0.3]; # background color - me.fg = [[1.0, 1.0, 1.0, 1.0]]; - # - # "private" - if (contains(aircraft_dual_control, "copilot_view")) { - me.title = "Pilot selection"; - } else { - me.title = "Copilot selection"; - } - me.basenode = props.globals.getNode("sim/remote", 1); - me.dialog = nil; - me.namenode = props.Node.new({"dialog-name" : me.title }); - me.listeners = []; - me.copilot_type = copilot_type; -} -############################################################ -copilot_dialog.create = func { - if (me.dialog != nil) - me.close(); - - me.dialog = gui.Widget.new(); - me.dialog.set("name", me.title); - if (me.x != nil) - me.dialog.set("x", me.x); - if (me.y != nil) - me.dialog.set("y", me.y); - - me.dialog.set("layout", "vbox"); - me.dialog.set("default-padding", 0); - var titlebar = me.dialog.addChild("group"); - titlebar.set("layout", "hbox"); - titlebar.addChild("empty").set("stretch", 1); - if (contains(aircraft_dual_control, "copilot_view")) { - titlebar.addChild("text").set("label", "Book your flight"); - } else { - titlebar.addChild("text").set("label", "Passengers online"); - } - var w = titlebar.addChild("button"); - w.set("pref-width", 16); - w.set("pref-height", 16); - w.set("legend", ""); - w.set("default", 0); - w.set("key", "esc"); - w.setBinding("nasal", "dual_control_tools.copilot_dialog.destroy(); "); - w.setBinding("dialog-close"); - me.dialog.addChild("hrule"); - - var content = me.dialog.addChild("group"); - content.set("layout", "vbox"); - content.set("halign", "center"); - content.set("default-padding", 5); - - # Generate the dialog contents. - me.players = me.find_copilot_players(); - var i = 0; - var tmpbase = me.basenode.getNode("dialog", 1); - var selected = me.basenode.getNode("pilot-callsign").getValue(); - foreach (var p; me.players) { - var tmp = tmpbase.getNode("b[" ~ i ~ "]", 1); - tmp.setBoolValue(streq(selected, p)); - var w = content.addChild("checkbox"); - w.node.setValues({"label" : p, - "halign" : "left", - "property" : tmp.getPath()}); - w.setBinding - ("nasal", - "dual_control_tools.copilot_dialog.select_action(" ~ i ~ ");"); - i = i + 1; - } - me.dialog.addChild("hrule"); - - # Display the dialog. - fgcommand("dialog-new", me.dialog.prop()); - fgcommand("dialog-show", me.namenode); -} -############################################################ -copilot_dialog.close = func { - fgcommand("dialog-close", me.namenode); -} -############################################################ -copilot_dialog.destroy = func { - COPILOT_DLG = 0; - me.close(); - foreach(var l; me.listeners) - removelistener(l); - delete(gui.dialog, "\"" ~ me.title ~ "\""); -} -############################################################ -copilot_dialog.show = func (copilot_type) { -# print("Showing MPCopilots dialog!"); - if (!COPILOT_DLG) { - COPILOT_DLG = int(getprop("/sim/time/elapsed-sec")); - me.init(copilot_type); - me.create(); - me._update_(COPILOT_DLG); - } -} -############################################################ -copilot_dialog._redraw_ = func { - if (me.dialog != nil) { - me.close(); - me.create(); - } -} -############################################################ -copilot_dialog._update_ = func (id) { - if (COPILOT_DLG != id) return; - me._redraw_(); - settimer(func { me._update_(id); }, 4.1); -} -############################################################ -copilot_dialog.select_action = func (n) { - var selected = me.basenode.getNode("pilot-callsign").getValue(); - var bs = me.basenode.getNode("dialog").getChildren(); - # Assumption: There are two true b:s or none. The one not matching selected - # is the new selection. - var i = 0; - me.basenode.getNode("pilot-callsign").setValue(""); - foreach (var b; bs) { - if (!b.getValue() and (i == n)) { - b.setValue(1); - me.basenode.getNode("pilot-callsign").setValue(me.players[i]); - } else { - b.setValue(0); - } - i = i + 1; - } - dual_control.main.reset(); - me._redraw_(); -} -############################################################ -# Return a list containing all nearby copilot players of the right type. -copilot_dialog.find_copilot_players = func { - var mpplayers = - props.globals.getNode("ai/models").getChildren("multiplayer"); - - var res = []; - foreach (var pilot; mpplayers) { - if ((pilot.getNode("valid") != nil) and - (pilot.getNode("valid").getValue()) and - (pilot.getNode("sim/model/path") != nil)) { - var type = pilot.getNode("sim/model/path").getValue(); - - if (type == me.copilot_type) { - append(res, pilot.getNode("callsign").getValue()); - } - } - } -# debug.dump(res); - return res; -} -############################################################################### diff --git a/test/neo4j.nas b/test/neo4j.nas deleted file mode 100644 index da44c4a..0000000 --- a/test/neo4j.nas +++ /dev/null @@ -1,162 +0,0 @@ -import("lib.nas"); - -rand(time(0)); -var chartable='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; -var node=func(type) -{ - var s=""; - for(var i=0;i<10;i+=1) - s~=chr(chartable[rand()*62]); - return {name:s,type:type,next:[]}; -} -var film_node=[]; -for(var i=0;i<1000;i+=1) - append(film_node,node("film")); -var director_node=[]; -for(var i=0;i<200;i+=1) - append(director_node,node("direct")); -var actor_node=[]; -for(var i=0;i<400;i+=1) - append(actor_node,node("actor")); -var writer_node=[]; -for(var i=0;i<100;i+=1) - append(writer_node,node("writer")); -var type_node=[]; -for(var i=0;i<40;i+=1) - append(type_node,node("type")); -var lang_node=[]; -for(var i=0;i<120;i+=1) - append(lang_node,node("lang")); -var country_node=[]; -for(var i=0;i<120;i+=1) - append(country_node,node("country")); - -func() -{ - var director_size=size(director_node); - var actor_size=size(actor_node); - var writer_size=size(writer_node); - var type_size=size(type_node); - var lang_size=size(lang_node); - var country_size=size(country_node); - - foreach(var film;film_node) - { - var director_link=int(1+rand()*2); - var actor_link=int(1+rand()*20); - var writer_link=int(1+rand()*2); - var type_link=int(1+rand()*5); - var lang_link=int(1+rand()*4); - var country_link=int(1+rand()*4); - for(var i=0;i10?10:list_size; - for(var i=1;i=list_size) - die("choose a correct index"); - get_next(num(choose)); -} - -foreach(var film;film_node) - setsize(film.next,0); diff --git a/test/smartscreen.nas b/test/smartscreen.nas deleted file mode 100644 index ac5d13c..0000000 --- a/test/smartscreen.nas +++ /dev/null @@ -1,210 +0,0 @@ -var smartScreen = canvas.new({ - "name": "smartScreen", # The name is optional but allow for easier identification - "size": [2048, 2048], # Size of the underlying texture (should be a power of 2, required) [Resolution] - "view": [768, 768], # Virtual resolution (Defines the coordinate system of the canvas [Dimensions] - # which will be stretched the size of the texture, required) - "mipmapping": 1 # Enable mipmapping (optional) -}); - -smartScreen.addPlacement({"node": "screen", "texture": "screen.jpeg"}); -var group = smartScreen.createGroup(); - -# Create a text element and set some values -var text = group.createChild("text", "optional-id-for element") - .setTranslation(10, 20) # The origin is in the top left corner - .setAlignment("left-center") # All values from osgText are supported (see $FG_ROOT/Docs/README.osgtext) - .setFont("LiberationFonts/LiberationSans-Regular.ttf") # Fonts are loaded either from $AIRCRAFT_DIR/Fonts or $FG_ROOT/Fonts - .setFontSize(14, 1.2) # Set fontsize and optionally character aspect ratio - .setColor(1,0,0) # Text color - .setText("This is a text element"); -text.hide(); -text.setText("SELF TEST NORMAL").show(); - - - -var ui_root = smartScreen.createGroup(); -var vbox = canvas.VBoxLayout.new(); -smartScreen.setLayout(vbox); - - -var button_onl = canvas.gui.widgets.Button.new(ui_root, canvas.style, {}).setText("Online OSM").listen("clicked", func showOnlineMap()); -var button_offl = canvas.gui.widgets.Button.new(ui_root, canvas.style, {}).setText("Offline OSM").listen("clicked", func showOfflineMap()); -button_onl.setSizeHint([32, 128]); -button_offl.setSizeHint([32, 128]); - -var label = canvas.gui.widgets.Label.new(ui_root, canvas.style, {}); - -var button_box = canvas.HBoxLayout.new(); -button_box.addItem(button_onl); -button_box.addItem(button_offl); -button_box.addItem(label); -button_box.addStretch(1); - -vbox.addItem(button_box); -vbox.addStretch(1); - - -var showOnlineMap = func(){ - TestMap.show(); - g.hide(); - label.setText("Online Mode"); -} - - -var showOfflineMap = func(){ - TestMap.hide(); - g.show(); - label.setText("Offline Mode"); -} - - -# Online Map using MapStructure -var TestMap = smartScreen.createGroup().createChild("map"); -TestMap.setTranslation(smartScreen.get("view[0]")/2,smartScreen.get("view[1]")/2); - - -var ctrl_ns = canvas.Map.Controller.get("Aircraft position"); -var source = ctrl_ns.SOURCES["map-dialog"]; -if (source == nil) { - # TODO: amend - var source = ctrl_ns.SOURCES["map-dialog"] = { - getPosition: func subvec(geo.aircraft_position().latlon(), 0, 2),# ? ? ? - getAltitude: func getprop('/position/altitude-ft'), - getHeading: func { - if (me.aircraft_heading) - getprop('/orientation/heading-deg'); - else - 0; - }, - aircraft_heading: 1, - }; -} -setlistener("/sim/gui/dialogs/map-canvas/aircraft-heading-up", func(n){source.aircraft_heading = n.getBoolValue();}, 1); -TestMap.setController("Aircraft position", "map-dialog"); -TestMap.setRange(1); - -var r = func(name,vis=1,zindex=nil){return caller(0)[0];}; -# TODO: we'll need some z-indexing here, right now it's just random - -foreach(var type; [r('APS')] ){ - TestMap.addLayer(factory: canvas.SymbolLayer, type_arg: type.name, visible: type.vis, priority: 2); -} - -foreach(var type; [ r('OSM')]) { - TestMap.addLayer(factory: canvas.OverlayLayer, - type_arg: type.name, - visible: type.vis, - priority: 1); -} - - -TestMap.hide(); - -# Offline map - -var g = smartScreen.createGroup(); -var zoom = 15; -var type = "intl"; -var tile_size = 256; - - -var changeZoom = func(d) -{ - zoom = math.max(2, math.min(19, zoom + d)); - updateTiles(); -} - -# http://polymaps.org/docs/ -# https://github.com/simplegeo/polymaps -# https://github.com/Leaflet/Leaflet - -var maps_base = getprop("/sim/fg-home") ~ '/cache/maps'; - -var makePath = -string.compileTemplate(maps_base ~ '/osm-{type}/{z}/{x}/{y}.jpg'); -var num_tiles = [4, 4]; - -var center_tile_offset = [(num_tiles[0]-1)/2, (num_tiles[1]-1)/ 2]; - -# simple aircraft icon at current position/center of the map -g.createChild("path") - .moveTo( tile_size*center_tile_offset[0]-10, tile_size*center_tile_offset[1]) - .horiz(20) - .move(-10,-10) - .vert(20) - .set("stroke", "red") - .set("stroke-width", 2) - .set("z-index", 1); - -# initialize the map by setting up -# a grid of raster images - -var tiles = setsize([], num_tiles[0]); -for(var x=0; x