diff --git a/firmware-arduino/README.md b/firmware-arduino/README.md index 11d416cb..a3c63f27 100644 --- a/firmware-arduino/README.md +++ b/firmware-arduino/README.md @@ -107,4 +107,18 @@ openssl s_client -showcerts -connect .deno.dev:443 = 255) // Changed from 255 to 128 - { - fadeAmount = -fadeAmount; - } -} - -void pulseMagenta() -{ - setLEDColor(brightness, 0, brightness); - brightness += fadeAmount; - if (brightness <= 0 || brightness >= 255) // Changed from 255 to 128 - { - fadeAmount = -fadeAmount; - } -} - -void pulseYellow() -{ - setLEDColor(brightness, brightness, 0); - brightness += fadeAmount; - if (brightness <= 0 || brightness >= 255) // Changed from 255 to 128 - { - fadeAmount = -fadeAmount; - } -} - -void pulseBlue() -{ - setLEDColor(0, 0, brightness); - brightness += fadeAmount; - if (brightness <= 0 || brightness >= 255) // Changed from 255 to 128 - { - fadeAmount = -fadeAmount; - } -} - -void blinkWhite() -{ - int out = ledState ? HIGH : LOW; - digitalWrite(RED_LED_PIN, out); - digitalWrite(GREEN_LED_PIN, out); - digitalWrite(BLUE_LED_PIN, out); -} - -void blinkGreen() -{ - int out = ledState ? HIGH : LOW; - digitalWrite(BLUE_LED_PIN, LOW); - digitalWrite(RED_LED_PIN, LOW); - digitalWrite(GREEN_LED_PIN, out); -} - -void blinkYellow() -{ - int out = ledState ? HIGH : LOW; - digitalWrite(BLUE_LED_PIN, LOW); - digitalWrite(RED_LED_PIN, out); - digitalWrite(GREEN_LED_PIN, out); -} - -void turnOffLED() -{ - digitalWrite(RED_LED_PIN, LOW); - digitalWrite(GREEN_LED_PIN, LOW); - digitalWrite(BLUE_LED_PIN, LOW); -} - -void turnOnLED() -{ - digitalWrite(RED_LED_PIN, HIGH); - digitalWrite(GREEN_LED_PIN, HIGH); - digitalWrite(BLUE_LED_PIN, HIGH); -} - -void setupRGBLED() -{ - pinMode(RED_LED_PIN, OUTPUT); - pinMode(GREEN_LED_PIN, OUTPUT); - pinMode(BLUE_LED_PIN, OUTPUT); - turnOffLED(); // Turn off the LED initially -} - -void blinkCyanPulse() -{ - analogWrite(GREEN_LED_PIN, brightness); - analogWrite(BLUE_LED_PIN, brightness); - - brightness += fadeAmount; - if (brightness <= 0 || brightness >= 255) - { - fadeAmount = -fadeAmount; +#include "Config.h" // für deviceState & State-Enums +#include +#include + +// ================== Board-spezifisch ================== +#define LED_PIN 48 // Freenove: WS2812 an GPIO 48 +#define LED_COUNT 1 + +static Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); + +// ================== LED-Interna ================== +static uint8_t g_brightness = 20; // 0..255 (NeoPixel Brightness) +static uint32_t lastToggle = 0; +static bool ledState = false; + +// kleiner Helfer (sicher auf 0..255 begrenzen) +static inline uint8_t clamp8(int v) { return (v < 0) ? 0 : (v > 255) ? 255 : (uint8_t)v; } + +// zentral setzen & anzeigen +static inline void ws_show_rgb(uint8_t r, uint8_t g, uint8_t b) { + strip.setPixelColor(0, strip.Color(r, g, b)); + strip.show(); +} + +// ================== öffentliche API ================== +void setupRGBLED() { + strip.begin(); + strip.setBrightness(g_brightness); + strip.show(); // aus +} + +void setLEDColor(uint8_t r, uint8_t g, uint8_t b) { + ws_show_rgb(r, g, b); +} + +void turnOffLED() { ws_show_rgb(0, 0, 0); } +void turnOnLED() { ws_show_rgb(255, 255, 255); } + +void setStaticColor(StaticColor color) { + switch (color) { + case StaticColor::RED: ws_show_rgb(255, 0, 0); break; + case StaticColor::GREEN: ws_show_rgb( 0, 255, 0); break; + case StaticColor::BLUE: ws_show_rgb( 0, 0, 255); break; + case StaticColor::YELLOW: ws_show_rgb(255, 255, 0); break; + case StaticColor::MAGENTA: ws_show_rgb(255, 0, 255); break; + case StaticColor::CYAN: ws_show_rgb( 0, 255, 255); break; + case StaticColor::WHITE: ws_show_rgb(255, 255, 255); break; + case StaticColor::OFF: ws_show_rgb( 0, 0, 0); break; + default: ws_show_rgb( 0, 0, 0); break; + } +} + +// sanftes Atmen (nicht blockierend) +static void breatheColor(uint8_t r, uint8_t g, uint8_t b) { + static uint16_t t = 0; // 0..149 + t = (t + 1) % 150; // ~3 Hz / 20 ms Schritte + float phase = (t < 75) ? (t / 75.0f) : (2.0f - t / 75.0f); // 0..1..0 + float g1 = phase * phase; // leichte Gamma + uint8_t rr = clamp8((int)(r * g1)); + uint8_t gg = clamp8((int)(g * g1)); + uint8_t bb = clamp8((int)(b * g1)); + ws_show_rgb(rr, gg, bb); +} + +void ledTask(void *parameter) { + setupRGBLED(); + const TickType_t tick = 20 / portTICK_PERIOD_MS; // 20 ms Tick + + for (;;) { + uint32_t now = millis(); + if (now - lastToggle >= 200) { // optionaler 5 Hz Toggler (falls gebraucht) + ledState = !ledState; + lastToggle = now; } -} - - -void blinkBlue() -{ - int out = ledState ? HIGH : LOW; - digitalWrite(GREEN_LED_PIN, LOW); - digitalWrite(RED_LED_PIN, LOW); - digitalWrite(BLUE_LED_PIN, out); -} - -void staticYellow() -{ - digitalWrite(BLUE_LED_PIN, LOW); - digitalWrite(RED_LED_PIN, HIGH); - digitalWrite(GREEN_LED_PIN, HIGH); -} - -static const uint8_t colorSequence[][3] = { - {0, 255, 255}, // Cyan (R=0, G=255, B=255) - {255, 0, 255}, // Pink (R=255, G=0, B=255) - {255, 255, 0}, // Yellow (R=255, G=255, B=0) -}; - -static const int NUM_COLORS = sizeof(colorSequence) / sizeof(colorSequence[0]); - -void loopCyanPinkYellowPulse(unsigned long currentTime) -{ - // Duration of each color fade - const unsigned long transitionDuration = 1000; // 500 ms per fade - - // colorIndex = which color in colorSequence we’re currently *starting* from - static int colorIndex = 0; - // We'll store the "start color" and "end color" for the current fade - static uint8_t startColor[3]; - static uint8_t endColor[3]; - - // The timestamp at which the current fade *started* - static unsigned long transitionStartTime = 0; - - // A flag so we can initialize the first fade - static bool initialized = false; - - if (!initialized) - { - // On the very first call, set the starting color to colorSequence[0] - // and the endColor to the next color in the array - memcpy(startColor, colorSequence[colorIndex], 3); - int nextIndex = (colorIndex + 1) % NUM_COLORS; - memcpy(endColor, colorSequence[nextIndex], 3); - - transitionStartTime = currentTime; - initialized = true; + // deviceState stammt aus deiner State-Machine (Config.h) + switch (deviceState) { + case IDLE: setStaticColor(StaticColor::GREEN); break; + case SOFT_AP: breatheColor(255, 0, 255); break; // Magenta + case PROCESSING: breatheColor(255, 64, 0); break; // Amber + case SPEAKING: setStaticColor(StaticColor::BLUE); break; + case LISTENING: setStaticColor(StaticColor::YELLOW); break; + case OTA: setStaticColor(StaticColor::CYAN); break; + default: setStaticColor(StaticColor::WHITE); break; } - // How long has this transition been running? - unsigned long elapsed = currentTime - transitionStartTime; - float t = (float)elapsed / (float)transitionDuration; - if (t > 1.0f) - { - t = 1.0f; // clamp - } - - // Interpolate each channel: R, G, B - uint8_t r = startColor[0] + (endColor[0] - startColor[0]) * t; - uint8_t g = startColor[1] + (endColor[1] - startColor[1]) * t; - uint8_t b = startColor[2] + (endColor[2] - startColor[2]) * t; - - // Write these values to your LED pins - analogWrite(RED_LED_PIN, r); - analogWrite(GREEN_LED_PIN, g); - analogWrite(BLUE_LED_PIN, b); - - // Check if this transition has finished - if (elapsed >= transitionDuration) - { - // Move to next color in the sequence - colorIndex = (colorIndex + 1) % NUM_COLORS; - memcpy(startColor, endColor, 3); // old 'end' becomes new 'start' - - int nextIndex = (colorIndex + 1) % NUM_COLORS; - memcpy(endColor, colorSequence[nextIndex], 3); - - transitionStartTime = currentTime; // reset the clock for the next fade - } + vTaskDelay(tick); + } } - -void ledTask(void *parameter) -{ - setupRGBLED(); - unsigned long currentTime = 0; - while (1) - { - currentTime += 20; // Track time based on vTaskDelay - - // Toggle LED state every 200ms for blinking functions - if (currentTime - lastToggle >= 200) - { - ledState = !ledState; - lastToggle = currentTime; - } - - switch (deviceState) - { - case IDLE: - setStaticColor(StaticColor::GREEN); - break; - case SOFT_AP: - setStaticColor(StaticColor::MAGENTA); - break; - case PROCESSING: - setStaticColor(StaticColor::RED); - break; - case SPEAKING: - setStaticColor(StaticColor::BLUE); - break; - case LISTENING: - setStaticColor(StaticColor::YELLOW); - break; - case OTA: - setStaticColor(StaticColor::CYAN); - break; - default: - setStaticColor(StaticColor::GREEN); // LED on - break; - } - - // Delay for smoother LED transitions - vTaskDelay(20 / portTICK_PERIOD_MS); // Approximate the delay from the original `pulsateLED()` - } -} \ No newline at end of file diff --git a/firmware-arduino/src/LEDHandler.h b/firmware-arduino/src/LEDHandler.h index 60701519..6e2eaf45 100644 --- a/firmware-arduino/src/LEDHandler.h +++ b/firmware-arduino/src/LEDHandler.h @@ -2,13 +2,19 @@ #define LEDHANDLER_H #include "Config.h" +#include +// Grundfarben per Name void setLEDColor(uint8_t r, uint8_t g, uint8_t b); void turnOffLED(); void turnOnLED(); void setupRGBLED(); -void turnOnBlueLED(); -void turnOnRedLEDFlash(); void ledTask(void *parameter); -#endif \ No newline at end of file +// (optional) Status-Farben bequem setzen +enum class StaticColor : uint8_t { + RED, GREEN, BLUE, YELLOW, MAGENTA, CYAN, WHITE, OFF +}; +void setStaticColor(StaticColor color); + +#endif diff --git a/frontend-nextjs/.env b/frontend-nextjs/.env new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/frontend-nextjs/.env @@ -0,0 +1 @@ + diff --git a/frontend-nextjs/.env.example b/frontend-nextjs/.env.example deleted file mode 100644 index 6220bbff..00000000 --- a/frontend-nextjs/.env.example +++ /dev/null @@ -1,22 +0,0 @@ -# If you want to skip device registration, set this to True. Set to False in production. -NEXT_PUBLIC_SKIP_DEVICE_REGISTRATION=True - -# Update these with your Supabase details from your project settings > API -# https://app.supabase.com/project/_/settings/api -NEXT_PUBLIC_SUPABASE_URL=http://127.0.0.1:54321 -NEXT_PUBLIC_SUPABASE_ANON_KEY= -JWT_SECRET_KEY=super-secret-jwt-token-with-at-least-32-characters-long - -# (Optional) Encryption key for E2E encryption of API keys -# You can generate a random key with `openssl rand -base64 32` -ENCRYPTION_KEY= - -# OpenAI API key -OPENAI_API_KEY= - -# NEXT_PUBLIC_SUPABASE_URL=http://localhost:54321 -GOOGLE_OAUTH=True - -# Stripe -STRIPE_SECRET_KEY= -NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=