From 7bd9f1df7f9636e3b63ed40c16966d1e54377a98 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Tue, 28 May 2024 11:32:19 +0300 Subject: [iot/goam] Added display invertion setting --- Year 3/Internet of things/goam/main/main.c | 14 ++++++++++++++ Year 3/Internet of things/goam/main/main.h | 1 + Year 3/Internet of things/goam/main/webserver.c | 19 +++++++++++++++++++ Year 3/Internet of things/goam/webserver/index.html | 8 ++++++++ 4 files changed, 42 insertions(+) diff --git a/Year 3/Internet of things/goam/main/main.c b/Year 3/Internet of things/goam/main/main.c index bceab07..32a49a2 100644 --- a/Year 3/Internet of things/goam/main/main.c +++ b/Year 3/Internet of things/goam/main/main.c @@ -110,6 +110,18 @@ void main_store_resolution(int32_t value) { display_resolution(); } +static int32_t inv = NORMAL; + +void main_store_invertion(int32_t value) { + if (value != NORMAL && value != INVERSE) { + ESP_LOGW(TAG, "Invalid value for invertion was passed, not assigning"); + return; + } + nvs_write_i32("invertion", value); + inv = value; + display_invertion((enum Inversion)inv); +} + /* * On button press */ @@ -192,6 +204,8 @@ void app_main(void) display_imagesave(); nvs_read_i32("resolution", &res); display_resolution(); + nvs_read_i32("invertion", &inv); + display_invertion((enum Inversion)inv); // This is really slow wifi_init(); diff --git a/Year 3/Internet of things/goam/main/main.h b/Year 3/Internet of things/goam/main/main.h index b08e83f..3745494 100644 --- a/Year 3/Internet of things/goam/main/main.h +++ b/Year 3/Internet of things/goam/main/main.h @@ -2,3 +2,4 @@ void main_store_saveimage(uint32_t value); void main_store_resolution(int32_t value); +void main_store_invertion(int32_t value); diff --git a/Year 3/Internet of things/goam/main/webserver.c b/Year 3/Internet of things/goam/main/webserver.c index 6da93ef..b2a4843 100644 --- a/Year 3/Internet of things/goam/main/webserver.c +++ b/Year 3/Internet of things/goam/main/webserver.c @@ -151,6 +151,24 @@ static const httpd_uri_t post_resolution = { .handler = post_resolution_handler, }; +static esp_err_t post_invertion_handler(httpd_req_t *req) { + char* buffer = malloc(req->content_len + 1); + httpd_req_recv(req, buffer, req->content_len); + + main_store_invertion((int32_t)(strtol(strchr(buffer, '=') + 2, NULL, 16))); + + httpd_resp_send(req, "", 0); + free(buffer); + + logi_post(req); + return ESP_OK; +} +static const httpd_uri_t post_invertion = { + .uri = "/invertion", + .method = HTTP_POST, + .handler = post_invertion_handler, +}; + static esp_err_t ws_camera_handler(httpd_req_t *req) { if (req->method == HTTP_GET) { ESP_LOGI(TAG, "Established websocket connection"); @@ -233,6 +251,7 @@ void webserver_start() httpd_register_uri_handler(server, &post_network); httpd_register_uri_handler(server, &post_imagesave); httpd_register_uri_handler(server, &post_resolution); + httpd_register_uri_handler(server, &post_invertion); httpd_register_uri_handler(server, &ws_camera); ESP_LOGI(TAG, "Started server on port %d", config.httpd.server_port); diff --git a/Year 3/Internet of things/goam/webserver/index.html b/Year 3/Internet of things/goam/webserver/index.html index 27f24df..a8cdff6 100644 --- a/Year 3/Internet of things/goam/webserver/index.html +++ b/Year 3/Internet of things/goam/webserver/index.html @@ -87,6 +87,14 @@ iframe { +
+
+ + +