Skip to content

Commit

Permalink
added reset button and baud rate switching
Browse files Browse the repository at this point in the history
  • Loading branch information
tve committed Jun 6, 2015
1 parent c2e56be commit 1b1ee53
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 9 deletions.
36 changes: 28 additions & 8 deletions html/console.tpl
Expand Up @@ -9,12 +9,12 @@
<p>The Microcontroller console shows the last 1024 characters
received from UART0, to which a microcontroller is typically attached.</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:
<a href="#" class="pure-button">57600</a>
<a href="#" class="pure-button">115200</a>
<a href="#" class="pure-button">230400</a>
<a href="#" class="pure-button">460800</a>
<a id="57600-button" href="#" class="pure-button">57600</a>
<a id="115200-button" href="#" class="pure-button">115200</a>
<a id="230400-button" href="#" class="pure-button">230400</a>
<a id="460800-button" href="#" class="pure-button">460800</a>
</p>
<pre class="console" id="console"></pre>
</div>
Expand All @@ -36,14 +36,14 @@
if(xhr.status !== 200) {
//console.log("handleEv error cb");
errCb(xhr);
if (errCb != null) errCb(xhr);
return;
}
// all is well
if(xhr.readyState === 4) {
//console.log("handleEv success cb");
okCb(xhr, JSON.parse(xhr.responseText));
if (okCb != null) okCb(xhr, JSON.parse(xhr.responseText));
}
} catch(e) {return;}
}
Expand All @@ -59,7 +59,7 @@
el.innerHTML = "";
}
window.setTimeout(function() {
loadJSON("/console?start=" + el.textEnd, updateText, retryLoad);
loadJSON("/console/text?start=" + el.textEnd, updateText, retryLoad);
}, delay);
}
Expand Down Expand Up @@ -87,8 +87,28 @@
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() {
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>
</body></html>
26 changes: 26 additions & 0 deletions serial/console.c
@@ -1,6 +1,8 @@
#include <esp8266.h>
#include "uart.h"
#include "cgi.h"
#include "uart.h"
#include "serbridge.h"
#include "console.h"

// Microcontroller console capturing the last 1024 characters received on the uart so
Expand Down Expand Up @@ -49,6 +51,30 @@ jsonHeader(HttpdConnData *connData, int code) {
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
ajaxConsole(HttpdConnData *connData) {
char buff[2048];
Expand Down
2 changes: 2 additions & 0 deletions serial/console.h
Expand Up @@ -6,6 +6,8 @@
void consoleInit(void);
void ICACHE_FLASH_ATTR console_write_char(char c);
int ajaxConsole(HttpdConnData *connData);
int ajaxConsoleReset(HttpdConnData *connData);
int ajaxConsoleBaud(HttpdConnData *connData);
int tplConsole(HttpdConnData *connData, char *token, void **arg);

#endif
7 changes: 7 additions & 0 deletions serial/serbridge.c
Expand Up @@ -172,6 +172,13 @@ telnetUnwrap(uint8_t *inBuf, int len, uint8_t 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
static void ICACHE_FLASH_ATTR serbridgeRecvCb(void *arg, char *data, unsigned short len) {
Expand Down
1 change: 1 addition & 0 deletions serial/serbridge.h
Expand Up @@ -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 serbridgeUartCb(char *buf, int len);
void ICACHE_FLASH_ATTR serbridgeReset();

#endif /* __SER_BRIDGE_H__ */
5 changes: 5 additions & 0 deletions serial/uart.c
Expand Up @@ -237,6 +237,11 @@ uart_recvTask(os_event_t *events)
ETS_UART_INTR_ENABLE();
}

void ICACHE_FLASH_ATTR
uart0_baud(int rate) {
uart_div_modify(UART0, UART_CLK_FREQ / rate);
}

/******************************************************************************
* FunctionName : uart_init
* Description : user interface for init uart
Expand Down
2 changes: 2 additions & 0 deletions serial/uart.h
Expand Up @@ -21,4 +21,6 @@ STATUS uart_tx_one_char(uint8 uart, uint8 c);
// with all new characters.
void ICACHE_FLASH_ATTR uart_add_recv_cb(UartRecv_cb cb);

void ICACHE_FLASH_ATTR uart0_baud(int rate);

#endif /* __UART_H__ */
4 changes: 3 additions & 1 deletion user/user_main.c
Expand Up @@ -68,7 +68,9 @@ HttpdBuiltInUrl builtInUrls[]={
{"/help.tpl", cgiEspFsTemplate, tplCounter},
{"/log.tpl", cgiEspFsTemplate, tplLog},
{"/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.

Expand Down

0 comments on commit 1b1ee53

Please sign in to comment.