This commit is contained in:
2025-11-13 20:54:45 +08:00
commit 2b5cfc1538
13 changed files with 479 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
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 convention is to give header files names that end with `.h'.
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
+25
View File
@@ -0,0 +1,25 @@
#ifndef INIT_H
#define INIT_H
#include <Adafruit_ST7735.h>
#include <Arduino.h>
namespace esp32 {
namespace init {
// 在屏幕上打印日志
void tftLog(const char* msg, uint16_t color);
// 读取并解析配置文件
bool loadSettings();
// 连接 WiFi
void connectWiFi();
// 初始化系统
void initSystem(Adafruit_ST7735& tft);
} // namespace init
} // namespace esp32
#endif // INIT_H
+48
View File
@@ -0,0 +1,48 @@
#ifndef UTILS_H
#define UTILS_H
#include <stdint.h>
namespace esp32 {
namespace utils {
// 三次贝塞尔曲线计算
float cubicBezier(float t, float p0, float p1, float p2, float p3);
float solveCubicBezierX(float xTarget,
float x1,
float x2,
float epsilon = 0.00001f);
float linear2CubicBezier(float source,
float x1 = 0.42f,
float y1 = 0.0f,
float x2 = 0.58f,
float y2 = 1.0f);
// RGB 颜色转换
uint16_t rgbTo565(uint32_t rgbColor);
} // namespace utils
// 颜色常量 (全局命名空间)
namespace colors {
inline uint16_t BLACK() { return utils::rgbTo565(0x000000); }
inline uint16_t WHITE() { return utils::rgbTo565(0xFFFFFF); }
inline uint16_t RED() { return utils::rgbTo565(0xFF0000); }
inline uint16_t GREEN() { return utils::rgbTo565(0x00FF00); }
inline uint16_t BLUE() { return utils::rgbTo565(0x0000FF); }
inline uint16_t YELLOW() { return utils::rgbTo565(0xFFFF00); }
} // namespace colors
} // namespace esp32
// 为了兼容性,保留宏定义
#define BLACK esp32::colors::BLACK()
#define WHITE esp32::colors::WHITE()
#define RED esp32::colors::RED()
#define GREEN esp32::colors::GREEN()
#define BLUE esp32::colors::BLUE()
#define YELLOW esp32::colors::YELLOW()
#endif // UTILS_H