<!--
-
-
- Copyright (C) 2019 Xilinx, Inc.  All rights reserved.
-
- Permission is hereby granted, free of charge, to any person obtaining a copy of
- this software and associated documentation files (the "Software"), to deal in
- the Software without restriction, including without limitation the rights to
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
- of the Software, and to permit persons to whom the Software is furnished to do
- so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
-
-
- Author: Michael Chyziak <chyziak@xilinx.com>
-
-->


{% extends "Default/default.html" %}
{% block content %}

<div class="page-header">
  <h1 class="display-4"><b>{% block title %}Touch Sensor and Relay{% endblock %}</b></h1>
</div>

<h2>Description</h2>
<div class="well">
  <p>Build a system that toggles a relay on and off when the touch sensor is tapped. The pins on the connectors G1 through G5 are connected to GPIO pins on the baseboard and can be directly controlled from Linux. In this project, the application reads the state of the touch sensor from GPIO-AB on connector GAB, and toggles the relay by driving GPIO-E on connector G2. Each time the sensors is tapped, the relay will toggle between on and off. The GPIO pins E-L cannot be used by the sensor mezzanine examples that use sensors to provide input, like the touch sensor. These GPIO pins are being used by the bitstream to connect the MIPI camera sensor. For more information on the Grove Sensor Kit please visit <a href="grove_starter_kit.html">Grover Starter Kit</a>.</p>
</div>

<h2>Hardware Setup</h2>
<div class="well">
  <ul class="features" style="list-style-position:inside">  
    <li>Attach the relay to GAB</li>
    <li>Attach the touch sensor to G3</li>
  </ul>
  <img class="img-responsive center-block" src="{{url_for('static', filename='images/96boards_images/Example_Touch_Relay.png')}}" onclick="showImageModal(this)"/>
  <br>
  <form id="run_project_form" action="touch_sensor.html" method="post">
    <center><button type="submit" id="start" name="submit" value="start" class="btn btn-primary btn-lg" onclick="onRunProject()">Run Project</button>
		Timeout: <select id="timeout" name="timeout"> 
		    <option value="5">5</option>
		    <option value="10">10</option>
		    <option value="15">15</option>
		    <option value="20">20</option>
		    <option value="25">25</option>
		    <option value="30">30</option>
		    <option value="35">35</option>
		    <option value="40">40</option>
		    <option value="45">45</option>
		    <option value="50">50</option>
		    <option value="55">55</option>
		    <option value="60">60</option>
    </select>
    </center>
    <br>
    <center><button type="submit" id="stop" name="submit" value="stop" class="btn btn-primary btn-lg" onclick="onRunProject()">Stop Project</button>
    </center>	  
  </form>
</div>

<h2>Source Code</h2>
<div class="well">
  <form action="viewer.html" method="get">
    <button type="submit" name="filename" value="touch_switch/touch_switch.cpp" class="btn btn-primary">touch_switch.cpp</button>
  </form>
</div>

<script>
  document.getElementById("timeout").value = "{{timeout}}";
  var timeleft = "{{remaining_time}}";
  var runbutton = document.getElementById("start");
  var timer_status = "{{timer_status}}";
  if (timer_status == "timer_enabled") {
    runbutton.disabled = true;
    var timer = setInterval(function() {
      timeleft--;
      runbutton.textContent = "Project Running " + timeleft + " s";
      if (timeleft <= 0) {
        clearInterval(timer);
	runbutton.disabled = false;
	runbutton.textContent = "Run Project";
	timer_status = "timer_disabled";
      }
    }, 1000);
  }
  function onRunProject(){
    var form = document.getElementById("run_project_form");
    form.submit();
  }
</script>

{% endblock %}
