Enclosure files + firmware

This commit is contained in:
Salim Benbouziyane
2024-12-27 16:11:21 -05:00
parent a0ae88370c
commit 5fd10e2f6b
62 changed files with 3587 additions and 1 deletions

View File

@@ -0,0 +1,40 @@
#pragma once
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "Animation.h"
class DisplayController
{
public:
DisplayController(uint8_t oledWidth, uint8_t oledHeight, uint8_t oledAddress = 0x3C);
void begin();
void drawSplashScreen();
void drawIdleScreen(int duration, bool wifi);
void drawTimerScreen(int remainingSeconds);
void drawPausedScreen(int remainingSeconds);
void drawResetScreen(bool resetSelected);
void drawDoneScreen();
void drawAdjustScreen(int duration);
void drawProvisionScreen();
void clear();
void showAnimation(const byte frames[][288], int frameCount, bool loop = false, bool reverse = false, unsigned long durationMs = 0, int width = 48, int height = 48);
void updateAnimation();
bool isAnimationRunning();
void showConfirmation();
void showCancel();
void showReset();
void showConnected();
void showTimerDone();
void showTimerStart();
void showTimerPause();
void showTimerResume();
private:
Adafruit_SSD1306 oled;
Animation animation;
};

View File

@@ -0,0 +1,46 @@
#pragma once
#include <Arduino.h>
#include <OneButton.h>
#include <RotaryEncoder.h>
#include <functional>
class InputController
{
public:
InputController(uint8_t buttonPin, uint8_t encoderPinA, uint8_t encoderPinB);
void begin();
void update();
void onPressHandler(std::function<void()> handler);
void onDoublePressHandler(std::function<void()> handler);
void onLongPressHandler(std::function<void()> handler);
void onEncoderRotateHandler(std::function<void(int delta)> handler);
void releaseHandlers();
private:
OneButton button;
RotaryEncoder encoder;
uint8_t buttonPin;
uint8_t encoderPinA;
uint8_t encoderPinB;
std::function<void()> pressHandler = nullptr;
std::function<void()> doublePressHandler = nullptr;
std::function<void()> longPressHandler = nullptr;
std::function<void(int delta)> encoderRotateHandler = nullptr;
int lastPosition;
void onButtonClick();
void onButtonDoubleClick();
void onButtonLongPress();
void onEncoderRotate(int delta);
static void handleEncoderInterrupt();
static void handleButtonInterrupt();
};
extern InputController inputController;

View File

@@ -0,0 +1,57 @@
#pragma once
#include <Adafruit_NeoPixel.h>
class LEDController
{
public:
LEDController(uint8_t ledPin, uint16_t numLeds, uint8_t brightness = 255);
void begin();
void update();
void startFillAndDecay(uint32_t color, uint32_t totalDuration);
void setSpinner(uint32_t color, int cycles);
void setBreath(uint32_t color, int cycles, bool endFilled, uint32_t speed);
void setSolid(uint32_t color);
void turnOff();
void printDebugInfo();
private:
Adafruit_NeoPixel leds;
uint16_t numLeds;
uint8_t brightness;
int brightnessLevel;
enum AnimationType
{
None,
FillAndDecay,
Spinner,
Breath
} currentAnimation;
unsigned long lastUpdateTime;
uint32_t animationColor;
uint32_t animationDuration;
uint32_t animationSpeed;
int currentStep;
int currentCycle;
int pixelIndex;
int animationCycles;
bool endFilled;
bool decayStarted;
// Animation handling methods
void handleFillAndDecay();
void handleSpinner();
void handleBreath();
// Reset animation state
void stopCurrentAnimation();
// Helper to scale color by brightness
uint32_t scaleColor(uint32_t color, uint8_t brightness);
};

View File

@@ -0,0 +1,56 @@
#pragma once
#include <BluetoothA2DPSink.h>
#include <WiFiProvisioner.h>
#include <Preferences.h>
class NetworkController
{
public:
NetworkController();
void begin();
void update();
void startProvisioning();
void stopProvisioning();
void reset();
bool isWiFiProvisioned();
bool isWiFiConnected();
bool isBluetoothPaired();
void initializeBluetooth();
void startBluetooth();
void stopBluetooth();
void sendWebhookAction(const String &action);
private:
BluetoothA2DPSink a2dp_sink;
Preferences preferences;
WiFiProvisioner::WiFiProvisioner wifiProvisioner; // Instance of WiFiProvisioner
String webhookURL;
bool btPaired; // Paired state loaded from NVS
bool bluetoothActive;
bool bluetoothAttempted;
bool provisioningMode;
unsigned long lastBluetoothtAttempt;
void WiFiProvisionerSettings();
void saveBluetoothPairedState(bool paired);
static void btConnectionStateCallback(esp_a2d_connection_state_t state, void *obj);
// Tasks
TaskHandle_t bluetoothTaskHandle;
TaskHandle_t webhookTaskHandle;
QueueHandle_t webhookQueue;
static void bluetoothTask(void *param);
static void webhookTask(void *param);
bool sendWebhookRequest(const String &action);
static NetworkController *instance;
static bool validateInputCallback(const String &input);
static void factoryResetCallback();
bool validateInput(const String &input);
void handleFactoryReset();
};