84 lines
No EOL
1.6 KiB
C++
84 lines
No EOL
1.6 KiB
C++
#include "Arduino.h"
|
|
|
|
#include "nvs_flash.h"
|
|
#include <mutex>
|
|
|
|
#include "ESP32epdx.h"
|
|
#include "EPD.h"
|
|
#include "mesh_netif.h"
|
|
#include "tcphelper.h"
|
|
#include "main.h"
|
|
|
|
std::mutex epd_mtx;
|
|
|
|
/*
|
|
SPI: SCK = 6 ; MISO = 2 ; MOSI = 7 ; SS = 16
|
|
EPD: RES = 22 ; DC = 23 ; CS = 1 ; BUSY = 0
|
|
*/
|
|
|
|
#define IMAGE_BUF_SIZE 5624
|
|
uint8_t *image_buf = nullptr;
|
|
|
|
extern "C" int tcp_server_callback(char *buf, size_t len) {
|
|
if (!strncmp(buf, "ping", 4)) { // ping
|
|
return 0;
|
|
} else if (!strncmp(buf, "image", 5) && len == 5 + 5624) { // update image
|
|
if (epd_mtx.try_lock())
|
|
{
|
|
// work
|
|
EPD_HW_Init_Fast();
|
|
EPD_Display((unsigned char *)(buf+5));
|
|
EPD_DeepSleep();
|
|
|
|
//vTaskDelay(pdMS_TO_TICKS(1000));
|
|
|
|
// unlock
|
|
epd_mtx.unlock();
|
|
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
// locked
|
|
return -2;
|
|
}
|
|
} else { // invalid request
|
|
return -3;
|
|
}
|
|
}
|
|
|
|
extern "C" void app_main()
|
|
{
|
|
initArduino();
|
|
|
|
// init image_buf
|
|
image_buf = (uint8_t *)malloc(IMAGE_BUF_SIZE);
|
|
memset(image_buf, 0, IMAGE_BUF_SIZE);
|
|
|
|
//Initialize NVS
|
|
esp_err_t ret = nvs_flash_init();
|
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
|
ret = nvs_flash_init();
|
|
}
|
|
ESP_ERROR_CHECK(ret);
|
|
|
|
// Initialize EPD
|
|
EPD_Pin_Init(6, 2, 7, 16,
|
|
22, 23, 1, 0);
|
|
|
|
mesh_main();
|
|
|
|
// tcp server
|
|
start_tcp_server();
|
|
|
|
// Arduino-like setup()
|
|
|
|
// Arduino-like loop()
|
|
while (true)
|
|
{
|
|
vTaskDelay(500);
|
|
}
|
|
|
|
// WARNING: if program reaches end of function app_main() the MCU will restart.
|
|
} |