Skip to content

Commit 5367835

Browse files
committed
chore: reformat code
Run `clang-format -i main/*.{c,cpp,h}` for consistent style, no functional change.
1 parent 7544885 commit 5367835

18 files changed

Lines changed: 1571 additions & 1432 deletions

main/ap.c

Lines changed: 498 additions & 443 deletions
Large diffs are not rendered by default.

main/ap.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
#pragma once
22

3-
#include "wifi.h"
4-
53
#include <esp_err.h>
64
#include <esp_http_server.h>
75
#include <freertos/FreeRTOS.h>
86
#include <freertos/timers.h>
97

8+
#include "wifi.h"
9+
1010
#ifdef __cplusplus
1111
extern "C" {
1212
#endif
1313

1414
/**
1515
* @brief Initialize the Access Point and start services
16-
*
16+
*
1717
* @return esp_err_t ESP_OK on success
1818
*/
1919
esp_err_t ap_start(void);
2020

2121
/**
2222
* @brief Stop the Access Point services
23-
*
23+
*
2424
* @return esp_err_t ESP_OK on success
2525
*/
2626
esp_err_t ap_stop(void);
@@ -43,12 +43,7 @@ void ap_configure(void);
4343

4444
void ap_start_shutdown_timer(void);
4545

46-
47-
4846
#ifdef __cplusplus
49-
5047
}
5148

5249
#endif
53-
54-

main/display.cpp

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#include "display.h"
2-
#include "font5x7.h"
3-
#include "nvs_settings.h"
4-
#include "esp_log.h"
5-
#include "esp_heap_caps.h"
62

73
#include <hub75.h>
84

