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

<section data-heading="speed" class="content-wrapper" id="speed-page">
	<!--Heading-->
	<div class="page-title">
		<h1>Speed 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>

	<!--Non-Pulse Calibration-->
	<div id="data-calibration-container" hidden>
		<div class="box box-top">
			<div class="flex-row">
				<div class="flex-half"></div>
				<div class="flex-half">
					<div class="flex-heading">
						<h2>Source Speed</h2>
					</div>
					<div class="field-container" id="source-speed" title="Speed received from source."
						data-field="<?php echo fieldEnum::Boat_Speed_Kts;?>"
						data-sender="" data-instance="">
						&nbsp;
					</div>
				</div>
			</div>
		</div>
		<div class="box box-stack">
			<div class="flex-row">
				<div class="flex-half">
					<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" id="calibration-factor">
				</div>
				<div class="flex-half">
					<div class="flex-heading">
						<h2>Base Boat Speed</h2>
					</div>
					<div class="field-container" id="calibrated-speed-nonpulse" title="Calibrated boat speed."
						data-field="<?php echo fieldEnum::Base_Boat_Speed;?>">
						&nbsp;
					</div>
				</div>
			</div>
		</div>
		<div class="box box-bottom">
			<div class="flex-row">
				<div class="flex-half">
					<div class="flex-heading">
						<h2>Advanced Corr.</h2>
					</div>
					<div class="field-container" id="correction-value" title="Advanced correction value."
						data-field="<?php echo fieldEnum::Advanced_Heel_Calibration;?>">
						&nbsp;
					</div>
					<a class="button button-gray button-medium" name="advanced-calibration">Advanced</a>
				</div>
				<div class="flex-half">
					<div class="flex-heading">
						<h2>Calibrated Boat Speed</h2>
					</div>
					<div class="field-container" id="calibrated-speed" title="Boat Speed."
						data-field="<?php echo fieldEnum::BSPD_Source_1;?>"
						data-sender="<?php echo PROCESSOR_ID;?>"
						data-instance="<?php echo PROCESSOR_INSTANCE;?>">
						&nbsp;
					</div>
				</div>
			</div>
		</div>
	</div>

	<!--Pulse Calibration-->
	<div id="pulse-calibration-container" hidden>
		<div class="box box-top">
			<div class="flex-row">
				<div class="flex-half">
					<div class="flex-heading">
						<h2>Computation Estimator Time</h2>
						<div class="tooltip">
							<p>
								This defines how boat speed is calculated for internal use. It has no effect on displayed boat speed,
								which can be adjusted on the 'Damping' page.
							</p>
						</div>
					</div>
					<div class="input-unit">
						<input id="computation-estimator" type="number" step="0.1" min="0.1"><span>s</span>
					</div>
				</div>
				<div class="flex-half">
					<div class="flex-heading">
						<h2>Pulse Frequency</h2>
					</div>
					<div class="field-container" id="pulse-frequency" title="Uncalibrated pulse frequency."
						data-field=""
						data-sender="<?php echo PROCESSOR_ID;?>"
						data-instance="<?php echo PROCESSOR_INSTANCE;?>">
						&nbsp;
					</div>
				</div>
			</div>
		</div>
		<div class="box box-stack">
			<div class="flex-row">
				<div class="flex-half">
					<div class="flex-heading">
						<h2>Pulse Calibration</h2>
						<div class="tooltip">
							<p>
								The number of pulses per second when water speed is 1 knot. This may
								need adjusting, typically between 1-6Hz.
							</p>
						</div>
					</div>
					<div class="input-unit">
						<input type="number" step="0.01" min="0" max="10" id="pulse-calibration">
						<span>Hz</span>
					</div>
				</div>
				<div class="flex-half">
					<div class="flex-heading">
						<h2>Base Boat Speed</h2>
					</div>
					<div class="field-container" id="calibrated-speed-pulse" title="Calibrated boat speed."
						data-field="<?php echo fieldEnum::Base_Boat_Speed;?>">
						&nbsp;
					</div>
				</div>
			</div>
		</div>
		<div class="box box-bottom">
			<div class="flex-row">
				<div class="flex-half">
					<div class="flex-heading">
						<h2>Advanced Corr.</h2>
					</div>
					<div class="field-container" id="correction-value-pulse" title="Advanced correction value."
						data-field="<?php echo fieldEnum::Advanced_Heel_Calibration;?>">
						&nbsp;
					</div>
					<a class="button button-gray button-medium" name="advanced-calibration">Advanced</a>
				</div>
				<div class="flex-half">
					<div class="flex-heading">
						<h2>Calibrated Boat Speed</h2>
					</div>
					<div class="field-container" id="displayed-speed" title="Boat speed."
						data-field="<?php echo fieldEnum::BSPD_Source_1;?>"
						data-sender="<?php echo PROCESSOR_ID;?>"
						data-instance="<?php echo PROCESSOR_INSTANCE;?>">
						&nbsp;
					</div>
				</div>
			</div>
		</div>
	</div>

	<!--SoG-->
	<div id="sog-container" hidden>
		<div class="box">
			<div class="flex-row">
				<div class="flex-half">
					<div class="flex-heading">
						<h2>Use GNSS as speed input</h2>
						<div class="tooltip">
							<p>
								Uses Speed-over-Ground for all internal calculation and display. Note: No current can be calculated.<br>
								<em>Not accurate, use with caution.</em>
							</p>
						</div>
					</div>
					<input type="checkbox" id="use-sog">
				</div>
				<div class="flex-half">
					<div class="flex-heading">
						<h2>SoG</h2>
					</div>
					<div class="field-container" id="speed-over-ground" title="Speed over ground."
						data-field="<?php echo fieldEnum::GPS_SOG_KTS;?>"
						data-sender="Damping" data-instance="0">
						&nbsp;
					</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>

<script type="text/javascript" src="js/utils.string.js" defer></script>
<script type="text/javascript" src="js/atp.data-sources.js" defer></script>
<script type="text/javascript" src="js/atp.sensor-model.js" defer></script>
<script type="text/javascript" src="js/atp.sensor-controller.js" defer></script>
<script type="text/javascript" src="js/atp.sensor-view.js" defer></script>
<script>
$(document).ready(function() {
	var url = new URL(window.location.href);

	var model = new SpeedSensorModel(url.searchParams.get("src"));
	var controller = new SpeedSensorController(model);
	var view = new SpeedSensorView(controller);
});
</script>

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