From d2bf95d9444b2177ab15237fbeb5526711d000f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomislav=20Kopi=C4=87?= Date: Mon, 15 Sep 2025 22:26:22 +0200 Subject: [PATCH] Allow skipping WiFi setup --- .vscode/settings.json | 6 +++ src/SmartCube/cubeDemo.h | 89 +++++++++++++++++++++++++++++++++ src/SmartCube/cubeWifiManager.h | 29 +++++++---- src/main.cpp | 16 +++--- 4 files changed, 122 insertions(+), 18 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 src/SmartCube/cubeDemo.h diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..1ac3c2a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "functional": "cpp", + "cmath": "cpp" + } +} \ No newline at end of file diff --git a/src/SmartCube/cubeDemo.h b/src/SmartCube/cubeDemo.h new file mode 100644 index 0000000..ba88e17 --- /dev/null +++ b/src/SmartCube/cubeDemo.h @@ -0,0 +1,89 @@ +void interactiveCubeDemo() { + const int cx = SCREEN_WIDTH / 2; + const int cy = SCREEN_HEIGHT / 2; + const int size = 15; // small cube + float angle = 0; + float speed = 0.05; + bool rotating = true; + bool showVersion = false; + + bool lastMiddleState = LOW; // Track previous middle button state + + while (true) { + display.clearDisplay(); + + // Read buttons + bool leftPressed = digitalRead(PIN_BTN_L) == HIGH; + bool rightPressed = digitalRead(PIN_BTN_R) == HIGH; + bool middlePressed = digitalRead(PIN_BTN_M) == HIGH; + + // Button actions + if (leftPressed) { + speed = -0.05; + beep(1000); + } + if (rightPressed) { + speed = 0.05; + beep(1000); + } + // Detect middle button press event + if (middlePressed && !lastMiddleState) { + rotating = !rotating; // toggle rotation + showVersion = !rotating; // show image if stopped + beep(1000); + } + lastMiddleState = middlePressed; // update previous state + + // Draw either image or cube + if (showVersion) { + display.clearDisplay(); + display.setTextSize(2); + display.setCursor(10, 0); + display.println("SmartCube"); + display.setTextSize(1); + display.setCursor(40, 18); + display.println("version"); + display.setCursor(52, 28); + display.println("1.1"); + display.drawLine(0, 40, SCREEN_WIDTH, 40, WHITE); + display.setCursor(0, 44); + display.println("by besna_shnita"); + display.setCursor(18, 55); + display.println("tomislav@kopic.hr"); + } else { + if (rotating) angle += speed; + + float cosA = cos(angle); + float sinA = sin(angle); + + int x[8], y[8]; + int vx[8] = {-size, size, size, -size, -size, size, size, -size}; + int vy[8] = {-size, -size, size, size, -size, -size, size, size}; + int vz[8] = {-size, -size, -size, -size, size, size, size, size}; + + for (int i = 0; i < 8; i++) { + float x3d = vx[i] * cosA - vz[i] * sinA; + float z3d = vx[i] * sinA + vz[i] * cosA; + float y3d = vy[i]; + float factor = 50.0 / (z3d + 50.0); + x[i] = cx + x3d * factor; + y[i] = cy + y3d * factor; + } + + int edges[12][2] = { + {0,1},{1,2},{2,3},{3,0}, + {4,5},{5,6},{6,7},{7,4}, + {0,4},{1,5},{2,6},{3,7} + }; + for (int i = 0; i < 12; i++) + display.drawLine(x[edges[i][0]], y[edges[i][0]], + x[edges[i][1]], y[edges[i][1]], WHITE); + } + + display.display(); + delay(50); + + // Exit demo if all buttons pressed + if (leftPressed && middlePressed && rightPressed) break; + } +} diff --git a/src/SmartCube/cubeWifiManager.h b/src/SmartCube/cubeWifiManager.h index a7132a2..2278632 100644 --- a/src/SmartCube/cubeWifiManager.h +++ b/src/SmartCube/cubeWifiManager.h @@ -164,18 +164,22 @@ void cubeWifiManager::createAP() { WiFi.softAP(_ssid.c_str(), _pass.c_str(), 1, _hidden); display.clearDisplay(); - display.setCursor(0, 0); - display.println("AccessPoint created"); - display.setCursor(0, 14); - display.println("SSID:"); - display.setCursor(0, 24); + display.setCursor(10, 0); + display.println("Access Point Ready"); + display.drawLine(0, 10, 127, 10, WHITE); + display.setCursor(0, 15); + display.print("SSID: "); display.println(_ssid.c_str()); - display.setCursor(0, 40); + display.setCursor(0, 28); display.println("Config portal:"); - display.setCursor(0, 50); + display.setCursor(0, 38); display.print("http://"); display.println(WiFi.softAPIP().toString()); - display.display(); + display.drawLine(0, 50, 127, 50, WHITE); + display.setCursor(3, 54); + display.println("Press button to skip"); + + display.display(); server.reset(new ESP8266WebServer(80)); DNSServer dnsServer; @@ -188,22 +192,25 @@ void cubeWifiManager::createAP() { server->begin(); - // 🟢 Modified loop: exit if button is pressed while (true) { dnsServer.processNextRequest(); server->handleClient(); delay(10); - if (digitalRead(PIN_BTN_M) == HIGH) { // adjust pin to your button + if (digitalRead(PIN_BTN_L) == HIGH || digitalRead(PIN_BTN_M) == HIGH || digitalRead(PIN_BTN_R) == HIGH) { + + tone(PIN_BUZZER, 1000, 100); + display.clearDisplay(); display.setCursor(0, 0); - display.println("Exiting AP mode..."); + display.println("Skipping WiFi setup..."); display.display(); delay(500); break; // exit AP mode loop } } + // Clean up AP mode and return server->stop(); WiFi.softAPdisconnect(true); diff --git a/src/main.cpp b/src/main.cpp index 15ce0ab..fa5059a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,9 +1,10 @@ -#include "example_config.h" // Include the configuration header file -#include // Include the core Arduino library -#include // Include the Adafruit library for the SSD1306 OLED display -#include "SmartCube/cubeSound.h" // Include custom header for sound functions -#include "SmartCube/cubeButtons.h" // Include custom header for button handling functions +#include "example_config.h" // Include the configuration header file +#include // Include the core Arduino library +#include // Include the Adafruit library for the SSD1306 OLED display +#include "SmartCube/cubeSound.h" // Include custom header for sound functions +#include "SmartCube/cubeButtons.h" // Include custom header for button handling functions #include "SmartCube/cubeWifiManager.h" // Include custom header for managing WiFi connections +#include "SmartCube/cubeDemo.h" // Remove this if not using demo functions // Initialize the OLED display with specified width, height, and reset pin Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); @@ -44,5 +45,6 @@ void setup() { } void loop() { - cubeButtonHandler(); // Continuously check and handle button actions -} + interactiveCubeDemo(); // Run the demo screen animation + cubeButtonHandler(); // Continuously check and handle button actions +} \ No newline at end of file