added reset button and baud rate switching

pull/10/head 0.9.5
Thorsten von Eicken 10 years ago
parent c2e56bed4a
commit 1b1ee532de
  1. 36
      html/console.tpl
  2. 26
      serial/console.c
  3. 2
      serial/console.h
  4. 7
      serial/serbridge.c
  5. 1
      serial/serbridge.h
  6. 5
      serial/uart.c
  7. 2
      serial/uart.h
  8. 4
      user/user_main.c

@ -9,12 +9,12 @@
<p>The Microcontroller console shows the last 1024 characters <p>The Microcontroller console shows the last 1024 characters
received from UART0, to which a microcontroller is typically attached.</p> received from UART0, to which a microcontroller is typically attached.</p>
<p> <p>
<a class="pure-button button-primary" href="#">Reset µC</a> <a id="reset-button" class="pure-button button-primary" href="#">Reset µC</a>
&nbsp;Baud: &nbsp;Baud:
<a href="#" class="pure-button">57600</a> <a id="57600-button" href="#" class="pure-button">57600</a>
<a href="#" class="pure-button">115200</a> <a id="115200-button" href="#" class="pure-button">115200</a>
<a href="#" class="pure-button">230400</a> <a id="230400-button" href="#" class="pure-button">230400</a>
<a href="#" class="pure-button">460800</a> <a id="460800-button" href="#" class="pure-button">460800</a>
</p> </p>
<pre class="console" id="console"></pre> <pre class="console" id="console"></pre>
</div> </div>
@ -36,14 +36,14 @@
if(xhr.status !== 200) { if(xhr.status !== 200) {
//console.log("handleEv error cb"); //console.log("handleEv error cb");
errCb(xhr); if (errCb != null) errCb(xhr);
return; return;
} }
// all is well // all is well
if(xhr.readyState === 4) { if(xhr.readyState === 4) {
//console.log("handleEv success cb"); //console.log("handleEv success cb");
okCb(xhr, JSON.parse(xhr.responseText)); if (okCb != null) okCb(xhr, JSON.parse(xhr.responseText));
} }
} catch(e) {return;} } catch(e) {return;}
} }
@ -59,7 +59,7 @@
el.innerHTML = ""; el.innerHTML = "";
} }
window.setTimeout(function() { window.setTimeout(function() {
loadJSON("/console?start=" + el.textEnd, updateText, retryLoad); loadJSON("/console/text?start=" + el.textEnd, updateText, retryLoad);
}, delay); }, delay);
} }
@ -87,8 +87,28 @@
fetchText(1000); fetchText(1000);
} }
function baudButton(baud) {
document.getElementById(""+baud+"-button").addEventListener("click", function(e) {
console.log("switching to", baud, "baud");
e.preventDefault();
loadJSON("/console/baud?rate="+baud);
});
}
window.onload = function() { window.onload = function() {
fetchText(100); fetchText(100);
document.getElementById("reset-button").addEventListener("click", function(e) {
el = document.getElementById("console");
e.preventDefault();
//console.log("reset click");
el.innerHTML = "";
loadJSON("/console/reset");
});
baudButton(57600);
baudButton(115200);
baudButton(230400);
baudButton(460800);
} }
</script> </script>
</body></html> </body></html>

