From 56f1890a7cc3397346350c644a7be98fe66ad528 Mon Sep 17 00:00:00 2001
From: Jonathan Redpath <legoboyvdlp@gmail.com>
Date: Fri, 8 Feb 2019 19:57:48 +0000
Subject: [PATCH] Add flap lever not zero warning

---
 Nasal/ECAM/ECAM-controller.nas |  9 ++++--
 Nasal/ECAM/ECAM-logic.nas      | 54 +++++-----------------------------
 Nasal/ECAM/ECAM-messages.nas   |  3 +-
 3 files changed, 16 insertions(+), 50 deletions(-)

diff --git a/Nasal/ECAM/ECAM-controller.nas b/Nasal/ECAM/ECAM-controller.nas
index 61885634..84b8c8c6 100644
--- a/Nasal/ECAM/ECAM-controller.nas
+++ b/Nasal/ECAM/ECAM-controller.nas
@@ -138,10 +138,10 @@ var ECAM_controller = {
 	loop: func() {
 		# check active messages
 		# config_warnings();
-		# messages_priority_3();
+		messages_priority_3();
 		messages_priority_2();
-		# messages_priority_1();
-		# messages_priority_0();
+		messages_priority_1();
+		messages_priority_0();
 		messages_memo();
 		messages_right_memo();
 		
@@ -219,6 +219,9 @@ var ECAM_controller = {
 			}
 		}
 	},
