Commit 9efab768 authored by MagoKimbra's avatar MagoKimbra

Add M35 Gcode

M35 download firmware nextion from SD
parent d0e26714
......@@ -43,6 +43,7 @@
* M30 - Delete file from SD (M30 filename.g)
* M31 - Output time since last M109 or SD card start to serial
* M32 - Make directory
* M35 - Download Firmware Nextion from SD
* M42 - Change pin status via gcode Use M42 Px Sy to set pin x to value y, when omitting Px the onboard led will be used.
* M49 - Z probe repetability test
* M80 - Turn on Power Supply
......
### Version 4.2.8
* Add board folder with files of various board containing the pins
* Add End time on Graphics display when SD print
* Add M35 for download firmware nextion from SD
* Rewrite macros
* Fix M109 so it won't wait for cooling
* Clear code
......
......@@ -79,6 +79,7 @@
* M30 - Delete file from SD (M30 filename.g)
* M31 - Output time since last M109 or SD card start to serial
* M32 - Make directory
* M35 - Download Firmware Nextion from SD
* M42 - Change pin status via gcode Use M42 Px Sy to set pin x to value y, when omitting Px the onboard led will be used.
* M48 - Measure Z_Probe repeatability. M48 [P # of points] [X position] [Y position] [V_erboseness #] [E_ngage Probe] [L # of legs of travel]
* M70 - Power consumption sensor calibration
......
......@@ -4424,6 +4424,15 @@ inline void gcode_M17() {
card.mount();
}
}
#if ENABLED(NEXTION)
/**
* M35: Download Firmware Nextion
*/
inline void gcode_M35() {
DownloadNewFirmware();
}
#endif
#endif
/**
......@@ -7438,6 +7447,10 @@ void process_next_command() {
gcode_M31(); break;
case 32: // M32 - Make directory
gcode_M32(); break;
#if ENABLED(NEXTION)
case 35: // M35 - Download Firmware Nextion
gcode_M35(); break;
#endif
#endif //SDSUPPORT
case 42: // M42 -Change pin status via gcode
......@@ -7526,7 +7539,7 @@ void process_next_command() {
gcode_M120(); break;
case 121: // M121 Disable endstops
gcode_M121(); break;
case 122: // M121 Disable or enable software endstops
case 122: // M122 Disable or enable software endstops
gcode_M122(); break;
#if ENABLED(BARICUDA)
......
......@@ -70,6 +70,12 @@
#define ORIG_HEATER_BED_PIN 8 // BED
#define ORIG_TEMP_BED_PIN 14 // ANALOG NUMBERING
#if ENABLED(REPRAP_DISCOUNT_SMART_CONTROLLER) || ENABLED(G3D_PANEL)
#define KILL_PIN 41
#else
#define KILL_PIN -1
#endif
#if NUM_SERVOS > 0
#define SERVO0_PIN 11
#if NUM_SERVOS > 1
......
......@@ -70,6 +70,12 @@
#define ORIG_HEATER_BED_PIN -1 // BED
#define ORIG_TEMP_BED_PIN 14 // ANALOG NUMBERING
#if ENABLED(REPRAP_DISCOUNT_SMART_CONTROLLER) || ENABLED(G3D_PANEL)
#define KILL_PIN 41
#else
#define KILL_PIN -1
#endif
#if NUM_SERVOS > 0
#define SERVO0_PIN 11
#if NUM_SERVOS > 1
......
......@@ -70,6 +70,12 @@
#define ORIG_HEATER_BED_PIN 8 // BED
#define ORIG_TEMP_BED_PIN 14 // ANALOG NUMBERING
#if ENABLED(REPRAP_DISCOUNT_SMART_CONTROLLER) || ENABLED(G3D_PANEL)
#define KILL_PIN 41
#else
#define KILL_PIN -1
#endif
#if NUM_SERVOS > 0
#define SERVO0_PIN 11
#if NUM_SERVOS > 1
......
......@@ -70,6 +70,12 @@
#define ORIG_HEATER_BED_PIN -1 // BED
#define ORIG_TEMP_BED_PIN -1 // ANALOG NUMBERING
#if ENABLED(REPRAP_DISCOUNT_SMART_CONTROLLER) || ENABLED(G3D_PANEL)
#define KILL_PIN 41
#else
#define KILL_PIN -1
#endif
#if NUM_SERVOS > 0
#define SERVO0_PIN 11
#if NUM_SERVOS > 1
......
/**
* @file NexDownload.cpp
*
* The implementation of download tft file for nextion.
*
* @author Chen Zengpeng (email:<zengpeng.chen@itead.cc>)
* @date 2016/3/29
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#include "NexDownload.h"
#if ENABLED(SDSUPPORT)
NexDownload::NexDownload(const char *file_name, uint32_t download_baudrate) {
_file_name = file_name;
_download_baudrate = download_baudrate;
}
NexDownload::NexDownload(const String file_Name, uint32_t download_baudrate) {
NexDownload(file_Name.c_str(), download_baudrate);
}
void NexDownload::startDownload(void) {
if (!_checkFile()) {
ECHO_LM(ER, "The file is error");
return;
}
if (_getBaudrate() == 0) {
ECHO_LM(ER, "baudrate error");
return;
}
if (!_setDownloadBaudrate(_download_baudrate)) {
ECHO_LM(ER, "modify baudrate error");
return;
}
if (!_downloadTftFile()) {
ECHO_LM(ER, "download file error");
return;
}
card.closeFile();
ECHO_LM(DB, "download ok");
}
uint16_t NexDownload::_getBaudrate(void) {
uint32_t baudrate_array[7] = {115200, 57600, 38400, 19200, 9600, 4800, 2400};
for (uint8_t i = 0; i < 7; i++) {
if (_searchBaudrate(baudrate_array[i])) {
_baudrate = baudrate_array[i];
break;
}
}
return _baudrate;
}
bool NexDownload::_checkFile(void) {
ECHO_LM(DB, "start _checkFile");
if (!card.selectFile(_file_name)) {
ECHO_LM(ER, "file is not exit");
return 0;
}
_undownloadByte = card.fileSize;
return 1;
}
bool NexDownload::_searchBaudrate(uint32_t baudrate) {
String string = String("");
nexSerial.end();
HAL::delayMilliseconds(100);
nexSerial.begin(baudrate);
this->sendCommand("");
this->sendCommand("connect");
this->recvRetString(string);
if(string.indexOf("comok") != -1)
return 1;
return 0;
}
void NexDownload::sendCommand(const char* cmd) {
while (nexSerial.available())
nexSerial.read();
nexSerial.print(cmd);
nexSerial.write(0xFF);
nexSerial.write(0xFF);
nexSerial.write(0xFF);
}
uint16_t NexDownload::recvRetString(String &string, uint32_t timeout,bool recv_flag) {
uint16_t ret = 0;
uint8_t c = 0;
long start;
bool exit_flag = false;
start = millis();
while (millis() - start <= timeout) {
while (nexSerial.available()) {
c = nexSerial.read();
if(c == 0) continue;
string += (char)c;
if(recv_flag) {
if(string.indexOf(0x05) != -1)
exit_flag = true;
}
}
if(exit_flag) break;
}
ret = string.length();
return ret;
}
bool NexDownload::_setDownloadBaudrate(uint32_t baudrate) {
String string = String("");
String cmd = String("");
String filesize_str = String(_undownloadByte, 10);
String baudrate_str = String(baudrate, 10);
cmd = "whmi-wri " + filesize_str + "," + baudrate_str + ",0";
this->sendCommand("");
this->sendCommand(cmd.c_str());
HAL::delayMilliseconds(50);
nexSerial.begin(baudrate);
this->recvRetString(string, 500);
if(string.indexOf(0x05) != -1)
return 1;
return 0;
}
bool NexDownload::_downloadTftFile(void) {
uint8_t c;
uint16_t send_timer = 0;
uint16_t last_send_num = 0;
String string = String("");
send_timer = _undownloadByte / 4096 + 1;
last_send_num = _undownloadByte % 4096;
while(send_timer) {
if(send_timer == 1) {
for(uint16_t j = 1; j <= 4096; j++) {
if(j <= last_send_num) {
c = card.get();
nexSerial.write(c);
}
else
break;
}
}
else {
for(uint16_t i = 1; i <= 4096; i++) {
c = card.get();
nexSerial.write(c);
}
}
this->recvRetString(string, 500, true);
if(string.indexOf(0x05) != -1)
string = "";
else
return 0;
--send_timer;
}
}
#endif // SDSUPPORT
/**
* @file NexDownload.h
*
* The definition of class NexDownload.
*
* @author Chen Zengpeng (email:<zengpeng.chen@itead.cc>)
* @date 2016/3/29
*
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#ifndef __NEXDOWNLOAD_H__
#define __NEXDOWNLOAD_H__
#include "NexHardware.h"
/**
* @addtogroup CoreAPI
* @{
*/
/**
*
* Provides the API for nextion to download the ftf file.
*/
class NexDownload
{
public: /* methods */
/**
* Constructor.
*
* @param file_name - tft file name.
* @download_baudrate - set download baudrate.
*/
NexDownload(const char *file_name, uint32_t download_baudrate);
/**
* Constructor.
*
* @param file_name - tft file name.
* @param SD_chip_select - sd chip select pin.
* @download_baudrate - set download baudrate.
*/
NexDownload(const String file_Name, uint32_t download_baudrate);
/**
* destructor.
*
*/
~NexDownload(){}
/*
* start download.
*
* @return none.
*/
void startDownload();
private: /* methods */
/*
* get communicate baudrate.
*
* @return communicate baudrate.
*
*/
uint16_t _getBaudrate(void);
/*
* check tft file.
*
* @return true if success, false for failure.
*/
bool _checkFile(void);
/*
* search communicate baudrate.
*
* @param baudrate - communicate baudrate.
*
* @return true if success, false for failure.
*/
bool _searchBaudrate(uint32_t baudrate);
/*
* set download baudrate.
*
* @param baudrate - set download baudrate.
*
* @return true if success, false for failure.
*/
bool _setDownloadBaudrate(uint32_t baudrate);
/**
* start dowload tft file to nextion.
*
* @return none.
*/
bool _downloadTftFile(void);
/*
* Send command to Nextion.
*
* @param cmd - the string of command.
*
* @return none.
*/
void sendCommand(const char* cmd);
/*
* Receive string data.
*
* @param buffer - save string data.
* @param timeout - set timeout time.
* @param recv_flag - if recv_flag is true,will braak when receive 0x05.
*
* @return the length of string buffer.
*
*/
uint16_t recvRetString(String &string, uint32_t timeout = 100,bool recv_flag = false);
private: /* data */
uint32_t _baudrate; /*nextion serail baudrate*/
const char *_file_name; /*nextion tft file name*/
uint32_t _undownloadByte; /*undownload byte of tft file*/
uint32_t _download_baudrate; /*download baudrate*/
};
#endif /* #ifndef __NEXDOWNLOAD_H__ */
......@@ -84,7 +84,6 @@ __return:
return ret;
}
/*
* Receive string data.
*
......@@ -232,19 +231,19 @@ bool nexInit(void)
sendCommand("page 0");
ret2 = recvRetCommandFinished();
// If baudrate is 9600 set to 57600 and reconnect
// If baudrate is 9600 set to 115200 and reconnect
if (ret1 && ret2) {
sendCommand("baud=57600");
sendCommand("baud=115200");
nexSerial.end();
HAL::delayMilliseconds(1000);
nexSerial.begin(57600);
nexSerial.begin(115200);
return ret1 && ret2;
// Else try to 57600 baudrate
// Else try to 115200 baudrate
} else {
nexSerial.end();
HAL::delayMilliseconds(1000);
nexSerial.begin(57600);
nexSerial.begin(115200);
sendCommand("");
sendCommand("bkcmd=1");
ret1 = recvRetCommandFinished();
......
......@@ -21,6 +21,7 @@
#include "NexConfig.h"
#include "NexTouch.h"
#include "NexHardware.h"
#include "NexDownload.h"
#include "NexButton.h"
//#include "NexCrop.h"
......
......@@ -148,7 +148,7 @@
cmd += ",";
cmd += buf2;
cmd += ",";
cmd +=buf3;
cmd += buf3;
cmd += ",";
cmd += buf4;
sendCommand(cmd.c_str());
......
......@@ -16,6 +16,7 @@
#if ENABLED(SDSUPPORT)
uint8_t SDstatus = 0; // 0 SD not insert, 1 SD insert, 2 SD printing
NexDownload Firmware(NEXTION_FIRMWARE_FILE, 57600);
#endif
#if ENABLED(NEXTION_GFX)
......@@ -43,9 +44,7 @@
NexText Hotend2 = NexText(1, 6, "t2");
NexText LedStatus = NexText(1, 7, "status");
NexText LedCoord1 = NexText(1, 8, "icoord");
NexPicture Menu = NexPicture(1, 9, "p0");
NexPicture MSD1 = NexPicture(1, 10, "p1");
NexPicture MSetup = NexPicture(1, 11, "p2");
NexPicture Hend0 = NexPicture(1, 12, "p3");
NexHotspot hot0 = NexHotspot(1, 13, "hot0");
NexPicture Hend1 = NexPicture(1, 14, "p4");
......@@ -123,12 +122,10 @@
NexTouch *nex_listen_list[] =
{
&Pstart,
&Menu,
&MSD1,
&MSD3,
&MSD5,
&MSD6,
&MSetup,
&Fanpic,
&Speedpic,
&NPlay,
......@@ -222,7 +219,6 @@
}
Pinfo.show();
NextionPage = 1;
#if ENABLED(NEXTION_GFX)
#if MECH(DELTA)
......@@ -291,7 +287,6 @@
}
void setpageSDPopCallback(void *ptr) {
NextionPage = 4;
Psdcard.show();
uint16_t fileCnt = card.getnrfilenames();
......@@ -360,6 +355,14 @@
card.updir();
setpageSDPopCallback(&MSD1);
}
void DownloadNewFirmware() {
if(IS_SD_INSERTED || card.cardOK) {
Firmware.startDownload();
nexSerial.end();
lcd_init();
}
}
#endif
void ExitPopCallback(void *ptr) {
......@@ -372,7 +375,6 @@
void hotPopCallback(void *ptr) {
Ptemp.show();
NextionPage = 2;
memset(buffer, 0, sizeof(buffer));
if (ptr == &hot0) {
if (degTargetHotend(0) != 0) {
......@@ -437,24 +439,15 @@
Pmenu.show();
}
void setpagePopCallback(void *ptr) {
if (ptr == &Menu) {
NextionPage = 3;
Pmenu.show();
}
else if (ptr == &MSetup) {
NextionPage = 5;
Psetup.show();
}
else if (ptr == &Speedpic) {
NextionPage = 7;
Pspeed.show();
void setfanPopCallback(void *ptr) {
if (fanSpeed) {
fanSpeed = 0;
fantimer.disable();
}
else {
fanSpeed = 255;
fantimer.enable();
}
void setfanPopCallback(void *ptr) {
if (fanSpeed) fanSpeed = 0;
else fanSpeed = 255;
}
void setmovePopCallback(void *ptr) {
......@@ -463,7 +456,6 @@
enqueuecommands_P(PSTR("G91"));
enqueuecommands_P(buffer);
enqueuecommands_P(PSTR("G90"));
NextionPage = 6;
}
#if ENABLED(SDSUPPORT)
......@@ -534,9 +526,6 @@
hot2.attachPop(hotPopCallback, &hot2);
#endif
Menu.attachPop(setpagePopCallback, &Menu);
MSetup.attachPop(setpagePopCallback, &MSetup);
Speedpic.attachPop(setpagePopCallback, &Speedpic);
Fanpic.attachPop(setfanPopCallback, &Fanpic);
m11.attachPop(sethotPopCallback, &m11);
tup.attachPop(settempPopCallback, &tup);
......@@ -619,8 +608,10 @@
millis_t ms = millis();
if (ms > next_lcd_update_ms) {
if (NextionPage == 1) {
sendCurrentPageId(&NextionPage);
if (NextionPage == 1) {
if (fanSpeed > 0) fantimer.enable();
else fantimer.disable();
......
......@@ -3,9 +3,9 @@
#if ENABLED(NEXTION)
#define LCD_UPDATE_INTERVAL 4000
#define NEXTION_FIRMWARE_FILE "marlinkimbra.tft"
void ExitPopCallback(void *ptr);
void setpagePopCallback(void *ptr);
void hotPopCallback(void *ptr);
void sethotPopCallback(void *ptr);
void settempPopCallback(void *ptr);
......@@ -33,6 +33,7 @@
void sdfolderUpPopCallback(void *ptr);
void PlayPausePopCallback(void *ptr);
void StopPopCallback(void *ptr);
void DownloadNewFirmware();
#endif
FORCE_INLINE bool lcd_hasstatus() { return false; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment