Fix up segmentation fault
This commit is contained in:
parent
eb5ead3b22
commit
d031d3a4c2
@ -1,8 +1,8 @@
|
||||
extern Adafruit_SSD1306 display; // Reference to the OLED display object
|
||||
bool is_display_off = false; // State variable to track display on/off status
|
||||
|
||||
int buttonDebounceDelay = 50; // Debounce delay in milliseconds
|
||||
int buttonLongPressDelay = 2000; // Long press threshold in milliseconds
|
||||
unsigned long buttonDebounceDelay = 50; // Debounce delay in milliseconds
|
||||
unsigned long buttonLongPressDelay = 2000; // Long press threshold in milliseconds
|
||||
|
||||
void cubeButtonHandler() {
|
||||
unsigned long currentMillis = millis(); // Get the current time in milliseconds
|
||||
|
@ -12,23 +12,27 @@ static const String configFile = "/cubeWifiManager";
|
||||
|
||||
// Timeout for WiFi connection attempts
|
||||
static const unsigned long connectionTimeout = 15000; // 15 seconds
|
||||
|
||||
struct cubeWifiManager {
|
||||
class cubeWifiManager {
|
||||
public:
|
||||
// Constructors
|
||||
cubeWifiManager(Adafruit_SSD1306& display);
|
||||
cubeWifiManager(String ssid, String pass, bool hidden, Adafruit_SSD1306& display);
|
||||
|
||||
// Public methods
|
||||
bool start();
|
||||
void reset();
|
||||
void addSsid(String ssid, String password);
|
||||
void removeSsid(String ssid, String password);
|
||||
|
||||
private:
|
||||
// Private members
|
||||
Adafruit_SSD1306& display;
|
||||
std::unique_ptr<ESP8266WebServer> server;
|
||||
std::map<String, String> _ssids;
|
||||
String _ssid, _pass;
|
||||
bool _hidden;
|
||||
|
||||
// Private methods
|
||||
void init(String ssid, String pass, bool hidden);
|
||||
bool tryConnectToSsid(const char* ssid, const char* pass);
|
||||
bool tryConnect();
|
||||
|
30
src/main.cpp
30
src/main.cpp
@ -1,6 +1,6 @@
|
||||
#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 "example_config.h" // Include the configuration header file (presumably contains constants and settings)
|
||||
#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
|
||||
@ -11,7 +11,35 @@ Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||
// Initialize the WiFi manager, passing the display object for any display output
|
||||
cubeWifiManager cubeWifiManager(display);
|
||||
|
||||
void initSystems() {
|
||||
pinMode(PIN_BTN_L, INPUT);
|
||||
pinMode(PIN_BTN_M, INPUT);
|
||||
pinMode(PIN_BTN_R, INPUT);
|
||||
pinMode(PIN_BUZZER, OUTPUT);
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
Wire.begin(); // Initialize I2C
|
||||
Wire.setClock(400000L); // Set I2C to Fast Mode (400 kHz)
|
||||
display.ssd1306_command(SSD1306_SETCONTRAST);
|
||||
display.ssd1306_command(200); // Value between 0 and 255
|
||||
// Initialize the SSD1306 display
|
||||
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Adjust I2C address if needed
|
||||
for(;;); // Don't proceed, loop forever
|
||||
}
|
||||
|
||||
// Rotate the display 180 degrees
|
||||
display.setRotation(2);
|
||||
|
||||
// Clear the display buffer
|
||||
display.clearDisplay();
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(WHITE);
|
||||
display.setCursor(0, 0);
|
||||
display.display();
|
||||
}
|
||||
|
||||
void setup() {
|
||||
initSystems();
|
||||
cubeWifiManager.start(); // Start the WiFi manager
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user