added UI to change pin assignments

pull/25/head
Thorsten von Eicken 10 years ago
parent 8b3161a3f4
commit 279da6dcef
  1. 81
      html/home.tpl
  2. 18
      html/style.css
  3. 64
      user/cgipins.c
  4. 8
      user/cgipins.h
  5. 2
      user/user_main.c

@ -4,13 +4,86 @@
<h2 id="version"></h2>
</div>
<div class="content">
<p>The ESP Link bridges the ESP8266 serial port to Wifi and it can
program microcontrollers over the serial port, in particular Arduinos, AVRs, and
NXP's LPC800-series ARM processors.</p>
<div class="content">
<div class="pure-g">
<div class="pure-u-24-24"><div class="card">
<p>The ESP Link bridges the ESP8266 serial port to Wifi and it can
program microcontrollers over the serial port, in particular Arduinos, AVRs, and
NXP's LPC800-series ARM processors.</p>
</div></div>
</div>
<div class="pure-g">
<div class="pure-u-12-24"><div class="card">
<h1>Wifi summary</h2>
<div id="wifi-spinner" class="spinner spinner-small"></div>
<table id="wifi-table" class="pure-table pure-table-horizontal" hidden><tbody>
<tr><td>WiFi mode</td><td id="wifi-mode"></td></tr>
<tr><td>Configured network</td><td id="wifi-ssid"></td></tr>
<tr><td>Wifi status</td><td id="wifi-status"></td></tr>
<tr><td>Wifi address</td><td id="wifi-ip"></td></tr>
</tbody> </table>
</div></div>
<div class="pure-u-12-24"><div class="card">
<h1>Pin assignment</h2>
<legend>Select one of the following signal/pin assignments to match your hardware</legend>
<fieldset class='radios' id='pin-mux'>
<div class="spinner spinner-small"></div>
</fieldset>
</div></div>
</div>
</div>
</div>
</div>
<script src="ui.js"></script>
<script type="text/javascript">
var currPin;
// pin={reset:12, isp:13, LED_conn:0, LED_ser:2}
function createInputForPin(pin) {
var input = document.createElement("input");
input.type = "radio";
input.name = "pins";
input.value= pin.value;
input.id = "opt-" + pin.value;
input.onclick = "setPins("+pin.value+", '"+pin.name+"')";
if (currPin == pin.value) input.checked = "1";
var descr = m('<label for="opt-'+pin.value+'"><b>'+pin.name+":</b>"+pin.descr+"</label>");
descr.for = "opt-" + pin.value;
var div = document.createElement("div");
div.appendChild(input);
div.appendChild(descr);
return div;
}
function displayPins(resp) {
var po = $("#pin-mux");
po.innerHTML = "";
currPin = resp.curr;
resp.map.forEach(function(v) {
po.appendChild(createInputForPin(v));
});
}
function fetchPins() {
ajaxJson("GET", "/pins", displayPins, function() {
window.setTimeout(fetchPins, 1000);
});
}
function setPins(v, name) {
ajaxJson("POST", "/pins?value="+v, function() {
showNotification("Pin assignment changed to " + name);
}, function() {
showNotification("Pin assignment change failed");
window.setTimeout(fetchPins, 100);
});
}
window.onload=function(e) {
fetchPins();
//$("#pinform").onsubmit = setPins;
};
</script>
</body></html>

@ -21,6 +21,24 @@ body {
#aps label div {
display: inline-block;
margin: 0em 0.2em;
vertical-align: top;
}
fieldset.radios {
border: none;
padding-left: 0px;
}
fieldset fields {
clear: both;
}
#pin-mux input {
display: block;
margin-top: 0.4em;
float: left;
}
#pin-mux label {
display: block;
margin: 0em 0.2em 0em 2em;
width: 90%;
}
.pure-table td, .pure-table th {

@ -0,0 +1,64 @@
#include <esp8266.h>
#include "cgi.h"
#include "espfs.h"
static char *map_names[] = {
"esp-bridge", "jn-esp-v2", "esp-01"
};
static char* map_func[] = { "reset", "isp", "conn_led", "ser_led" };
static uint8_t map_asn[][4] = {
{ 12, 13, 0, 14 }, // esp-bridge
{ 12, 13, 0, 2 }, // jn-esp-v2
{ 0, 2, 12, 13 }, // esp-01
};
// Cgi to return choice of pin assignments
int ICACHE_FLASH_ATTR cgiPinsGet(HttpdConnData *connData) {
char buff[1024];
int len;
if (connData->conn==NULL) {
return HTTPD_CGI_DONE; // Connection aborted
}
len = os_sprintf(buff, "{ \"curr\":\"esp-bridge\", \"map\": [ ");
for (int i=0; i<sizeof(map_names)/sizeof(char*); i++) {
if (i != 0) buff[len++] = ',';
len += os_sprintf(buff+len, "\n{ \"value\":%d, \"name\":\"%s\"", i, map_names[i]);
for (int f=0; f<sizeof(map_func)/sizeof(char*); f++) {
len += os_sprintf(buff+len, ", \"%s\":%d", map_func[f], map_asn[i][f]);
}
len += os_sprintf(buff+len, ", \"descr\":\"");
for (int f=0; f<sizeof(map_func)/sizeof(char*); f++) {
len += os_sprintf(buff+len, " %s:gpio%d", map_func[f], map_asn[i][f]);
}
len += os_sprintf(buff+len, "\" }");
}
len += os_sprintf(buff+len, "\n] }");
jsonHeader(connData, 200);
httpdSend(connData, buff, len);
return HTTPD_CGI_DONE;
}
// Cgi to change choice of pin assignments
int ICACHE_FLASH_ATTR cgiPinsSet(HttpdConnData *connData) {
if (connData->conn==NULL) {
return HTTPD_CGI_DONE; // Connection aborted
}
jsonHeader(connData, 200);
return HTTPD_CGI_DONE;
}
int ICACHE_FLASH_ATTR cgiPins(HttpdConnData *connData) {
if (connData->requestType == HTTPD_METHOD_GET) {
return cgiPinsGet(connData);
} else if (connData->requestType == HTTPD_METHOD_POST) {
return cgiPinsSet(connData);
} else {
jsonHeader(connData, 404);
return HTTPD_CGI_DONE;
}
}

@ -0,0 +1,8 @@
#ifndef CGIPINS_H
#define CGIPINS_H
#include "httpd.h"
int cgiPins(HttpdConnData *connData);
#endif

@ -15,6 +15,7 @@
#include "httpdespfs.h"
#include "cgi.h"
#include "cgiwifi.h"
#include "cgipins.h"
#include "cgiflash.h"
#include "auth.h"
#include "espfs.h"
@ -86,6 +87,7 @@ HttpdBuiltInUrl builtInUrls[]={
{"/wifi/connect", cgiWiFiConnect, NULL},
{"/wifi/connstatus", cgiWiFiConnStatus, NULL},
{"/wifi/setmode", cgiWiFiSetMode, NULL},
{"/pins", cgiPins, NULL},
{"*", cgiEspFsHook, NULL}, //Catch-all cgi function for the filesystem
{NULL, NULL, NULL}

Loading…
Cancel
Save