Skip to content

Commit cbb2e56

Browse files
committed
ci: Ubuntu 22.04, clang-format-15, esp32cam
1 parent 3fc245b commit cbb2e56

22 files changed

+131
-244
lines changed

.clang-format

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ BasedOnStyle: Mozilla
33
AllowShortFunctionsOnASingleLine: Empty
44
BinPackArguments: true
55
BinPackParameters: true
6+
BreakBeforeBraces: Attach
67
ColumnLimit: 100
78
Cpp11BracedListStyle: true
89
FixNamespaceComments: true
10+
IncludeIsMainRegex: '(\.t)?$'
11+
InsertBraces: true
12+
QualifierAlignment: Custom
13+
QualifierOrder: ['static', 'inline', 'const', 'constexpr', 'volatile', 'type', 'restrict']
914
ReflowComments: false
10-
SortIncludes: true
11-
SortUsingDeclarations: true
15+
ShortNamespaceLines: 1000000
1216
SpacesInContainerLiterals: false

.github/workflows/build.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
permissions: {}
77
jobs:
88
build:
9-
runs-on: ubuntu-20.04
9+
runs-on: ubuntu-22.04
1010
steps:
1111
- uses: arduino/setup-arduino-cli@v1
1212
- id: cores
@@ -26,8 +26,8 @@ jobs:
2626
arduino-cli core install esp32:esp32 --additional-urls "$(<~/arduino-cores.txt)"
2727
- name: Install dependencies
2828
run: |
29-
sudo apt-get install -y --no-install-recommends clang-format-11 doxygen
30-
- uses: actions/checkout@v3
29+
sudo apt-get install -y --no-install-recommends clang-format-15 doxygen
30+
- uses: actions/checkout@v4
3131
- name: Check code style
3232
run: |
3333
mk/format-code.sh
@@ -50,13 +50,13 @@ jobs:
5050
ODROIDGO_VERSION: 4a496e337d16bca4ddedbeca3486d7b60662d017
5151
- name: Compile examples
5252
run: |
53-
arduino-cli compile -b esp32:esp32:esp32wrover ./examples/WifiCam
54-
arduino-cli compile -b esp32:esp32:esp32wrover ./examples/AsyncCam
53+
arduino-cli compile -b esp32:esp32:esp32cam ./examples/WifiCam
54+
arduino-cli compile -b esp32:esp32:esp32cam ./examples/AsyncCam
5555
arduino-cli compile -b esp32:esp32:odroid_esp32 ./examples/GoDisplay
5656
- name: Build docs
5757
run: docs/build.sh
5858
- name: Deploy docs
59-
uses: nwtgck/actions-netlify@30aa80fe8d5eec30813fc8b17b77e0a6663f09b5
59+
uses: nwtgck/actions-netlify@v2.1.0
6060
with:
6161
publish-dir: ./docs/html/
6262
production-deploy: true

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ This library has been tested with AI Thinker [ESP32-CAM](http://www.ai-thinker.c
1616

1717
1. Clone this repository under `$HOME/Arduino/libraries` directory.
1818
2. Add `#include <esp32cam.h>` to your sketch.
19-
3. In *Tools* - *Board* menu, select **ESP32 Wrover Module** to enable 4MB external PSRAM.
19+
3. In *Tools* - *Board* menu, select **AI Thinker ESP32-CAM** to enable 4MB external PSRAM.
2020
4. Check out the [examples](examples/) for how to use.

examples/AsyncCam/AsyncCam.ino

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ esp32cam::Resolution currentResolution;
1010
AsyncWebServer server(80);
1111

1212
void
13-
setup()
14-
{
13+
setup() {
1514
Serial.begin(115200);
1615
Serial.println();
1716
delay(2000);
@@ -55,8 +54,7 @@ setup()
5554
}
5655

5756
void
58-
loop()
59-
{
57+
loop() {
6058
// esp32cam-asyncweb.h depends on FreeRTOS task API including vTaskDelete, so you must have a
6159
// non-zero delay in the loop() function; otherwise, FreeRTOS kernel memory cannot be freed
6260
// properly and the system would run out of memory.

examples/AsyncCam/handlers.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ for (const $ctrl of document.querySelectorAll("#controls button")) {
6464
)EOT";
6565

6666
static String
67-
rewriteFrontpage(const String& var)
68-
{
67+
rewriteFrontpage(const String& var) {
6968
StreamString b;
7069
if (var == "RESOLUTION_OPTIONS") {
7170
for (const auto& r : esp32cam::Camera.listResolutions()) {
@@ -85,8 +84,7 @@ rewriteFrontpage(const String& var)
8584
}
8685

8786
void
88-
addRequestHandlers()
89-
{
87+
addRequestHandlers() {
9088
server.on("/", HTTP_GET, [](AsyncWebServerRequest* request) {
9189
request->send_P(200, "text/html", reinterpret_cast<const uint8_t*>(FRONTPAGE),
9290
sizeof(FRONTPAGE), rewriteFrontpage);

examples/GoDisplay/GoDisplay.ino

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ static const uint16_t CAM_PORT = 80;
1111
static const char* CAM_URI = "/320x240.jpg";
1212

1313
void
14-
setup()
15-
{
14+
setup() {
1615
GO.begin(115200);
1716

1817
WiFi.persistent(false);
@@ -26,8 +25,7 @@ setup()
2625
}
2726

2827
void
29-
loop()
30-
{
28+
loop() {
3129
WiFiClient tcp;
3230
HTTPClient http;
3331
http.begin(tcp, CAM_SERVER, CAM_PORT, CAM_URI);

examples/GoDisplay/SpiRamOStream.hpp

+10-20
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,45 @@
44
#include <Arduino.h>
55

66
/** @brief write-only Stream backed by fixed-size SPIRAM buffer. */
7-
class SpiRamOStream : public Stream
8-
{
7+
class SpiRamOStream : public Stream {
98
public:
109
explicit SpiRamOStream(size_t cap)
1110
: m_buf(reinterpret_cast<uint8_t*>(heap_caps_malloc(cap, MALLOC_CAP_SPIRAM)))
1211
, m_len(0)
13-
, m_cap(cap)
14-
{}
12+
, m_cap(cap) {}
1513

16-
~SpiRamOStream()
17-
{
14+
~SpiRamOStream() {
1815
free(m_buf);
1916
}
2017

21-
const uint8_t* data() const
22-
{
18+
const uint8_t* data() const {
2319
return m_buf;
2420
}
2521

26-
const size_t size() const
27-
{
22+
const size_t size() const {
2823
return m_len;
2924
}
3025

31-
size_t write(const uint8_t* buffer, size_t size) override
32-
{
26+
size_t write(const uint8_t* buffer, size_t size) override {
3327
size_t count = min(size, m_cap - m_len);
3428
memcpy(m_buf + m_len, buffer, count);
3529
m_len += count;
3630
return count;
3731
}
3832

39-
size_t write(uint8_t data) override
40-
{
33+
size_t write(uint8_t data) override {
4134
return write(&data, 1);
4235
}
4336

44-
int available() override
45-
{
37+
int available() override {
4638
return 0;
4739
}
4840

49-
int read() override
50-
{
41+
int read() override {
5142
return -1;
5243
}
5344

54-
int peek() override
55-
{
45+
int peek() override {
5646
return -1;
5747
}
5848

examples/WifiCam/WifiCam.ino

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ esp32cam::Resolution initialResolution;
99
WebServer server(80);
1010

1111
void
12-
setup()
13-
{
12+
setup() {
1413
Serial.begin(115200);
1514
Serial.println();
1615
delay(2000);
@@ -53,7 +52,6 @@ setup()
5352
}
5453

5554
void
56-
loop()
57-
{
55+
loop() {
5856
server.handleClient();
5957
}

examples/WifiCam/handlers.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ try {
4141
)EOT";
4242

4343
static void
44-
serveStill(bool wantBmp)
45-
{
44+
serveStill(bool wantBmp) {
4645
auto frame = esp32cam::capture();
4746
if (frame == nullptr) {
4847
Serial.println("capture() failure");
@@ -69,8 +68,7 @@ serveStill(bool wantBmp)
6968
}
7069

7170
static void
72-
serveMjpeg()
73-
{
71+
serveMjpeg() {
7472
Serial.println("MJPEG streaming begin");
7573
WiFiClient client = server.client();
7674
auto startTime = millis();
@@ -80,8 +78,7 @@ serveMjpeg()
8078
}
8179

8280
void
83-
addRequestHandlers()
84-
{
81+
addRequestHandlers() {
8582
server.on("/", HTTP_GET, [] {
8683
server.setContentLength(sizeof(FRONTPAGE));
8784
server.send(200, "text/html");

mk/format-code.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ set -eo pipefail
33
cd "$( dirname "${BASH_SOURCE[0]}" )"/..
44

55
find -name '*.h' -or -name '*.[hc]pp' -or -name '*.ino' | \
6-
xargs clang-format-11 -i -style=file
6+
xargs clang-format-15 -i -style=file

src/esp32cam-asyncweb.h

+16-32
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,25 @@ namespace esp32cam {
1515
namespace asyncweb {
1616

1717
/** @brief HTTP response of one still image. */
18-
class StillResponse : public AsyncAbstractResponse
19-
{
18+
class StillResponse : public AsyncAbstractResponse {
2019
public:
2120
/**
2221
* @brief Constructor.
2322
* @param frame a frame of still image.
2423
*/
2524
explicit StillResponse(std::unique_ptr<Frame> frame)
26-
: m_frame(std::move(frame))
27-
{
25+
: m_frame(std::move(frame)) {
2826
_code = 200;
2927
_contentType = determineMineType(*m_frame);
3028
_contentLength = m_frame->size();
3129
_sendContentLength = true;
3230
}
3331

34-
bool _sourceValid() const override
35-
{
32+
bool _sourceValid() const override {
3633
return true;
3734
}
3835

39-
size_t _fillBuffer(uint8_t* buf, size_t buflen) override
40-
{
36+
size_t _fillBuffer(uint8_t* buf, size_t buflen) override {
4137
if (m_index >= m_frame->size()) {
4238
return 0;
4339
}
@@ -55,8 +51,7 @@ class StillResponse : public AsyncAbstractResponse
5551
*
5652
* This function must run as a FreeRTOS task. It self-deletes upon completion.
5753
*/
58-
static void captureTask(void* ctx)
59-
{
54+
static void captureTask(void* ctx) {
6055
auto request = reinterpret_cast<AsyncWebServerRequest*>(ctx);
6156

6257
auto frame = Camera.capture();
@@ -70,8 +65,7 @@ class StillResponse : public AsyncAbstractResponse
7065
}
7166

7267
private:
73-
static const char* determineMineType(const Frame& frame)
74-
{
68+
static const char* determineMineType(const Frame& frame) {
7569
if (frame.isJpeg()) {
7670
return "image/jpeg";
7771
}
@@ -99,8 +93,7 @@ class StillResponse : public AsyncAbstractResponse
9993
* to do these, and then call this function.
10094
*/
10195
inline void
102-
handleStill(AsyncWebServerRequest* request)
103-
{
96+
handleStill(AsyncWebServerRequest* request) {
10497
TaskHandle_t task;
10598
auto res = xTaskCreatePinnedToCore(StillResponse::captureTask, "esp32cam-still", 2048, request, 1,
10699
&task, xPortGetCoreID());
@@ -119,12 +112,10 @@ handleStill(AsyncWebServerRequest* request)
119112
* If task creation fails, respond with HTTP 500 error.
120113
* If image capture fails, the stream is stopped.
121114
*/
122-
class MjpegResponse : public AsyncAbstractResponse
123-
{
115+
class MjpegResponse : public AsyncAbstractResponse {
124116
public:
125117
explicit MjpegResponse(const MjpegConfig& cfg = MjpegConfig())
126-
: m_ctrl(cfg)
127-
{
118+
: m_ctrl(cfg) {
128119
m_queue = xQueueCreate(4, sizeof(Frame*));
129120
if (xTaskCreatePinnedToCore(captureTask, "esp32cam-mjpeg", 2048, this, 1, &m_task,
130121
xPortGetCoreID()) != pdPASS) {
@@ -142,8 +133,7 @@ class MjpegResponse : public AsyncAbstractResponse
142133
_sendContentLength = false;
143134
}
144135

145-
~MjpegResponse() override
146-
{
136+
~MjpegResponse() override {
147137
if (m_task != nullptr) {
148138
vTaskDelete(m_task);
149139
m_task = nullptr;
@@ -159,13 +149,11 @@ class MjpegResponse : public AsyncAbstractResponse
159149
}
160150
}
161151

162-
bool _sourceValid() const override
163-
{
152+
bool _sourceValid() const override {
164153
return true;
165154
}
166155

167-
size_t _fillBuffer(uint8_t* buf, size_t buflen) override
168-
{
156+
size_t _fillBuffer(uint8_t* buf, size_t buflen) override {
169157
auto act = m_ctrl.decideAction();
170158
switch (act) {
171159
case Ctrl::CAPTURE: {
@@ -201,8 +189,7 @@ class MjpegResponse : public AsyncAbstractResponse
201189
}
202190

203191
private:
204-
static void captureTask(void* ctx)
205-
{
192+
static void captureTask(void* ctx) {
206193
auto self = reinterpret_cast<MjpegResponse*>(ctx);
207194
while (true) {
208195
uint32_t value = 0;
@@ -218,8 +205,7 @@ class MjpegResponse : public AsyncAbstractResponse
218205
}
219206
}
220207

221-
size_t sendPart(uint8_t* buf, size_t buflen)
222-
{
208+
size_t sendPart(uint8_t* buf, size_t buflen) {
223209
if (m_sendRemain == 0) {
224210
switch (m_sendNext) {
225211
case SIPartHeader:
@@ -259,8 +245,7 @@ class MjpegResponse : public AsyncAbstractResponse
259245
Ctrl m_ctrl;
260246
detail::MjpegHeader m_hdr;
261247

262-
enum SendItem
263-
{
248+
enum SendItem {
264249
SINone,
265250
SIPartHeader,
266251
SIFrame,
@@ -277,8 +262,7 @@ class MjpegResponse : public AsyncAbstractResponse
277262
* To specify MjpegConfig, construct MjpegResponse directly.
278263
*/
279264
inline void
280-
handleMjpeg(AsyncWebServerRequest* request)
281-
{
265+
handleMjpeg(AsyncWebServerRequest* request) {
282266
request->send(new MjpegResponse());
283267
}
284268

0 commit comments

Comments
 (0)