@ -1,6 +1,8 @@
#include <esp8266.h> #include <esp8266.h>
#include "uart.h" #include "uart.h"
#include "cgi.h" #include "cgi.h"
#include "uart.h"
#include "serbridge.h"
#include "console.h" #include "console.h"
// Microcontroller console capturing the last 1024 characters received on the uart so // Microcontroller console capturing the last 1024 characters received on the uart so
@ -49,6 +51,30 @@ jsonHeader(HttpdConnData *connData, int code) {
httpdEndHeaders(connData); httpdEndHeaders(connData);
} }
int ICACHE_FLASH_ATTR
ajaxConsoleReset(HttpdConnData *connData) {
jsonHeader(connData, 200);
serbridgeReset();
return HTTPD_CGI_DONE;
}
int ICACHE_FLASH_ATTR
ajaxConsoleBaud(HttpdConnData *connData) {
char buff[2048];
int len;
len = httpdFindArg(connData->getArgs, "rate", buff, sizeof(buff));
if (len > 0) {
int rate = atoi(buff);
if (rate >= 9600 && rate <= 1000000) {
jsonHeader(connData, 200);
uart0_baud(rate);
return HTTPD_CGI_DONE;
}
}
jsonHeader(connData, 400);
return HTTPD_CGI_DONE;
}
int ICACHE_FLASH_ATTR int ICACHE_FLASH_ATTR
ajaxConsole(HttpdConnData *connData) { ajaxConsole(HttpdConnData *connData) {
char buff[2048]; char buff[2048];

@ -6,6 +6,8 @@
void consoleInit(void); void consoleInit(void);
void ICACHE_FLASH_ATTR console_write_char(char c); void ICACHE_FLASH_ATTR console_write_char(char c);
int ajaxConsole(HttpdConnData *connData); int ajaxConsole(HttpdConnData *connData);
int ajaxConsoleReset(HttpdConnData *connData);
int ajaxConsoleBaud(HttpdConnData *connData);
int tplConsole(HttpdConnData *connData, char *token, void **arg); int tplConsole(HttpdConnData *connData, char *token, void **arg);
#endif #endif

@ -172,6 +172,13 @@ telnetUnwrap(uint8_t *inBuf, int len, uint8_t state)
return state; return state;
} }
void ICACHE_FLASH_ATTR serbridgeReset() {
os_printf("MCU reset gpio%d\n", mcu_reset_pin);
GPIO_OUTPUT_SET(mcu_reset_pin, 0);
os_delay_us(100L);
GPIO_OUTPUT_SET(mcu_reset_pin, 1);
}
// Receive callback // Receive callback
static void ICACHE_FLASH_ATTR serbridgeRecvCb(void *arg, char *data, unsigned short len) { static void ICACHE_FLASH_ATTR serbridgeRecvCb(void *arg, char *data, unsigned short len) {

@ -34,5 +34,6 @@ struct serbridgeConnData {
void ICACHE_FLASH_ATTR serbridgeInit(int port, uint8_t reset_pin, uint8_t isp_pin); void ICACHE_FLASH_ATTR serbridgeInit(int port, uint8_t reset_pin, uint8_t isp_pin);
void ICACHE_FLASH_ATTR serbridgeUartCb(char *buf, int len); void ICACHE_FLASH_ATTR serbridgeUartCb(char *buf, int len);
void ICACHE_FLASH_ATTR serbridgeReset();
#endif /* __SER_BRIDGE_H__ */ #endif /* __SER_BRIDGE_H__ */

@ -237,6 +237,11 @@ uart_recvTask(os_event_t *events)
ETS_UART_INTR_ENABLE(); ETS_UART_INTR_ENABLE();
} }
void ICACHE_FLASH_ATTR
uart0_baud(int rate) {
uart_div_modify(UART0, UART_CLK_FREQ / rate);
}
/****************************************************************************** /******************************************************************************
* FunctionName : uart_init * FunctionName : uart_init
* Description : user interface for init uart * Description : user interface for init uart

@ -21,4 +21,6 @@ STATUS uart_tx_one_char(uint8 uart, uint8 c);
// with all new characters. // with all new characters.
void ICACHE_FLASH_ATTR uart_add_recv_cb(UartRecv_cb cb); void ICACHE_FLASH_ATTR uart_add_recv_cb(UartRecv_cb cb);
void ICACHE_FLASH_ATTR uart0_baud(int rate);
#endif /* __UART_H__ */ #endif /* __UART_H__ */

@ -68,7 +68,9 @@ HttpdBuiltInUrl builtInUrls[]={
{"/help.tpl", cgiEspFsTemplate, tplCounter}, {"/help.tpl", cgiEspFsTemplate, tplCounter},
{"/log.tpl", cgiEspFsTemplate, tplLog}, {"/log.tpl", cgiEspFsTemplate, tplLog},
{"/console.tpl", cgiEspFsTemplate, tplConsole}, {"/console.tpl", cgiEspFsTemplate, tplConsole},
{"/console", ajaxConsole, NULL}, {"/console/reset", ajaxConsoleReset, NULL},
{"/console/baud", ajaxConsoleBaud, NULL},
{"/console/text", ajaxConsole, NULL},
//Routines to make the /wifi URL and everything beneath it work. //Routines to make the /wifi URL and everything beneath it work.

Loading…
Cancel
Save