UI Code
This commit is contained in:
parent
1324cc6e13
commit
726194ca61
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
.pio
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/ipch
|
10
.vscode/extensions.json
vendored
Normal file
10
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
|
// for the documentation about the extensions.json format
|
||||||
|
"recommendations": [
|
||||||
|
"platformio.platformio-ide"
|
||||||
|
],
|
||||||
|
"unwantedRecommendations": [
|
||||||
|
"ms-vscode.cpptools-extension-pack"
|
||||||
|
]
|
||||||
|
}
|
39
include/README
Normal file
39
include/README
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
|
||||||
|
This directory is intended for project header files.
|
||||||
|
|
||||||
|
A header file is a file containing C declarations and macro definitions
|
||||||
|
to be shared between several project source files. You request the use of a
|
||||||
|
header file in your project source file (C, C++, etc) located in `src` folder
|
||||||
|
by including it, with the C preprocessing directive `#include'.
|
||||||
|
|
||||||
|
```src/main.c
|
||||||
|
|
||||||
|
#include "header.h"
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Including a header file produces the same results as copying the header file
|
||||||
|
into each source file that needs it. Such copying would be time-consuming
|
||||||
|
and error-prone. With a header file, the related declarations appear
|
||||||
|
in only one place. If they need to be changed, they can be changed in one
|
||||||
|
place, and programs that include the header file will automatically use the
|
||||||
|
new version when next recompiled. The header file eliminates the labor of
|
||||||
|
finding and changing all the copies as well as the risk that a failure to
|
||||||
|
find one copy will result in inconsistencies within a program.
|
||||||
|
|
||||||
|
In C, the usual convention is to give header files names that end with `.h'.
|
||||||
|
It is most portable to use only letters, digits, dashes, and underscores in
|
||||||
|
header file names, and at most one dot.
|
||||||
|
|
||||||
|
Read more about using header files in official GCC documentation:
|
||||||
|
|
||||||
|
* Include Syntax
|
||||||
|
* Include Operation
|
||||||
|
* Once-Only Headers
|
||||||
|
* Computed Includes
|
||||||
|
|
||||||
|
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
46
lib/README
Normal file
46
lib/README
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
This directory is intended for project specific (private) libraries.
|
||||||
|
PlatformIO will compile them to static libraries and link into executable file.
|
||||||
|
|
||||||
|
The source code of each library should be placed in a an own separate directory
|
||||||
|
("lib/your_library_name/[here are source files]").
|
||||||
|
|
||||||
|
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||||
|
|
||||||
|
|--lib
|
||||||
|
| |
|
||||||
|
| |--Bar
|
||||||
|
| | |--docs
|
||||||
|
| | |--examples
|
||||||
|
| | |--src
|
||||||
|
| | |- Bar.c
|
||||||
|
| | |- Bar.h
|
||||||
|
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||||
|
| |
|
||||||
|
| |--Foo
|
||||||
|
| | |- Foo.c
|
||||||
|
| | |- Foo.h
|
||||||
|
| |
|
||||||
|
| |- README --> THIS FILE
|
||||||
|
|
|
||||||
|
|- platformio.ini
|
||||||
|
|--src
|
||||||
|
|- main.c
|
||||||
|
|
||||||
|
and a contents of `src/main.c`:
|
||||||
|
```
|
||||||
|
#include <Foo.h>
|
||||||
|
#include <Bar.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
PlatformIO Library Dependency Finder will find automatically dependent
|
||||||
|
libraries scanning project source files.
|
||||||
|
|
||||||
|
More information about PlatformIO Library Dependency Finder
|
||||||
|
- https://docs.platformio.org/page/librarymanager/ldf.html
|
20
platformio.ini
Normal file
20
platformio.ini
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[env:d1_mini]
|
||||||
|
platform = espressif8266
|
||||||
|
board = d1_mini
|
||||||
|
framework = arduino
|
||||||
|
upload_port = COM3
|
||||||
|
monitor_speed = 115200
|
||||||
|
lib_deps =
|
||||||
|
olikraus/U8g2@^2.34.18
|
||||||
|
links2004/WebSockets@^2.4.1
|
||||||
|
tzapu/WiFiManager@^0.16.0
|
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);
|
||||||
|
}
|
11
test/README
Normal file
11
test/README
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
This directory is intended for PlatformIO Test Runner and project tests.
|
||||||
|
|
||||||
|
Unit Testing is a software testing method by which individual units of
|
||||||
|
source code, sets of one or more MCU program modules together with associated
|
||||||
|
control data, usage procedures, and operating procedures, are tested to
|
||||||
|
determine whether they are fit for use. Unit testing finds problems early
|
||||||
|
in the development cycle.
|
||||||
|
|
||||||
|
More information about PlatformIO Unit Testing:
|
||||||
|
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
Loading…
Reference in New Issue
Block a user