UI Code
This commit is contained in:
7
src/config.h
Normal file
7
src/config.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef _CONFIG
|
||||
#define _CONFIG
|
||||
|
||||
#define AP_NAME "Dragon Capsule is best capsule"
|
||||
#define ENABLE_SERIAL true
|
||||
|
||||
#endif
|
155
src/main.cpp
Normal file
155
src/main.cpp
Normal file
@@ -0,0 +1,155 @@
|
||||
// Base Platform Libraries
|
||||
#include <Arduino.h>
|
||||
#include <Hash.h>
|
||||
|
||||
// Display Libraries
|
||||
#include <U8g2lib.h>
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
|
||||
// Wireless Libraries
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <WiFiManager.h>
|
||||
|
||||
// Config
|
||||
#include "config.h"
|
||||
|
||||
U8G2_SSD1309_128X64_NONAME2_1_4W_HW_SPI disp(U8G2_R0, /* cs=*/ 15, /* dc=*/ 2, /* reset=*/ 16);
|
||||
double progress = 0;
|
||||
|
||||
// TODO:
|
||||
// 1. Add WPA2 and connect QR to display
|
||||
// "WIFI:S:"+ssid+";T:WPA;P:"+pass+";;"
|
||||
|
||||
void statusMsg(String msg){
|
||||
disp.firstPage();
|
||||
do {
|
||||
disp.drawUTF8(110, 1, msg.c_str());
|
||||
}while ( disp.nextPage() );
|
||||
}
|
||||
|
||||
void configModeCallback (WiFiManager *myWiFiManager) {
|
||||
Serial.println("Entered config mode");
|
||||
statusMsg("Setup");
|
||||
Serial.println(WiFi.softAPIP());
|
||||
// print the ssid that we should connect to to configure the ESP8266
|
||||
Serial.print("Created config portal AP ");
|
||||
Serial.println(myWiFiManager->getConfigPortalSSID());
|
||||
}
|
||||
|
||||
void drawUI(){
|
||||
disp.drawFrame(2,2,124,20);
|
||||
disp.setFont(u8g2_font_6x12_mf);
|
||||
disp.drawUTF8(100, 57, "%");
|
||||
}
|
||||
|
||||
void drawTime(int xOffset, String label, uint64 time){
|
||||
disp.setFont(u8g2_font_simple1_tf);
|
||||
disp.drawUTF8(xOffset, 25, label.c_str());
|
||||
disp.setFont(u8g2_font_4x6_tf);
|
||||
uint64 hours = time / 3600;
|
||||
uint64 minutes = (time % 3600) / 60;
|
||||
uint64 seconds = (time % 3600) % 60;
|
||||
String timeStr = "";
|
||||
if (hours < 10){
|
||||
timeStr += "0";
|
||||
}
|
||||
timeStr += String(hours);
|
||||
timeStr += ":";
|
||||
if (minutes < 10){
|
||||
timeStr += "0";
|
||||
}
|
||||
timeStr += String(minutes);
|
||||
timeStr += ":";
|
||||
if (seconds < 10){
|
||||
timeStr += "0";
|
||||
}
|
||||
timeStr += String(seconds);
|
||||
disp.drawUTF8(xOffset-10, 25, timeStr.c_str());
|
||||
}
|
||||
|
||||
void drawTemp(int xOffset, String label, int temperature){
|
||||
disp.setFont(u8g2_font_tom_thumb_4x6_t_all);
|
||||
disp.drawUTF8(xOffset, 25, label.c_str());
|
||||
disp.setFont(u8g2_font_luRS08_tf);
|
||||
String temperatureString = "";
|
||||
if (temperature < 100 && temperature >= 10){
|
||||
temperatureString += "0";
|
||||
}else if(temperature < 10){
|
||||
temperatureString += "00";
|
||||
}
|
||||
temperatureString += String(temperature);
|
||||
temperatureString += " C";
|
||||
disp.drawUTF8(xOffset-10, 25, temperatureString.c_str());
|
||||
}
|
||||
|
||||
void drawProgress(){
|
||||
// Progress Bar
|
||||
int mappedProgress = map(progress, 0, 100, 0, 124);
|
||||
disp.drawBox(2, 2, mappedProgress, 20);
|
||||
|
||||
// Percentage Label
|
||||
disp.setFont(u8g2_font_profont29_mf);
|
||||
String progressStr = (((int)progress < 10)?"0":"")+String((int)progress);
|
||||
disp.drawUTF8(100, 25, progressStr.c_str());
|
||||
|
||||
// Hotend Temperature
|
||||
int temperature = (int)(progress*10); // TODO: Replace with actual temperature
|
||||
drawTemp(90, "Hotend", temperature);
|
||||
|
||||
// Build Plate Temperature
|
||||
drawTemp(70, "Bed", temperature);
|
||||
|
||||
// Time Elapsed
|
||||
drawTime(40, "Elapsed", progress*10); // TODO: Replace with actual time
|
||||
|
||||
// Time Remaining
|
||||
drawTime(20, "Left", progress*10); // TODO: Replace with actual time
|
||||
}
|
||||
|
||||
void setup(void) {
|
||||
// Initialize Serial
|
||||
Serial.begin(115200);
|
||||
|
||||
// Initialize Display
|
||||
disp.begin();
|
||||
// disp.setDisplayRotation(U8G2_R1); // Half of the display is broken with this
|
||||
disp.setFont(u8g2_font_6x10_tf);
|
||||
disp.setFontDirection(1);
|
||||
// Serial.println(disp.getDisplayWidth());
|
||||
statusMsg("Connecting");
|
||||
|
||||
|
||||
// Initialilze Wireless
|
||||
WiFiManager wifiManager;
|
||||
wifiManager.setAPCallback(configModeCallback);
|
||||
wifiManager.setTimeout(180);
|
||||
if(!wifiManager.autoConnect(AP_NAME)) {
|
||||
Serial.println("failed to connect and hit timeout");
|
||||
//reset and try again, or maybe put it to deep sleep
|
||||
ESP.reset();
|
||||
delay(1000);
|
||||
}
|
||||
//if you get here you have connected to the WiFi
|
||||
Serial.println("connected to " + WiFi.SSID() + " : " + WiFi.localIP().toString());
|
||||
}
|
||||
|
||||
|
||||
void loop(void) {
|
||||
|
||||
disp.firstPage();
|
||||
do {
|
||||
disp.setDrawColor(1);
|
||||
drawUI();
|
||||
drawProgress();
|
||||
}while ( disp.nextPage() );
|
||||
|
||||
// TODO: Replace this with data fetch
|
||||
progress += 0.1;
|
||||
if(progress > 100){
|
||||
progress = 0;
|
||||
}
|
||||
|
||||
delay(150);
|
||||
}
|
Reference in New Issue
Block a user