diff --git a/.gitignore b/.gitignore index 89cc49c..5f2b65d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .vscode/c_cpp_properties.json .vscode/launch.json .vscode/ipch +src/config.h diff --git a/platformio.ini b/platformio.ini index 9cdde03..abc241f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -17,3 +17,5 @@ lib_deps = adafruit/Adafruit GFX Library@^1.11.11 adafruit/Adafruit SSD1306@^2.5.13 chunkysteveo/OctoPrintAPI@^1.1.6 + moononournation/GFX Library for Arduino@^1.4.9 +monitor_speed = 115200 diff --git a/src/config.h b/src/example_config.h similarity index 71% rename from src/config.h rename to src/example_config.h index f125092..2875c4a 100644 --- a/src/config.h +++ b/src/example_config.h @@ -12,4 +12,10 @@ #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 -#define FRAMERATE 8 \ No newline at end of file +#define FRAMERATE 8 + +// Buttons and buzzer +#define PIN_BTN_L 12 // D6 +#define PIN_BTN_M 13 // D7 +#define PIN_BTN_R 15 // D8 +#define PIN_BUZZER 0 // D3 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 59686cb..4c1294f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,73 @@ - +#include +#include +#include +#include +#include #include "config.h" -#include "setup.h" +// Initialize display with defined dimensions and reset pin +Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); + +void setup() { + Serial.begin(115200); + Serial.println("Power On"); + + // Initialize the SSD1306 display + if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Adjust I2C address if needed + Serial.println("SSD1306 allocation failed"); + for(;;); // Don't proceed, loop forever + } + + // Rotate the display 180 degrees + display.setRotation(2); + + // Clear the display buffer + display.clearDisplay(); + + // Display initial message + display.setTextSize(1); + display.setTextColor(WHITE); + display.setCursor(0, 0); + display.print("Connecting to WiFi..."); + display.display(); + + // Connect to WiFi + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); + Serial.print("Connecting to WiFi"); + + int attemptCount = 0; + while (WiFi.status() != WL_CONNECTED && attemptCount < 20) { // Timeout after 20 attempts + delay(500); + Serial.print("."); + display.print("."); + display.display(); + attemptCount++; + } + + // Check if connected + if (WiFi.status() == WL_CONNECTED) { + Serial.println("\nConnected to WiFi!"); + Serial.print("IP Address: "); + Serial.println(WiFi.localIP()); + + // Display connection success and IP address + display.clearDisplay(); + display.setCursor(0, 0); + display.print("WiFi Connected!"); + display.setCursor(0, 10); + display.print("IP: "); + display.print(WiFi.localIP()); + display.display(); + } else { + Serial.println("\nFailed to connect to WiFi."); + display.clearDisplay(); + display.setCursor(0, 0); + display.print("WiFi Connection"); + display.setCursor(0, 10); + display.print("Failed"); + display.display(); + } +} void loop() { - // put your main code here, to run repeatedly: + // Nothing to do here for now } diff --git a/src/setup.h b/src/setup.h deleted file mode 100644 index b73a618..0000000 --- a/src/setup.h +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -String printerOperational; -String printerPaused; -String printerPrinting; -String printerReady; -String printerText; -String printerHotend; -String printerTarget; -String payload; - -WiFiClient client; - -OctoprintApi api(client, ip, octoprint_httpPort, octoprint_apikey); - -void setup() { - -// Connect to wifi - Serial.begin(115200); - Serial.println("Connecting to WiFi..."); - Serial.print("SSID: "); - Serial.println(WIFI_SSID); - - Serial.print("OctoPrint URL: "); - Serial.println(OCTOPRINT_URL); - Serial.print("OctoPrint API Key: "); - Serial.println(OCTOPRINT_API_KEY); -} \ No newline at end of file