Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions src/leds.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int currentBlue = 0;
int currentWarm = 0;
int currentCold = 0;

unsigned long tempms = 0;
unsigned long lastUpdatems = 0;
unsigned long oldms = 0;

COLOR hex2rgb(String hex, short ww_value = 0, short cw_value = 0) {
Expand Down Expand Up @@ -135,7 +135,10 @@ void RGBCycle() {
if(printerConfig.discoMode_update){
printerConfig.discoMode_update = false;
if (printerConfig.debugingchange){
Serial.println(F("RGB Mode, turning LEDs... w-i-l-d!"));
Serial.print(F("["));
Serial.print(millis());
Serial.print(F("]"));
Serial.println(F(" ** RGB Cycle Mode **"));
};
}

Expand Down Expand Up @@ -205,12 +208,15 @@ void updateleds(){
tweenToColor(0,0,0,255,255); //WHITE
printerConfig.maintMode_update = false;
printLogs("Maintenance Mode", 0,0,0,255,255);
Serial.println(F("(Expect MQTT connection to drop and need reconnecting after exiting maintenance mode)"));
Serial.print(F("["));
Serial.print(millis());
Serial.print(F("]"));
Serial.println(F(" ** Maintenance Mode **"));
return;
}

//Use LED to show WIFI Strength (enabled via Setup Webpage, priortised over Custom TEST color)
if (printerConfig.debugwifi == true && !printerConfig.maintMode){
//Use LED to show WIFI Strength (enabled via Setup Webpage)
if (printerConfig.debugwifi){
//<=-50 dBm Green, <= -60 dBm LightGreen, <= -70 dBm Yellow, <= -80 dBm Orange, >80 Red
if (WiFi.status() == WL_CONNECTED){
long wifiNow = WiFi.RSSI();
Expand All @@ -232,16 +238,14 @@ void updateleds(){
if (printerConfig.testcolorEnabled && printerConfig.testcolor_update){
tweenToColor(printerConfig.testColor); //Variable Test Color
printLogs("LED Test ON", printerConfig.testColor);
Serial.println(F("(Expect MQTT connection to drop and need reconnecting after exiting test color mode)"));
Serial.print(F("["));
Serial.print(millis());
Serial.print(F("]"));
Serial.println(F(" ** Test Color Mode **"));
printerConfig.testcolor_update = false;
return;
}

if(printerConfig.testcolorEnabled || printerConfig.maintMode || printerConfig.debugwifi){
//Skip trying to set a color as it's in one of the override states
return;
}

//From here the BBLP status sets the colors
if (printerConfig.debuging == true){
Serial.println(F("Updating LEDs"));
Expand All @@ -265,6 +269,10 @@ void updateleds(){
return;
}

if(printerConfig.testcolorEnabled || printerConfig.maintMode || printerConfig.debugwifi || printerConfig.discoMode){
//Skip trying to set a color as it's in one of the override states
return;
}

//TOGGLE LIGHTS via DOOR
//If door is closed twice in 6 seconds, it will flip the state of the lights
Expand Down Expand Up @@ -529,12 +537,15 @@ void setupLeds() {

void ledsloop(){
RGBCycle();
if((millis() - tempms) > 30000 && printerConfig.discoMode) {
if((millis() - lastUpdatems) > 30000 && (printerConfig.maintMode || printerConfig.testcolorEnabled || printerConfig.discoMode || printerConfig.debugwifi)) {
Serial.print(F("["));
Serial.print(millis());
Serial.print(F("]"));
Serial.print(F("RGB Cycle Mode - next update in 30 seconds"));
tempms = millis();
if(printerConfig.maintMode) Serial.println(F(" Maintenance Mode - next update in 30 seconds"));
if(printerConfig.testcolorEnabled) Serial.println(F(" Test Color - next update in 30 seconds"));
if(printerConfig.discoMode) Serial.println(F(" RGB Cycle Mode - next update in 30 seconds"));
if(printerConfig.debugwifi) Serial.println(F(" Wifi Debug Mode - next update in 30 seconds"));
lastUpdatems = millis();
}

// Turn off GREEN if... finished and Door OPENED or CLOSED in last 5 secs AND user wants Finish Indication enabled
Expand Down
33 changes: 4 additions & 29 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void defaultcolors(){
printerConfig.finishColor = hex2rgb("#00FF00"); //Green Finish

printerConfig.stage14Color = hex2rgb("#000000"); //OFF Cleaning Nozzle
printerConfig.stage1Color = hex2rgb("#0000AA"); //OFF Bed Leveling
printerConfig.stage1Color = hex2rgb("#000055"); //OFF Bed Leveling
printerConfig.stage8Color = hex2rgb("#000000"); //OFF Calibrating Extrusion
printerConfig.stage9Color = hex2rgb("#000000"); //OFF Scanning Bed Surface
printerConfig.stage10Color = hex2rgb("#000000"); //OFF First Layer Inspection
Expand All @@ -34,7 +34,6 @@ void defaultcolors(){


}
unsigned long lastUpdatems = 0;

void setup(){
Serial.begin(115200);
Expand All @@ -48,7 +47,7 @@ void setup(){
Serial.println("");
defaultcolors();
setupLeds();
tweenToColor(255,255,255,255,255); //ALL LEDS ON
tweenToColor(100,100,100,100,100); //ALL LEDS ON
Serial.println(F(""));
delay(1000);

Expand All @@ -63,7 +62,7 @@ void setup(){

if (strlen(globalVariables.SSID) == 0 || strlen(globalVariables.APPW) == 0) {
Serial.println(F("SSID or password is missing. Please configure both by going to: https://dutchdevelop.com/blled-configuration-setup/"));
tweenToColor(255,0,255,0,0); //PINK
tweenToColor(100,0,100,0,0); //PINK
return;
}

Expand Down Expand Up @@ -92,31 +91,7 @@ void setup(){

void loop(){
serialLoop();
if(printerConfig.maintMode){
//Doesn't require monitoring of Wifi or MQTT if LEDs only need to be ON
webserverloop();
if(printerConfig.maintMode_update) updateleds();
if((millis() - lastUpdatems) > 30000) {
Serial.print(F("["));
Serial.print(millis());
Serial.print(F("]"));
Serial.println(F(" Maintenance Mode (no MQTT updates) - next update in 30 seconds"));
lastUpdatems = millis();
}
}
else if (printerConfig.testcolorEnabled){
//Doesn't require monitoring of Wifi or MQTT if LEDs set to a custom color
webserverloop();
if(printerConfig.testcolor_update) updateleds();
if((millis() - lastUpdatems) > 30000) {
Serial.print(F("["));
Serial.print(millis());
Serial.print(F("]"));
Serial.println(F(" Test Color (no MQTT updates) - next update in 30 seconds"));
lastUpdatems = millis();
}
}
else if (globalVariables.started){
if (globalVariables.started){
mqttloop();
webserverloop();
ledsloop();
Expand Down
14 changes: 12 additions & 2 deletions src/mqttmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ void ParseCallback(char *topic, byte *payload, unsigned int length){
Serial.println();
}

if(printerConfig.mqttdebug && (printerConfig.maintMode || printerConfig.testcolorEnabled || printerConfig.discoMode || printerConfig.debugwifi)) {
Serial.print(F("MQTT Message Ignored while in "));
if (printerConfig.maintMode) Serial.print(F("Maintenance"));
if (printerConfig.testcolorEnabled) Serial.print(F("Test Color"));
if (printerConfig.discoMode) Serial.print(F("RGB Cycle"));
if (printerConfig.debugwifi) Serial.print(F("Wifi Debug"));
Serial.println(F(" mode"));
return;
}

//Check for Door Status
if (messageobject["print"].containsKey("home_flag")){
//https://github.com/greghesp/ha-bambulab/blob/main/custom_components/bambu_lab/pybambu/const.py#L324
Expand Down Expand Up @@ -168,7 +178,7 @@ void ParseCallback(char *topic, byte *payload, unsigned int length){
}

//Check BBLP GCode State
if (messageobject["print"].containsKey("gcode_state") && ((millis() - lastMQTTupdate) > 2000)){
if (messageobject["print"].containsKey("gcode_state") && ((millis() - lastMQTTupdate) > 3000)){
String mqttgcodeState = messageobject["print"]["gcode_state"].as<String>();

if(mqttgcodeState =="RUNNING" || mqttgcodeState =="PAUSE"){
Expand Down Expand Up @@ -205,7 +215,7 @@ void ParseCallback(char *topic, byte *payload, unsigned int length){
}

//Added a delay so the slower MQTT status message doesn't reverse the "system" commands
if (messageobject["print"].containsKey("lights_report") && ((millis() - lastMQTTupdate) > 2000)) {
if (messageobject["print"].containsKey("lights_report") && ((millis() - lastMQTTupdate) > 3000)) {
JsonArray lightsReport = messageobject["print"]["lights_report"];
for (JsonObject light : lightsReport) {
if (light["node"] == "chamber_light") {
Expand Down
4 changes: 2 additions & 2 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern "C"
typedef struct GlobalVariablesStruct{
char SSID[32];
char APPW[63];
String FWVersion = "Stable 26.3.24";
String FWVersion = "Experimental 27.3.24";
String Host = "BLLED";
bool started = false;
} GlobalVariables;
Expand All @@ -62,7 +62,7 @@ extern "C"
char serialNumber[16]; //BBLP Serial Number - used for MQTT reports

char BSSID[18]; //Nominated AP to connect to (Useful if multiple accesspoints with same name)
int brightness = 100; //Brightness of LEDS
int brightness = 20; //Brightness of LEDS - Default to 20% in case user use LED's that draw too much power for their PS
bool rescanWiFiNetwork = false; //Scans available WiFi networks for strongest signal
// LED Behaviour (Choose One)
bool maintMode = false; //White lights on, even if printer is unpowered
Expand Down
10 changes: 2 additions & 8 deletions src/wifi-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,8 @@ bool connectToWifi(){
switch (status)
{
case WL_CONNECTED:
Serial.print(F("Wifi Status: "));
Serial.println(wl_status_to_string(status));
break;
case WL_IDLE_STATUS:
case WL_CONNECT_FAILED:
Serial.print(F("Wifi Status: "));
Serial.println(wl_status_to_string(status));
break;
Expand All @@ -118,14 +116,10 @@ bool connectToWifi(){
Serial.println(wl_status_to_string(status));
Serial.println(F("Bad WiFi credentials"));
return false;
case WL_CONNECT_FAILED:
Serial.print(F("Wifi Status: "));
Serial.println(wl_status_to_string(status));
break;
case WL_DISCONNECTED:
Serial.print(F("Wifi Status: "));
Serial.println(wl_status_to_string(status));
Serial.print(F("Disconnected. (Check low RSSI)"));
Serial.println(F("Disconnected. (Check low RSSI)"));
return false;
default:
Serial.print(F("Uncaught Status - Wifi Status: "));
Expand Down
Loading