This commit is contained in:
2026-01-12 00:53:54 +01:00
commit 2f827c168d
26 changed files with 3145 additions and 0 deletions

37
include/README Normal file
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

31
include/camera_service.h Normal file
View File

@@ -0,0 +1,31 @@
#pragma once
#include "esp_camera.h"
class CameraService {
public:
class Frame {
camera_fb_t* fb;
public:
Frame(camera_fb_t* _fb) : fb(_fb) {}
~Frame() {
if (fb) {
esp_camera_fb_return(fb);
}
}
Frame(const Frame&) = delete;
Frame& operator=(const Frame&) = delete;
Frame(Frame&& other) noexcept : fb(other.fb) {
other.fb = nullptr;
}
bool isValid() const { return fb != nullptr; }
uint8_t* getData() const { return fb ? fb->buf : nullptr; }
size_t getWidth() const { return fb ? fb->width : 0; }
size_t getHeight() const { return fb ? fb->height : 0; }
size_t getLength() const { return fb ? fb->len : 0; }
};
static void init();
static Frame capture();
};

17
include/config.h Normal file
View File

@@ -0,0 +1,17 @@
#pragma once
#include <Arduino.h>
namespace Config {
// Hardware Pins (ESP32-CAM AI-Thinker)
constexpr int PIN_CAM_PWDN = 32;
constexpr int PIN_CAM_RESET = -1;
// ... (Add standard camera pins here to keep main clean) ...
// Printer Pins
constexpr int PIN_PRINTER_RX = 14;
constexpr int PIN_PRINTER_TX = 15;
// Settings
constexpr int PRINTER_WIDTH = 384;
constexpr int BAUD_RATE = 9600; // Check your printer specs (some are 19200)
}

11
include/image_processor.h Normal file
View File

@@ -0,0 +1,11 @@
#pragma once
#include "camera_service.h"
#include "printer_service.h"
#include "settings_service.h"
class ImageProcessor
{
public:
static void processAndPrint(const CameraService::Frame &frame, PrinterService &printer, const AppSettings &settings);
static void uploadImage(const uint8_t *bitmap, int size, const String &url);
};

31
include/printer_service.h Normal file
View File

@@ -0,0 +1,31 @@
#pragma once
#include <Arduino.h>
#include <Adafruit_Thermal.h>
#include "config.h"
class PrinterService
{
private:
HardwareSerial *printerSerial;
Adafruit_Thermal *printer;
static PrinterService *instance;
PrinterService();
public:
PrinterService(const PrinterService &) = delete;
PrinterService &operator=(const PrinterService &) = delete;
static void init();
static PrinterService &getInstance();
void wake();
void sleep();
void feed(int lines);
void setHeat(uint8_t heatTime);
void printBitmap(int w, int h, const uint8_t *bitmap);
void printText(const String &text);
};

View File

@@ -0,0 +1,41 @@
#pragma once
#include <Arduino.h>
#include <Preferences.h>
#include <WebServer.h>
struct AppSettings
{
// Camera
int contrast = 0; // -2 to 2
int brightness = 0; // -2 to 2
bool vFlip = false;
bool hMirror = false;
// Printer
int heatTime = 120; // 0-255 (Higher = darker but slower)
int heatInterval = 50; // 0-255
// Upload
String uploadUrl = ""; // e.g., "http://192.168.1.10:3000/upload"
bool enableUpload = false;
};
class SettingsService
{
private:
Preferences prefs;
WebServer server;
AppSettings currentSettings;
bool wifiConnected = false;
void setupRoutes();
void loadSettings();
public:
SettingsService();
void begin();
void handle();
AppSettings &get() { return currentSettings; }
void save();
};