Commit 4ff8a3a3 authored by MagoKimbra's avatar MagoKimbra

Fix CORE_XZ planner width specific Nicholas Seward’s and more

parent 51f681c3
...@@ -865,7 +865,7 @@ void get_command() { ...@@ -865,7 +865,7 @@ void get_command() {
if (drain_queued_commands_P()) return; // priority is given to non-serial commands if (drain_queued_commands_P()) return; // priority is given to non-serial commands
#ifdef NO_TIMEOUTS #if ENABLED(NO_TIMEOUTS)
static millis_t last_command_time = 0; static millis_t last_command_time = 0;
millis_t ms = millis(); millis_t ms = millis();
...@@ -880,7 +880,7 @@ void get_command() { ...@@ -880,7 +880,7 @@ void get_command() {
// //
while (MYSERIAL.available() > 0 && commands_in_queue < BUFSIZE) { while (MYSERIAL.available() > 0 && commands_in_queue < BUFSIZE) {
#ifdef NO_TIMEOUTS #if ENABLED(NO_TIMEOUTS)
last_command_time = ms; last_command_time = ms;
#endif #endif
...@@ -905,15 +905,13 @@ void get_command() { ...@@ -905,15 +905,13 @@ void get_command() {
#endif #endif
char *npos = strchr(command, 'N'); char *npos = strchr(command, 'N');
if (npos == NULL) npos = strchr(command, 'n');
char *apos = strchr(command, '*'); char *apos = strchr(command, '*');
if (npos) { if (npos) {
boolean M110 = strstr_P(command, PSTR("M110")) != NULL || strstr_P(command, PSTR("m110")) != NULL; boolean M110 = strstr_P(command, PSTR("M110")) != NULL;
if (M110) { if (M110) {
char *n2pos = strchr(command + 4, 'N'); char *n2pos = strchr(command + 4, 'N');
if (n2pos == NULL) n2pos = strchr(command + 4, 'n');
if (n2pos) npos = n2pos; if (n2pos) npos = n2pos;
} }
...@@ -924,8 +922,6 @@ void get_command() { ...@@ -924,8 +922,6 @@ void get_command() {
return; return;
} }
gcode_LastN = gcode_N;
if (apos) { if (apos) {
byte checksum = 0, count = 0; byte checksum = 0, count = 0;
while (command[count] != '*') checksum ^= command[count++]; while (command[count] != '*') checksum ^= command[count++];
...@@ -940,6 +936,9 @@ void get_command() { ...@@ -940,6 +936,9 @@ void get_command() {
gcode_line_error(PSTR(MSG_ERR_NO_CHECKSUM)); gcode_line_error(PSTR(MSG_ERR_NO_CHECKSUM));
return; return;
} }
gcode_LastN = gcode_N;
// if no errors, continue parsing
} }
else if (apos) { // No '*' without 'N' else if (apos) { // No '*' without 'N'
gcode_line_error(PSTR(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM), false); gcode_line_error(PSTR(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM), false);
...@@ -949,7 +948,6 @@ void get_command() { ...@@ -949,7 +948,6 @@ void get_command() {
// Movement commands alert when stopped // Movement commands alert when stopped
if (IsStopped()) { if (IsStopped()) {
char *gpos = strchr(command, 'G'); char *gpos = strchr(command, 'G');
if (gpos == NULL) gpos = strchr(command, 'g');
if (gpos) { if (gpos) {
int codenum = strtol(gpos + 1, NULL, 10); int codenum = strtol(gpos + 1, NULL, 10);
switch (codenum) { switch (codenum) {
...@@ -965,7 +963,7 @@ void get_command() { ...@@ -965,7 +963,7 @@ void get_command() {
} }
// If command was e-stop process now // If command was e-stop process now
if (strcmp(command, "M112") == 0 || strcmp(command, "m112") == 0) kill(PSTR(MSG_KILLED)); if (strcmp(command, "M112") == 0) kill(PSTR(MSG_KILLED));
cmd_queue_index_w = (cmd_queue_index_w + 1) % BUFSIZE; cmd_queue_index_w = (cmd_queue_index_w + 1) % BUFSIZE;
commands_in_queue += 1; commands_in_queue += 1;
...@@ -1050,7 +1048,7 @@ bool code_has_value() { ...@@ -1050,7 +1048,7 @@ bool code_has_value() {
float code_value() { float code_value() {
float ret; float ret;
char *e = strchr(seen_pointer, 'E'); if (e == NULL) e = strchr(seen_pointer, 'e'); char *e = strchr(seen_pointer, 'E');
if (e) { if (e) {
*e = 0; *e = 0;
ret = strtod(seen_pointer + 1, NULL); ret = strtod(seen_pointer + 1, NULL);
...@@ -1067,7 +1065,6 @@ int16_t code_value_short() { return (int16_t)strtol(seen_pointer + 1, NULL, 10); ...@@ -1067,7 +1065,6 @@ int16_t code_value_short() { return (int16_t)strtol(seen_pointer + 1, NULL, 10);
bool code_seen(char code) { bool code_seen(char code) {
seen_pointer = strchr(current_command_args, code); // +3 since "G0 " is the shortest prefix seen_pointer = strchr(current_command_args, code); // +3 since "G0 " is the shortest prefix
if (seen_pointer == NULL) seen_pointer = strchr(current_command_args, code + ('a'-'A'));
return (seen_pointer != NULL); //Return True if a character was found return (seen_pointer != NULL); //Return True if a character was found
} }
...@@ -3554,8 +3551,9 @@ inline void gcode_G28() { ...@@ -3554,8 +3551,9 @@ inline void gcode_G28() {
double eqnAMatrix[abl2 * 3], // "A" matrix of the linear system of equations double eqnAMatrix[abl2 * 3], // "A" matrix of the linear system of equations
eqnBVector[abl2]; // "B" vector of Z points eqnBVector[abl2]; // "B" vector of Z points
int8_t indexIntoAB[auto_bed_leveling_grid_points][auto_bed_leveling_grid_points];
int probePointCounter = 0; int probePointCounter = 0;
bool zig = true; bool zig = (auto_bed_leveling_grid_points & 1) ? true : false; //always end at [RIGHT_PROBE_BED_POSITION, BACK_PROBE_BED_POSITION]
for (int yCount = 0; yCount < auto_bed_leveling_grid_points; yCount++) { for (int yCount = 0; yCount < auto_bed_leveling_grid_points; yCount++) {
double yProbe = front_probe_bed_position + yGridSpacing * yCount; double yProbe = front_probe_bed_position + yGridSpacing * yCount;
...@@ -3572,9 +3570,8 @@ inline void gcode_G28() { ...@@ -3572,9 +3570,8 @@ inline void gcode_G28() {
xInc = -1; xInc = -1;
} }
// If do_topography_map is set then don't zig-zag. Just scan in one direction. zig = !zig;
// This gets the probe points in more readable order.
if (!do_topography_map) zig = !zig;
for (int xCount = xStart; xCount != xStop; xCount += xInc) { for (int xCount = xStart; xCount != xStop; xCount += xInc) {
double xProbe = left_probe_bed_position + xGridSpacing * xCount; double xProbe = left_probe_bed_position + xGridSpacing * xCount;
...@@ -3606,6 +3603,7 @@ inline void gcode_G28() { ...@@ -3606,6 +3603,7 @@ inline void gcode_G28() {
eqnAMatrix[probePointCounter + 0 * abl2] = xProbe; eqnAMatrix[probePointCounter + 0 * abl2] = xProbe;
eqnAMatrix[probePointCounter + 1 * abl2] = yProbe; eqnAMatrix[probePointCounter + 1 * abl2] = yProbe;
eqnAMatrix[probePointCounter + 2 * abl2] = 1; eqnAMatrix[probePointCounter + 2 * abl2] = 1;
indexIntoAB[xCount][yCount] = probePointCounter;
probePointCounter++; probePointCounter++;
...@@ -3661,7 +3659,7 @@ inline void gcode_G28() { ...@@ -3661,7 +3659,7 @@ inline void gcode_G28() {
for (int8_t yy = auto_bed_leveling_grid_points - 1; yy >= 0; yy--) { for (int8_t yy = auto_bed_leveling_grid_points - 1; yy >= 0; yy--) {
ECHO_S(DB); ECHO_S(DB);
for (int8_t xx = 0; xx < auto_bed_leveling_grid_points; xx++) { for (int8_t xx = 0; xx < auto_bed_leveling_grid_points; xx++) {
int8_t ind = yy * auto_bed_leveling_grid_points + xx; int8_t ind = indexIntoAB[xx][yy];
float diff = eqnBVector[ind]; float diff = eqnBVector[ind];
...@@ -3679,7 +3677,7 @@ inline void gcode_G28() { ...@@ -3679,7 +3677,7 @@ inline void gcode_G28() {
for (int8_t yy = auto_bed_leveling_grid_points - 1; yy >= 0; yy--) { for (int8_t yy = auto_bed_leveling_grid_points - 1; yy >= 0; yy--) {
ECHO_S(DB); ECHO_S(DB);
for (int8_t xx = 0; xx < auto_bed_leveling_grid_points; xx++) { for (int8_t xx = 0; xx < auto_bed_leveling_grid_points; xx++) {
int8_t ind = yy * auto_bed_leveling_grid_points + xx; int8_t ind = indexIntoAB[xx][yy];
float diff = eqnBVector[ind] - min_diff; float diff = eqnBVector[ind] - min_diff;
...@@ -3697,7 +3695,7 @@ inline void gcode_G28() { ...@@ -3697,7 +3695,7 @@ inline void gcode_G28() {
for (int8_t yy = auto_bed_leveling_grid_points - 1; yy >= 0; yy--) { for (int8_t yy = auto_bed_leveling_grid_points - 1; yy >= 0; yy--) {
ECHO_S(DB); ECHO_S(DB);
for (int8_t xx = 0; xx < auto_bed_leveling_grid_points; xx++) { for (int8_t xx = 0; xx < auto_bed_leveling_grid_points; xx++) {
int8_t ind = yy * auto_bed_leveling_grid_points + xx; int8_t ind = indexIntoAB[xx][yy];
vector_3 probe_point = vector_3(eqnAMatrix[ind + 0 * abl2], eqnAMatrix[ind + 1 * abl2], eqnBVector[ind]); vector_3 probe_point = vector_3(eqnAMatrix[ind + 0 * abl2], eqnAMatrix[ind + 1 * abl2], eqnBVector[ind]);
probe_point.apply_rotation(inverse_bed_level_matrix); probe_point.apply_rotation(inverse_bed_level_matrix);
...@@ -3718,7 +3716,7 @@ inline void gcode_G28() { ...@@ -3718,7 +3716,7 @@ inline void gcode_G28() {
for (int8_t yy = auto_bed_leveling_grid_points - 1; yy >= 0; yy--) { for (int8_t yy = auto_bed_leveling_grid_points - 1; yy >= 0; yy--) {
ECHO_S(DB); ECHO_S(DB);
for (int8_t xx = 0; xx < auto_bed_leveling_grid_points; xx++) { for (int8_t xx = 0; xx < auto_bed_leveling_grid_points; xx++) {
int8_t ind = yy * auto_bed_leveling_grid_points + xx; int8_t ind = indexIntoAB[xx][yy];
vector_3 probe_point = vector_3(eqnAMatrix[ind + 0 * abl2], eqnAMatrix[ind + 1 * abl2], eqnBVector[ind]); vector_3 probe_point = vector_3(eqnAMatrix[ind + 0 * abl2], eqnAMatrix[ind + 1 * abl2], eqnBVector[ind]);
probe_point.apply_rotation(inverse_bed_level_matrix); probe_point.apply_rotation(inverse_bed_level_matrix);
...@@ -6321,7 +6319,7 @@ inline void gcode_M999() { ...@@ -6321,7 +6319,7 @@ inline void gcode_M999() {
inline void gcode_T(uint8_t tmp_extruder) { inline void gcode_T(uint8_t tmp_extruder) {
long csteps; long csteps;
if (tmp_extruder >= EXTRUDERS) { if (tmp_extruder >= EXTRUDERS) {
ECHO_SMV(DB, "T", tmp_extruder); ECHO_SMV(DB, "T", (int)tmp_extruder);
ECHO_EM(" " MSG_INVALID_EXTRUDER); ECHO_EM(" " MSG_INVALID_EXTRUDER);
} }
else { else {
...@@ -6524,10 +6522,10 @@ inline void gcode_T(uint8_t tmp_extruder) { ...@@ -6524,10 +6522,10 @@ inline void gcode_T(uint8_t tmp_extruder) {
if (csteps > 0) colorstep(csteps,true); if (csteps > 0) colorstep(csteps,true);
old_color = active_extruder = target_extruder; old_color = active_extruder = target_extruder;
active_driver = 0; active_driver = 0;
ECHO_LMV(DB, MSG_ACTIVE_COLOR, active_extruder); ECHO_LMV(DB, MSG_ACTIVE_COLOR, (int)active_extruder);
#else #else
active_driver = active_extruder = target_extruder; active_driver = active_extruder = target_extruder;
ECHO_LMV(DB, MSG_ACTIVE_EXTRUDER, active_extruder); ECHO_LMV(DB, MSG_ACTIVE_EXTRUDER, (int)active_extruder);
#endif // end MKR4 || NPR2 #endif // end MKR4 || NPR2
#endif // end no DUAL_X_CARRIAGE #endif // end no DUAL_X_CARRIAGE
......
/** /**
* @file NexButton.cpp * @file NexButton.cpp
* *
* API of NexButton. * The implementation of class NexButton.
* *
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>) * @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10 * @date 2015/8/13
* @copyright * @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -15,23 +15,11 @@ ...@@ -15,23 +15,11 @@
#include "NexButton.h" #include "NexButton.h"
/** NexButton::NexButton(uint8_t pid, uint8_t cid, const char *name)
* Constructor,inherited NexTouch's constructor function. :NexTouch(pid, cid, name)
*
*/
NexButton::NexButton(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop, void *pop_ptr)
:NexTouch(pid, cid, name, pop, pop_ptr)
{ {
} }
/**
* Get text value from button component.
*
* @param buffer - text buffer.
* @param len - text buffer length.
*
* @return the text buffer length
*/
uint16_t NexButton::getText(char *buffer, uint16_t len) uint16_t NexButton::getText(char *buffer, uint16_t len)
{ {
String cmd; String cmd;
...@@ -42,14 +30,6 @@ uint16_t NexButton::getText(char *buffer, uint16_t len) ...@@ -42,14 +30,6 @@ uint16_t NexButton::getText(char *buffer, uint16_t len)
return recvRetString(buffer,len); return recvRetString(buffer,len);
} }
/**
* Set text value of button component.
*
* @param buffer - text buffer.
*
* @retval true - success.
* @retval false - failed.
*/
bool NexButton::setText(const char *buffer) bool NexButton::setText(const char *buffer)
{ {
String cmd; String cmd;
...@@ -60,25 +40,3 @@ bool NexButton::setText(const char *buffer) ...@@ -60,25 +40,3 @@ bool NexButton::setText(const char *buffer)
sendCommand(cmd.c_str()); sendCommand(cmd.c_str());
return recvRetCommandFinished(); return recvRetCommandFinished();
} }
/**
* Register button pop callback function.
*
* @param pop - the pointer to button pop callback function.
* @param ptr - the parameter to be transmitted to button pop callback function.
*/
void NexButton::attachPop(NexTouchEventCb pop, void *ptr)
{
NexTouch::attachPop(pop, ptr);
}
/**
* Unload button pop callback function.
*
*/
void NexButton::detachPop(void)
{
NexTouch::detachPop();
}
/** /**
* @file NexButton.h * @file NexButton.h
* *
* API of NexButton. * The definition of class NexButton.
* *
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>) * @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10 * @date 2015/8/13
*
* @copyright * @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -15,24 +16,51 @@ ...@@ -15,24 +16,51 @@
#ifndef __NEXBUTTON_H__ #ifndef __NEXBUTTON_H__
#define __NEXBUTTON_H__ #define __NEXBUTTON_H__
#ifdef __cplusplus
#include "NexTouch.h" #include "NexTouch.h"
#include "NexHardware.h"
/**
* @addtogroup Component
* @{
*/
/** /**
* NexButton,subclass of NexTouch,provides simple methods to control button component. * NexButton component.
* *
* Commonly, you want to do something after push and pop it. It is recommanded that only
* call @ref NexTouch::attachPop to satisfy your purpose.
*
* @warning Please do not call @ref NexTouch::attachPush on this component, even though you can.
*/ */
class NexButton: public NexTouch class NexButton: public NexTouch
{ {
public: /* methods */ public: /* methods */
NexButton(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop = NULL, void *pop_ptr = NULL);
void attachPop(NexTouchEventCb pop, void *ptr = NULL); /**
void detachPop(void); * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name);
*/
NexButton(uint8_t pid, uint8_t cid, const char *name);
/**
* Get text attribute of component.
*
* @param buffer - buffer storing text returned.
* @param len - length of buffer.
* @return The real length of text returned.
*/
uint16_t getText(char *buffer, uint16_t len); uint16_t getText(char *buffer, uint16_t len);
/**
* Set text attribute of component.
*
* @param buffer - text buffer terminated with '\0'.
* @return true if success, false for failure.
*/
bool setText(const char *buffer); bool setText(const char *buffer);
}; };
/**
* @}
*/
#endif /* #ifdef __cplusplus */
#endif /* #ifndef __NEXBUTTON_H__ */ #endif /* #ifndef __NEXBUTTON_H__ */
/** /**
* @file NexSerialConfig.h * @file NexConfig.h
* *
* Serial configure. * Options for user can be found here.
* *
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>) * @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10 * @date 2015/8/13
* @copyright * @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -12,31 +12,49 @@ ...@@ -12,31 +12,49 @@
* published by the Free Software Foundation; either version 2 of * published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
*/ */
#ifndef __NEXCONFIG_H__
#define __NEXCONFIG_H__
#ifndef __NexSerialConfig_H__ /**
#define __NexSerialConfig_H__ * @addtogroup Configuration
* @{
*/
// Nextion Baudrate - default 9600 /**
// 2400 - 4800 - 9600 - 19200 - 38400 - 57600 - 115200 * Nextion Baudrate - default 9600
* 2400 - 4800 - 9600 - 19200 - 38400 - 57600 - 115200
*/
#define NEXTION_BAUDRATE 9600 #define NEXTION_BAUDRATE 9600
/*enable debug serial*/ /**
* Define DEBUG_SERIAL_ENABLE to enable debug serial.
* Comment it to disable debug serial.
*/
//#define DEBUG_SERIAL_ENABLE //#define DEBUG_SERIAL_ENABLE
/*define serial for debug*/ /**
* Define dbSerial for the output of debug messages.
*/
#define dbSerial Serial #define dbSerial Serial
/**
* Define nexSerial for communicate with Nextion touch panel.
*/
#define nexSerial Serial1
#ifdef DEBUG_SERIAL_ENABLE #ifdef DEBUG_SERIAL_ENABLE
#define dbSerialPrint(a) dbSerial.print(a) #define dbSerialPrint(a) dbSerial.print(a)
#define dbSerialPrintln(a) dbSerial.println(a) #define dbSerialPrintln(a) dbSerial.println(a)
#define dbSerialBegin(a) dbSerial.begin(a) #define dbSerialBegin(a) dbSerial.begin(a)
#else #else
#define dbSerialPrint(a) #define dbSerialPrint(a) do{}while(0)
#define dbSerialPrintln(a) #define dbSerialPrintln(a) do{}while(0)
#define dbSerialBegin(a) #define dbSerialBegin(a) do{}while(0)
#endif #endif
/*define serial for communicate with Nextion screen*/ /**
#define nexSerial Serial1 * @}
*/
#endif #endif /* #ifndef __NEXCONFIG_H__ */
/**
* @file NexHardware.cpp
*
* The implementation of base API for using Nextion.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/8/11
* @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 "NexHardware.h"
#define NEX_RET_CMD_FINISHED (0x01)
#define NEX_RET_EVENT_LAUNCHED (0x88)
#define NEX_RET_EVENT_UPGRADED (0x89)
#define NEX_RET_EVENT_TOUCH_HEAD (0x65)
#define NEX_RET_EVENT_POSITION_HEAD (0x67)
#define NEX_RET_EVENT_SLEEP_POSITION_HEAD (0x68)
#define NEX_RET_CURRENT_PAGE_ID_HEAD (0x66)
#define NEX_RET_STRING_HEAD (0x70)
#define NEX_RET_NUMBER_HEAD (0x71)
#define NEX_RET_INVALID_CMD (0x00)
#define NEX_RET_INVALID_COMPONENT_ID (0x02)
#define NEX_RET_INVALID_PAGE_ID (0x03)
#define NEX_RET_INVALID_PICTURE_ID (0x04)
#define NEX_RET_INVALID_FONT_ID (0x05)
#define NEX_RET_INVALID_BAUD (0x11)
#define NEX_RET_INVALID_VARIABLE (0x1A)
#define NEX_RET_INVALID_OPERATION (0x1B)
/*
* Receive uint32_t data.
*
* @param number - save uint32_t data.
* @param timeout - set timeout time.
*
* @retval true - success.
* @retval false - failed.
*
*/
bool recvRetNumber(uint32_t *number, uint32_t timeout)
{
bool ret = false;
uint8_t temp[8] = {0};
if (!number)
{
goto __return;
}
nexSerial.setTimeout(timeout);
if (sizeof(temp) != nexSerial.readBytes((char *)temp, sizeof(temp)))
{
goto __return;
}
if (temp[0] == NEX_RET_NUMBER_HEAD
&& temp[5] == 0xFF
&& temp[6] == 0xFF
&& temp[7] == 0xFF
)
{
*number = (temp[4] << 24) | (temp[3] << 16) | (temp[2] << 8) | (temp[1]);
ret = true;
}
__return:
if (ret)
{
dbSerialPrint("recvRetNumber :");
dbSerialPrintln(*number);
}
else
{
dbSerialPrintln("recvRetNumber err");
}
return ret;
}
/*
* Receive string data.
*
* @param buffer - save string data.
* @param len - string buffer length.
* @param timeout - set timeout time.
*
* @return the length of string buffer.
*
*/
uint16_t recvRetString(char *buffer, uint16_t len, uint32_t timeout)
{
uint16_t ret = 0;
bool str_start_flag = false;
uint8_t cnt_0xff = 0;
String temp = String("");
uint8_t c = 0;
long start;
if (!buffer || len == 0)
{
goto __return;
}
start = millis();
while (millis() - start <= timeout)
{
while (nexSerial.available())
{
c = nexSerial.read();
if (str_start_flag)
{
if (0xFF == c)
{
cnt_0xff++;
if (cnt_0xff >= 3)
{
break;
}
}
else
{
temp += (char)c;
}
}
else if (NEX_RET_STRING_HEAD == c)
{
str_start_flag = true;
}
}
if (cnt_0xff >= 3)
{
break;
}
}
ret = temp.length();
ret = ret > len ? len : ret;
strncpy(buffer, temp.c_str(), ret);
__return:
dbSerialPrint("recvRetString[");
dbSerialPrint(temp.length());
dbSerialPrint(",");
dbSerialPrint(temp);
dbSerialPrintln("]");
return ret;
}
/*
* Send command to Nextion.
*
* @param cmd - the string of command.
*/
void sendCommand(const char* cmd)
{
while (nexSerial.available())
{
nexSerial.read();
}
nexSerial.print(cmd);
nexSerial.write(0xFF);
nexSerial.write(0xFF);
nexSerial.write(0xFF);
}
/*
* Command is executed successfully.
*
* @param timeout - set timeout time.
*
* @retval true - success.
* @retval false - failed.
*
*/
bool recvRetCommandFinished(uint32_t timeout)
{
bool ret = false;
uint8_t temp[4] = {0};
nexSerial.setTimeout(timeout);
if (sizeof(temp) != nexSerial.readBytes((char *)temp, sizeof(temp)))
{
ret = false;
}
if (temp[0] == NEX_RET_CMD_FINISHED
&& temp[1] == 0xFF
&& temp[2] == 0xFF
&& temp[3] == 0xFF
)
{
ret = true;
}
if (ret)
{
dbSerialPrintln("recvRetCommandFinished ok");
}
else
{
dbSerialPrintln("recvRetCommandFinished err");
}
return ret;
}
bool nexInit(void)
{
bool ret1 = false;
bool ret2 = false;
dbSerialBegin(9600);
nexSerial.begin(NEXTION_BAUDRATE);
sendCommand("");
sendCommand("bkcmd=1");
ret1 = recvRetCommandFinished();
sendCommand("page 0");
ret2 = recvRetCommandFinished();
return ret1 && ret2;
}
void nexLoop(NexTouch *nex_listen_list[])
{
static uint8_t __buffer[10];
uint16_t i;
uint8_t c;
while (nexSerial.available() > 0)
{
delay(10);
c = nexSerial.read();
if (NEX_RET_EVENT_TOUCH_HEAD == c)
{
if (nexSerial.available() >= 6)
{
__buffer[0] = c;
for (i = 1; i < 7; i++)
{
__buffer[i] = nexSerial.read();
}
__buffer[i] = 0x00;
if (0xFF == __buffer[4] && 0xFF == __buffer[5] && 0xFF == __buffer[6])
{
NexTouch::iterate(nex_listen_list, __buffer[1], __buffer[2], (int32_t)__buffer[3]);
}
}
}
}
}
/**
* @file NexHardware.h
*
* The definition of base API for using Nextion.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/8/11
* @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 __NEXHARDWARE_H__
#define __NEXHARDWARE_H__
#include <Arduino.h>
#include "NexConfig.h"
#include "NexTouch.h"
/**
* @addtogroup CoreAPI
* @{
*/
/**
* Init Nextion.
*
* @return true if success, false for failure.
*/
bool nexInit(void);
/**
* Listen touch event and calling callbacks attached before.
*
* Supports push and pop at present.
*
* @param nex_listen_list - index to Nextion Components list.
* @return none.
*
* @warning This function must be called repeatedly to response touch events
* from Nextion touch panel. Actually, you should place it in your loop function.
*/
void nexLoop(NexTouch *nex_listen_list[]);
/**
* @}
*/
bool recvRetNumber(uint32_t *number, uint32_t timeout = 100);
uint16_t recvRetString(char *buffer, uint16_t len, uint32_t timeout = 100);
void sendCommand(const char* cmd);
bool recvRetCommandFinished(uint32_t timeout = 100);
#endif /* #ifndef __NEXHARDWARE_H__ */
/** /**
* @file NexHotspot.cpp * @file NexHotspot.cpp
* *
* API of NexHotspot. * The implementation of class NexHotspot.
* *
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>) * @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10 * @date 2015/8/13
* @copyright * @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -15,53 +15,8 @@ ...@@ -15,53 +15,8 @@
#include "NexHotspot.h" #include "NexHotspot.h"
/** NexHotspot::NexHotspot(uint8_t pid, uint8_t cid, const char *name)
* Constructor,inherited NexTouch's constructor function. :NexTouch(pid, cid, name)
*
*/
NexHotspot::NexHotspot(NexPid pid, NexCid cid, char *name,
NexTouchEventCb pop, void *pop_ptr,
NexTouchEventCb push, void *push_ptr)
:NexTouch(pid, cid, name, pop, pop_ptr, push, push_ptr)
{
}
/**
* Register hotspot push callback function.
*
* @param push - the pointer to hotspot push callback function.
* @param ptr - the parameter to be transmitted to hotspot push callback function.
*/
void NexHotspot::attachPush(NexTouchEventCb push, void *ptr)
{
NexTouch::attachPush(push, ptr);
}
/**
* Unload hotsopt push callback function.
*
*/
void NexHotspot::detachPush(void)
{ {
NexTouch::detachPush();
} }
/**
* Register hotspot pop callback function.
*
* @param pop - the pointer to hotspot pot callback function.
* @param ptr - the parameter to be transmitted to hotspot pop callback function.
*/
void NexHotspot::attachPop(NexTouchEventCb pop, void *ptr)
{
NexTouch::attachPop(pop, ptr);
}
/**
* Unload hotsopt pop callback function.
*
*/
void NexHotspot::detachPop(void)
{
NexTouch::detachPop();
}
/** /**
* @file NexHotspot.h * @file NexHotspot.h
* *
* API of NexHotspot. * The definition of class NexHotspot.
* *
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>) * @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10 * @date 2015/8/13
*
* @copyright * @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -15,26 +16,28 @@ ...@@ -15,26 +16,28 @@
#ifndef __NEXHOTSPOT_H__ #ifndef __NEXHOTSPOT_H__
#define __NEXHOTSPOT_H__ #define __NEXHOTSPOT_H__
#ifdef __cplusplus
#include "NexTouch.h" #include "NexTouch.h"
#include "NexHardware.h"
/**
* @addtogroup Component
* @{
*/
/** /**
* NexHotspot,subclass of NexTouch,provides simple methods to control hotspot component. * NexHotspot component.
*
*/ */
class NexHotspot: public NexTouch class NexHotspot: public NexTouch
{ {
public: /* methods */ public: /* methods */
NexHotspot(NexPid pid, NexCid cid, char *name, /**
NexTouchEventCb pop = NULL, void *pop_ptr = NULL, * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name);
NexTouchEventCb push = NULL, void *push_ptr = NULL); */
NexHotspot(uint8_t pid, uint8_t cid, const char *name);
void attachPush(NexTouchEventCb push, void *ptr = NULL);
void detachPush(void);
void attachPop(NexTouchEventCb pop, void *ptr = NULL);
void detachPop(void);
}; };
/**
* @}
*/
#endif /* #ifdef __cplusplus */
#endif /* #ifndef __NEXHOTSPOT_H__ */ #endif /* #ifndef __NEXHOTSPOT_H__ */
/**
* @file NexObject.cpp
*
* The implementation of class NexObject.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/8/13
* @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 "NexObject.h"
NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name)
{
this->__pid = pid;
this->__cid = cid;
this->__name = name;
}
uint8_t NexObject::getObjPid(void)
{
return __pid;
}
uint8_t NexObject::getObjCid(void)
{
return __cid;
}
const char* NexObject::getObjName(void)
{
return __name;
}
void NexObject::printObjInfo(void)
{
dbSerialPrint("[");
dbSerialPrint((uint32_t)this);
dbSerialPrint(":");
dbSerialPrint(__pid);
dbSerialPrint(",");
dbSerialPrint(__cid);
dbSerialPrint(",");
if (__name)
{
dbSerialPrint(__name);
}
else
{
dbSerialPrint("(null)");
}
dbSerialPrintln("]");
}
/**
* @file NexObject.h
*
* The definition of class NexObject.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/8/13
*
* @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 __NEXOBJECT_H__
#define __NEXOBJECT_H__
#include <Arduino.h>
#include "NexConfig.h"
/**
* @addtogroup CoreAPI
* @{
*/
/**
* Root class of all Nextion components.
*
* Provides the essential attributes of a Nextion component and the methods accessing
* them. At least, Page ID(pid), Component ID(pid) and an unique name are needed for
* creating a component in Nexiton library.
*/
class NexObject
{
public: /* methods */
/**
* Constructor.
*
* @param pid - page id.
* @param cid - component id.
* @param name - pointer to an unique name in range of all components.
*/
NexObject(uint8_t pid, uint8_t cid, const char *name);
/**
* Print current object'address, page id, component id and name.
*
* @warning this method does nothing, unless debug message enabled.
*/
void printObjInfo(void);
protected: /* methods */
/*
* Get page id.
*
* @return the id of page.
*/
uint8_t getObjPid(void);
/*
* Get component id.
*
* @return the id of component.
*/
uint8_t getObjCid(void);
/*
* Get component name.
*
* @return the name of component.
*/
const char *getObjName(void);
private: /* data */
uint8_t __pid; /* Page ID */
uint8_t __cid; /* Component ID */
const char *__name; /* An unique name */
};
/**
* @}
*/
#endif /* #ifndef __NEXOBJECT_H__ */
/** /**
* @file NexPage.cpp * @file NexPage.cpp
* *
* API of NexPage. * The implementation of class NexPage.
* *
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>) * @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10 * @date 2015/8/13
* @copyright * @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -15,21 +15,11 @@ ...@@ -15,21 +15,11 @@
#include "NexPage.h" #include "NexPage.h"
/** NexPage::NexPage(uint8_t pid, uint8_t cid, const char *name)
* Constructor,inherited NexTouch's constructor function. :NexTouch(pid, cid, name)
*
*/
NexPage::NexPage(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop, void *pop_ptr)
:NexTouch(pid, cid, name, pop, pop_ptr)
{ {
} }
/**
* Change page.
*
* @retval true - success.
* @retval false - failed.
*/
bool NexPage::show(void) bool NexPage::show(void)
{ {
uint8_t buffer[4] = {0}; uint8_t buffer[4] = {0};
...@@ -46,22 +36,3 @@ bool NexPage::show(void) ...@@ -46,22 +36,3 @@ bool NexPage::show(void)
return recvRetCommandFinished(); return recvRetCommandFinished();
} }
/**
* Register page pop callback function.
*
* @param pop - the pointer to page pop callback function.
* @param ptr - the parameter to be transmitted to page pop callback function.
*/
void NexPage::attachPop(NexTouchEventCb pop, void *ptr)
{
NexTouch::attachPop(pop, ptr);
}
/**
* Unload page pop callback function.
*
*/
void NexPage::detachPop(void)
{
NexTouch::detachPop();
}
/** /**
* @file NexPage.h * @file NexPage.h
* *
* API of NexPage. * The definition of class NexPage.
* *
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>) * @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10 * @date 2015/8/13
*
* @copyright * @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -15,23 +16,35 @@ ...@@ -15,23 +16,35 @@
#ifndef __NEXPAGE_H__ #ifndef __NEXPAGE_H__
#define __NEXPAGE_H__ #define __NEXPAGE_H__
#ifdef __cplusplus
#include "NexTouch.h" #include "NexTouch.h"
#include "NexHardware.h"
/**
* @addtogroup Component
* @{
*/
/** /**
* NexPage,subclass of NexTouch,provides simple methods to control page component. * A special component , which can contain other components such as NexButton,
* * NexText and NexWaveform, etc.
*/ */
class NexPage: public NexTouch class NexPage: public NexTouch
{ {
public: /* methods */ public: /* methods */
NexPage(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop = NULL, void *pop_ptr = NULL); /**
bool show(void); * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name);
*/
void attachPop(NexTouchEventCb pop, void *ptr = NULL); NexPage(uint8_t pid, uint8_t cid, const char *name);
void detachPop(void);
/**
* Show itself.
*
* @return true if success, false for faileure.
*/
bool show(void);
}; };
/**
* @}
*/
#endif /* #ifdef __cplusplus */
#endif /* #ifndef __NEXPAGE_H__ */ #endif /* #ifndef __NEXPAGE_H__ */
/** /**
* @file NexPicture.cpp * @file NexPicture.cpp
* *
* API of NexPicture. * The implementation of class NexPicture.
* *
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>) * @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10 * @date 2015/8/13
* @copyright * @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -15,23 +15,11 @@ ...@@ -15,23 +15,11 @@
#include "NexPicture.h" #include "NexPicture.h"
/** NexPicture::NexPicture(uint8_t pid, uint8_t cid, const char *name)
* Constructor,inherited NexTouch's constructor function. :NexTouch(pid, cid, name)
*
*/
NexPicture::NexPicture(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop, void *pop_ptr)
:NexTouch(pid, cid, name, pop, pop_ptr)
{ {
} }
/**
* Get picture's number.
*
* @param number - an output parameter to save picture number.
*
* @retval true - success.
* @retval false - failed.
*/
bool NexPicture::getPic(uint32_t *number) bool NexPicture::getPic(uint32_t *number)
{ {
String cmd = String("get "); String cmd = String("get ");
...@@ -41,14 +29,6 @@ bool NexPicture::getPic(uint32_t *number) ...@@ -41,14 +29,6 @@ bool NexPicture::getPic(uint32_t *number)
return recvRetNumber(number); return recvRetNumber(number);
} }
/**
* Set picture's number.
*
* @param number -the picture number.
*
* @retval true - success.
* @retval false - failed.
*/
bool NexPicture::setPic(uint32_t number) bool NexPicture::setPic(uint32_t number)
{ {
char buf[10] = {0}; char buf[10] = {0};
...@@ -63,23 +43,3 @@ bool NexPicture::setPic(uint32_t number) ...@@ -63,23 +43,3 @@ bool NexPicture::setPic(uint32_t number)
return recvRetCommandFinished(); return recvRetCommandFinished();
} }
/**
* Register picture pop callback function.
*
* @param pop - the pointer to picture pop callback function.
* @param ptr - the parameter to be transmitted to picture pop callback function.
*/
void NexPicture::attachPop(NexTouchEventCb pop, void *ptr)
{
NexTouch::attachPop(pop, ptr);
}
/**
* Unload picture pop callback function.
*
*/
void NexPicture::detachPop(void)
{
NexTouch::detachPop();
}
/** /**
* @file NexPicture.h * @file NexPicture.h
* *
* API of NexPicture. * The definition of class NexPicture.
* *
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>) * @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10 * @date 2015/8/13
*
* @copyright * @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -15,24 +16,48 @@ ...@@ -15,24 +16,48 @@
#ifndef __NEXPICTURE_H__ #ifndef __NEXPICTURE_H__
#define __NEXPICTURE_H__ #define __NEXPICTURE_H__
#ifdef __cplusplus
#include "NexTouch.h" #include "NexTouch.h"
#include "NexHardware.h"
/**
* @addtogroup Component
* @{
*/
/** /**
* NexPicture,subclass of NexTouch,provides simple methods to control picture component. * NexPicture component.
*
*/ */
class NexPicture: public NexTouch class NexPicture: public NexTouch
{ {
public: /* methods */ public: /* methods */
NexPicture(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop = NULL, void *pop_ptr = NULL); /**
* @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name);
void attachPop(NexTouchEventCb pop, void *ptr = NULL); */
void detachPop(void); NexPicture(uint8_t pid, uint8_t cid, const char *name);
/**
* Get picture's number.
*
* @param number - an output parameter to save picture number.
*
* @retval true - success.
* @retval false - failed.
*/
bool getPic(uint32_t *number); bool getPic(uint32_t *number);
/**
* Set picture's number.
*
* @param number -the picture number.
*
* @retval true - success.
* @retval false - failed.
*/
bool setPic(uint32_t number); bool setPic(uint32_t number);
}; };
#endif /* #ifdef __cplusplus */ /**
* @}
*/
#endif /* #ifndef __NEXPICTURE_H__ */ #endif /* #ifndef __NEXPICTURE_H__ */
#include "NexPointer.h"
/**
* Constructor,inherited NexTouch's constructor function.
*
*/
NexPointer::NexPointer(NexPid pid, NexCid cid, char *name)
:NexTouch(pid, cid, name)
{
}
/**
* Get the value of pointer.
*
* @param number - an output parameter to save pointer's value.
*
* @retval true - success.
* @retval false - failed.
*/
bool NexPointer::getValue(uint32_t *number)
{
String cmd = String("get ");
cmd += getObjName();
cmd += ".val";
sendCommand(cmd.c_str());
return recvRetNumber(number);
}
/**
* Set the value of pointer.
*
* @param number - the value of pointer.
*
* @retval true - success.
* @retval false - failed.
*/
bool NexPointer::setValue(uint32_t number)
{
char buf[10] = {0};
String cmd;
utoa(number, buf, 10);
cmd += getObjName();
cmd += ".val=";
cmd += buf;
sendCommand(cmd.c_str());
return recvRetCommandFinished();
}
#ifndef __NEXPOINTER_H__
#define __NEXPOINTER_H__
#ifdef __cplusplus
#include "NexTouch.h"
/**
* NexPointer,subclass of NexTouch,provides simple methods to control pointer component.
*
*/
class NexPointer: public NexTouch
{
public: /* methods */
NexPointer(NexPid pid, NexCid cid, char *name);
bool getValue(uint32_t *number);
bool setValue(uint32_t number);
};
#endif /* #ifdef __cplusplus */
#endif /* #ifndef __NEXPOINTER_H__ */
/** /**
* @file NexProgressBar.cpp * @file NexProgressBar.cpp
* *
* API of NexProgressBar. * The implementation of class NexProgressBar.
* *
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>) * @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10 * @date 2015/8/13
* @copyright * @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -15,23 +15,11 @@ ...@@ -15,23 +15,11 @@
#include "NexProgressBar.h" #include "NexProgressBar.h"
/** NexProgressBar::NexProgressBar(uint8_t pid, uint8_t cid, const char *name)
* Constructor,inherited NexTouch's constructor function. :NexObject(pid, cid, name)
*
*/
NexProgressBar::NexProgressBar(NexPid pid, NexCid cid, char *name)
:NexTouch(pid, cid, name)
{ {
} }
/**
* Get the value of progress bar.
*
* @param number - an output parameter to save the value of porgress bar.
*
* @retval true - success.
* @retval false - failed.
*/
bool NexProgressBar::getValue(uint32_t *number) bool NexProgressBar::getValue(uint32_t *number)
{ {
String cmd = String("get "); String cmd = String("get ");
...@@ -41,14 +29,6 @@ bool NexProgressBar::getValue(uint32_t *number) ...@@ -41,14 +29,6 @@ bool NexProgressBar::getValue(uint32_t *number)
return recvRetNumber(number); return recvRetNumber(number);
} }
/**
* Set the value of progress bar.
*
* @param number - the value of progress bar.
*
* @retval true - success.
* @retval false - failed.
*/
bool NexProgressBar::setValue(uint32_t number) bool NexProgressBar::setValue(uint32_t number)
{ {
char buf[10] = {0}; char buf[10] = {0};
......
/** /**
* @file NexProgressBar.h * @file NexProgressBar.h
* *
* API of NexProgressBar. * The definition of class NexProgressBar.
* *
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>) * @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10 * @date 2015/8/13
*
* @copyright * @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -15,21 +16,48 @@ ...@@ -15,21 +16,48 @@
#ifndef __NEXPROGRESSBAR_H__ #ifndef __NEXPROGRESSBAR_H__
#define __NEXPROGRESSBAR_H__ #define __NEXPROGRESSBAR_H__
#ifdef __cplusplus
#include "NexTouch.h" #include "NexTouch.h"
#include "NexHardware.h"
/**
* @addtogroup Component
* @{
*/
/** /**
* NexProgressBar,subclass of NexTouch,provides simple methods to control progress bar component. * NexProgressBar component.
*
*/ */
class NexProgressBar: public NexTouch class NexProgressBar: public NexObject
{ {
public: /* methods */ public: /* methods */
NexProgressBar(NexPid pid, NexCid cid, char *name); /**
* @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name);
*/
NexProgressBar(uint8_t pid, uint8_t cid, const char *name);
/**
* Get the value of progress bar.
*
* @param number - an output parameter to save the value of porgress bar.
*
* @retval true - success.
* @retval false - failed.
*/
bool getValue(uint32_t *number); bool getValue(uint32_t *number);
/**
* Set the value of progress bar.
*
* @param number - the value of progress bar.
*
* @retval true - success.
* @retval false - failed.
*/
bool setValue(uint32_t number); bool setValue(uint32_t number);
}; };
#endif /* #ifdef __cplusplus */ /**
* @}
*/
#endif /* #ifndef __NEXPROGRESSBAR_H__ */ #endif /* #ifndef __NEXPROGRESSBAR_H__ */
/** /**
* @file NexSlice.cpp * @file NexSlider.cpp
* *
* API of NexSlice. * The implementation of class NexSlider.
* *
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>) * @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10 * @date 2015/8/13
* @copyright * @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -12,74 +12,33 @@ ...@@ -12,74 +12,33 @@
* published by the Free Software Foundation; either version 2 of * published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
*/ */
#include "NexSlider.h"
#include "NexSlice.h" NexSlider::NexSlider(uint8_t pid, uint8_t cid, const char *name)
:NexTouch(pid, cid, name)
/**
* Constructor,inherited NexTouch's constructor function.
*
*/
NexSlice::NexSlice(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop, void *pop_ptr)
:NexTouch(pid, cid, name, pop, pop_ptr)
{ {
} }
/* bool NexSlider::getValue(uint32_t *number)
* Get the number of picture.
*
* @param number - an output parameter to save the number of picture.
*
* @retval true - success.
* @retval false - failed.
*/
bool NexSlice::getPic(uint32_t *number)
{ {
String cmd = String("get "); String cmd = String("get ");
cmd += getObjName(); cmd += getObjName();
cmd += ".picc"; cmd += ".val";
sendCommand(cmd.c_str()); sendCommand(cmd.c_str());
return recvRetNumber(number); return recvRetNumber(number);
} }
/* bool NexSlider::setValue(uint32_t number)
* Set the number of picture.
*
* @param number - the number of picture.
*
* @retval true - success.
* @retval false - failed.
*/
bool NexSlice::setPic(uint32_t number)
{ {
char buf[10] = {0}; char buf[10] = {0};
String cmd; String cmd;
utoa(number, buf, 10); utoa(number, buf, 10);
cmd += getObjName(); cmd += getObjName();
cmd += ".picc="; cmd += ".val=";
cmd += buf; cmd += buf;
sendCommand(cmd.c_str()); sendCommand(cmd.c_str());
return recvRetCommandFinished(); return recvRetCommandFinished();
} }
/**
* Register slice pop callback function.
*
* @param pop - the pointer to slice pop callback function.
* @param ptr - the parameter to be transmitted to slice pop callback function.
*/
void NexSlice::attachPop(NexTouchEventCb pop, void *ptr)
{
NexTouch::attachPop(pop, ptr);
}
/**
* Unload slice pop callback function.
*
*/
void NexSlice::detachPop(void)
{
NexTouch::detachPop();
}
/**
* @file NexSlider.h
*
* The definition of class NexSlider.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/8/13
*
* @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 __NEXSLIDER_H__
#define __NEXSLIDER_H__
#include "NexTouch.h"
#include "NexHardware.h"
/**
* @addtogroup Component
* @{
*/
/**
* NexSlider component.
*/
class NexSlider: public NexTouch
{
public: /* methods */
/**
* @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name);
*/
NexSlider(uint8_t pid, uint8_t cid, const char *name);
/**
* Get the value of slider.
*
* @param number - an output parameter to save the value of slider.
*
* @retval true - success.
* @retval false - failed.
*/
bool getValue(uint32_t *number);
/**
* Set the value of slider.
*
* @param number - the value of slider.
*
* @retval true - success.
* @retval false - failed.
*/
bool setValue(uint32_t number);
};
/**
* @}
*/
#endif /* #ifndef __NEXSLIDER_H__ */
/** /**
* @file NexText.cpp * @file NexText.cpp
* *
* API of NexText. * The implementation of class NexText.
* *
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>) * @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10 * @date 2015/8/13
* @copyright * @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -12,26 +12,13 @@ ...@@ -12,26 +12,13 @@
* published by the Free Software Foundation; either version 2 of * published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
*/ */
#include "NexText.h" #include "NexText.h"
/** NexText::NexText(uint8_t pid, uint8_t cid, const char *name)
* Constructor,inherited NexTouch's constructor function. :NexTouch(pid, cid, name)
*
*/
NexText::NexText(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop, void *pop_ptr)
:NexTouch(pid, cid, name, pop, pop_ptr)
{ {
} }
/**
* Get the value of text.
*
* @param buffer - text value buffer.
* @param len - the length of text value buffer.
*
* @return the length of text value buffer.
*/
uint16_t NexText::getText(char *buffer, uint16_t len) uint16_t NexText::getText(char *buffer, uint16_t len)
{ {
String cmd; String cmd;
...@@ -42,14 +29,6 @@ uint16_t NexText::getText(char *buffer, uint16_t len) ...@@ -42,14 +29,6 @@ uint16_t NexText::getText(char *buffer, uint16_t len)
return recvRetString(buffer,len); return recvRetString(buffer,len);
} }
/**
* Set the value of text.
*
* @param buffer - text value buffer.
*
* @retval true - success.
* @retval false - failed.
*/
bool NexText::setText(const char *buffer) bool NexText::setText(const char *buffer)
{ {
String cmd; String cmd;
...@@ -61,14 +40,6 @@ bool NexText::setText(const char *buffer) ...@@ -61,14 +40,6 @@ bool NexText::setText(const char *buffer)
return recvRetCommandFinished(); return recvRetCommandFinished();
} }
/**
* Set the value of color.
*
* @param value - color value.
*
* @retval true - success.
* @retval false - failed.
*/
bool NexText::setColor(uint32_t value) bool NexText::setColor(uint32_t value)
{ {
char buf[10] = {0}; char buf[10] = {0};
...@@ -82,23 +53,3 @@ bool NexText::setColor(uint32_t value) ...@@ -82,23 +53,3 @@ bool NexText::setColor(uint32_t value)
sendCommand(cmd.c_str()); sendCommand(cmd.c_str());
return recvRetCommandFinished(); return recvRetCommandFinished();
} }
/**
* Register text pop callback function.
*
* @param pop - the pointer to text pop callback function.
* @param ptr - the parameter to be transmitted to text pop callback function.
*/
void NexText::attachPop(NexTouchEventCb pop, void *ptr)
{
NexTouch::attachPop(pop, ptr);
}
/**
* Unload text pop callback function.
*
*/
void NexText::detachPop(void)
{
NexTouch::detachPop();
}
/** /**
* @file NexText.h * @file NexText.h
* *
* API of NexText. * The definition of class NexText.
* *
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>) * @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10 * @date 2015/8/13
*
* @copyright * @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -15,25 +16,46 @@ ...@@ -15,25 +16,46 @@
#ifndef __NEXTEXT_H__ #ifndef __NEXTEXT_H__
#define __NEXTEXT_H__ #define __NEXTEXT_H__
#ifdef __cplusplus
#include "NexTouch.h" #include "NexTouch.h"
#include "NexHardware.h"
/**
* @addtogroup Component
* @{
*/
/** /**
* NexText,subclass of NexTouch,provides simple methods to control text component. * NexText component.
*
*/ */
class NexText: public NexTouch class NexText: public NexTouch
{ {
public: /* methods */ public: /* methods */
NexText(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop = NULL, void *pop_ptr = NULL); /**
* @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name);
void attachPop(NexTouchEventCb pop, void *ptr = NULL); */
void detachPop(void); NexText(uint8_t pid, uint8_t cid, const char *name);
/**
* Get text attribute of component.
*
* @param buffer - buffer storing text returned.
* @param len - length of buffer.
* @return The real length of text returned.
*/
uint16_t getText(char *buffer, uint16_t len); uint16_t getText(char *buffer, uint16_t len);
/**
* Set text attribute of component.
*
* @param buffer - text buffer terminated with '\0'.
* @return true if success, false for failure.
*/
bool setText(const char *buffer); bool setText(const char *buffer);
bool setColor(uint32_t value); bool setColor(uint32_t value);
}; };
#endif /* #ifdef __cplusplus */ /**
* @}
*/
#endif /* #ifndef __NEXTEXT_H__ */ #endif /* #ifndef __NEXTEXT_H__ */
This diff is collapsed.
/** /**
* @file NexTouch.h * @file NexTouch.h
* *
* API of Nextion. * The definition of class NexTouch.
* *
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>) * @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10 * @date 2015/8/13
*
* @copyright * @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -15,107 +16,101 @@ ...@@ -15,107 +16,101 @@
#ifndef __NEXTOUCH_H__ #ifndef __NEXTOUCH_H__
#define __NEXTOUCH_H__ #define __NEXTOUCH_H__
#ifdef __cplusplus
#include <Arduino.h> #include <Arduino.h>
#include "NexSerialConfig.h" #include "NexConfig.h"
#include "NexObject.h"
typedef uint8_t NexPid;
typedef uint8_t NexCid;
typedef enum {
NEX_EVENT_POP = 0x00,
NEX_EVENT_PUSH = 0x01,
NEX_EVENT_NULL
} NexEventType;
/*The first byte of Nextoin's return value*/
#define NEX_RET_CMD_FINISHED (0x01)
#define NEX_RET_EVENT_LAUNCHED (0x88)
#define NEX_RET_EVENT_UPGRADED (0x89)
#define NEX_RET_EVENT_TOUCH_HEAD (0x65)
#define NEX_RET_EVENT_POSITION_HEAD (0x67)
#define NEX_RET_EVENT_SLEEP_POSITION_HEAD (0x68)
#define NEX_RET_CURRENT_PAGE_ID_HEAD (0x66)
#define NEX_RET_STRING_HEAD (0x70)
#define NEX_RET_NUMBER_HEAD (0x71)
#define NEX_RET_INVALID_CMD (0x00)
#define NEX_RET_INVALID_COMPONENT_ID (0x02)
#define NEX_RET_INVALID_PAGE_ID (0x03)
#define NEX_RET_INVALID_PICTURE_ID (0x04)
#define NEX_RET_INVALID_FONT_ID (0x05)
#define NEX_RET_INVALID_BAUD (0x11)
#define NEX_RET_INVALID_VARIABLE (0x1A)
#define NEX_RET_INVALID_OPERATION (0x1B)
/**
* @addtogroup TouchEvent
* @{
*/
/**
* Push touch event occuring when your finger or pen coming to Nextion touch pannel.
*/
#define NEX_EVENT_PUSH (0x01)
/**
* Pop touch event occuring when your finger or pen leaving from Nextion touch pannel.
*/
#define NEX_EVENT_POP (0x00)
/**
* Type of callback funciton when an touch event occurs.
*
* @param ptr - user pointer for any purpose. Commonly, it is a pointer to a object.
* @return none.
*/
typedef void (*NexTouchEventCb)(void *ptr); typedef void (*NexTouchEventCb)(void *ptr);
/** /**
* Root Class of Nextion Components. * Father class of the components with touch events.
* *
* Derives from NexObject and provides methods allowing user to attach
* (or detach) a callback function called when push(or pop) touch event occurs.
*/ */
class NexTouch class NexTouch: public NexObject
{ {
public: /* static methods */ public: /* static methods */
static uint8_t mainEventLoop(NexTouch **list); static void iterate(NexTouch **list, uint8_t pid, uint8_t cid, int32_t event);
static void sendCommand(const char *cmd);
static bool recvRetCommandFinished(uint32_t timeout = 100);
static uint16_t recvRetString(char *buffer, uint16_t len, uint32_t timeout = 500);
static bool recvRetNumber(uint32_t *number, uint32_t timeout = 500);
public: /* methods */ public: /* methods */
NexTouch(NexPid pid, NexCid cid, char *name,
NexTouchEventCb pop = NULL, void *pop_ptr = NULL,
NexTouchEventCb push = NULL, void *push_ptr = NULL);
NexPid getPid(void); /**
NexCid getCid(void); * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name);
const char *getObjName(void); */
void print(void); NexTouch(uint8_t pid, uint8_t cid, const char *name);
protected: /* static methods */
static bool setBrightness(uint32_t brightness);
static bool getBrightness(uint32_t *brightness);
protected: /* methods */ /**
* Attach an callback function of push touch event.
*
* @param push - callback called with ptr when a push touch event occurs.
* @param ptr - parameter passed into push[default:NULL].
* @return none.
*
* @note If calling this method multiply, the last call is valid.
*/
void attachPush(NexTouchEventCb push, void *ptr = NULL); void attachPush(NexTouchEventCb push, void *ptr = NULL);
/**
* Detach an callback function.
*
* @return none.
*/
void detachPush(void); void detachPush(void);
/**
* Attach an callback function of pop touch event.
*
* @param pop - callback called with ptr when a pop touch event occurs.
* @param ptr - parameter passed into pop[default:NULL].
* @return none.
*
* @note If calling this method multiply, the last call is valid.
*/
void attachPop(NexTouchEventCb pop, void *ptr = NULL); void attachPop(NexTouchEventCb pop, void *ptr = NULL);
void detachPop(void);
private: /* static methods */ /**
static void iterate(NexTouch **list, NexPid pid, NexCid cid, NexEventType event); * Detach an callback function.
*
* @return none.
*/
void detachPop(void);
private: /* methods */ private: /* methods */
void push(void); void push(void);
void pop(void); void pop(void);
private: /* static data */
static uint8_t __buffer[256];
private: /* data */ private: /* data */
NexPid pid; /* Page ID */ NexTouchEventCb __cb_push;
NexCid cid; /* Component ID */
char *name; /* An unique name */
NexTouchEventCb cbPush;
void *__cbpush_ptr; void *__cbpush_ptr;
NexTouchEventCb cbPop; NexTouchEventCb __cb_pop;
void *__cbpop_ptr; void *__cbpop_ptr;
}; };
bool nexInit(void); /**
bool nexLoop(NexTouch **nexListenList); * @}
bool sendCurrentPageId(uint8_t* pageId); */
bool touchCalibration(void);
bool disableTouchFocus(void);
bool pauseSerialCommand(void);
bool recoverySerialCommand(void);
bool clearSerialSurplusCommand(void);
bool setCurrentBrightness(uint8_t dimValue);
bool setDefaultBrightness(uint8_t dimDefaultValue);
bool sleepMode(uint8_t mode);
bool setCurrentBaudrate(uint32_t baudrate);
bool setDefaultBaudrate(uint32_t baudrate);
#endif /* #ifdef __cplusplus */
#endif /* #ifndef __NEXTOUCH_H__ */ #endif /* #ifndef __NEXTOUCH_H__ */
/**
* @file NexWaveform.cpp
*
* The implementation of class NexWaveform.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/8/13
* @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 "NexWaveform.h"
NexWaveform::NexWaveform(uint8_t pid, uint8_t cid, const char *name)
:NexObject(pid, cid, name)
{
}
bool NexWaveform::addValue(uint8_t ch, uint8_t number)
{
char buf[15] = {0};
if (ch > 3)
{
return false;
}
sprintf(buf, "add %u,%u,%u", getObjCid(), ch, number);
sendCommand(buf);
return true;
}
/**
* @file NexWaveform.h
*
* The definition of class NexWaveform.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/8/13
*
* @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 __NEXWAVEFORM_H__
#define __NEXWAVEFORM_H__
#include "NexTouch.h"
#include "NexHardware.h"
/**
* @addtogroup Component
* @{
*/
/**
* NexWaveform component.
*/
class NexWaveform: public NexObject
{
public: /* methods */
/**
* @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name);
*/
NexWaveform(uint8_t pid, uint8_t cid, const char *name);
/**
* Add value to show.
*
* @param ch - channel of waveform(0-3).
* @param number - the value of waveform.
*
* @retval true - success.
* @retval false - failed.
*/
bool addValue(uint8_t ch, uint8_t number);
};
/**
* @}
*/
#endif /* #ifndef __NEXWAVEFORM_H__ */
/** /**
* @file NexSlice.h * @file Nextion.h
* *
* API of NexSlice. * The header file including all other header files provided by this library.
*
* Every example sketch should include this file.
* *
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>) * @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10 * @date 2015/8/12
* @copyright * @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -12,27 +14,23 @@ ...@@ -12,27 +14,23 @@
* published by the Free Software Foundation; either version 2 of * published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
*/ */
#ifndef __NEXTION_H__
#define __NEXTION_H__
#ifndef __NEXSLICE_H__ #include "Arduino.h"
#define __NEXSLICE_H__ #include "NexConfig.h"
#ifdef __cplusplus
#include "NexTouch.h" #include "NexTouch.h"
#include "NexHardware.h"
/** #include "NexButton.h"
* NexSlice,subclass of NexTouch,provides simple methods to control slice component. //#include "NexCrop.h"
* //#include "NexGauge.h"
*/ #include "NexHotspot.h"
class NexSlice: public NexTouch #include "NexPage.h"
{ #include "NexPicture.h"
public: /* methods */ #include "NexProgressBar.h"
NexSlice(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop = NULL, void *pop_ptr = NULL); #include "NexSlider.h"
#include "NexText.h"
void attachPop(NexTouchEventCb pop, void *ptr = NULL); #include "NexWaveform.h"
void detachPop(void);
bool getPic(uint32_t *number);
bool setPic(uint32_t number);
};
#endif /* #ifdef __cplusplus */ #endif /* #ifndef __NEXTION_H__ */
#endif /* #ifndef __NEXSLICE_H__ */
...@@ -567,9 +567,9 @@ float junction_deviation = 0.1; ...@@ -567,9 +567,9 @@ float junction_deviation = 0.1;
block->steps[Z_AXIS] = labs(dz); block->steps[Z_AXIS] = labs(dz);
#elif ENABLED(COREXZ) #elif ENABLED(COREXZ)
// corexz planning // corexz planning
block->steps[A_AXIS] = labs(dx + dz); block->steps[A_AXIS] = labs(dx - 3 * dz);
block->steps[Y_AXIS] = labs(dy); block->steps[Y_AXIS] = labs(dy);
block->steps[C_AXIS] = labs(dx - dz); block->steps[C_AXIS] = labs(dx + 3 * dz);
#else #else
// default non-h-bot planning // default non-h-bot planning
block->steps[X_AXIS] = labs(dx); block->steps[X_AXIS] = labs(dx);
...@@ -609,8 +609,8 @@ float junction_deviation = 0.1; ...@@ -609,8 +609,8 @@ float junction_deviation = 0.1;
if (dx < 0) db |= BIT(X_HEAD); // Save the real Extruder (head) direction in X Axis if (dx < 0) db |= BIT(X_HEAD); // Save the real Extruder (head) direction in X Axis
if (dy < 0) db |= BIT(Y_AXIS); if (dy < 0) db |= BIT(Y_AXIS);
if (dz < 0) db |= BIT(Z_HEAD); // ...and Z if (dz < 0) db |= BIT(Z_HEAD); // ...and Z
if (dx + dz < 0) db |= BIT(A_AXIS); // Motor A direction if (dx - 3 * dz < 0) db |= BIT(A_AXIS); // Motor A direction
if (dx - dz < 0) db |= BIT(C_AXIS); // Motor B direction if (dx + 3 * dz < 0) db |= BIT(C_AXIS); // Motor B direction
#else #else
if (dx < 0) db |= BIT(X_AXIS); if (dx < 0) db |= BIT(X_AXIS);
if (dy < 0) db |= BIT(Y_AXIS); if (dy < 0) db |= BIT(Y_AXIS);
...@@ -752,8 +752,8 @@ float junction_deviation = 0.1; ...@@ -752,8 +752,8 @@ float junction_deviation = 0.1;
delta_mm[X_HEAD] = dx / axis_steps_per_unit[A_AXIS]; delta_mm[X_HEAD] = dx / axis_steps_per_unit[A_AXIS];
delta_mm[Y_AXIS] = dy / axis_steps_per_unit[Y_AXIS]; delta_mm[Y_AXIS] = dy / axis_steps_per_unit[Y_AXIS];
delta_mm[Z_HEAD] = dz / axis_steps_per_unit[C_AXIS]; delta_mm[Z_HEAD] = dz / axis_steps_per_unit[C_AXIS];
delta_mm[A_AXIS] = (dx + dz) / axis_steps_per_unit[A_AXIS]; delta_mm[A_AXIS] = (dx - 3 * dz) / axis_steps_per_unit[A_AXIS];
delta_mm[C_AXIS] = (dx - dz) / axis_steps_per_unit[C_AXIS]; delta_mm[C_AXIS] = (dx + 3 * dz) / axis_steps_per_unit[C_AXIS];
#else #else
float delta_mm[4]; float delta_mm[4];
delta_mm[X_AXIS] = dx / axis_steps_per_unit[X_AXIS]; delta_mm[X_AXIS] = dx / axis_steps_per_unit[X_AXIS];
......
...@@ -2257,10 +2257,9 @@ char *ftostr52(const float &x) { ...@@ -2257,10 +2257,9 @@ char *ftostr52(const float &x) {
#include "temperature.h" #include "temperature.h"
#include "stepper.h" #include "stepper.h"
#include "configuration_store.h" #include "configuration_store.h"
#include "NexText.h" #include "Nextion.h"
#include "NexHotspot.h"
#include "NexProgressBar.h"
bool NextionON = false;
char buffer[100] = {0}; char buffer[100] = {0};
char lcd_status_message[30] = WELCOME_MSG; // worst case is kana with up to 3*LCD_WIDTH+1 char lcd_status_message[30] = WELCOME_MSG; // worst case is kana with up to 3*LCD_WIDTH+1
uint8_t lcd_status_message_level = 0; uint8_t lcd_status_message_level = 0;
...@@ -2326,7 +2325,7 @@ void homePopCallback(void *ptr) { ...@@ -2326,7 +2325,7 @@ void homePopCallback(void *ptr) {
} }
void hotPopCallback(void *ptr) { void hotPopCallback(void *ptr) {
NexTouch::sendCommand("page 2"); sendCommand("page 2");
memset(buffer, 0, sizeof(buffer)); memset(buffer, 0, sizeof(buffer));
if (ptr == &hot0) { if (ptr == &hot0) {
if (degTargetHotend(0) != 0) { if (degTargetHotend(0) != 0) {
...@@ -2382,17 +2381,23 @@ void sethotPopCallback(void *ptr) { ...@@ -2382,17 +2381,23 @@ void sethotPopCallback(void *ptr) {
memset(buffer, 0, sizeof(buffer)); memset(buffer, 0, sizeof(buffer));
set1.getText(buffer, sizeof(buffer)); set1.getText(buffer, sizeof(buffer));
enqueuecommands_P(buffer); enqueuecommands_P(buffer);
NexTouch::sendCommand("page menu"); sendCommand("page menu");
lcd_setstatus(lcd_status_message); lcd_setstatus(lcd_status_message);
} }
millis_t next_lcd_update_ms; millis_t next_lcd_update_ms;
void lcd_init() { void lcd_init() {
nexInit(); NextionON = nexInit();
if (!NextionON) {
ECHO_LM(ER, "Nextion LCD not connected!");
}
else {
ECHO_LM(DB, "Nextion LCD connected!");
delay(SPLASH_SCREEN_DURATION); // wait to display the splash screen delay(SPLASH_SCREEN_DURATION); // wait to display the splash screen
NexTouch::sendCommand("page menu"); sendCommand("page menu");
lcd_setstatus(WELCOME_MSG); lcd_setstatus(WELCOME_MSG);
}
} }
static void temptoLCD(int h, int T1, int T2) { static void temptoLCD(int h, int T1, int T2) {
...@@ -2494,6 +2499,9 @@ static void coordtoLCD() { ...@@ -2494,6 +2499,9 @@ static void coordtoLCD() {
} }
void lcd_update() { void lcd_update() {
if (!NextionON) return;
millis_t ms = millis(); millis_t ms = millis();
if (ms > next_lcd_update_ms) { if (ms > next_lcd_update_ms) {
...@@ -2513,13 +2521,13 @@ void lcd_update() { ...@@ -2513,13 +2521,13 @@ void lcd_update() {
} }
void lcd_setstatus(const char* message, bool persist) { void lcd_setstatus(const char* message, bool persist) {
if (lcd_status_message_level > 0) return; if (lcd_status_message_level > 0 || !NextionON) return;
strncpy(lcd_status_message, message, 30); strncpy(lcd_status_message, message, 30);
LedStatus.setText(lcd_status_message); LedStatus.setText(lcd_status_message);
} }
void lcd_setstatuspgm(const char* message, uint8_t level) { void lcd_setstatuspgm(const char* message, uint8_t level) {
if (level >= lcd_status_message_level) { if (level >= lcd_status_message_level && NextionON) {
strncpy_P(lcd_status_message, message, 30); strncpy_P(lcd_status_message, message, 30);
lcd_status_message_level = level; lcd_status_message_level = level;
LedStatus.setText(lcd_status_message); LedStatus.setText(lcd_status_message);
......
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