5+
#include "esp_heap_caps.h"
6+
#include "esp_log.h"
7+
#include "font5x7.h"
8+
#include "nvs_settings.h"
9+
910
static Hub75Driver *_matrix;
1011
static uint8_t _brightness = (CONFIG_HUB75_BRIGHTNESS * 100) / 255;
1112
static const char *TAG = "display";
@@ -17,7 +18,8 @@ static uint32_t *_scaled_buffer = NULL;
1718
int display_initialize(void) {
1819
#if CONFIG_HUB75_PANEL_WIDTH == 128 && CONFIG_HUB75_PANEL_HEIGHT == 64
1920
if (_scaled_buffer == NULL) {
20-
_scaled_buffer = (uint32_t *)heap_caps_malloc(128 * 64 * 4, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
21+
_scaled_buffer = (uint32_t *)heap_caps_malloc(
22+
128 * 64 * 4, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
2123
if (_scaled_buffer == NULL) {
2224
ESP_LOGE(TAG, "Failed to allocate scaled buffer in PSRAM");
2325
return 1;
@@ -29,7 +31,8 @@ int display_initialize(void) {
2931
bool swap_colors = nvs_get_swap_colors();
3032

3133
// Initialize pin values based on hardware and swap_colors setting
32-
ESP_LOGI(TAG, "Initializing display with swap_colors=%s", swap_colors ? "true" : "false");
34+
ESP_LOGI(TAG, "Initializing display with swap_colors=%s",
35+
swap_colors ? "true" : "false");
3336

3437
// Initialize the panel.
3538
Hub75Config mxconfig;
@@ -123,7 +126,7 @@ int display_initialize(void) {
123126
mxconfig.pins.b2 = 39;
124127
}
125128
ESP_LOGI(TAG, "Board preset: MatrixPortal S3");
126-
#else // GEN1 from here down.
129+
#else // GEN1 from here down.
127130
mxconfig.pins.a = 26;
128131
mxconfig.pins.b = 5;
129132
mxconfig.pins.c = 25;
@@ -236,7 +239,8 @@ int display_initialize(void) {
236239

237240
static inline uint8_t brightness_percent_to_8bit(uint8_t pct) {
238241
if (pct > 100) pct = 100;
239-
return (uint8_t)(((uint32_t)pct * 230 + 50) / 100); // 230 as MAX 8 BIT HARDCODED
242+
return (uint8_t)(((uint32_t)pct * 230 + 50) /
243+
100); // 230 as MAX 8 BIT HARDCODED
240244
}
241245

242246
void display_set_brightness(uint8_t brightness_pct) {
@@ -247,11 +251,13 @@ void display_set_brightness(uint8_t brightness_pct) {
247251
uint8_t max_brightness_8bit = MAX_BRIGHTNESS_8BIT;
248252
if (brightness_8bit > max_brightness_8bit) {
249253
brightness_8bit = max_brightness_8bit;
250-
ESP_LOGI(TAG, "Clamping brightness to MAX_BRIGHTNESS (%d)", MAX_BRIGHTNESS_8BIT);
254+
ESP_LOGI(TAG, "Clamping brightness to MAX_BRIGHTNESS (%d)",
255+
MAX_BRIGHTNESS_8BIT);
251256
}
252257
#endif
253258

254-
ESP_LOGI(TAG, "Setting brightness to %d%% (%d)", brightness_pct, brightness_8bit);
259+
ESP_LOGI(TAG, "Setting brightness to %d%% (%d)", brightness_pct,
260+
brightness_8bit);
255261
_matrix->set_brightness(brightness_8bit);
256262
_matrix->clear();
257263
_brightness = brightness_pct;
@@ -283,14 +289,16 @@ void display_draw(const uint8_t *pix, int width, int height) {
283289
}
284290
}
285291

286-
_matrix->draw_pixels(0, 0, 128, 64, (uint8_t*)_scaled_buffer, Hub75PixelFormat::RGB888_32, Hub75ColorOrder::BGR);
292+
_matrix->draw_pixels(0, 0, 128, 64, (uint8_t *)_scaled_buffer,
293+
Hub75PixelFormat::RGB888_32, Hub75ColorOrder::BGR);
287294
_matrix->flip_buffer();
288295
return;
289296
}
290297
#endif
291298

292299
// Default path: bulk transfer for native resolution
293-
_matrix->draw_pixels(0, 0, width, height, pix, Hub75PixelFormat::RGB888_32, Hub75ColorOrder::BGR);
300+
_matrix->draw_pixels(0, 0, width, height, pix, Hub75PixelFormat::RGB888_32,
301+
Hub75ColorOrder::BGR);
294302
_matrix->flip_buffer();
295303
}
296304

@@ -303,18 +311,18 @@ void display_draw_pixel(int x, int y, uint8_t r, uint8_t g, uint8_t b) {
303311
}
304312
}
305313

306-
void display_fill_rect(int x, int y, int w, int h, uint8_t r, uint8_t g, uint8_t b) {
314+
void display_fill_rect(int x, int y, int w, int h, uint8_t r, uint8_t g,
315+
uint8_t b) {
307316
if (_matrix != NULL) {
308317
_matrix->fill(x, y, w, h, r, g, b);
309318
// Note: No flip here, caller must flip
310319
}
311320
}
312321

313-
void draw_error_indicator_pixel(void) {
314-
display_draw_pixel(0, 0, 100, 0, 0);
315-
}
322+
void draw_error_indicator_pixel(void) { display_draw_pixel(0, 0, 100, 0, 0); }
316323

317-
void display_text(const char* text, int x, int y, uint8_t r, uint8_t g, uint8_t b, int scale) {
324+
void display_text(const char *text, int x, int y, uint8_t r, uint8_t g,
325+
uint8_t b, int scale) {
318326
if (_matrix == NULL || text == NULL) {
319327
return;
320328
}
@@ -328,12 +336,12 @@ void display_text(const char* text, int x, int y, uint8_t r, uint8_t g, uint8_t
328336

329337
// Check if character is in font range
330338
if (c < FONT5X7_FIRST_CHAR || c > FONT5X7_LAST_CHAR) {
331-
c = ' '; // Replace unsupported characters with space
339+
c = ' '; // Replace unsupported characters with space
332340
}
333341

334342
// Get font data for this character
335343
int char_index = c - FONT5X7_FIRST_CHAR;
336-
const uint8_t* char_data = font5x7[char_index];
344+
const uint8_t *char_data = font5x7[char_index];
337345

338346
// Draw each column of the character
339347
for (int col = 0; col < FONT5X7_CHAR_WIDTH; col++) {
@@ -346,14 +354,15 @@ void display_text(const char* text, int x, int y, uint8_t r, uint8_t g, uint8_t
346354
int py = cursor_y + (row * scale);
347355

348356
if (scale > 1) {
349-
// Optimize scaled text using fill
350-
_matrix->fill(px, py, scale, scale, r, g, b);
357+
// Optimize scaled text using fill
358+
_matrix->fill(px, py, scale, scale, r, g, b);
351359
} else {
352-
// Draw pixel(s) based on scale
353-
// Check bounds
354-
if (px >= 0 && px < CONFIG_HUB75_PANEL_WIDTH && py >= 0 && py < CONFIG_HUB75_PANEL_HEIGHT) {
355-
_matrix->set_pixel(px, py, r, g, b);
356-
}
360+
// Draw pixel(s) based on scale
361+
// Check bounds
362+
if (px >= 0 && px < CONFIG_HUB75_PANEL_WIDTH && py >= 0 &&
363+
py < CONFIG_HUB75_PANEL_HEIGHT) {
364+
_matrix->set_pixel(px, py, r, g, b);
365+
}
357366
}
358367
}
359368
}

main/display.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#pragma once
22

3-
#include "sdkconfig.h"
43
#include <stddef.h>
54
#include <stdint.h>
65

6+
#include "sdkconfig.h"
7+
78
#define DISPLAY_MAX_BRIGHTNESS 100
89
#define DISPLAY_MIN_BRIGHTNESS 0
910

@@ -15,12 +16,14 @@ int display_initialize(void);
1516
void display_set_brightness(uint8_t brightness_pct);
1617
void display_shutdown(void);
1718

18-
void display_draw(const uint8_t *pix, int width, int height);
19+
void display_draw(const uint8_t* pix, int width, int height);
1920
void display_clear(void);
2021
void display_draw_pixel(int x, int y, uint8_t r, uint8_t g, uint8_t b);
21-
void display_fill_rect(int x, int y, int w, int h, uint8_t r, uint8_t g, uint8_t b);
22+
void display_fill_rect(int x, int y, int w, int h, uint8_t r, uint8_t g,
23+
uint8_t b);
2224
void draw_error_indicator_pixel(void);
23-
void display_text(const char* text, int x, int y, uint8_t r, uint8_t g, uint8_t b, int scale);
25+
void display_text(const char* text, int x, int y, uint8_t r, uint8_t g,
26+
uint8_t b, int scale);
2427
void display_flip(void);
2528
// int32_t isAnimating = 0; // Initialize with a valid value
2629

main/dns_wrapper.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#include <sys/types.h>
2-
#include <sys/socket.h>
1+
#include <esp_log.h>
32
#include <netdb.h>
43
#include <string.h>
5-
#include <esp_log.h>
4+
#include <sys/socket.h>
5+
#include <sys/types.h>
6+
67
#include "lwip/netdb.h"
78

89
static const char *TAG = "DNS_WRAPPER";
@@ -12,17 +13,21 @@ int __real_esp_getaddrinfo(const char *nodename, const char *servname,
1213
const struct addrinfo *hints, struct addrinfo **res);
1314

1415
int __wrap_esp_getaddrinfo(const char *nodename, const char *servname,
15-
const struct addrinfo *hints, struct addrinfo **res) {
16-
if (nodename != NULL) {
17-
const char *mdns_suffix = ".local";
18-
const size_t mdns_suffix_len = strlen(mdns_suffix);
19-
size_t len = strlen(nodename);
20-
// Check for .local suffix for mDNS
21-
if (len >= mdns_suffix_len && strcasecmp(nodename + len - mdns_suffix_len, mdns_suffix) == 0) {
22-
ESP_LOGD(TAG, "Redirecting mDNS query for %s to lwip_getaddrinfo", nodename);
23-
return lwip_getaddrinfo(nodename, servname, hints, res);
24-
}
16+
const struct addrinfo *hints,
17+
struct addrinfo **res) {
18+
if (nodename != NULL) {
19+
const char *mdns_suffix = ".local";
20+
const size_t mdns_suffix_len = strlen(mdns_suffix);
21+
size_t len = strlen(nodename);
22+
// Check for .local suffix for mDNS
23+
if (len >= mdns_suffix_len &&
24+
strcasecmp(nodename + len - mdns_suffix_len, mdns_suffix) == 0) {
25+
ESP_LOGD(TAG, "Redirecting mDNS query for %s to lwip_getaddrinfo",
26+
nodename);
27+
return lwip_getaddrinfo(nodename, servname, hints, res);
2528
}
26-
// Fallback to the standard ESP implementation (which handles IPv6/AF_UNSPEC better)
27-
return __real_esp_getaddrinfo(nodename, servname, hints, res);
29+
}
30+
// Fallback to the standard ESP implementation (which handles IPv6/AF_UNSPEC
31+
// better)
32+
return __real_esp_getaddrinfo(nodename, servname, hints, res);
2833
}

0 commit comments

Comments
 (0)