Allow skipping WiFi setup

This commit is contained in:
2025-09-15 22:26:22 +02:00
parent a90d6f2188
commit d2bf95d944
4 changed files with 122 additions and 18 deletions

6
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,6 @@
{
"files.associations": {
"functional": "cpp",
"cmath": "cpp"
}
}

89
src/SmartCube/cubeDemo.h Normal file
View File

@@ -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;
}
}

View File

@@ -164,17 +164,21 @@ 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.drawLine(0, 50, 127, 50, WHITE);
display.setCursor(3, 54);
display.println("Press button to skip");
display.display();
server.reset(new ESP8266WebServer(80));
@@ -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);

View File

@@ -1,9 +1,10 @@
#include "example_config.h" // Include the configuration header file
#include <Arduino.h> // Include the core Arduino library
#include <Adafruit_SSD1306.h> // 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 <Arduino.h> // Include the core Arduino library
#include <Adafruit_SSD1306.h> // 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
}