<!DOCTYPE html>
<html lang="en">
  <head>
    <link rel="stylesheet" href="max80.css" />
    <title class="update">MAX80: Update</title>
    <script src="max80.js"></script>
  </head>
  <body>
    <x-inc src="head.html"></x-inc>
    <h1 class="update">Update</h1>
    <form class="hw" id="boardid" action="sys/setboardrev" method="post"
	  onsubmit="uploadform()" data-ref="1" data-ref-url="update.html">
      <fieldset>
	<legend class="ver">Hardware Version</legend>
	<label class="unlock">
	  <b>Unlock Programming</b>
	  <input type="checkbox" name="unlock" id="unlock" onchange="bropen()">
	</label>
	<label class="ver">
	  <b>Hardware Version</b>
	  <select name="boardrevs" id="boardrevs" onchange="brn()" disabled>
	    <option value="MAX80 v1">v1.0.0</option>
	    <option value="MAX80 v2">v2.0.0</option>
	    <option value="MAX80 v2.0.1">v2.0.1</option>
	    <option class="other" value="MAX80 v">other...</option>
	  </select>
	  <input type="text" name="max80.hw.ver" id="ver"
		 oninput="brt()" disabled />
	</label>
	<p id="warnrev" class="warnrev hidden">Be careful: the board
	might fail to boot if the board revision is programmed
	incorrectly. In that case, reflashing via USB/serial port will
	be necessary.</p>
	<button type="submit" id="setrev" disabled>Write to flash</button>
      </fieldset>
    </form>
    <form id="upload" action="sys/fwupdate" method="post"
	  onsubmit="uploadform()" data-ref="10" data-ref-url="status.html">
      <fieldset class="fw">
	<legend>Firmware</legend>
	<p id="norev" class="norev hidden">
	  BOARD REVISION NOT PROGRAMMED. YOU MUST PROGRAM THE BOARD
	  REVISION BEFORE UPDATING THE FIRMWARE. MAKE SURE YOU KNOW
	  WHAT REVISION YOUR BOARD IS BEFORE DOING SO.
	</p>
	<input type="file" name="file" hidden accept=".fw" onchange="uploadform()" />
	<button type="submit" class="fromfile" id="upload.start"
		onclick="sib(this,'input').value=''">Update from file</button>
	<progress value="0"></progress>
      <ul>
	<li><a class="latest" href="https://max80.abc80.org/fw/latest/max80.fw">Latest official build</a></li>
	<li><a class="archive" href="https://max80.abc80.org/fw/">Official build archive</a></li>
      </ul>
      </fieldset>
      <output></output>
      <div class="onerr">
	<h3>Possible troubleshooting steps:</h3>
	<ol>
	  <li class="retry">Try again</li>
	  <li class="jtag">Make sure no JTAG cable is plugged in</li>
	  <li class="power">Power cycle board (remove both USB and power off ABC host)</li>
	  <li class="esp">Separately update ESP32 over USB before trying again</li>
	  <li class="console">Check serial console for more detailed status messages</li>
	</ol>
      </div>
      <script src="update.js"></script>
    </form>
  </body>
</html>