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

	define("NUM_FASTNET_LOADCELLS", 8);
?>

<section data-heading="other-data" class="content-wrapper" id="loadcell">
	<!--Heading-->
	<div class="page-title">
		<h1>Loadcells</h1>
		<p>
			Configure loadcell inputs from Fastent, Ethernet or Serial amplifiers.
		</p>
	</div>

    <!--Loadcells-->
    <div id="dla-container" class="loadcell-container"></div>

	<!--DCells-->
	<div id="dcell-container" class="loadcell-container" hidden></div>

	<!--BAndGCells-->
	<div id="bandg-container" class="loadcell-container"></div>

	<!--Fastnet Loadcells-->
	<div class="box bottom-wrapper top-wrapper">
		<div class="flex-row" id="loadcell-row">
			<div class="flex-row">
				<h2>Fastnet Loadcells</h2>
			</div>
			<a class="button button-gray button-small" id="loadcell-toggle">
				<i class="arrow arrow-down"></i>
			</a>
		</div>
		<div hidden id="fastnet-loadcell-container">
			<div id="loadcell-grid">
				<h2>Node</h2>
				<div class="tooltip-wrapper">
					<h2>Channel</h2>
					<div class="tooltip">
						<p>Enter any unused Fastnet channel, or select from the drop-down list.</p>
					</div>
				</div>
				<h2>Data Value</h2>
				<h2>Enable Input</h2>
				<?php 
					// Loadcell defaults copied from B&G system
					$DEFAULT_FASTNET_INPUTS = array(
						"loadcell1" => "70,64,false",
						"loadcell2" => "71,42,false",
						"loadcell3" => "72,43,false",
						"loadcell4" => "73,44,false",
						"loadcell5" => "74,45,false",
						"loadcell6" => "75,61,false",
						"loadcell7" => "76,62,false",
						"loadcell8" => "77,63,false"
					);
					// Merge overwrites default keys if they exist in the database
					$fastnetInputs = array_merge($DEFAULT_FASTNET_INPUTS, readSection("FastnetInput", 1));
					
					for ($i = 1; $i <= NUM_FASTNET_LOADCELLS; $i++) {
						$loadcell = "loadcell" . $i;
						$loadcellData = explode(',', $fastnetInputs[$loadcell]);
						
						echo "<h2>Loadcell " . $i . "</h2>";
						echo "<input data-key='" . $loadcell . "' name='node' type='number' value="
							. $loadcellData[0] . ">";
						echo "<input data-key='" . $loadcell . "' name='channel' type='number' value="
							. $loadcellData[1] . ">";
						echo
							"<div class='flex-field'>
								<div class='field-container' id='" . $loadcell . "'
								 data-sender='Fastnet' data-field=0x098" . $i . " data-instance=0>
									 &nbsp;
								</div>
							</div>";	
						echo "<input data-key='" . $loadcell . "' type='checkbox' name='enable' "
							. (($loadcellData[2] == "true") ? "checked" : "") . ">";			
					}
				?>
			</div>
		</div>
	</div>

    <!--Buttons-->
	<div class="button-box button-box-stack" id="button-container">
		<div class="box box-bottom">
			<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/atp.loadcell.js?v=<?php echo VERSION_NUMBER?>" defer></script>
<script>
$(document).ready(function() {
    var model = new LoadcellModel();
    var controller = new LoadcellController(model);
    var view = new LoadcellView(controller);
});
</script>

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