<?php require_once "atp.header.php"; ?>

<section data-heading="wind" class="content-wrapper" id="wind-measured"> 
	<!--Heading-->
	<div class="page-title">
		<h1>Wind Input</h1>
		<p></p>
	</div>
	
	<!--Source Selection-->
	<div id="source-selection-container">
		<div class="box box-top">
			<div class="flex-row">
				<div class="flex-heading">
					<h2>Sensor Name:</h2>
				</div>
				<input id="sensor-name">
			</div>
		</div>
		<div class="box box-stack">
			<div class="flex-row">
				<div class="flex-heading">
					<h2>Sensor Source:</h2>
				</div>
				<select id="sensor-source-select"></select>
			</div>
		</div>
	</div>
	
	<div class="box box-bottom">
		<!--NMEA Instance Selection-->
		<div id="nmea-instance-selection-container" hidden>
			<div class="flex-row">
				<div class="flex-heading">
					<h2>NMEA0183 Channel</h2>
				</div>
				<select id="nmea-instance-select"></select>
			</div>
			<a class="button button-gray button-medium redirect-button" id="nmea-configuration-redirect">NMEA0183 Settings</a>
		</div>
		<!--CANbus Device-->
		<div id="canbus-device-container" hidden></div>
	</div>

	<!--Pulse Source Grid-->
	<div class="box top-wrapper" id="pulse-calibration-container" hidden>
		<div class="measured-wind-grid">
			<div class="flex-row">
				<div class="flex-heading">
					<h2>Calculation Time</h2>
					<div class="tooltip">
						<p>Determines how many data points are used to calculate wind speed. A longer time will be less sensitive to sudden changes.</p>
					</div>
				</div>
				<div class="input-unit">
					<input type="number" step="0.1" id="calc-time"><span>s</span>
				</div>
			</div>
			<div class="flex-row">
				<div class="flex-heading">
					<h2>MHU Voltage</h2>
				</div>
				<div class="flex-field">
					<div class="field-container" id="mhu-voltage" title="Voltage to the MHU."
						data-field="<?php echo fieldEnum::Wind_MHU_Voltage;?>"
						data-sender="Wind Board" data-instance="<?php echo PROCESSOR_INSTANCE?>">
						&nbsp;
					</div>
				</div>
			</div>
			<div class="flex-row">
				<div class="flex-heading">
					<h2>Pulse Frequency</h2>
				</div>
				<div class="flex-field">
					<div class="field-container" id="pulse-frequency" title="Uncalibrated pulse frequency."
						data-field="<?php echo fieldEnum::Wind_PulseFreq;?>"
						data-sender="Wind Board" data-instance="<?php echo PROCESSOR_INSTANCE?>">
						&nbsp;
					</div>
				</div>
			</div>
			<div class="flex-row">
				<div class="flex-heading">
					<h2>Red Phase</h2>
					<div class="tooltip">
						<p>Wind direction is calculated from the three phase voltages.
							Red borders indicate a potential fault with the wind vane.</p>
					</div>
				</div>
				<div class="flex-field">
					<div class="field-container" id="red-phase" title="Red phase voltage."
						data-field="<?php echo fieldEnum::Wind_Phase_Red;?>"
						data-sender="Wind Board" data-instance="1" name="MHUPhase">
						&nbsp;
					</div>
				</div>
			</div>
			<div class="flex-row">
				<div class="flex-heading">
					<h2>Pulse Calibration</h2>
					<div class="tooltip">
						<p>The number of pulses per second when wind speed is 1 knot.</p>
					</div>
				</div>
				<input type="number" step="0.01" id="pulse-calibration">
			</div>
			<div class="flex-row">
				<div class="flex-heading">
					<h2>Green Phase</h2>
				</div>
				<div class="flex-field">
					<div class="field-container" id="green-phase" title="Green phase voltage."
						data-field="<?php echo fieldEnum::Wind_Phase_Green;?>"
						data-sender="Wind Board" data-instance="1" name="MHUPhase">
						&nbsp;
					</div>
				</div>
			</div>
			<div class="flex-row"><!--Empty--></div>
			<div class="flex-row">
				<div class="flex-heading">
					<h2>Blue Phase</h2>
				</div>
				<div class="flex-field">
					<div class="field-container" id="blue-phase" title="Blue phase voltage."
						data-field="<?php echo fieldEnum::Wind_Phase_Blue;?>"
						data-sender="Wind Board" data-instance="1" name="MHUPhase">
						&nbsp;
					</div>
				</div>
			</div>
		</div>
	</div>

	<!--Measured Value Grid-->
	<div class="box top-wrapper" id="measured-value-container" hidden>
		<div class="measured-wind-grid">
			<div class="flex-row">
				<div class="flex-heading">
					<h2>Raw MAWS</h2>
				</div>
				<div class="flex-field">
					<div class="field-container" id="raw-maws" title="Measured apparent wind speed, before calculation."
						data-field="<?php echo fieldEnum::Wind_MAWS_Raw;?>"
						data-sender="<?php echo PROCESSOR_ID;?>"
						data-instance="<?php echo PROCESSOR_INSTANCE;?>">
						&nbsp;
					</div>
				</div>
			</div>
			<div class="flex-row">
				<div class="flex-heading">
					<h2>Raw MAWA</h2>
				</div>
				<div class="flex-field">
					<div class="field-container" id="raw-mawa" title="Measured apparent wind angle, before calculation."
						data-field="<?php echo fieldEnum::Wind_MAWA_Raw;?>"
						data-sender="<?php echo PROCESSOR_ID;?>" data-instance="<?php echo PROCESSOR_INSTANCE;?>">
						&nbsp;
					</div>
				</div>
			</div>
			<div class="flex-row" id="speed-offset-container">
				<div class="flex-heading">
					<h2>Speed Offset</h2>
					<div class="tooltip">
						<p>Offset to compensate for wind cup stiction.</p>
					</div>
				</div>
				<input type="number" step="0.01" id="speed-offset">
			</div>
			<div class="flex-row" id="calibration-factor-container">
				<div class="flex-heading">
					<h2>Calibration Factor</h2>
					<div class="tooltip">
						<p>
							Multiplicative adjustment for NMEA0183/CANbus sources.
						</p>
					</div>
				</div>
				<input type="number" step="0.01" min="0" max="10" id="calibration-factor">
			</div>
			<div class="flex-row">
				<div class="flex-heading">
					<h2>MHU Offset</h2>
				</div>
				<div class="input-unit">
					<input type="number" step="0.1" id="mhu-offset">
					<span>&deg;</span>
				</div>
			</div>
			<div class="flex-row"><!--Empty--></div>
			<div class="flex-row">
				<div class="flex-heading">
					<h2>Wind Shear</h2>
				</div>
				<div class="input-unit">
					<input type="number" step="0.1" id="wind-shear">
					<span>&deg;</span>
				</div>
			</div>
			<div class="flex-row"><!--Empty--></div>
			<div class="flex-row">
				<div class="flex-heading">
					<h2>Mast Rotation</h2>
				</div>
				<div class="flex-field">
					<div class="field-container" id="mast-rotation" title="Mast rotation correction."
						data-field="<?php echo fieldEnum::Mast_Rotation?>"
						data-sender="<?php echo PROCESSOR_ID?>"
						data-instance="<?php echo PROCESSOR_INSTANCE?>">
						&nbsp;
					</div>
				</div>
				<a class="button button-gray button-medium button-advanced" id="modal-mast" name="modal-mast"><i class="fa fa-cog"></i></a>
			</div>
			<div class="flex-row mast-motion-row">
				<div class="flex-heading"><h2>Mast Motion</h2></div>
				<div class="flex-field">
					<div class="field-container" id="mast-motion-speed" title="Wind speed correction due to mast motion."
						data-field="<?php echo fieldEnum::Calc_MMAWS_Corr;?>">
						&nbsp;
					</div>
				</div>
			</div>
			<div class="flex-row mast-motion-row">
				<div class="flex-heading"><h2>Mast Motion</h2></div>
				<div class="flex-field">
					<div class="field-container" id="mast-motion-angle" title="Wind angle correction due to mast motion."
						data-field="<?php echo fieldEnum::Calc_MMAWA_Corr;?>">
						&nbsp;
					</div>
				</div>
                <a class="advanced button button-gray button-medium" id="mast-motion-button"><i class="fa fa-external-link-alt"></i></a>
			</div>
			<div class="flex-row mast-motion-row">
				<div class="flex-heading"><h2>Apply Mast Motion?</h2></div>
				<input type="checkbox" id="motion-speed-checkbox">
			</div>
			<div class="flex-row mast-motion-row">
				<div class="flex-heading"><h2>Apply Mast Motion?</h2></div>
				<input type="checkbox" id="motion-angle-checkbox">
			</div>
			<div class="flex-row">
				<div class="flex-heading">
					<h2>MAWS</h2>
				</div>
				<div class="flex-field">
					<div class="field-container" id="maws" title="Measured apparent wind speed, after calculation."
						data-field="<?php echo fieldEnum::Wind_MAWS_kts;?>"
						data-sender="<?php echo PROCESSOR_ID;?>" data-instance="<?php echo PROCESSOR_INSTANCE;?>">
						&nbsp;
					</div>
				</div>
			</div>
			<div class="flex-row">
				<div class="flex-heading">
					<h2>MAWA</h2>
				</div>
				<div class="flex-field">
					<div class="field-container" id="mawa" title="Measured apparent wind angle, after calculation."
						data-field="<?php echo fieldEnum::Wind_MAWA;?>"
						data-sender="<?php echo PROCESSOR_ID;?>"
						data-instance="<?php echo PROCESSOR_INSTANCE;?>">
						&nbsp;
					</div>
				</div>
			</div>
		</div>
	</div>

	<!--Heel Correction-->
	<div id="heel-correction-container" hidden>
		<div class="box top-wrapper">
			<div class="flex-row">
				<!--Column1-->
				<div class="flex-half">
					<div class="flex-row">
						<div class="flex-heading">
							<h2>Heel</h2>
						</div>
						<div class="flex-field">
							<div class="field-container" id="heel-angle" title="Heel angle."
								data-field="<?php echo fieldEnum::Heel_Angle_Deg;?>"
								data-sender="Damping"
								data-instance="<?php echo PROCESSOR_INSTANCE;?>">
								&nbsp;
							</div>
						</div>
					</div>
					<div class="flex-row">
						<div class="flex-heading">
							<h2>Heel Correction</h2>
						</div>
						<div class="flex-field">
							<div class="field-container" id="heel-speed-correction" title="Wind speed correction due to heel angle."
								data-field="<?php echo fieldEnum::Calc_Heel_Spd_Corr;?>"
								data-sender="<?php echo PROCESSOR_ID;?>"
								data-instance="<?php echo PROCESSOR_INSTANCE;?>">
								&nbsp;
							</div>
						</div>
					</div>
					<div class="flex-row">
						<div class="flex-heading">
							<h2>Apply Correction?</h2>
						</div>
						<input type="checkbox" id="heel-speed-checkbox">
					</div>
					<div class="flex-row">
						<div class="flex-heading">
							<h2>CAWS</h2>
						</div>
						<div class="flex-field">
							<div class="field-container" id="caws" title="Calibrated apparent wind speed."
								data-field="<?php echo fieldEnum::Calc_CAWS_kts;?>" 
								data-sender="<?php echo PROCESSOR_ID;?>"
								data-instance="<?php echo PROCESSOR_INSTANCE;?>">
								&nbsp;
							</div>
						</div>
					</div>
				</div>
				<!--Column 2-->
				<div class="flex-half">
					<div class="flex-row">
						&nbsp;
					</div>
					<div class="flex-row">
						<div class="flex-heading">
							<h2>Heel Correction</h2>
						</div>
						<div class="flex-field">
							<div class="field-container" id="heel-angle-correction" title="Wind angle correction due to heel angle."
								data-field="<?php echo fieldEnum::Calc_Heel_Ang_Corr;?>" 
								data-sender="<?php echo PROCESSOR_ID;?>"
								data-instance="<?php echo PROCESSOR_INSTANCE;?>">
								&nbsp;
							</div>
						</div>
					</div>
					<div class="flex-row">
						<div class="flex-heading">
							<h2>Apply Correction?</h2>
						</div>
						<input type="checkbox" id="heel-angle-checkbox">
					</div>
					<div class="flex-row">
						<div class="flex-heading">
							<h2>CAWA</h2>
						</div>
						<div class="flex-field">
							<div class="field-container" id="cawa" title="Calibrated apparent wind angle."
								data-field="<?php echo fieldEnum::Calc_CAWA_Degrees;?>"
								data-sender="<?php echo PROCESSOR_ID;?>"
								data-instance="<?php echo PROCESSOR_INSTANCE;?>">
								&nbsp;
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<!--Buttons-->
	<div class="button-box" id="button-container">
		<div class="box">
			<a id="ok-button" class="button button-gray button-medium">OK</a>
			<a id="cancel-button" class="button button-gray button-medium">Cancel</a>
			<a id="apply-button" class="button button-gray button-medium">Apply</a>
		</div>
	</div>
