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() {
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;
millis_t ms = millis();
......@@ -880,7 +880,7 @@ void get_command() {
//
while (MYSERIAL.available() > 0 && commands_in_queue < BUFSIZE) {
#ifdef NO_TIMEOUTS
#if ENABLED(NO_TIMEOUTS)
last_command_time = ms;
#endif
......@@ -905,15 +905,13 @@ void get_command() {
#endif
char *npos = strchr(command, 'N');
if (npos == NULL) npos = strchr(command, 'n');
char *apos = strchr(command, '*');
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) {
char *n2pos = strchr(command + 4, 'N');
if (n2pos == NULL) n2pos = strchr(command + 4, 'n');
if (n2pos) npos = n2pos;
}
......@@ -924,8 +922,6 @@ void get_command() {
return;
}
gcode_LastN = gcode_N;
if (apos) {
byte checksum = 0, count = 0;
while (command[count] != '*') checksum ^= command[count++];
......@@ -940,6 +936,9 @@ void get_command() {
gcode_line_error(PSTR(MSG_ERR_NO_CHECKSUM));
return;
}
gcode_LastN = gcode_N;
// if no errors, continue parsing
}
else if (apos) { // No '*' without 'N'
gcode_line_error(PSTR(MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM), false);
......@@ -949,7 +948,6 @@ void get_command() {
// Movement commands alert when stopped
if (IsStopped()) {
char *gpos = strchr(command, 'G');
if (gpos == NULL) gpos = strchr(command, 'g');
if (gpos) {
int codenum = strtol(gpos + 1, NULL, 10);
switch (codenum) {
......@@ -965,7 +963,7 @@ void get_command() {
}
// 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;
commands_in_queue += 1;
......@@ -1050,7 +1048,7 @@ bool code_has_value() {
float code_value() {
float ret;
char *e = strchr(seen_pointer, 'E'); if (e == NULL) e = strchr(seen_pointer, 'e');
char *e = strchr(seen_pointer, 'E');
if (e) {
*e = 0;
ret = strtod(seen_pointer + 1, NULL);
......@@ -1067,7 +1065,6 @@ int16_t code_value_short() { return (int16_t)strtol(seen_pointer + 1, NULL, 10);
bool code_seen(char code) {
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
}
......@@ -3554,8 +3551,9 @@ inline void gcode_G28() {
double eqnAMatrix[abl2 * 3], // "A" matrix of the linear system of equations
eqnBVector[abl2]; // "B" vector of Z points
int8_t indexIntoAB[auto_bed_leveling_grid_points][auto_bed_leveling_grid_points];
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++) {
double yProbe = front_probe_bed_position + yGridSpacing * yCount;
......@@ -3572,9 +3570,8 @@ inline void gcode_G28() {
xInc = -1;
}
// If do_topography_map is set then don't zig-zag. Just scan in one direction.
// This gets the probe points in more readable order.
if (!do_topography_map) zig = !zig;
zig = !zig;
for (int xCount = xStart; xCount != xStop; xCount += xInc) {
double xProbe = left_probe_bed_position + xGridSpacing * xCount;
......@@ -3606,6 +3603,7 @@ inline void gcode_G28() {
eqnAMatrix[probePointCounter + 0 * abl2] = xProbe;
eqnAMatrix[probePointCounter + 1 * abl2] = yProbe;
eqnAMatrix[probePointCounter + 2 * abl2] = 1;
indexIntoAB[xCount][yCount] = probePointCounter;
probePointCounter++;
......@@ -3661,7 +3659,7 @@ inline void gcode_G28() {
for (int8_t yy = auto_bed_leveling_grid_points - 1; yy >= 0; yy--) {
ECHO_S(DB);
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];
......@@ -3679,7 +3677,7 @@ inline void gcode_G28() {
for (int8_t yy = auto_bed_leveling_grid_points - 1; yy >= 0; yy--) {
ECHO_S(DB);
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;
......@@ -3697,7 +3695,7 @@ inline void gcode_G28() {
for (int8_t yy = auto_bed_leveling_grid_points - 1; yy >= 0; yy--) {
ECHO_S(DB);
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]);
probe_point.apply_rotation(inverse_bed_level_matrix);
......@@ -3718,7 +3716,7 @@ inline void gcode_G28() {
for (int8_t yy = auto_bed_leveling_grid_points - 1; yy >= 0; yy--) {
ECHO_S(DB);
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]);
probe_point.apply_rotation(inverse_bed_level_matrix);
......@@ -6321,7 +6319,7 @@ inline void gcode_M999() {
inline void gcode_T(uint8_t tmp_extruder) {
long csteps;
if (tmp_extruder >= EXTRUDERS) {
ECHO_SMV(DB, "T", tmp_extruder);
ECHO_SMV(DB, "T", (int)tmp_extruder);
ECHO_EM(" " MSG_INVALID_EXTRUDER);
}
else {
......@@ -6524,10 +6522,10 @@ inline void gcode_T(uint8_t tmp_extruder) {
if (csteps > 0) colorstep(csteps,true);
old_color = active_extruder = target_extruder;
active_driver = 0;
ECHO_LMV(DB, MSG_ACTIVE_COLOR, active_extruder);
ECHO_LMV(DB, MSG_ACTIVE_COLOR, (int)active_extruder);
#else
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 no DUAL_X_CARRIAGE
......
/**
* @file NexButton.cpp
*
* API of NexButton.
* The implementation of class NexButton.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10
* @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
......@@ -15,23 +15,11 @@
#include "NexButton.h"
/**
* Constructor,inherited NexTouch's constructor function.
*
*/
NexButton::NexButton(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop, void *pop_ptr)
:NexTouch(pid, cid, name, pop, pop_ptr)
NexButton::NexButton(uint8_t pid, uint8_t cid, const char *name)
:NexTouch(pid, cid, name)
{
}
/**
* 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)
{
String cmd;
......@@ -42,14 +30,6 @@ uint16_t NexButton::getText(char *buffer, uint16_t 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)
{
String cmd;
......@@ -60,25 +40,3 @@ bool NexButton::setText(const char *buffer)
sendCommand(cmd.c_str());
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
*
* API of NexButton.
* The definition of class NexButton.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/8/13
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
......@@ -15,24 +16,51 @@
#ifndef __NEXBUTTON_H__
#define __NEXBUTTON_H__
#ifdef __cplusplus
#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
{
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);
uint16_t getText(char *buffer, uint16_t len);
bool setText(const char *buffer);
/**
* @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);
/**
* Set text attribute of component.
*
* @param buffer - text buffer terminated with '\0'.
* @return true if success, false for failure.
*/
bool setText(const char *buffer);
};
/**
* @}
*/
#endif /* #ifdef __cplusplus */
#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>)
* @date 2015/7/10
* @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
......@@ -12,31 +12,49 @@
* published by the Free Software Foundation; either version 2 of
* 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
/*enable debug serial*/
/**
* Define DEBUG_SERIAL_ENABLE to enable debug serial.
* Comment it to disable debug serial.
*/
//#define DEBUG_SERIAL_ENABLE
/*define serial for debug*/
/**
* Define dbSerial for the output of debug messages.
*/
#define dbSerial Serial
/**
* Define nexSerial for communicate with Nextion touch panel.
*/
#define nexSerial Serial1
#ifdef DEBUG_SERIAL_ENABLE
#define dbSerialPrint(a) dbSerial.print(a)
#define dbSerialPrintln(a) dbSerial.println(a)
#define dbSerialBegin(a) dbSerial.begin(a)
#else
#define dbSerialPrint(a)
#define dbSerialPrintln(a)
#define dbSerialBegin(a)
#define dbSerialPrint(a) do{}while(0)
#define dbSerialPrintln(a) do{}while(0)
#define dbSerialBegin(a) do{}while(0)
#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
*
* API of NexHotspot.
* The implementation of class NexHotspot.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10
* @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
......@@ -15,53 +15,8 @@
#include "NexHotspot.h"
/**
* Constructor,inherited NexTouch's constructor function.
*
*/
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)
NexHotspot::NexHotspot(uint8_t pid, uint8_t cid, const char *name)
:NexTouch(pid, cid, name)
{
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
*
* API of NexHotspot.
* The definition of class NexHotspot.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/8/13
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
......@@ -15,26 +16,28 @@
#ifndef __NEXHOTSPOT_H__
#define __NEXHOTSPOT_H__
#ifdef __cplusplus
#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
{
public: /* methods */
NexHotspot(NexPid pid, NexCid cid, char *name,
NexTouchEventCb pop = NULL, void *pop_ptr = NULL,
NexTouchEventCb push = NULL, void *push_ptr = NULL);
void attachPush(NexTouchEventCb push, void *ptr = NULL);
void detachPush(void);
void attachPop(NexTouchEventCb pop, void *ptr = NULL);
void detachPop(void);
/**
* @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name);
*/
NexHotspot(uint8_t pid, uint8_t cid, const char *name);
};
/**
* @}
*/
#endif /* #ifdef __cplusplus */
#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
*
* API of NexPage.
* The implementation of class NexPage.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10
* @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
......@@ -15,21 +15,11 @@
#include "NexPage.h"
/**
* Constructor,inherited NexTouch's constructor function.
*
*/
NexPage::NexPage(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop, void *pop_ptr)
:NexTouch(pid, cid, name, pop, pop_ptr)
NexPage::NexPage(uint8_t pid, uint8_t cid, const char *name)
:NexTouch(pid, cid, name)
{
}
/**
* Change page.
*
* @retval true - success.
* @retval false - failed.
*/
bool NexPage::show(void)
{
uint8_t buffer[4] = {0};
......@@ -46,22 +36,3 @@ bool NexPage::show(void)
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
*
* API of NexPage.
* The definition of class NexPage.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/8/13
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
......@@ -15,23 +16,35 @@
#ifndef __NEXPAGE_H__
#define __NEXPAGE_H__
#ifdef __cplusplus
#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
{
public: /* methods */
NexPage(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);
*/
NexPage(uint8_t pid, uint8_t cid, const char *name);
/**
* Show itself.
*
* @return true if success, false for faileure.
*/
bool show(void);
void attachPop(NexTouchEventCb pop, void *ptr = NULL);
void detachPop(void);
};
/**
* @}
*/
#endif /* #ifdef __cplusplus */
#endif /* #ifndef __NEXPAGE_H__ */
/**
* @file NexPicture.cpp
*
* API of NexPicture.
* The implementation of class NexPicture.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10
* @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
......@@ -15,23 +15,11 @@
#include "NexPicture.h"
/**
* Constructor,inherited NexTouch's constructor function.
*
*/
NexPicture::NexPicture(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop, void *pop_ptr)
:NexTouch(pid, cid, name, pop, pop_ptr)
NexPicture::NexPicture(uint8_t pid, uint8_t cid, const char *name)
:NexTouch(pid, cid, name)
{
}
/**
* 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)
{
String cmd = String("get ");
......@@ -41,14 +29,6 @@ bool NexPicture::getPic(uint32_t *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)
{
char buf[10] = {0};
......@@ -62,24 +42,4 @@ bool NexPicture::setPic(uint32_t number)
sendCommand(cmd.c_str());
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
*
* API of NexPicture.
* The definition of class NexPicture.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/8/13
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
......@@ -15,24 +16,48 @@
#ifndef __NEXPICTURE_H__
#define __NEXPICTURE_H__
#ifdef __cplusplus
#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
{
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);
*/
NexPicture(uint8_t pid, uint8_t cid, const char *name);
void attachPop(NexTouchEventCb pop, void *ptr = NULL);
void detachPop(void);
/**
* Get picture's number.
*
* @param number - an output parameter to save picture number.
*
* @retval true - success.
* @retval false - failed.
*/
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);
};
#endif /* #ifdef __cplusplus */
/**
* @}
*/
#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
*
* API of NexProgressBar.
* The implementation of class NexProgressBar.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10
* @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
......@@ -15,23 +15,11 @@
#include "NexProgressBar.h"
/**
* Constructor,inherited NexTouch's constructor function.
*
*/
NexProgressBar::NexProgressBar(NexPid pid, NexCid cid, char *name)
:NexTouch(pid, cid, name)
NexProgressBar::NexProgressBar(uint8_t pid, uint8_t cid, const char *name)
:NexObject(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)
{
String cmd = String("get ");
......@@ -41,14 +29,6 @@ bool NexProgressBar::getValue(uint32_t *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)
{
char buf[10] = {0};
......
/**
* @file NexProgressBar.h
*
* API of NexProgressBar.
* The definition of class NexProgressBar.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/8/13
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
......@@ -15,21 +16,48 @@
#ifndef __NEXPROGRESSBAR_H__
#define __NEXPROGRESSBAR_H__
#ifdef __cplusplus
#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 */
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);
/**
* Set the value of progress bar.
*
* @param number - the value of progress bar.
*
* @retval true - success.
* @retval false - failed.
*/
bool setValue(uint32_t number);
};
#endif /* #ifdef __cplusplus */
/**
* @}
*/
#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>)
* @date 2015/7/10
* @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
......@@ -12,74 +12,33 @@
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#include "NexSlider.h"
#include "NexSlice.h"
/**
* 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)
NexSlider::NexSlider(uint8_t pid, uint8_t cid, const char *name)
:NexTouch(pid, cid, name)
{
}
/*
* 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)
bool NexSlider::getValue(uint32_t *number)
{
String cmd = String("get ");
cmd += getObjName();
cmd += ".picc";
cmd += ".val";
sendCommand(cmd.c_str());
return recvRetNumber(number);
}
/*
* Set the number of picture.
*
* @param number - the number of picture.
*
* @retval true - success.
* @retval false - failed.
*/
bool NexSlice::setPic(uint32_t number)
bool NexSlider::setValue(uint32_t number)
{
char buf[10] = {0};
String cmd;
utoa(number, buf, 10);
cmd += getObjName();
cmd += ".picc=";
cmd += ".val=";
cmd += buf;
sendCommand(cmd.c_str());
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
*
* API of NexText.
* The implementation of class NexText.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10
* @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
......@@ -12,26 +12,13 @@
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#include "NexText.h"
/**
* Constructor,inherited NexTouch's constructor function.
*
*/
NexText::NexText(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop, void *pop_ptr)
:NexTouch(pid, cid, name, pop, pop_ptr)
NexText::NexText(uint8_t pid, uint8_t cid, const char *name)
:NexTouch(pid, cid, name)
{
}
/**
* 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)
{
String cmd;
......@@ -42,14 +29,6 @@ uint16_t NexText::getText(char *buffer, uint16_t 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)
{
String cmd;
......@@ -61,14 +40,6 @@ bool NexText::setText(const char *buffer)
return recvRetCommandFinished();
}
/**
* Set the value of color.
*
* @param value - color value.
*
* @retval true - success.
* @retval false - failed.
*/
bool NexText::setColor(uint32_t value)
{
char buf[10] = {0};
......@@ -82,23 +53,3 @@ bool NexText::setColor(uint32_t value)
sendCommand(cmd.c_str());
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
*
* API of NexText.
* The definition of class NexText.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/8/13
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
......@@ -15,25 +16,46 @@
#ifndef __NEXTEXT_H__
#define __NEXTEXT_H__
#ifdef __cplusplus
#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
{
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);
*/
NexText(uint8_t pid, uint8_t cid, const char *name);
void attachPop(NexTouchEventCb pop, void *ptr = NULL);
void detachPop(void);
/**
* 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);
/**
* 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 setColor(uint32_t value);
};
#endif /* #ifdef __cplusplus */
/**
* @}
*/
#endif /* #ifndef __NEXTEXT_H__ */
/**
* @file NexTouch.cpp
*
* API of Nextion.
* The implementation of class NexTouch.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10
* @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
......@@ -12,689 +12,84 @@
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#include "NexTouch.h"
uint8_t NexTouch::__buffer[256] = {0};
/**
* Watting for Nextion's touch event.
*
* @param list - index to Nextion Components list.
*
*/
uint8_t NexTouch::mainEventLoop(NexTouch **list) {
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) {
//memset(__buffer, 0, sizeof(__buffer));
__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])
iterate(list, (NexPid)__buffer[1], (NexCid)__buffer[2], (NexEventType)__buffer[3]);
}
}
}
return 0;
}
/**
* Constructor of Nextouch.
*
* @param pid - page id.
* @param cid - component id.
* @param name - component name.
* @param pop - pop event function pointer.
* @param pop_ptr - the parameter was transmitted to pop event function pointer.
* @param push - push event function pointer.
* @param push_ptr - the parameter was transmitted to push event function pointer.
*
*/
NexTouch::NexTouch(NexPid pid, NexCid cid, char *name,
NexTouchEventCb pop, void *pop_ptr,
NexTouchEventCb push, void *push_ptr) {
this->pid = pid;
this->cid = cid;
this->name = name;
this->cbPush = push;
this->cbPop = pop;
this->__cbpop_ptr = pop_ptr;
this->__cbpush_ptr = push_ptr;
}
/**
* Get page id.
*
* @return the id of page.
*/
NexPid NexTouch::getPid(void) {
return pid;
}
/**
* Get component id.
*
* @return the id of component.
*/
NexCid NexTouch::getCid(void) {
return cid;
}
/**
* Get component name.
*
* @return the name of component.
*/
const char* NexTouch::getObjName(void) {
return name;
}
/**
* Print current object address,page id,component id,
* component name,pop event function address,push event function address.
*
*/
void NexTouch::print(void) {
dbSerialPrint("[");
dbSerialPrint((uint32_t)this);
dbSerialPrint(":");
dbSerialPrint(pid);
dbSerialPrint(",");
dbSerialPrint(cid);
dbSerialPrint(",");
if (name) {
dbSerialPrint(name);
}
else {
dbSerialPrint("(null)");
}
dbSerialPrint(",");
dbSerialPrint((uint32_t)cbPush);
dbSerialPrint(",");
dbSerialPrint((uint32_t)cbPop);
dbSerialPrintln("]");
}
void NexTouch::attachPush(NexTouchEventCb push, void *ptr) {
this->cbPush = push;
this->__cbpush_ptr = ptr;
}
void NexTouch::detachPush(void) {
this->cbPush = NULL;
this->__cbpush_ptr = NULL;
}
void NexTouch::attachPop(NexTouchEventCb pop, void *ptr) {
this->cbPop = pop;
this->__cbpop_ptr = ptr;
}
void NexTouch::detachPop(void) {
this->cbPop = NULL;
this->__cbpop_ptr = NULL;
}
void NexTouch::iterate(NexTouch **list, NexPid pid, NexCid cid, NexEventType event) {
NexTouch *e = NULL;
uint16_t i = 0;
if (NULL == list) {
return;
}
for(i = 0; (e = list[i]) != NULL; i++) {
if (e->getPid() == pid && e->getCid() == cid) {
e->print();
if (NEX_EVENT_PUSH == event) {
e->push();
}
else if (NEX_EVENT_POP == event) {
e->pop();
}
break;
}
}
}
void NexTouch::push(void) {
if (cbPush) {
cbPush(__cbpush_ptr);
}
}
void NexTouch::pop(void) {
if (cbPop) {
cbPop(__cbpop_ptr);
}
}
/**
* Command is executed successfully.
*
* @param timeout - set timeout time.
*
* @retval true - success.
* @retval false - failed.
*
*/
bool NexTouch::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;
}
/**
* Send command to Nextion.
*
* @param cmd - the string of command.
*/
void NexTouch::sendCommand(const char* cmd)
{
while (nexSerial.available()) {
nexSerial.read();
}
nexSerial.print(cmd);
nexSerial.write(0xFF);
nexSerial.write(0xFF);
nexSerial.write(0xFF);
}
/**
* 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 NexTouch::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;
}
/**
* Receive uint32_t data.
*
* @param number - save uint32_t data.
* @param timeout - set timeout time.
*
* @retval true - success.
* @retval false - failed.
*
*/
bool NexTouch::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;
}
bool NexTouch::getBrightness(uint32_t *brightness)
{
sendCommand("get dim");
return recvRetNumber(brightness);
}
/**
* Init Nextion's baudrate,page id.
*
* @retval true - success.
* @retval false - failed.
*/
bool nexInit(void)
NexTouch::NexTouch(uint8_t pid, uint8_t cid, const char *name)
:NexObject(pid, cid, name)
{
nexSerial.begin(NEXTION_BAUDRATE);
NexTouch::sendCommand("");
NexTouch::sendCommand("page 0");
delay(100);
return true;
this->__cb_push = NULL;
this->__cb_pop = NULL;
this->__cbpop_ptr = NULL;
this->__cbpush_ptr = NULL;
}
/**
* Call mainEventLoop,watting for Nextion's touch event.
*
* @param nexListenList - index to Nextion Components list.
*
* @retval false - failed.
*/
bool nexLoop(NexTouch **nexListenList)
void NexTouch::attachPush(NexTouchEventCb push, void *ptr)
{
NexTouch::mainEventLoop(nexListenList);
return false;
this->__cb_push = push;
this->__cbpush_ptr = ptr;
}
/**
* Return current page id.
*
* @param pageId - output parameter,to save page id.
*
* @retval true - success.
* @retval false - failed.
*/
bool sendCurrentPageId(uint8_t* pageId)
void NexTouch::detachPush(void)
{
bool ret = false;
uint8_t temp[5] = {0};
if (!pageId)
{
goto __return;
}
NexTouch::sendCommand("sendme");
delay(50);
nexSerial.setTimeout(500);
if (sizeof(temp) != nexSerial.readBytes((char *)temp, sizeof(temp)))
{
goto __return;
}
if (temp[0] == NEX_RET_CURRENT_PAGE_ID_HEAD
&& temp[2] == 0xFF
&& temp[3] == 0xFF
&& temp[4] == 0xFF
)
{
*pageId = temp[1];
ret = true;
}
__return:
if (ret)
{
dbSerialPrint("recvPageId :");
dbSerialPrintln(*pageId);
}
else
{
dbSerialPrintln("recvPageId err");
}
return ret;
this->__cb_push = NULL;
this->__cbpush_ptr = NULL;
}
/**
* Touch screen calibration.
*
* @retval true - success.
* @retval false - failed.
*/
bool touchCalibration(void)
void NexTouch::attachPop(NexTouchEventCb pop, void *ptr)
{
bool ret = false;
NexTouch::sendCommand("touch_j");
delay(10);
if(NexTouch::recvRetCommandFinished())
{
dbSerialPrintln("TouchCalibration ok ");
ret = true;
}
else
{
dbSerialPrintln("TouchCalibration err ");
}
return ret;
this->__cb_pop = pop;
this->__cbpop_ptr = ptr;
}
/**
* Disable all touch hot.
*
* @retval true - success.
* @retval false - failed.
*/
bool disableTouchFocus(void)
void NexTouch::detachPop(void)
{
bool ret = false;
NexTouch::sendCommand("cle_c");
delay(10);
if(NexTouch::recvRetCommandFinished())
{
dbSerialPrintln("disableTouchFocus ok ");
ret = true;
}
else
{
dbSerialPrintln("disableTouchFocus err ");
}
return ret;
this->__cb_pop = NULL;
this->__cbpop_ptr = NULL;
}
/**
* Pause serial instruction execution.
*
* @retval true - success.
* @retval false - failed.
*/
bool pauseSerialCommand(void)
void NexTouch::push(void)
{
bool ret = false;
NexTouch::sendCommand("com_stop");
delay(10);
if(NexTouch::recvRetCommandFinished())
if (__cb_push)
{
dbSerialPrintln("pauseSerialCommand ok ");
ret = true;
__cb_push(__cbpush_ptr);
}
else
{
dbSerialPrintln("pauseSerialCommand err ");
}
return ret;
}
/**
* Recovery serial instruction execution.
*
* @retval true - success.
* @retval false - failed.
*/
bool recoverySerialCommand(void)
{
bool ret = false;
NexTouch::sendCommand("com_star");
delay(10);
if(NexTouch::recvRetCommandFinished())
{
dbSerialPrintln("recoverySerialCommand ok ");
ret = true;
}
else
{
dbSerialPrintln("recoverySerialCommand err ");
}
return ret;
}
/**
* Set current backlight brightness value.
*
* @param dimValue - current backlight brightness value.
*
* @retval true - success.
* @retval false - failed.
*/
bool setCurrentBrightness(uint8_t dimValue)
void NexTouch::pop(void)
{
bool ret = false;
char buf[10] = {0};
String cmd;
utoa(dimValue, buf, 10);
cmd += "dim=";
cmd += buf;
NexTouch::sendCommand(cmd.c_str());
delay(10);
if(NexTouch::recvRetCommandFinished())
{
dbSerialPrint("setCurrentBrightness[ ");
dbSerialPrint(dimValue);
dbSerialPrintln("]ok ");
ret = true;
}
else
if (__cb_pop)
{
dbSerialPrintln("setCurrentBrightness err ");
__cb_pop(__cbpop_ptr);
}
return ret;
}
/**
* Set default backlight brightness value.
*
* @param dimDefaultValue - default backlight brightness value.
*
* @retval true - success.
* @retval false - failed.
*/
bool setDefaultBrightness(uint8_t dimDefaultValue)
void NexTouch::iterate(NexTouch **list, uint8_t pid, uint8_t cid, int32_t event)
{
bool ret = false;
char buf[10] = {0};
String cmd;
utoa(dimDefaultValue, buf, 10);
cmd += "dims=";
cmd += buf;
NexTouch::sendCommand(cmd.c_str());
delay(10);
NexTouch *e = NULL;
uint16_t i = 0;
if(NexTouch::recvRetCommandFinished())
{
dbSerialPrint("setDefaultBrightness[");
dbSerialPrint(dimDefaultValue);
dbSerialPrintln("]ok");
ret = true;
}
else
if (NULL == list)
{
dbSerialPrintln("setDefaultBrightness err ");
return;
}
return ret;
}
/**
* Set device in sleep mode.
*
* @param mode - 1:into sleep mode,0:exit sleep mode.
*
* @retval true - success.
* @retval false - failed.
*/
bool sleepMode(uint8_t mode)
{
bool ret = false;
char buf[10] = {0};
String cmd;
if(mode != 0 && mode != 1)
{
dbSerialPrintln("mode input ok ");
return ret;
}
utoa(mode, buf, 10);
cmd += "sleep=";
cmd += buf;
NexTouch::sendCommand(cmd.c_str());
delay(10);
if(NexTouch::recvRetCommandFinished())
{
dbSerialPrintln("sleepMode ok ");
ret = true;
}
else
{
dbSerialPrintln("sleepMode err ");
}
return ret;
}
/**
* Set current baudrate.
*
* @param baudrate - current baudrate,it supports 2400,4800,9600,19200,38400,57600,115200.
*
* @retval true - success.
* @retval false - failed.
*/
bool setCurrentBaudrate(uint32_t baudrate)
{
bool ret = false;
char buf[10] = {0};
String cmd;
utoa(baudrate, buf, 10);
cmd += "baud=";
cmd += buf;
NexTouch::sendCommand(cmd.c_str());
delay(10);
if(NexTouch::recvRetCommandFinished())
{
dbSerialPrintln("setCurrentBaudrate ok ");
ret = true;
}
else
{
dbSerialPrintln("setCurrentBaudrate err ");
for(i = 0; (e = list[i]) != NULL; i++)
{
if (e->getObjPid() == pid && e->getObjCid() == cid)
{
e->printObjInfo();
if (NEX_EVENT_PUSH == event)
{
e->push();
}
else if (NEX_EVENT_POP == event)
{
e->pop();
}
break;
}
}
return ret;
}
/**
* Set default baudrate.
*
* @param defaultBaudrate - default baudrate,it supports 2400,4800,9600,19200,38400,57600,115200.
*
* @retval true - success.
* @retval false - failed.
*/
bool setDefaultBaudrate(uint32_t defaultBaudrate)
{
bool ret = false;
char buf[10] = {0};
String cmd;
utoa(defaultBaudrate, buf, 10);
cmd += "bauds=";
cmd += buf;
NexTouch::sendCommand(cmd.c_str());
delay(10);
if(NexTouch::recvRetCommandFinished())
{
dbSerialPrintln("setDefaultBaudrate ok ");
ret = true;
}
else
{
dbSerialPrintln("setDefaultBaudrate err ");
}
return ret;
}
/**
* @file NexTouch.h
*
* API of Nextion.
* The definition of class NexTouch.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/8/13
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/7/10
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
......@@ -15,107 +16,101 @@
#ifndef __NEXTOUCH_H__
#define __NEXTOUCH_H__
#ifdef __cplusplus
#include <Arduino.h>
#include "NexSerialConfig.h"
typedef uint8_t NexPid;
typedef uint8_t NexCid;
#include <Arduino.h>
#include "NexConfig.h"
#include "NexObject.h"
typedef enum {
NEX_EVENT_POP = 0x00,
NEX_EVENT_PUSH = 0x01,
NEX_EVENT_NULL
} NexEventType;
/**
* @addtogroup TouchEvent
* @{
*/
/*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)
/**
* 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);
/**
* 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 */
static uint8_t mainEventLoop(NexTouch **list);
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: /* static methods */
static void iterate(NexTouch **list, uint8_t pid, uint8_t cid, int32_t event);
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);
const char *getObjName(void);
void print(void);
protected: /* static methods */
static bool setBrightness(uint32_t brightness);
static bool getBrightness(uint32_t *brightness);
/**
* @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name);
*/
NexTouch(uint8_t pid, uint8_t cid, const char *name);
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);
/**
* Detach an callback function.
*
* @return none.
*/
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 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 */
void push(void);
void pop(void);
private: /* static data */
static uint8_t __buffer[256];
private: /* data */
NexPid pid; /* Page ID */
NexCid cid; /* Component ID */
char *name; /* An unique name */
NexTouchEventCb cbPush;
NexTouchEventCb __cb_push;
void *__cbpush_ptr;
NexTouchEventCb cbPop;
NexTouchEventCb __cb_pop;
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__ */
/**
* @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>)
* @date 2015/7/10
* @date 2015/8/12
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
......@@ -12,27 +14,23 @@
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#ifndef __NEXTION_H__
#define __NEXTION_H__
#ifndef __NEXSLICE_H__
#define __NEXSLICE_H__
#ifdef __cplusplus
#include "Arduino.h"
#include "NexConfig.h"
#include "NexTouch.h"
#include "NexHardware.h"
/**
* NexSlice,subclass of NexTouch,provides simple methods to control slice component.
*
*/
class NexSlice: public NexTouch
{
public: /* methods */
NexSlice(NexPid pid, NexCid cid, char *name, NexTouchEventCb pop = NULL, void *pop_ptr = NULL);
void attachPop(NexTouchEventCb pop, void *ptr = NULL);
void detachPop(void);
bool getPic(uint32_t *number);
bool setPic(uint32_t number);
};
#include "NexButton.h"
//#include "NexCrop.h"
//#include "NexGauge.h"
#include "NexHotspot.h"
#include "NexPage.h"
#include "NexPicture.h"
#include "NexProgressBar.h"
#include "NexSlider.h"
#include "NexText.h"
#include "NexWaveform.h"
#endif /* #ifdef __cplusplus */
#endif /* #ifndef __NEXSLICE_H__ */
#endif /* #ifndef __NEXTION_H__ */
......@@ -567,9 +567,9 @@ float junction_deviation = 0.1;
block->steps[Z_AXIS] = labs(dz);
#elif ENABLED(COREXZ)
// 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[C_AXIS] = labs(dx - dz);
block->steps[C_AXIS] = labs(dx + 3 * dz);
#else
// default non-h-bot planning
block->steps[X_AXIS] = labs(dx);
......@@ -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 (dy < 0) db |= BIT(Y_AXIS);
if (dz < 0) db |= BIT(Z_HEAD); // ...and Z
if (dx + 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(A_AXIS); // Motor A direction
if (dx + 3 * dz < 0) db |= BIT(C_AXIS); // Motor B direction
#else
if (dx < 0) db |= BIT(X_AXIS);
if (dy < 0) db |= BIT(Y_AXIS);
......@@ -752,8 +752,8 @@ float junction_deviation = 0.1;
delta_mm[X_HEAD] = dx / axis_steps_per_unit[A_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[A_AXIS] = (dx + dz) / axis_steps_per_unit[A_AXIS];
delta_mm[C_AXIS] = (dx - dz) / axis_steps_per_unit[C_AXIS];
delta_mm[A_AXIS] = (dx - 3 * dz) / axis_steps_per_unit[A_AXIS];
delta_mm[C_AXIS] = (dx + 3 * dz) / axis_steps_per_unit[C_AXIS];
#else
float delta_mm[4];
delta_mm[X_AXIS] = dx / axis_steps_per_unit[X_AXIS];
......
......@@ -2257,10 +2257,9 @@ char *ftostr52(const float &x) {
#include "temperature.h"
#include "stepper.h"
#include "configuration_store.h"
#include "NexText.h"
#include "NexHotspot.h"
#include "NexProgressBar.h"
#include "Nextion.h"
bool NextionON = false;
char buffer[100] = {0};
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;
......@@ -2326,7 +2325,7 @@ void homePopCallback(void *ptr) {
}
void hotPopCallback(void *ptr) {
NexTouch::sendCommand("page 2");
sendCommand("page 2");
memset(buffer, 0, sizeof(buffer));
if (ptr == &hot0) {
if (degTargetHotend(0) != 0) {
......@@ -2382,17 +2381,23 @@ void sethotPopCallback(void *ptr) {
memset(buffer, 0, sizeof(buffer));
set1.getText(buffer, sizeof(buffer));
enqueuecommands_P(buffer);
NexTouch::sendCommand("page menu");
sendCommand("page menu");
lcd_setstatus(lcd_status_message);
}
millis_t next_lcd_update_ms;
void lcd_init() {
nexInit();
delay(SPLASH_SCREEN_DURATION); // wait to display the splash screen
NexTouch::sendCommand("page menu");
lcd_setstatus(WELCOME_MSG);
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
sendCommand("page menu");
lcd_setstatus(WELCOME_MSG);
}
}
static void temptoLCD(int h, int T1, int T2) {
......@@ -2494,6 +2499,9 @@ static void coordtoLCD() {
}
void lcd_update() {
if (!NextionON) return;
millis_t ms = millis();
if (ms > next_lcd_update_ms) {
......@@ -2513,13 +2521,13 @@ void lcd_update() {
}
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);
LedStatus.setText(lcd_status_message);
}
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);
lcd_status_message_level = level;
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