mirror of https://github.com/jeelabs/esp-link.git
parent
79495f6b42
commit
8bb8e1124b
After Width: | Height: | Size: 5.3 KiB |
@ -0,0 +1,14 @@ |
||||
<html><head><title>Log - ESP Link</title> |
||||
<link rel="stylesheet" type="text/css" href="style.css"> |
||||
</head> |
||||
<body> |
||||
<div id="main"> |
||||
<div id="topnav">%topnav%</div> |
||||
<h1><span class="esp">esp</span> link - Debug Log</h1> |
||||
<p>The debug log shows the 1024 last characters printed by the esp-link software itself to |
||||
its own debug log.</p> |
||||
<pre class="console"> |
||||
%log% |
||||
</pre> |
||||
</div> |
||||
</body></html> |
@ -0,0 +1,65 @@ |
||||
#include <esp8266.h> |
||||
#include "uart.h" |
||||
#include "cgi.h" |
||||
#include "console.h" |
||||
|
||||
// Microcontroller console capturing the last 1024 characters received on the uart so
|
||||
// they can be shown on a web page
|
||||
|
||||
#define BUF_MAX (1024) |
||||
static char console_buf[BUF_MAX]; |
||||
static int console_wr, console_rd; |
||||
static int console_pos; // offset since reset of console_rd position
|
||||
|
||||
static void ICACHE_FLASH_ATTR |
||||
console_write(char c) { |
||||
int wr = (console_wr+1)%BUF_MAX; |
||||
if (wr == console_rd) { |
||||
console_rd = (console_rd+1) % BUF_MAX; // full, eat first char
|
||||
console_pos++; |
||||
} |
||||
console_buf[console_wr] = c; |
||||
console_wr = wr; |
||||
} |
||||
|
||||
// return previous character in console, 0 if at start
|
||||
static char ICACHE_FLASH_ATTR |
||||
console_prev(void) { |
||||
if (console_wr == console_rd) return 0; |
||||
return console_buf[(console_wr+1+BUF_MAX)%BUF_MAX]; |
||||
} |
||||
|
||||
void ICACHE_FLASH_ATTR |
||||
console_write_char(char c) { |
||||
if (c == '\n' && console_prev() != '\r') console_write('\r'); |
||||
console_write(c); |
||||
} |
||||
|
||||
//===== Display a web page with the console
|
||||
int ICACHE_FLASH_ATTR |
||||
tplConsole(HttpdConnData *connData, char *token, void **arg) { |
||||
if (token==NULL) return HTTPD_CGI_DONE; |
||||
char buff[256]; |
||||
|
||||
if (os_strcmp(token, "console") == 0) { |
||||
if (console_wr > console_rd) { |
||||
httpdSend(connData, console_buf+console_rd, console_wr-console_rd); |
||||
} else if (console_rd != console_wr) { |
||||
httpdSend(connData, console_buf+console_rd, BUF_MAX-console_rd); |
||||
httpdSend(connData, console_buf, console_wr); |
||||
} |
||||
} else if (os_strcmp(token, "topnav")==0) { |
||||
printNav(buff); |
||||
httpdSend(connData, buff, -1); |
||||
} else { |
||||
httpdSend(connData, "Unknown\n", -1); |
||||
} |
||||
return HTTPD_CGI_DONE; |
||||
} |
||||
|
||||
void ICACHE_FLASH_ATTR consoleInit() { |
||||
console_wr = 0; |
||||
console_rd = 0; |
||||
} |
||||
|
||||
|
@ -1,51 +0,0 @@ |
||||
|
||||
/*
|
||||
* ---------------------------------------------------------------------------- |
||||
* "THE BEER-WARE LICENSE" (Revision 42): |
||||
* Jeroen Domburg <jeroen@spritesmods.com> wrote this file. As long as you retain
|
||||
* this notice you can do whatever you want with this stuff. If we meet some day,
|
||||
* and you think this stuff is worth it, you can buy me a beer in return.
|
||||
* ---------------------------------------------------------------------------- |
||||
*/ |
||||
|
||||
|
||||
#include <esp8266.h> |
||||
|
||||
#define LEDGPIO 2 |
||||
#define BTNGPIO 0 |
||||
|
||||
static ETSTimer resetBtntimer; |
||||
|
||||
void ICACHE_FLASH_ATTR ioLed(int ena) { |
||||
//gpio_output_set is overkill. ToDo: use better mactos
|
||||
if (ena) { |
||||
gpio_output_set((1<<LEDGPIO), 0, (1<<LEDGPIO), 0); |
||||
} else { |
||||
gpio_output_set(0, (1<<LEDGPIO), (1<<LEDGPIO), 0); |
||||
} |
||||
} |
||||
|
||||
static void ICACHE_FLASH_ATTR resetBtnTimerCb(void *arg) { |
||||
static int resetCnt=0; |
||||
if (!GPIO_INPUT_GET(BTNGPIO)) { |
||||
resetCnt++; |
||||
} else { |
||||
if (resetCnt>=6) { //3 sec pressed
|
||||
wifi_station_disconnect(); |
||||
wifi_set_opmode(0x3); //reset to AP+STA mode
|
||||
os_printf("Reset to AP mode. Restarting system...\n"); |
||||
system_restart(); |
||||
} |
||||
resetCnt=0; |
||||
} |
||||
} |
||||
|
||||
void ioInit() { |
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2); |
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0); |
||||
gpio_output_set(0, 0, (1<<LEDGPIO), (1<<BTNGPIO)); |
||||
os_timer_disarm(&resetBtntimer); |
||||
os_timer_setfn(&resetBtntimer, resetBtnTimerCb, NULL); |
||||
os_timer_arm(&resetBtntimer, 500, 1); |
||||
} |
||||
|
@ -1,7 +0,0 @@ |
||||
#ifndef IO_H |
||||
#define IO_H |
||||
|
||||
void ICACHE_FLASH_ATTR ioLed(int ena); |
||||
void ioInit(void); |
||||
|
||||
#endif |
@ -0,0 +1,94 @@ |
||||
#include <esp8266.h> |
||||
#include "uart.h" |
||||
#include "cgi.h" |
||||
#include "log.h" |
||||
|
||||
// Web log for the esp8266 to replace outputting to uart1.
|
||||
// The web log has a 1KB circular in-memory buffer which os_printf prints into and
|
||||
// the HTTP handler simply displays the buffer content on a web page.
|
||||
|
||||
#define BUF_MAX (1024) |
||||
static char log_buf[BUF_MAX]; |
||||
static int log_wr, log_rd; |
||||
static bool log_no_uart; // start out printing to uart
|
||||
static bool log_newline; // at start of a new line
|
||||
|
||||
void ICACHE_FLASH_ATTR |
||||
log_uart(bool enable) { |
||||
if (!enable && !log_no_uart) { |
||||
os_printf("Turning OFF uart log\n"); |
||||
os_delay_us(4*1000L); // time for uart to flush
|
||||
log_no_uart = !enable; |
||||
} else if (enable && log_no_uart) { |
||||
log_no_uart = !enable; |
||||
os_printf("Turning ON uart log\n"); |
||||
} |
||||
} |
||||
|
||||
static void ICACHE_FLASH_ATTR |
||||
log_write(char c) { |
||||
int wr = (log_wr+1)%BUF_MAX; |
||||
if (wr == log_rd) |
||||
log_rd = (log_rd+1) % BUF_MAX; // full, eat first char
|
||||
log_buf[log_wr] = c; |
||||
log_wr = wr; |
||||
} |
||||
|
||||
#if 0 |
||||
static char ICACHE_FLASH_ATTR |
||||
log_read(void) { |
||||
char c = 0; |
||||
if (log_rd != log_wr) { |
||||
c = log_buf[log_rd]; |
||||
log_rd = (log_rd+1) % BUF_MAX; |
||||
} |
||||
return c; |
||||
} |
||||
#endif |
||||
|
||||
static void ICACHE_FLASH_ATTR |
||||
log_write_char(char c) { |
||||
// Uart output unless disabled
|
||||
if (!log_no_uart) { |
||||
if (log_newline) { |
||||
uart0_write_char('>'); |
||||
uart0_write_char(' '); |
||||
log_newline = false; |
||||
} |
||||
uart0_write_char(c); |
||||
log_newline = c == '\n'; |
||||
} |
||||
// Store in log buffer
|
||||
if (c == '\n') log_write('\r'); |
||||
log_write(c); |
||||
} |
||||
|
||||
//===== Display a web page with the log
|
||||
int ICACHE_FLASH_ATTR |
||||
tplLog(HttpdConnData *connData, char *token, void **arg) { |
||||
if (token==NULL) return HTTPD_CGI_DONE; |
||||
char buff[256]; |
||||
|
||||
if (os_strcmp(token, "log") == 0) { |
||||
if (log_wr > log_rd) { |
||||
httpdSend(connData, log_buf+log_rd, log_wr-log_rd); |
||||
} else if (log_rd != log_wr) { |
||||
httpdSend(connData, log_buf+log_rd, BUF_MAX-log_rd); |
||||
httpdSend(connData, log_buf, log_wr); |
||||
} |
||||
} else if (os_strcmp(token, "topnav")==0) { |
||||
printNav(buff); |
||||
httpdSend(connData, buff, -1); |
||||
} else { |
||||
httpdSend(connData, "Unknown\n", -1); |
||||
} |
||||
return HTTPD_CGI_DONE; |
||||
} |
||||
|
||||
void ICACHE_FLASH_ATTR logInit() { |
||||
log_wr = 0; |
||||
log_rd = 0; |
||||
os_install_putc1((void *)log_write_char); |
||||
} |
||||
|
||||
|
@ -0,0 +1,10 @@ |
||||
#ifndef LOG_H |
||||
#define LOG_H |
||||
|
||||
#include "httpd.h" |
||||
|
||||
void logInit(void); |
||||
void ICACHE_FLASH_ATTR log_uart(bool enable); |
||||
int tplLog(HttpdConnData *connData, char *token, void **arg); |
||||
|
||||
#endif |
@ -1,47 +0,0 @@ |
||||
//Stupid bit of code that does the bare minimum to make os_printf work.
|
||||
|
||||
/*
|
||||
* ---------------------------------------------------------------------------- |
||||
* "THE BEER-WARE LICENSE" (Revision 42): |
||||
* Jeroen Domburg <jeroen@spritesmods.com> wrote this file. As long as you retain
|
||||
* this notice you can do whatever you want with this stuff. If we meet some day,
|
||||
* and you think this stuff is worth it, you can buy me a beer in return.
|
||||
* ---------------------------------------------------------------------------- |
||||
*/ |
||||
|
||||
|
||||
#include <esp8266.h> |
||||
|
||||
static void ICACHE_FLASH_ATTR stdoutUartTxd(char c) { |
||||
//Wait until there is room in the FIFO
|
||||
while (((READ_PERI_REG(UART_STATUS(0))>>UART_TXFIFO_CNT_S)&UART_TXFIFO_CNT)>=126) ; |
||||
//Send the character
|
||||
WRITE_PERI_REG(UART_FIFO(0), c); |
||||
} |
||||
|
||||
static void ICACHE_FLASH_ATTR stdoutPutchar(char c) { |
||||
//convert \n -> \r\n
|
||||
if (c=='\n') stdoutUartTxd('\r'); |
||||
stdoutUartTxd(c); |
||||
} |
||||
|
||||
|
||||
void stdoutInit() { |
||||
//Enable TxD pin
|
||||
PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0TXD_U); |
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD); |
||||
|
||||
//Set baud rate and other serial parameters to 115200,n,8,1
|
||||
uart_div_modify(0, UART_CLK_FREQ/BIT_RATE_115200); |
||||
WRITE_PERI_REG(UART_CONF0(0), (STICK_PARITY_DIS)|(ONE_STOP_BIT << UART_STOP_BIT_NUM_S)| \
|
||||
(EIGHT_BITS << UART_BIT_NUM_S)); |
||||
|
||||
//Reset tx & rx fifo
|
||||
SET_PERI_REG_MASK(UART_CONF0(0), UART_RXFIFO_RST|UART_TXFIFO_RST); |
||||
CLEAR_PERI_REG_MASK(UART_CONF0(0), UART_RXFIFO_RST|UART_TXFIFO_RST); |
||||
//Clear pending interrupts
|
||||
WRITE_PERI_REG(UART_INT_CLR(0), 0xffff); |
||||
|
||||
//Install our own putchar handler
|
||||
os_install_putc1((void *)stdoutPutchar); |
||||
} |
@ -1,6 +0,0 @@ |
||||
#ifndef STDOUT_H |
||||
#define STDOUT_H |
||||
|
||||
void stdoutInit(); |
||||
|
||||
#endif |
Loading…
Reference in new issue