2025-11-13 20:54:45 +08:00

49 lines
1.4 KiB
C++

#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