Init
This commit is contained in:
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
.pio
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/ipch
|
||||||
|
lib/*
|
||||||
7
.vscode/extensions.json
vendored
Normal file
7
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
|
// for the documentation about the extensions.json format
|
||||||
|
"recommendations": [
|
||||||
|
"platformio.platformio-ide"
|
||||||
|
]
|
||||||
|
}
|
||||||
39
include/README
Normal file
39
include/README
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
|
||||||
|
This directory is intended for project header files.
|
||||||
|
|
||||||
|
A header file is a file containing C declarations and macro definitions
|
||||||
|
to be shared between several project source files. You request the use of a
|
||||||
|
header file in your project source file (C, C++, etc) located in `src` folder
|
||||||
|
by including it, with the C preprocessing directive `#include'.
|
||||||
|
|
||||||
|
```src/main.c
|
||||||
|
|
||||||
|
#include "header.h"
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Including a header file produces the same results as copying the header file
|
||||||
|
into each source file that needs it. Such copying would be time-consuming
|
||||||
|
and error-prone. With a header file, the related declarations appear
|
||||||
|
in only one place. If they need to be changed, they can be changed in one
|
||||||
|
place, and programs that include the header file will automatically use the
|
||||||
|
new version when next recompiled. The header file eliminates the labor of
|
||||||
|
finding and changing all the copies as well as the risk that a failure to
|
||||||
|
find one copy will result in inconsistencies within a program.
|
||||||
|
|
||||||
|
In C, the usual convention is to give header files names that end with `.h'.
|
||||||
|
It is most portable to use only letters, digits, dashes, and underscores in
|
||||||
|
header file names, and at most one dot.
|
||||||
|
|
||||||
|
Read more about using header files in official GCC documentation:
|
||||||
|
|
||||||
|
* Include Syntax
|
||||||
|
* Include Operation
|
||||||
|
* Once-Only Headers
|
||||||
|
* Computed Includes
|
||||||
|
|
||||||
|
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||||
22
platformio.ini
Normal file
22
platformio.ini
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[env:esp-wrover-kit]
|
||||||
|
platform = espressif32
|
||||||
|
board = esp-wrover-kit
|
||||||
|
framework = arduino
|
||||||
|
build_flags = -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue
|
||||||
|
monitor_port = COM[13678]
|
||||||
|
monitor_speed = 115200
|
||||||
|
monitor_rts = 0
|
||||||
|
monitor_dtr = 0
|
||||||
|
lib_deps =
|
||||||
|
yoursunny/esp32cam@^0.0.20210226
|
||||||
|
naguissa/uTimerLib@^1.6.7
|
||||||
178
src/main.cpp
Normal file
178
src/main.cpp
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
#define CAMERA_MODEL_AI_THINKER
|
||||||
|
#include <WebServer.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <esp32cam.h>
|
||||||
|
#include "uTimerLib.h"
|
||||||
|
|
||||||
|
const char* WIFI_SSID = "CAMAP";
|
||||||
|
const char* WIFI_PASS = "camera4okutt*8";
|
||||||
|
const uint8_t port = 12;
|
||||||
|
const uint16_t pulseTimeout = 4;
|
||||||
|
|
||||||
|
WebServer server(80);
|
||||||
|
|
||||||
|
static auto loRes = esp32cam::Resolution::find(320, 240);
|
||||||
|
static auto hiRes = esp32cam::Resolution::find(800, 600);
|
||||||
|
|
||||||
|
void
|
||||||
|
handleBmp()
|
||||||
|
{
|
||||||
|
if (!esp32cam::Camera.changeResolution(loRes)) {
|
||||||
|
Serial.println("SET-LO-RES FAIL");
|
||||||
|
}
|
||||||
|
|
||||||
|
auto frame = esp32cam::capture();
|
||||||
|
if (frame == nullptr) {
|
||||||
|
Serial.println("CAPTURE FAIL");
|
||||||
|
server.send(503, "", "");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Serial.printf("CAPTURE OK %dx%d %db\n", frame->getWidth(), frame->getHeight(),
|
||||||
|
static_cast<int>(frame->size()));
|
||||||
|
|
||||||
|
if (!frame->toBmp()) {
|
||||||
|
Serial.println("CONVERT FAIL");
|
||||||
|
server.send(503, "", "");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Serial.printf("CONVERT OK %dx%d %db\n", frame->getWidth(), frame->getHeight(),
|
||||||
|
static_cast<int>(frame->size()));
|
||||||
|
|
||||||
|
server.setContentLength(frame->size());
|
||||||
|
server.send(200, "image/bmp");
|
||||||
|
WiFiClient client = server.client();
|
||||||
|
frame->writeTo(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
serveJpg()
|
||||||
|
{
|
||||||
|
auto frame = esp32cam::capture();
|
||||||
|
if (frame == nullptr) {
|
||||||
|
Serial.println("CAPTURE FAIL");
|
||||||
|
server.send(503, "", "");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Serial.printf("CAPTURE OK %dx%d %db\n", frame->getWidth(), frame->getHeight(),
|
||||||
|
static_cast<int>(frame->size()));
|
||||||
|
|
||||||
|
server.setContentLength(frame->size());
|
||||||
|
server.send(200, "image/jpeg");
|
||||||
|
WiFiClient client = server.client();
|
||||||
|
frame->writeTo(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
handleJpgLo()
|
||||||
|
{
|
||||||
|
if (!esp32cam::Camera.changeResolution(loRes)) {
|
||||||
|
Serial.println("SET-LO-RES FAIL");
|
||||||
|
}
|
||||||
|
serveJpg();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
handleJpgHi()
|
||||||
|
{
|
||||||
|
if (!esp32cam::Camera.changeResolution(hiRes)) {
|
||||||
|
Serial.println("SET-HI-RES FAIL");
|
||||||
|
}
|
||||||
|
serveJpg();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
handleJpg()
|
||||||
|
{
|
||||||
|
server.sendHeader("Location", "/cam-hi.jpg");
|
||||||
|
server.send(302, "", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
handleMjpeg()
|
||||||
|
{
|
||||||
|
if (!esp32cam::Camera.changeResolution(hiRes)) {
|
||||||
|
Serial.println("SET-HI-RES FAIL");
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("STREAM BEGIN");
|
||||||
|
WiFiClient client = server.client();
|
||||||
|
auto startTime = millis();
|
||||||
|
int res = esp32cam::Camera.streamMjpeg(client);
|
||||||
|
if (res <= 0) {
|
||||||
|
Serial.printf("STREAM ERROR %d\n", res);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto duration = millis() - startTime;
|
||||||
|
Serial.printf("STREAM END %dfrm %0.2ffps\n", res, 1000.0 * res / duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleOne()
|
||||||
|
{
|
||||||
|
digitalWrite(port,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleZero()
|
||||||
|
{
|
||||||
|
digitalWrite(port,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void handlePulse()
|
||||||
|
{
|
||||||
|
handleOne();
|
||||||
|
|
||||||
|
TimerLib.setTimeout_s(handleZero,pulseTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
{
|
||||||
|
using namespace esp32cam;
|
||||||
|
Config cfg;
|
||||||
|
cfg.setPins(pins::AiThinker);
|
||||||
|
cfg.setResolution(hiRes);
|
||||||
|
cfg.setBufferCount(2);
|
||||||
|
cfg.setJpeg(80);
|
||||||
|
|
||||||
|
bool ok = Camera.begin(cfg);
|
||||||
|
Serial.println(ok ? "CAMERA OK" : "CAMERA FAIL");
|
||||||
|
|
||||||
|
pinMode(port, OUTPUT);
|
||||||
|
Serial.println("SET PORT OUTPUT\n");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
WiFi.persistent(false);
|
||||||
|
WiFi.mode(WIFI_STA);
|
||||||
|
WiFi.begin(WIFI_SSID, WIFI_PASS);
|
||||||
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
|
delay(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.print("http://");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
|
Serial.println(" /cam.bmp");
|
||||||
|
Serial.println(" /cam-lo.jpg");
|
||||||
|
Serial.println(" /cam-hi.jpg");
|
||||||
|
Serial.println(" /cam.mjpeg");
|
||||||
|
|
||||||
|
server.on("/cam.bmp", handleBmp);
|
||||||
|
server.on("/cam-lo.jpg", handleJpgLo);
|
||||||
|
server.on("/cam-hi.jpg", handleJpgHi);
|
||||||
|
server.on("/cam.jpg", handleJpg);
|
||||||
|
server.on("/cam.mjpeg", handleMjpeg);
|
||||||
|
server.on("/send.zero",handleZero);
|
||||||
|
server.on("/send.one",handleOne);
|
||||||
|
server.on("/send.pulse",handlePulse);
|
||||||
|
|
||||||
|
server.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
loop()
|
||||||
|
{
|
||||||
|
server.handleClient();
|
||||||
|
}
|
||||||
11
test/README
Normal file
11
test/README
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
This directory is intended for PlatformIO Unit Testing and project tests.
|
||||||
|
|
||||||
|
Unit Testing is a software testing method by which individual units of
|
||||||
|
source code, sets of one or more MCU program modules together with associated
|
||||||
|
control data, usage procedures, and operating procedures, are tested to
|
||||||
|
determine whether they are fit for use. Unit testing finds problems early
|
||||||
|
in the development cycle.
|
||||||
|
|
||||||
|
More information about PlatformIO Unit Testing:
|
||||||
|
- https://docs.platformio.org/page/plus/unit-testing.html
|
||||||
Reference in New Issue
Block a user