+	clear: func() {
+		print("Clear!");
+	},
 };
 
 setlistener("/systems/electrical/bus/dc-ess", func {
diff --git a/Nasal/ECAM/ECAM-logic.nas b/Nasal/ECAM/ECAM-logic.nas
index 44cdcc94..2d4fb90e 100644
--- a/Nasal/ECAM/ECAM-logic.nas
+++ b/Nasal/ECAM/ECAM-logic.nas
@@ -3,17 +3,15 @@
 # Copyright (c) 2019 Jonathan Redpath (legoboyvdlp)
 
 var messages_priority_3 = func {
-	if ((getprop("/position/gear-agl-ft") < 750 and getprop("/gear/gear[1]/position-norm") != 1 and (getprop("/ECAM/warning-phase") <= 3 and getprop("/ECAM/warning-phase") >= 5)) and ((((getprop("/engines/engine[0]/n1-actual") < 75.0 and getprop("/engines/engine[1]/n1-actual") < 75.0)) or ((getprop("/engines/engine[0]/n1-actual") < 77.0 and getprop("/controls/engines/engine[1]/cutoff-switch") == 0) or (getprop("/engines/engine[1]/n1-actual") < 77.0 and getprop("/controls/engines/engine[0]/cutoff-switch") == 0))) or getprop("/controls/flight/flap-pos") > 1)) {
-		lg_not_dn.active = 1;
-		setprop("/systems/gear/landing-gear-warning-light", 1);
+	# FCTL
+	if (getprop("/ECAM/warning-phase") == 6 and getprop("/controls/flight/flap-lever") != 0 and getprop("/instrumentation/altimeter/indicated-altitude-ft") > 22000) {
+		flap_not_zero.active = 1;
 	} else {
-		lg_not_dn.active = 0;
-		lg_not_dn.noRepeat = 0;
-		setprop("/systems/gear/landing-gear-warning-light", 0);
+		flap_not_zero.active = 0;
+		flap_not_zero.noRepeat = 0;
 	}
-}
-
-var messages_priority_2 = func {
+	
+	# AUTOFLT
 	if (getprop("/it-autoflight/output/ap-warning") == 2) {
 		ap_offw.active = 1;
 	} else {
@@ -52,43 +50,7 @@ var messages_priority_2 = func {
 	}
 }
 
-var messages_priority_2_old = func {
-	if ((((getprop("/ECAM/warning-phase") >= 1 and getprop("/ECAM/warning-phase") <= 2) or (getprop("/ECAM/warning-phase") >= 9 and getprop("/ECAM/warning-phase") <= 10) and (wow and getprop("/engines/engine[0]/state") == 3)) or getprop("/ECAM/warning-phase") == 6) and getprop("/systems/failures/pack1") == 1) {
-		pack1_fault.active = 1;
-	} else {
-		pack1_fault.active = 0;
-		pack1_fault.noRepeat = 0;
-	}
-	
-	if (pack1_fault.active == 1 and getprop("/controls/pneumatic/switches/pack1") == 1) {
-		pack1_fault_subwarn_1.active = 1;
-	} else {
-		pack1_fault_subwarn_1.active = 0;
-		pack1_fault_subwarn_1.noRepeat = 0;
-	}
-	
-	if ((((getprop("/ECAM/warning-phase") >= 1 and getprop("/ECAM/warning-phase") <= 2) or (getprop("/ECAM/warning-phase") >= 9 and getprop("/ECAM/warning-phase") <= 10) and (wow and getprop("/engines/engine[1]/state") == 3)) or getprop("/ECAM/warning-phase") == 6) and getprop("/systems/failures/pack2") == 1) {
-		pack2_fault.active = 1;
-	} else {
-		pack2_fault.active = 0;
-		pack2_fault.noRepeat = 0;
-	}
-	
-	if (pack2_fault.active == 1 and getprop("/controls/pneumatic/switches/pack2") == 1) {
-		pack2_fault_subwarn_1.active = 1;
-	} else {
-		pack2_fault_subwarn_1.active = 0;
-		pack2_fault_subwarn_1.noRepeat = 0;
-	}
-	
-	if (getprop("/controls/gear/brake-parking") and (getprop("/ECAM/warning-phase") >= 6 and getprop("/ECAM/warning-phase") <= 7)) {
-		park_brk_on.active = 1;
-	} else {
-		park_brk_on.active = 0;
-		park_brk_on.noRepeat = 0;
-	}
-}
-
+var messages_priority_2 = func {}
 var messages_priority_1 = func {}
 var messages_priority_0 = func {}
 
diff --git a/Nasal/ECAM/ECAM-messages.nas b/Nasal/ECAM/ECAM-messages.nas
index aed5bf2f..b3b4375b 100644
--- a/Nasal/ECAM/ECAM-messages.nas
+++ b/Nasal/ECAM/ECAM-messages.nas
@@ -15,13 +15,14 @@ var warningsOld               = std.Vector.new([
 ]);
 
 var warnings				  = std.Vector.new([
+	var flap_not_zero         = warning.new(msg: "F/CTL FLAP LVR NOT ZERO",  active: 0, colour: "r", aural: "crc",   light: "warning", noRepeat: 0),
 	var ap_offw				  = warning.new(msg: "AUTO FLT AP OFF",			 active: 0, colour: "r", aural: "calv",  light: "warning", noRepeat: 0),
 	var athr_offw			  = warning.new(msg: "AUTO FLT A/THR OFF", 	     active: 0, colour: "a", aural: "chime", light: "caution", noRepeat: 0),
 	var athr_offw_1			  = warning.new(msg: "-THR LEVERS........MOVE",  active: 0, colour: "b", aural: "none",  light: "none",    noRepeat: 0),
 	var athr_lock			  = warning.new(msg: "ENG THRUST LOCKED", 		 active: 0, colour: "a", aural: "chime", light: "caution", noRepeat: 0),
 	var athr_lock_1			  = warning.new(msg: "-THR LEVERS........MOVE",  active: 0, colour: "b", aural: "none",  light: "none",    noRepeat: 0),
 	var athr_lim			  = warning.new(msg: "AUTO FLT A/THR LIMITED",   active: 0, colour: "a", aural: "chime", light: "caution", noRepeat: 0),
-	var athr_lim_1			  = warning.new(msg: "-THR LEVERS........MOVE",  active: 0, colour: "b", aural: "none",  light: "none",    noRepeat: 0),
+	var athr_lim_1			  = warning.new(msg: "-THR LEVERS........MOVE",  active: 0, colour: "b", aural: "none",  light: "none",    noRepeat: 0)
 ]);
 
 var leftmemos                 = std.Vector.new([