</section>

<section class="modal" name="modal-mast">
	<div class="modal-content">
		<div class="modal-title-container">
			<div class="modal-title" id="modal-title">
				<h1>Mast Rotation</h1>
			</div>
			<span class="modal-close">&times;</span>
		</div>
		
		<form action="" method="post" class="modal-body" onkeypress="return event.keyCode!= 13;" id="modal-container">
			<div class="box">
				<fieldset>
					<legend><h2>Mast Rotation</h2></legend>
					<div class="flex-row">
						<div class="flex-half">
							<div class="flex-heading">
								<h2>Rotation Source</h2>
							</div>
							<select id="mast-rotation-source">
								<option value="" selected>No Source</option>
							</select>
						</div>
						<div class="flex-half">
							<div class="flex-heading">
								<h2>Apply Rotation?</h2>
							</div>
							<input type="checkbox" id="mast-rotation-checkbox">
						</div>
					</div>
				</fieldset>
			</div>

			<div class="button-box">
				<div class="box">
					<a class="button button-gray button-medium modal-submit" id="modal-OK">OK</a>
					<a class="button button-gray button-medium modal-submit" id="modal-Cancel">Cancel</a>
					<a class="button button-gray button-medium modal-submit" id="modal-Apply">Apply</a>
				</div>
			</div>
		</form>
	</div>
</section>

<script type="text/javascript" src="js/modalHandler.js?v=<?php echo VERSION_NUMBER?>" defer></script>
<script type="text/javascript" src="js/utils.string.js?v=<?php echo VERSION_NUMBER?>" defer></script>
<script type="text/javascript" src="js/atp.data-sources.js?v=<?php echo VERSION_NUMBER?>" defer></script>
<script type="text/javascript" src="js/atp.sensor-model.js?v=<?php echo VERSION_NUMBER?>" defer></script>
<script type="text/javascript" src="js/atp.sensor-controller.js?v=<?php echo VERSION_NUMBER?>" defer></script>
<script type="text/javascript" src="js/atp.sensor-view.js?v=<?php echo VERSION_NUMBER?>" defer></script>
<script>
$(document).ready(function() {
	var url = new URL(window.location.href);
	var model = new WindSensorModel(url.searchParams.get("src"));
	var controller = new WindSensorController(model);
	var view = new WindSensorView(controller);		
});
</script>

<?php require_once "footer.php"; ?>
