allow updating screen via web interface
This commit is contained in:
parent
d3de814d75
commit
8986c51d4d
4 changed files with 54 additions and 26 deletions
|
|
@ -88,10 +88,6 @@
|
|||
z-index: -1;
|
||||
}
|
||||
|
||||
dt code {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
@media screen and (min-width: 800px) {
|
||||
body {
|
||||
padding: 72px;
|
||||
|
|
@ -102,8 +98,39 @@
|
|||
<body>
|
||||
<h1>inkblot</h1>
|
||||
<p>Welcome to your inkblot. You can use the text field below to enter and send Lua scripts that will change what is displayed on your screen. At the bottom of the screen you can get a short list of functions available for drawing.</p>
|
||||
<form method="POST" id="blot" action="/draw">
|
||||
<textarea></textarea>
|
||||
<form method="POST" id="blot" action="/draw" enctype="multipart/form-data">
|
||||
<textarea name="script">local math = require("math")
|
||||
local paper = require("paper")
|
||||
|
||||
paper.init()
|
||||
paper.set_rotation("portrait")
|
||||
paper.clear()
|
||||
|
||||
local width = paper.get_width()
|
||||
local height = paper.get_height()
|
||||
|
||||
print(
|
||||
'width: ' .. width,
|
||||
'height: ' .. height
|
||||
)
|
||||
|
||||
paper.clear()
|
||||
paper.fill_rect(0, 0, width, height, 0x22)
|
||||
|
||||
for i = 0, 4 do
|
||||
local off = 40 * i
|
||||
|
||||
local color
|
||||
if i % 2 == 0 then
|
||||
color = 0x22
|
||||
else
|
||||
color = 0xDD
|
||||
end
|
||||
|
||||
paper.fill_rect(off, off, width - off, height - off, color)
|
||||
end
|
||||
|
||||
paper.update()</textarea>
|
||||
<button type="submit">Draw</button>
|
||||
</form>
|
||||
<h2>How to draw</h2>
|
||||
|
|
@ -141,12 +168,6 @@
|
|||
<dt><code>paper.draw_line(x1, y1, x2, y2, color)</code></dt>
|
||||
<dd>Draw a line from <code>(x1,y1)</code> to <code>(x2,y2)</code> in the given <code>color</code>.</dd>
|
||||
|
||||
<dt><code>paper.draw_hline(x, y, length, color)</code></dt>
|
||||
<dd>Draw a horizontal line from <code>(x,y)</code> with the given <code>length</code> in the given <code>color</code>.</dd>
|
||||
|
||||
<dt><code>paper.draw_vline(x, y, length, color)</code></dt>
|
||||
<dd>Draw a vertical line from <code>(x,y)</code> with the given <code>length</code> in the given <code>color</code>.</dd>
|
||||
|
||||
<dt><code>paper.draw_circle(x, y, radius, color)</code> / <code>paper.fill_circle(x, y, radius, color)</code></dt>
|
||||
<dd>Draw an outline around a circle at <code>(x,y)</code> with the given <code>radius</code> in the given <code>color</code>. <code>fill_circle</code> draws the same circle with a solid filling.</dd>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
local math = require('math')
|
||||
local paper = require('paper')
|
||||
local math = require("math")
|
||||
local paper = require("paper")
|
||||
|
||||
paper.init()
|
||||
paper.set_rotation("portrait")
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@
|
|||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
/* Scratch buffer size for sending files to HTTP clients */
|
||||
#define SCRATCH_BUFSIZE 8192
|
||||
// Scratch buffer size for sending files to HTTP clients
|
||||
#define SCRATCH_BUFSIZE 2048
|
||||
|
||||
struct file_server_data {
|
||||
/* Scratch buffer for temporary storage during file transfer */
|
||||
|
|
@ -241,9 +241,7 @@ esp_err_t http_draw(httpd_req_t* req) {
|
|||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// READING STREAM
|
||||
int ret, remaining = req->content_len;
|
||||
|
||||
while (remaining > 0) {
|
||||
/* Read the data for the request */
|
||||
if ((ret = httpd_req_recv(req, buf,
|
||||
|
|
@ -255,8 +253,6 @@ esp_err_t http_draw(httpd_req_t* req) {
|
|||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
/* Send back the same data */
|
||||
httpd_resp_send_chunk(req, buf, ret);
|
||||
remaining -= ret;
|
||||
|
||||
/* Log data received */
|
||||
|
|
@ -265,18 +261,29 @@ esp_err_t http_draw(httpd_req_t* req) {
|
|||
ESP_LOGI(TAG, "====================================");
|
||||
}
|
||||
|
||||
// TODO: Error handling
|
||||
// Extract script from multipart-encoded POST body
|
||||
// NOTE: This will break as soon as you send more than just the script. Be careful!
|
||||
int first_lf = strcspn(buf, "\n") + 2; // get form boundary length
|
||||
buf[strlen(buf) - first_lf - 2] = 0; // remove form boundary at end
|
||||
memmove(buf, buf + first_lf, strlen(buf) - first_lf + 1);
|
||||
|
||||
// take only part after headers, which is designated by a dual linebreak
|
||||
int header_end = strcspn(buf, "\n\n") + 3;
|
||||
memmove(buf, buf + header_end, strlen(buf) - header_end + 1);
|
||||
|
||||
ESP_LOGI(TAG, "%s", buf);
|
||||
|
||||
// TODO: Error handling; we could probably even notify about syntax errors?
|
||||
vTaskPrioritySet(NULL, tskIDLE_PRIORITY); // ensure that FreeRTOS task watchdog does not complain
|
||||
run_lua_string(buf, "E-Paper Script via HTTP");
|
||||
heap_caps_free(buf);
|
||||
|
||||
// Done reading
|
||||
char response[100];
|
||||
sprintf(
|
||||
response, "script drawn!"
|
||||
);
|
||||
sprintf(response, "Thanks, I updated my screen!");
|
||||
httpd_resp_set_type(req, "text/plain");
|
||||
httpd_resp_set_status(req, "200");
|
||||
httpd_resp_set_status(req, "301");
|
||||
httpd_resp_set_hdr(req, "Location", "/");
|
||||
httpd_resp_send(req, response, HTTPD_RESP_USE_STRLEN);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -765,7 +765,7 @@ CONFIG_ESP_HTTP_CLIENT_EVENT_POST_TIMEOUT=2000
|
|||
#
|
||||
# HTTP Server
|
||||
#
|
||||
CONFIG_HTTPD_MAX_REQ_HDR_LEN=512
|
||||
CONFIG_HTTPD_MAX_REQ_HDR_LEN=1024
|
||||
CONFIG_HTTPD_MAX_URI_LEN=512
|
||||
CONFIG_HTTPD_ERR_RESP_NO_DELAY=y
|
||||
CONFIG_HTTPD_PURGE_BUF_LEN=32
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue