Skip to content

Commit

Permalink
✨ 1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
fiber-punk committed May 17, 2022
1 parent 99ba085 commit be904f9
Show file tree
Hide file tree
Showing 6 changed files with 351 additions and 124 deletions.
Binary file modified Images/1-3-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 17 additions & 14 deletions WifiNode/nodeconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ AsyncWebServer server(88);
AsyncEventSource events("/events");

HTTPClient http_client;
WiFiClient socket_client;
AsyncClient socket_client;
CRC8 gcrc;

File uploadFile;
Expand All @@ -19,11 +19,11 @@ String current_layers = "";
String current_temp = "";
String current_bed_temp = "";
String pc_ipaddress = "";
String current_file="";

OP_STATUS g_status=P_IDEL;
ERROR_CODE g_error=NORMAL;


bool recv_ok = false;
bool recvl_ok = false;
bool hasSD = false;
Expand All @@ -32,15 +32,18 @@ bool paused_for_user = false;
bool paused_for_filament = false;

//printer sd type: 0==spi 1==sdio
uint8_t printer_sd_type = 1;
uint8_t printer_sd_type = 0;

//last power status 0==idle 1==printing
uint8_t last_power_status = 0;
uint8_t print_start_flag = 0;
uint8_t reset_sd_559 = 0;
unsigned char current_usb_status = 0;
unsigned char pre_usb_status = 0;



uint8_t cmd_length=0;


void sendCaptureImage(String);
void sendHttpMsg(String);
void writeLog(String);

Expand All @@ -52,10 +55,9 @@ void writeLog(String log_txt)
sendHttpMsg(log_txt);
}
}

void sendHttpMsg(String url)
void sendCaptureImage(String url)
{
#if 0
#if 1
String http_url = "http://"+pc_ipaddress+":8002/"+"api/"+url;
http_client.begin(http_url);
int httpRsponCode = http_client.POST(http_url);
Expand All @@ -67,12 +69,13 @@ void sendHttpMsg(String url)
else
{
//send failed

}
#endif
if(socket_client.connected())
socket_client.print(url);

#endif
}
void sendHttpMsg(String url)
{
if(socket_client.connected())
socket_client.write(url.c_str());
}
NodeConfig::NodeConfig()
{
Expand Down
19 changes: 13 additions & 6 deletions WifiNode/nodeconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "crc8.h"
#include "FiberPunk_SSD1306.h"

#define VERSION "2022-3-27-2002"
#define VERSION "2022-5-9-2004"
#define DBG_OUTPUT_PORT Serial
#define PRINTER_PORT Serial
#define RED_LED 26
Expand All @@ -40,8 +40,8 @@ enum OP_STATUS
PRINTING=1,
PAUSE=2,
RECOVER=3,
CANCEL=4,
HEATING=5,
CANCLE=4,
HEEATING=5,
};

enum ERROR_CODE
Expand All @@ -53,7 +53,7 @@ enum ERROR_CODE
extern AsyncWebServer server;
extern AsyncEventSource events;
// extern HTTPClient http_client;
extern WiFiClient socket_client;
extern AsyncClient socket_client;
extern CRC8 gcrc;

extern File uploadFile;
Expand All @@ -67,7 +67,7 @@ extern String current_layers;
extern String current_temp;
extern String current_bed_temp;
extern String pc_ipaddress;

extern String current_file;
extern OP_STATUS g_status;
extern ERROR_CODE g_error;

Expand All @@ -83,14 +83,21 @@ extern bool paused_for_user;
extern bool paused_for_filament;

extern uint8_t printer_sd_type;
extern uint8_t last_power_status;
extern uint8_t cmd_length;
extern uint8_t reset_sd_559;
extern uint8_t print_start_flag;

extern unsigned char current_usb_status;
extern unsigned char pre_usb_status;


extern void sendCaptureImage(String);
extern void sendHttpMsg(String);
extern void writeLog(String);
extern void saveCurrentPrintStatus(String status_str);
extern String getValue(String data, char separator, int index);
extern void Write_String(int a,int b,String str);
extern uint8_t lastPowerOffPrinting();
class NodeConfig
{
public:
Expand Down
69 changes: 60 additions & 9 deletions WifiNode/printerprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,48 @@
#include "nodeconfig.h"
#include "soc/rtc_wdt.h"

extern void cancelOrFinishPrint();
extern void cancleOrFinishPrint();
void printLoop(void * parameter);


void setWifiConfigByPort(String config_str)
{
String cmd_str = config_str.substring(2);
String cmd_name = getValue(cmd_str, ':', 0);
String cmd_value = getValue(cmd_str, ':', 1);
if(cmd_name=="SSID")
{
cf_ssid = cmd_value.substring(0,cmd_value.length()-1);
Serial.print("SSID");
}
else if(cmd_name=="PASS")
{
cf_password = cmd_value.substring(0,cmd_value.length()-1);
Serial.print("PASS");
}
else if(cmd_name=="NAME")
{
cf_node_name = cmd_value.substring(0,cmd_value.length()-1);
Serial.print("NAME");
}
else if(cmd_name=="SAVE")
{
Write_String(1,30,cf_ssid);
delay(100);
Write_String(5,60,cf_password);
delay(100);
Write_String(9,90,cf_node_name);
delay(100);
Serial.print("SAVE");
}
else
{
Serial.print("ERROR");
}


}

String inData="";//Gcode Command return value
void readPrinterBack()
{
Expand All @@ -27,10 +65,13 @@ void readPrinterBack()
{
writeLog(cf_node_name+":"+inData);
// writeLog(inData);

if(inData.startsWith("&&"))
{
setWifiConfigByPort(inData);
}
if(inData.indexOf("setusb")!=-1)
{
if (g_status!=PRINTING)
// if (g_status!=PRINTING)
rst_usb = true;
}
//check temp
Expand Down Expand Up @@ -74,20 +115,21 @@ void readPrinterBack()
{
current_layers = inData;
}
if(inData.indexOf("X:")!=-1)
if(inData.indexOf("@Capture")!=-1)
{
String capture_cmd = "Camera-"+cf_node_name+"-TakeImg";
sendHttpMsg(capture_cmd);
Serial2.print("#%");
String capture_cmd = cf_node_name+"@TakeImg";
sendCaptureImage(capture_cmd);
}

if(inData.indexOf("Finish")!=-1)
{
cancelOrFinishPrint();
cancleOrFinishPrint();

}
else if(inData.indexOf("Done")!=-1)
{
cancelOrFinishPrint();
cancleOrFinishPrint();

}
else if(inData.indexOf("resumed")!=-1)
Expand All @@ -97,9 +139,18 @@ void readPrinterBack()

if(inData.indexOf("No media")!=-1)
{
cancelOrFinishPrint();
cancleOrFinishPrint();

}

if(inData.indexOf("no file")!=-1)
{
cancleOrFinishPrint();
print_start_flag = 1;
}

//Current file: (no file)


}
inData="";
Expand Down
Loading

0 comments on commit be904f9

Please sign in to comment.