diff --git a/NexButton.cpp b/NexButton.cpp index 37aa3a9d..5d92d3ce 100755 --- a/NexButton.cpp +++ b/NexButton.cpp @@ -5,6 +5,8 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -15,16 +17,27 @@ #include "NexButton.h" -NexButton::NexButton(uint8_t pid, uint8_t cid, const char *name) - :NexTouch(pid, cid, name) +NexButton::NexButton(uint8_t pid, uint8_t cid, const char *name, const NexObject* page) + :NexTouch(pid, cid, name, page) { } -uint16_t NexButton::getText(char *buffer, uint16_t len) +bool NexButton::getText(String &str) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); + cmd += ".txt"; + sendCommand(cmd.c_str()); + return recvRetString(str); +} + + +bool NexButton::getText(char *buffer, uint16_t &len) +{ + String cmd; + cmd += "get "; + getObjGlobalPageName(cmd); cmd += ".txt"; sendCommand(cmd.c_str()); return recvRetString(buffer,len); @@ -33,7 +46,7 @@ uint16_t NexButton::getText(char *buffer, uint16_t len) bool NexButton::setText(const char *buffer) { String cmd; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".txt=\""; cmd += buffer; cmd += "\""; @@ -46,7 +59,7 @@ uint32_t NexButton::Get_background_color_bco(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -58,14 +71,14 @@ bool NexButton::Set_background_color_bco(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco="; cmd += buf; sendCommand(cmd.c_str()); cmd=""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -74,7 +87,7 @@ uint32_t NexButton::Get_press_background_color_bco2(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco2"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -86,14 +99,14 @@ bool NexButton::Set_press_background_color_bco2(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco2="; cmd += buf; sendCommand(cmd.c_str()); cmd=""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -102,7 +115,7 @@ uint32_t NexButton::Get_font_color_pco(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pco"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -114,14 +127,14 @@ bool NexButton::Set_font_color_pco(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pco="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -130,7 +143,7 @@ uint32_t NexButton::Get_press_font_color_pco2(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pco2"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -142,14 +155,14 @@ bool NexButton::Set_press_font_color_pco2(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pco2="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -158,7 +171,7 @@ uint32_t NexButton::Get_place_xcen(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".xcen"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -170,14 +183,14 @@ bool NexButton::Set_place_xcen(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".xcen="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -186,7 +199,7 @@ uint32_t NexButton::Get_place_ycen(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".ycen"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -198,14 +211,14 @@ bool NexButton::Set_place_ycen(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".ycen="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -214,7 +227,7 @@ uint32_t NexButton::getFont(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".font"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -226,14 +239,14 @@ bool NexButton::setFont(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".font="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -242,7 +255,7 @@ uint32_t NexButton::Get_background_cropi_picc(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".picc"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -254,14 +267,14 @@ bool NexButton::Set_background_crop_picc(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".picc="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -270,7 +283,7 @@ uint32_t NexButton::Get_press_background_crop_picc2(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".picc2"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -282,14 +295,14 @@ bool NexButton::Set_press_background_crop_picc2(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".picc2="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -298,7 +311,7 @@ uint32_t NexButton::Get_background_image_pic(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pic"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -310,14 +323,14 @@ bool NexButton::Set_background_image_pic(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pic="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -326,7 +339,7 @@ uint32_t NexButton::Get_press_background_image_pic2(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pic2"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -338,14 +351,14 @@ bool NexButton::Set_press_background_image_pic2(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pic2="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } diff --git a/NexButton.h b/NexButton.h index 66d01c70..1e827a32 100755 --- a/NexButton.h +++ b/NexButton.h @@ -5,6 +5,7 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n @@ -37,18 +38,32 @@ class NexButton: public NexTouch public: /* methods */ /** - * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name); + * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); */ - NexButton(uint8_t pid, uint8_t cid, const char *name); + NexButton(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); + + /* + * Get text attribute of component. + * + * @param str - String storing text returned. + * + * @retval true - success. + * @retval false - failed. + * + */ + bool getText(String &str); /** * Get text attribute of component. * * @param buffer - buffer storing text returned. - * @param len - length of buffer. - * @return The real length of text returned. + * @param len - in buffer len / out saved string len excluding null char. + * + * @retval true - success. + * @retval false - failed. */ - uint16_t getText(char *buffer, uint16_t len); + bool getText(char *buffer, uint16_t &len); + /** * Set text attribute of component. diff --git a/NexCheckbox.cpp b/NexCheckbox.cpp index 5ba205d0..4b03b47d 100755 --- a/NexCheckbox.cpp +++ b/NexCheckbox.cpp @@ -5,6 +5,8 @@ * * @author huang xiaoming (email:) * @date 2016/9/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -14,15 +16,15 @@ */ #include "NexCheckbox.h" -NexCheckbox::NexCheckbox(uint8_t pid, uint8_t cid, const char *name) - :NexTouch(pid, cid, name) +NexCheckbox::NexCheckbox(uint8_t pid, uint8_t cid, const char *name, const NexObject* page) + :NexTouch(pid, cid, name, page) { } uint32_t NexCheckbox::getValue(uint32_t *number) { String cmd = String("get "); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".val"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -34,7 +36,7 @@ bool NexCheckbox::setValue(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".val="; cmd += buf; @@ -46,7 +48,7 @@ uint32_t NexCheckbox::Get_background_color_bco(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -58,14 +60,14 @@ bool NexCheckbox::Set_background_color_bco(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco="; cmd += buf; sendCommand(cmd.c_str()); cmd=""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -74,7 +76,7 @@ uint32_t NexCheckbox::Get_font_color_pco(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pco"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -86,14 +88,14 @@ bool NexCheckbox::Set_font_color_pco(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pco="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } \ No newline at end of file diff --git a/NexCheckbox.h b/NexCheckbox.h index d3982863..23e848f7 100755 --- a/NexCheckbox.h +++ b/NexCheckbox.h @@ -5,6 +5,7 @@ * * @author huang xiaoming (email:) * @date 2016/9/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n @@ -37,9 +38,9 @@ class NexCheckbox: public NexTouch public: /* methods */ /** - * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name); + * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); */ - NexCheckbox(uint8_t pid, uint8_t cid, const char *name); + NexCheckbox(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); /** * Get val attribute of component diff --git a/NexConfig.h b/NexConfig.h index aa095d31..58b6ce12 100644 --- a/NexConfig.h +++ b/NexConfig.h @@ -5,6 +5,8 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -20,31 +22,54 @@ * @{ */ +/** + * Define STD_SUPPORT to enable c++ std templates usage like std::vector + * +*/ +// #define STD_SUPPORT + /** - * Define DEBUG_SERIAL_ENABLE to enable debug serial. + * Define NEX_DEBUG_SERIAL_ENABLE to enable debug serial. * Comment it to disable debug serial. */ -#define DEBUG_SERIAL_ENABLE +// #define NEX_DEBUG_SERIAL_ENABLE /** * Define dbSerial for the output of debug messages. + * it is resonsibility of main program to initialize debug serial port (begin(...) */ -#define dbSerial Serial +//#define dbSerial Serial /** * Define nexSerial for communicate with Nextion touch panel. + * Define NEX_SOFTWARE_SERIAL if software serial used + * NodeMcu/Esp8266 can use harware serial (Serial) but it uses same serial as usb communication and + * during SW upload NodeMcu RX pin must be disconnected from Nextion */ -#define nexSerial Serial2 +#define NEX_SOFTWARE_SERIAL +#ifndef NEX_SOFTWARE_SERIAL +// hardware Serial port +#define nexSerial Serial +#else +// NodeMcu / Esp8266 Softwareserial if usb port used for debug +// NodeMcu board pin numbers not match with Esp8266 pin numbers use NodeMcu Pin number definitions (pins_arduino.h) +#define NEX_RX D2 +#define NEX_TX D1 +#endif -#ifdef DEBUG_SERIAL_ENABLE +#ifdef NEX_DEBUG_SERIAL_ENABLE #define dbSerialPrint(a) dbSerial.print(a) #define dbSerialPrintln(a) dbSerial.println(a) #define dbSerialBegin(a) dbSerial.begin(a) +#define dbSerialPrintByte(a) {if(a<10)dbSerial.print(0);dbSerial.print((unsigned char)a,HEX);} +#define dbSerialPrintlnByte(a) {if(a<10)dbSerial.print(0);dbSerial.println((unsigned char)a,HEX);} #else -#define dbSerialPrint(a) do{}while(0) -#define dbSerialPrintln(a) do{}while(0) -#define dbSerialBegin(a) do{}while(0) +#define dbSerialPrint(a) do{}while(0) +#define dbSerialPrintln(a) do{}while(0) +#define dbSerialBegin(a) do{}while(0) +#define dbSerialPrintByte(a) do{}while(0) +#define dbSerialPrintlnByte(a) do{}while(0) #endif /** diff --git a/NexCrop.cpp b/NexCrop.cpp index d8a34725..087e7546 100755 --- a/NexCrop.cpp +++ b/NexCrop.cpp @@ -5,6 +5,8 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -15,15 +17,15 @@ #include "NexCrop.h" -NexCrop::NexCrop(uint8_t pid, uint8_t cid, const char *name) - :NexTouch(pid, cid, name) +NexCrop::NexCrop(uint8_t pid, uint8_t cid, const char *name, const NexObject* page) + :NexTouch(pid, cid, name, page) { } bool NexCrop::Get_background_crop_picc(uint32_t *number) { String cmd = String("get "); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".picc"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -35,7 +37,7 @@ bool NexCrop::Set_background_crop_picc(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".picc="; cmd += buf; @@ -46,7 +48,7 @@ bool NexCrop::Set_background_crop_picc(uint32_t number) bool NexCrop::getPic(uint32_t *number) { String cmd = String("get "); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".picc"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -58,7 +60,7 @@ bool NexCrop::setPic(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".picc="; cmd += buf; diff --git a/NexCrop.h b/NexCrop.h index 2ce13426..350c5880 100755 --- a/NexCrop.h +++ b/NexCrop.h @@ -5,6 +5,7 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n @@ -32,9 +33,9 @@ class NexCrop: public NexTouch public: /* methods */ /** - * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name); + * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); */ - NexCrop(uint8_t pid, uint8_t cid, const char *name); + NexCrop(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); /** * Get the number of picture. diff --git a/NexDualStateButton.cpp b/NexDualStateButton.cpp index 7f2e5d03..270fa9f1 100755 --- a/NexDualStateButton.cpp +++ b/NexDualStateButton.cpp @@ -5,6 +5,8 @@ * * @author huang xianming (email:) * @date 2015/11/11 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -15,15 +17,15 @@ #include "NexDualStateButton.h" -NexDSButton::NexDSButton(uint8_t pid, uint8_t cid, const char *name) - :NexTouch(pid, cid, name) +NexDSButton::NexDSButton(uint8_t pid, uint8_t cid, const char *name, const NexObject* page) + :NexTouch(pid, cid, name, page) { } bool NexDSButton::getValue(uint32_t *number) { String cmd = String("get "); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".val"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -35,7 +37,7 @@ bool NexDSButton::setValue(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".val="; cmd += buf; @@ -43,11 +45,22 @@ bool NexDSButton::setValue(uint32_t number) return recvRetCommandFinished(); } -uint16_t NexDSButton::getText(char *buffer, uint16_t len) +bool NexDSButton::getText(String &str) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); + cmd += ".txt"; + sendCommand(cmd.c_str()); + return recvRetString(str); +} + + +bool NexDSButton::getText(char *buffer, uint16_t &len) +{ + String cmd; + cmd += "get "; + getObjGlobalPageName(cmd); cmd += ".txt"; sendCommand(cmd.c_str()); return recvRetString(buffer,len); @@ -56,7 +69,7 @@ uint16_t NexDSButton::getText(char *buffer, uint16_t len) bool NexDSButton::setText(const char *buffer) { String cmd; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".txt=\""; cmd += buffer; cmd += "\""; @@ -68,7 +81,7 @@ uint32_t NexDSButton::Get_state0_color_bco0(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco0"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -80,14 +93,14 @@ bool NexDSButton::Set_state0_color_bco0(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco0="; cmd += buf; sendCommand(cmd.c_str()); cmd=""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -96,7 +109,7 @@ uint32_t NexDSButton::Get_state1_color_bco1(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco1"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -108,14 +121,14 @@ bool NexDSButton::Set_state1_color_bco1(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco1="; cmd += buf; sendCommand(cmd.c_str()); cmd=""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -124,7 +137,7 @@ uint32_t NexDSButton::Get_font_color_pco(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pco"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -136,14 +149,14 @@ bool NexDSButton::Set_font_color_pco(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pco="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -152,7 +165,7 @@ uint32_t NexDSButton::Get_place_xcen(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".xcen"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -164,14 +177,14 @@ bool NexDSButton::Set_place_xcen(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".xcen="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -180,7 +193,7 @@ uint32_t NexDSButton::Get_place_ycen(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".ycen"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -192,14 +205,14 @@ bool NexDSButton::Set_place_ycen(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".ycen="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -208,7 +221,7 @@ uint32_t NexDSButton::getFont(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".font"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -220,14 +233,14 @@ bool NexDSButton::setFont(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".font="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -236,7 +249,7 @@ uint32_t NexDSButton::Get_state0_crop_picc0(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".picc0"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -248,14 +261,14 @@ bool NexDSButton::Set_state0_crop_picc0(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".picc0="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -264,7 +277,7 @@ uint32_t NexDSButton::Get_state1_crop_picc1(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".picc1"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -276,14 +289,14 @@ bool NexDSButton::Set_state1_crop_picc1(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".picc1="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -292,7 +305,7 @@ uint32_t NexDSButton::Get_state0_image_pic0(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pic0"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -304,14 +317,14 @@ bool NexDSButton::Set_state0_image_pic0(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pic0="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -320,7 +333,7 @@ uint32_t NexDSButton::Get_state1_image_pic1(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pic1"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -332,14 +345,14 @@ bool NexDSButton::Set_state1_image_pic1(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pic1="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } diff --git a/NexDualStateButton.h b/NexDualStateButton.h index 428baeb8..d0d5e159 100755 --- a/NexDualStateButton.h +++ b/NexDualStateButton.h @@ -5,7 +5,7 @@ * * @author huang xianming (email:) * @date 2015/11/11 - * + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n @@ -37,9 +37,9 @@ class NexDSButton: public NexTouch { public: /* methods */ /** - * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name); + * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); */ - NexDSButton(uint8_t pid, uint8_t cid, const char *name); + NexDSButton(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); /** * Get number attribute of component. @@ -57,14 +57,27 @@ class NexDSButton: public NexTouch */ bool setValue(uint32_t number); + /* + * Get text attribute of component. + * + * @param str - String storing text returned. + * + * @retval true - success. + * @retval false - failed. + * + */ + bool getText(String &str); + /** * Get text attribute of component. * * @param buffer - buffer storing text returned. - * @param len - length of buffer. - * @return The real length of text returned. + * @param len - in buffer len / out saved string len excluding null char. + * + * @retval true - success. + * @retval false - failed. */ - uint16_t getText(char *buffer, uint16_t len); + bool getText(char *buffer, uint16_t &len); /** * Set text attribute of component. diff --git a/NexGauge.cpp b/NexGauge.cpp index 4f294fbb..002e0d91 100755 --- a/NexGauge.cpp +++ b/NexGauge.cpp @@ -5,6 +5,8 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -15,15 +17,15 @@ #include "NexGauge.h" -NexGauge::NexGauge(uint8_t pid, uint8_t cid, const char *name) - :NexObject(pid, cid, name) +NexGauge::NexGauge(uint8_t pid, uint8_t cid, const char *name, const NexObject* page) + :NexObject(pid, cid, name, page) { } bool NexGauge::getValue(uint32_t *number) { String cmd = String("get "); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".val"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -35,7 +37,7 @@ bool NexGauge::setValue(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".val="; cmd += buf; @@ -47,7 +49,7 @@ uint32_t NexGauge::Get_background_color_bco(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -59,14 +61,14 @@ bool NexGauge::Set_background_color_bco(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco="; cmd += buf; sendCommand(cmd.c_str()); cmd=""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -75,7 +77,7 @@ uint32_t NexGauge::Get_font_color_pco(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pco"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -87,14 +89,14 @@ bool NexGauge::Set_font_color_pco(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pco="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -103,7 +105,7 @@ uint32_t NexGauge::Get_pointer_thickness_wid(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".wid"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -115,14 +117,14 @@ bool NexGauge::Set_pointer_thickness_wid(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".wid="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -131,7 +133,7 @@ uint32_t NexGauge::Get_background_cropi_picc(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".picc"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -143,14 +145,14 @@ bool NexGauge::Set_background_crop_picc(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".picc="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } diff --git a/NexGauge.h b/NexGauge.h index 10796abf..19f17554 100755 --- a/NexGauge.h +++ b/NexGauge.h @@ -5,6 +5,7 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n @@ -31,9 +32,9 @@ class NexGauge: public NexObject { public: /* methods */ /** - * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name); + * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); */ - NexGauge(uint8_t pid, uint8_t cid, const char *name); + NexGauge(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); /** * Get the value of gauge. diff --git a/NexHardware.cpp b/NexHardware.cpp index 1f82a8bd..f10b811f 100644 --- a/NexHardware.cpp +++ b/NexHardware.cpp @@ -5,6 +5,8 @@ * * @author Wu Pengfei (email:) * @date 2015/8/11 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -14,26 +16,57 @@ */ #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) + +#ifdef NEX_SOFTWARE_SERIAL +#include +SoftwareSerial nexSerial(NEX_RX,NEX_TX); +#endif + +#define NEX_RET_EVENT_NEXTION_STARTUP (0x00) //Returned when Nextion has started or reset +#define NEX_RET_EVENT_TOUCH_HEAD (0x65) //Returned when Touch occurs and component’s corresponding Send Component ID is checked in the users HMI design. +#define NEX_RET_CURRENT_PAGE_ID_HEAD (0x66) //Returned when the sendme command is used. +#define NEX_RET_EVENT_POSITION_HEAD (0x67) //Returned when sendxy=1 and not in sleep mode +#define NEX_RET_EVENT_SLEEP_POSITION_HEAD (0x68) //Returned when sendxy=1 and in sleep mode +#define NEX_RET_STRING_HEAD (0x70) //Returned when using get command for a string. +#define NEX_RET_NUMBER_HEAD (0x71) //Returned when get command to return a number 4 byte 32-bit value in little endian order. +#define NEX_RET_AUTOMATIC_SLEEP (0x86) //Returned when Nextion enters sleep automatically Using sleep=1 will not return an 0x86 +#define NEX_RET_AUTOMATIC_WAKE_UP (0x87) //Returned when Nextion leaves sleep automatically Using sleep=0 will not return an 0x87 +#define NEX_RET_EVENT_NEXTION_READY (0x88) //Returned when Nextion has powered up and is now initialized successfully +#define NEX_RET_START_SD_UPGRADE (0x89) //Returned when power on detects inserted microSD and begins Upgrade by microSD process +#define Nex_RET_TRANSPARENT_DATA_FINISHED (0xFD) //Returned when all requested bytes of Transparent Data mode have been received, and is now leaving transparent data mode +#define Nex_RET_TRANSPARENT_DATA_READY (0xFE) //Returned when requesting Transparent Data mode, and device is now ready to begin receiving the specified quantity of data + +#define NEX_RET_INVALID_CMD (0x00) //Returned when instruction sent by user has failed +#define NEX_RET_CMD_FINISHED_OK (0x01) //Returned when instruction sent by user was successful +#define NEX_RET_INVALID_COMPONENT_ID (0x02) //Returned when invalid Component ID or name was used +#define NEX_RET_INVALID_PAGE_ID (0x03) //Returned when invalid Page ID or name was used +#define NEX_RET_INVALID_PICTURE_ID (0x04) //Returned when invalid Picture ID was used +#define NEX_RET_INVALID_FONT_ID (0x05) //Returned when invalid Font ID was used +#define NEX_RET_INVALID_FILE_OPERATION (0x06) //Returned when File operation fails +#define NEX_RET_INVALID_CRC (0x09) //Returned when Instructions with CRC validation fails their CRC check +#define NEX_RET_INVALID_BAUD (0x11) //Returned when invalid Baud rate was used +#define NEX_RET_INVALID_WAVEFORM_ID_OR_CHANNEL_NRO (0x12) //Returned when invalid Waveform ID or Channel # was used +#define NEX_RET_INVALID_VARIABLE_OR_ATTRIBUTE (0x1A) //Returned when invalid Variable name or invalid attribute was used +#define NEX_RET_INVALID_VARIABLE_OPERATION (0x1B) //Returned when Operation of Variable is invalid. ie: Text assignment t0.txt=abc or t0.txt=23, Numeric assignment j0.val=”50″ or j0.val=abc +#define NEX_RET_ASSIGNMENT_FAILED_TO_ASSIGN (0x1C) //Returned when attribute assignment failed to assign +#define NEX_RET_EEPROM_OPERATION_FAILED (0x1D) //Returned when an EEPROM Operation has failed +#define NEX_RET_INVALID_QUANTITY_OF_PARAMETERS (0x1E) //Returned when the number of instruction parameters is invalid +#define NEX_RET_IO_OPERATION_FAILED (0x1F) //Returned when an IO operation has failed +#define NEX_RET_ESCAPE_CHARACTER_INVALID (0x20) //Returned when an unsupported escape character is used +#define NEX_RET_VARIABLE_NAME_TOO_LONG (0x23) //Returned when variable name is too long. Max length is 29 characters: 14 for page + “.” + 14 for component. +#define NEX_RET_SERIAL_BUFFER_OVERFLOW (0x24) //Returned when a Serial Buffer overflow occurs Buffer will continue to receive the current instruction, all previous instructions are lost. + +void (*nextionStartupCallback)() =nullptr; +void (*currentPageIdCallback)(uint8_t) =nullptr; +void (*touchCoordinateCallback)(uint16_t,uint16_t,uint8_t)=nullptr; +void(*touchEventInSleepModeCallback)(uint16_t,uint16_t,uint8_t) =nullptr; +void (*automaticSleepCallback)() =nullptr; +void (*automaticWakeUpCallback)() =nullptr; +void (*nextionReadyCallback)() =nullptr; +void (*startSdUpgradeCallback)() =nullptr; /* - * Receive uint32_t data. + * Receive unt32_t data. * * @param number - save uint32_t data. * @param timeout - set timeout time. @@ -42,7 +75,7 @@ * @retval false - failed. * */ -bool recvRetNumber(uint32_t *number, uint32_t timeout) +bool recvRetNumber(uint32_t *number, size_t timeout) { bool ret = false; uint8_t temp[8] = {0}; @@ -52,8 +85,7 @@ bool recvRetNumber(uint32_t *number, uint32_t timeout) goto __return; } - nexSerial.setTimeout(timeout); - if (sizeof(temp) != nexSerial.readBytes((char *)temp, sizeof(temp))) + if (sizeof(temp) != readBytes(temp, sizeof(temp), timeout)) { goto __return; } @@ -64,7 +96,7 @@ bool recvRetNumber(uint32_t *number, uint32_t timeout) && temp[7] == 0xFF ) { - *number = ((uint32_t)temp[4] << 24) | ((uint32_t)temp[3] << 16) | (temp[2] << 8) | (temp[1]); + *number = ((uint32_t)temp[4] << 24) | ((uint32_t)temp[3] << 16) | ((uint32_t)temp[2] << 8) | (temp[1]); ret = true; } @@ -83,37 +115,82 @@ bool recvRetNumber(uint32_t *number, uint32_t timeout) return ret; } - /* - * Receive string data. + * Receive int32_t data. * - * @param buffer - save string data. - * @param len - string buffer length. + * @param number - save int32_t data. * @param timeout - set timeout time. * - * @return the length of string buffer. + * @retval true - success. + * @retval false - failed. * */ -uint16_t recvRetString(char *buffer, uint16_t len, uint32_t timeout) +bool recvRetNumber(int32_t *number, size_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; + bool ret = false; + uint8_t temp[8] = {0}; - if (!buffer || len == 0) + if (!number) { goto __return; } - start = millis(); - while (millis() - start <= timeout) + if (sizeof(temp) != readBytes(temp, sizeof(temp),timeout)) + { + goto __return; + } + + if (temp[0] == NEX_RET_NUMBER_HEAD + && temp[5] == 0xFF + && temp[6] == 0xFF + && temp[7] == 0xFF + ) + { + *number = ((int32_t)temp[4] << 24) | ((int32_t)temp[3] << 16) | ((int32_t)temp[2] << 8) | (temp[1]); + ret = true; + } + +__return: + + if (ret) + { + dbSerialPrint("recvRetNumber :"); + dbSerialPrintln(*number); + } + else + { + dbSerialPrintln("recvRetNumber err"); + } + + return ret; +} + +/* + * Receive string data. + * + * @param str - save string data. + * @param timeout - set timeout time. + * + * @retval true - success. + * @retval false - failed. + * + */ +bool recvRetString(String &str, size_t timeout) +{ + str = ""; + bool ret{false}; + bool str_start_flag{false}; + uint8_t cnt_0xff = 0; + uint8_t c = 0; + uint32_t start{millis()}; + size_t avail{(size_t)nexSerial.available()}; + while(ret == false && (millis()-start)= 3) { + ret = true; break; } } else { - temp += (char)c; + str += (char)c; } } else if (NEX_RET_STRING_HEAD == c) { str_start_flag = true; } + yield(); } - - if (cnt_0xff >= 3) - { - break; - } + delayMicroseconds(20); } - - ret = temp.length(); - ret = ret > len ? len : ret; - strncpy(buffer, temp.c_str(), ret); - -__return: - + dbSerialPrintln(""); dbSerialPrint("recvRetString["); - dbSerialPrint(temp.length()); + dbSerialPrint(str.length()); dbSerialPrint(","); - dbSerialPrint(temp); + dbSerialPrint(str); dbSerialPrintln("]"); return ret; } +/* + * Receive string data. + * + * @param buffer - save string data. + * @param len - in buffer len / out saved string len excluding null char. + * @param timeout - set timeout time. + * + * @retval true - success. + * @retval false - failed. + * + */ +bool recvRetString(char *buffer, uint16_t &len, size_t timeout) +{ + String temp; + bool ret = recvRetString(temp,timeout); + + if(ret && len) + { + len=temp.length()>len?len:temp.length(); + strncpy(buffer,temp.c_str(), len); + } + return ret; +} + /* * Send command to Nextion. * @@ -163,6 +256,7 @@ uint16_t recvRetString(char *buffer, uint16_t len, uint32_t timeout) */ void sendCommand(const char* cmd) { + // empty in buffer for clean responce while (nexSerial.available()) { nexSerial.read(); @@ -172,38 +266,76 @@ void sendCommand(const char* cmd) nexSerial.write(0xFF); nexSerial.write(0xFF); nexSerial.write(0xFF); + dbSerialPrintln(cmd); +} + +#ifdef STD_SUPPORT +void sendRawData(const std::vector &data) +{ + nexSerial.write(data.data(),data.size()); } +#endif +void sendRawData(const uint8_t *buf, uint16_t len) +{ + nexSerial.write(buf, len); +} -/* - * Command is executed successfully. - * - * @param timeout - set timeout time. - * - * @retval true - success. - * @retval false - failed. - * - */ -bool recvRetCommandFinished(uint32_t timeout) -{ +void sendRawByte(const uint8_t byte) +{ + nexSerial.write(&byte, 1); +} + +size_t readBytes(uint8_t* buffer, size_t size, size_t timeout) +{ + uint32_t start{millis()}; + size_t avail{(size_t)nexSerial.available()}; + while(size>avail && (millis()-start) 0) - { - delay(10); - c = nexSerial.read(); - - if (NEX_RET_EVENT_TOUCH_HEAD == c) + while (nexSerial.available()) + { + __buffer[0] = nexSerial.read(); + switch(__buffer[0]) { - if (nexSerial.available() >= 6) + case NEX_RET_EVENT_NEXTION_STARTUP: + { + if(5==readBytes(&__buffer[1],5,200)) + { + if (0x00 == __buffer[1] && 0x00 == __buffer[2] && 0xFF == __buffer[3] && 0xFF == __buffer[4] && 0xFF == __buffer[5]) + { + if(nextionStartupCallback!=nullptr) + { + nextionStartupCallback(); + } + } + } + break; + } + case NEX_RET_EVENT_TOUCH_HEAD: { - __buffer[0] = c; - for (i = 1; i < 7; i++) + if(6==readBytes(&__buffer[1],6,200)) { - __buffer[i] = nexSerial.read(); + if (0xFF == __buffer[4] && 0xFF == __buffer[5] && 0xFF == __buffer[6]) + { + NexTouch::iterate(nex_listen_list, __buffer[1], __buffer[2], __buffer[3]); + } } - __buffer[i] = 0x00; - - if (0xFF == __buffer[4] && 0xFF == __buffer[5] && 0xFF == __buffer[6]) + break; + } + case NEX_RET_CURRENT_PAGE_ID_HEAD: + { + if(4==readBytes(&__buffer[1],4,200)) { - NexTouch::iterate(nex_listen_list, __buffer[1], __buffer[2], (int32_t)__buffer[3]); + if (0xFF == __buffer[2] && 0xFF == __buffer[3] && 0xFF == __buffer[4]) + { + if(currentPageIdCallback!=nullptr) + { + currentPageIdCallback(__buffer[1]); + } + } } - + break; } - } + case NEX_RET_EVENT_POSITION_HEAD: + case NEX_RET_EVENT_SLEEP_POSITION_HEAD: + { + if(8==readBytes(&__buffer[1],8,200)) + { + if (0xFF == __buffer[6] && 0xFF == __buffer[7] && 0xFF == __buffer[8]) + { + if(__buffer[0] == NEX_RET_EVENT_POSITION_HEAD && touchCoordinateCallback!=nullptr) + { + + touchCoordinateCallback(((int16_t)__buffer[2] << 8) | (__buffer[1]), ((int16_t)__buffer[4] << 8) | (__buffer[3]),__buffer[5]); + } + else if(__buffer[0] == NEX_RET_EVENT_SLEEP_POSITION_HEAD && touchCoordinateCallback!=nullptr) + { + + touchEventInSleepModeCallback(((int16_t)__buffer[2] << 8) | (__buffer[1]), ((int16_t)__buffer[4] << 8) | (__buffer[3]),__buffer[5]); + } + } + } + break; + } + case NEX_RET_AUTOMATIC_SLEEP: + case NEX_RET_AUTOMATIC_WAKE_UP: + { + if(3==readBytes(&__buffer[1],3,200)) + { + if (0xFF == __buffer[1] && 0xFF == __buffer[2] && 0xFF == __buffer[3]) + { + if(__buffer[0]==NEX_RET_AUTOMATIC_SLEEP && automaticSleepCallback!=nullptr) + { + automaticSleepCallback(); + } + else if(__buffer[0]==NEX_RET_AUTOMATIC_WAKE_UP && automaticWakeUpCallback!=nullptr) + { + automaticWakeUpCallback(); + } + } + } + break; + } + case NEX_RET_EVENT_NEXTION_READY: + { + if(nextionReadyCallback!=nullptr) + { + nextionReadyCallback(); + } + break; + } + case NEX_RET_START_SD_UPGRADE: + { + if(startSdUpgradeCallback!=nullptr) + { + startSdUpgradeCallback(); + } + break; + } + default: + { + // unnoun data clean buffer. + dbSerialPrint("Unexpected data received hex: "); + while (nexSerial.available()) + { + dbSerialPrintByte(__buffer[0]); + __buffer[0]=nexSerial.read(); + yield(); + } + dbSerialPrintln(__buffer[0]); + break; + } + }; } } - diff --git a/NexHardware.h b/NexHardware.h index 474dfef0..6addc899 100644 --- a/NexHardware.h +++ b/NexHardware.h @@ -5,6 +5,8 @@ * * @author Wu Pengfei (email:) * @date 2015/8/11 + * @author Jyrki Berg 2/24/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -23,12 +25,178 @@ * @{ */ +/** + * Nextion Startup callback function + * Returned when Nextion has started or reset + * + */ +extern void (*nextionStartupCallback)(); +//extern std::function nextionStartupCallback; + + +/** + * Current Page ID callback function + * The device returns this data after receiving “sendme” instruction) + * + * uint8_t pageId + */ +extern void (*currentPageIdCallback)(uint8_t); +//extern std::function currentPageIdCallback; + +/** + * Touch Coordinate callback function + * When the system variable “sendxy” is 1, return this data at TouchEvent occurring + * + * uint16_t x + * uint16_t y + * uint8_t TouchEvent + * + * Definition of TouchEvent: Press Event 0x01, Release Event 0X00 + */ +extern void (*touchCoordinateCallback)(uint16_t,uint16_t,uint8_t); +//extern std::function touchCoordinateCallback; + +/** + * Touch Event in sleep mode callback function + * When the device enters sleep mode, return this data at TouchEvent occurring + * + * uint16_t x + * uint16_t y + * uint8_t TouchEvent + * + * Definition of TouchEvent: Press Event 0x01, Release Event 0X00 + */ +extern void (*touchEventInSleepModeCallback)(uint16_t,uint16_t,uint8_t); +//extern std::function touchEventInSleepModeCallback; + +/** + * Device automatically enters into sleep mode callback function + * Only when the device automatically enters into sleep mode will return this data. + * If execute serial command “sleep = 1” to enter into sleep mode, it will not return this data. + */ +extern void (*automaticSleepCallback)(); +//extern std::function automaticSleepCallback; + +/** + * Device automatically wake up callback function + * Only when the device automatically wake up will return this data. + * If execute serial command “sleep=0” to wake up, it will not return this data. + */ +extern void (*automaticWakeUpCallback)(); +//extern std::function automaticWakeUpCallback; + +/** + * Nextion Ready callback function + * Returned when Nextion has powered up and is now initialized successfully + */ +extern void (*nextionReadyCallback)(); +//extern std::function nextionReadyCallback; + +/** + * Start SD card upgrade callback function + * This data is sent after the device power on and detect SD card, and then enter upgrade interface + */ +extern void (*startSdUpgradeCallback)(); +//extern std::function startSdUpgradeCallback; + +/** + * @} + */ +bool recvRetNumber(uint32_t *number, size_t timeout = 100); +bool recvRetNumber(int32_t *number, size_t timeout = 100); +bool recvRetString(String &str, size_t timeout = 100); +bool recvRetString(char *buffer, uint16_t &len, size_t timeout = 100); + +/* Send Command to device +* +* parameter command string +*/ +void sendCommand(const char* cmd); + +/* Send Raw data to device +* +* parameter raw data buffer +*/ +#ifdef STD_SUPPORT +void sendRawData(const std::vector &data); +#endif + +/* Send Raw data to device +* +* @param buf - raw data buffer poiter +* @param len - raw data buffer pointer +*/ +void sendRawData(const uint8_t *buf, uint16_t len); + + +/* Send Raw byte to device +* +* parameter raw byte +*/ +void sendRawByte(const uint8_t byte); + +/* read Bytes from device + * @brief + * + * @param buffer - receive buffer + * @param size - bytes to read + * @param timeout timeout ms + * @return size_t read bytes can be less that size (timeout case) + */ +size_t readBytes(uint8_t* buffer, size_t size, size_t timeout=1000); + + +/* Receive command +* +* @param command - command to be received / checked +* @param timeout - set timeout time. +* +* @retval true - success. +* @retval false - failed. +*/ +bool recvCommand(const uint8_t command, size_t timeout); + +/* + * Command is executed successfully. + * + * @param timeout - set timeout time. + * + * @retval true - success. + * @retval false - failed. + * + */ +bool recvRetCommandFinished(size_t timeout = 200); + +/* + * Transpared data mode setup successfully + * + * @param timeout - set timeout time. + * + * @retval true - success. + * @retval false - failed. + * + */ +bool RecvTransparendDataModeReady(size_t timeout = 400); + +/* + * Transpared data mode finished + * + * @param timeout - set timeout time. + * + * @retval true - success. + * @retval false - failed. + * + */ +bool RecvTransparendDataModeFinished(size_t timeout = 200); + /** * Init Nextion. * + * @param paud (2400, 4800, 9600, 19200, 38400, 57600, 115200 ) + * * @return true if success, false for failure. */ -bool nexInit(void); +bool nexInit(const uint32_t baud=9600); /** * Listen touch event and calling callbacks attached before. @@ -43,13 +211,4 @@ bool nexInit(void); */ 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__ */ diff --git a/NexHotspot.cpp b/NexHotspot.cpp index f21263b6..ae19be15 100644 --- a/NexHotspot.cpp +++ b/NexHotspot.cpp @@ -5,6 +5,8 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -15,8 +17,8 @@ #include "NexHotspot.h" -NexHotspot::NexHotspot(uint8_t pid, uint8_t cid, const char *name) - :NexTouch(pid, cid, name) +NexHotspot::NexHotspot(uint8_t pid, uint8_t cid, const char *name, const NexObject* page) + :NexTouch(pid, cid, name, page) { } diff --git a/NexHotspot.h b/NexHotspot.h index 8892d618..b2eedc79 100644 --- a/NexHotspot.h +++ b/NexHotspot.h @@ -5,6 +5,7 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n @@ -31,9 +32,9 @@ class NexHotspot: public NexTouch { public: /* methods */ /** - * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name); + * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); */ - NexHotspot(uint8_t pid, uint8_t cid, const char *name); + NexHotspot(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); }; /** * @} diff --git a/NexNumber.cpp b/NexNumber.cpp index 86217cb7..93a6521e 100755 --- a/NexNumber.cpp +++ b/NexNumber.cpp @@ -5,6 +5,8 @@ * * @author huang xianming (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -14,15 +16,15 @@ */ #include "NexNumber.h" -NexNumber::NexNumber(uint8_t pid, uint8_t cid, const char *name) - :NexTouch(pid, cid, name) +NexNumber::NexNumber(uint8_t pid, uint8_t cid, const char *name, const NexObject* page) + :NexTouch(pid, cid, name, page) { } bool NexNumber::getValue(uint32_t *number) { String cmd = String("get "); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".val"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -34,7 +36,7 @@ bool NexNumber::setValue(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".val="; cmd += buf; @@ -46,7 +48,7 @@ uint32_t NexNumber::Get_background_color_bco(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -58,14 +60,14 @@ bool NexNumber::Set_background_color_bco(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco="; cmd += buf; sendCommand(cmd.c_str()); cmd=""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -74,7 +76,7 @@ uint32_t NexNumber::Get_font_color_pco(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pco"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -86,14 +88,14 @@ bool NexNumber::Set_font_color_pco(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pco="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -102,7 +104,7 @@ uint32_t NexNumber::Get_place_xcen(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".xcen"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -114,14 +116,14 @@ bool NexNumber::Set_place_xcen(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".xcen="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -130,7 +132,7 @@ uint32_t NexNumber::Get_place_ycen(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".ycen"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -142,14 +144,14 @@ bool NexNumber::Set_place_ycen(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".ycen="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -158,7 +160,7 @@ uint32_t NexNumber::getFont(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".font"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -170,14 +172,14 @@ bool NexNumber::setFont(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".font="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -186,7 +188,7 @@ uint32_t NexNumber::Get_number_lenth(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".lenth"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -198,14 +200,14 @@ bool NexNumber::Set_number_lenth(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".lenth="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -214,7 +216,7 @@ uint32_t NexNumber::Get_background_crop_picc(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".picc"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -226,14 +228,14 @@ bool NexNumber::Set_background_crop_picc(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".picc="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -241,7 +243,7 @@ bool NexNumber::Set_background_crop_picc(uint32_t number) uint32_t NexNumber::Get_background_image_pic(uint32_t *number) { String cmd = String("get "); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pic"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -253,14 +255,14 @@ bool NexNumber::Set_background_image_pic(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pic="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } \ No newline at end of file diff --git a/NexNumber.h b/NexNumber.h index 5f227904..487f5482 100755 --- a/NexNumber.h +++ b/NexNumber.h @@ -5,6 +5,7 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n @@ -31,9 +32,9 @@ class NexNumber: public NexTouch { public: /* methods */ /** - * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name); + * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); */ - NexNumber(uint8_t pid, uint8_t cid, const char *name); + NexNumber(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); /** * Get number attribute of component. diff --git a/NexObject.cpp b/NexObject.cpp index 081ad73a..21757203 100644 --- a/NexObject.cpp +++ b/NexObject.cpp @@ -5,6 +5,8 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -13,12 +15,11 @@ * the License, or (at your option) any later version. */ #include "NexObject.h" +#include "NexHardware.h" -NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name) +NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name, const NexObject* page): +__pid{pid},__cid{cid},__name{name}, __page{page} { - this->__pid = pid; - this->__cid = cid; - this->__name = name; } uint8_t NexObject::getObjPid(void) @@ -31,11 +32,50 @@ uint8_t NexObject::getObjCid(void) return __cid; } -const char* NexObject::getObjName(void) +const char* NexObject::getObjName(void) const { return __name; } +const char* NexObject::getObjPageName(void) +{ + if(__page) + { + return __page->getObjName(); + } + return nullptr; +} + +void NexObject::getObjGlobalPageName(String &gName) +{ + if(__page) + { + gName += __page->getObjName(); + gName += "."; + } + gName +=__name; +} + +bool NexObject::GetObjectWidth( uint32_t &width) +{ + String cmd; + cmd = "get "; + getObjGlobalPageName(cmd); + cmd += ".w"; + sendCommand(cmd.c_str()); + return recvRetNumber(&width); +} + +bool NexObject::GetObjectHeight( uint32_t &height) +{ + String cmd; + cmd = "get "; + getObjGlobalPageName(cmd); + cmd += ".h"; + sendCommand(cmd.c_str()); + return recvRetNumber(&height); +} + void NexObject::printObjInfo(void) { dbSerialPrint("["); @@ -45,6 +85,14 @@ void NexObject::printObjInfo(void) dbSerialPrint(","); dbSerialPrint(__cid); dbSerialPrint(","); + if(__page) + { + dbSerialPrint(__page->getObjName()); + } + else + { + dbSerialPrint("(null)"); + } if (__name) { dbSerialPrint(__name); diff --git a/NexObject.h b/NexObject.h index d9678266..adaa3c4d 100644 --- a/NexObject.h +++ b/NexObject.h @@ -5,6 +5,7 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n @@ -40,7 +41,23 @@ class NexObject * @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); + NexObject(uint8_t pid, uint8_t cid, const char* name, const NexObject* page) ; + + /** + * Get object width + * + * @param number - buffer storing data return + * @return true if success, false for failure + */ + bool GetObjectWidth( uint32_t &width); + + /** + * Get object height + * + * @param number - buffer storing data return + * @return true if success, false for failure + */ + bool GetObjectHeight( uint32_t &height); /** * Print current object'address, page id, component id and name. @@ -70,12 +87,27 @@ class NexObject * * @return the name of component. */ - const char *getObjName(void); - + const char *getObjName(void) const; + + /* + * Get component page name. + * + * @return the name of component page, nullptr if not defined (local). + */ + const char* getObjPageName(void); + + /* + * Get component global name + * + * @return the global name of component in page + */ + void getObjGlobalPageName(String &gName); + private: /* data */ - uint8_t __pid; /* Page ID */ - uint8_t __cid; /* Component ID */ - const char *__name; /* An unique name */ + const uint8_t __pid; /* Page ID */ + const uint8_t __cid; /* Component ID */ + const char* __name; /* An unique name */ + const NexObject* __page; /* page information for global objects nullptr for local */ }; /** * @} diff --git a/NexPage.cpp b/NexPage.cpp index e6ca3504..7a006479 100644 --- a/NexPage.cpp +++ b/NexPage.cpp @@ -5,6 +5,8 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -16,14 +18,12 @@ #include "NexPage.h" NexPage::NexPage(uint8_t pid, uint8_t cid, const char *name) - :NexTouch(pid, cid, name) + :NexTouch(pid, cid, name, nullptr) { } bool NexPage::show(void) { - uint8_t buffer[4] = {0}; - const char *name = getObjName(); if (!name) { diff --git a/NexPage.h b/NexPage.h index c833e700..b875b06b 100644 --- a/NexPage.h +++ b/NexPage.h @@ -5,6 +5,7 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n diff --git a/NexPicture.cpp b/NexPicture.cpp index dc070c52..421a2801 100755 --- a/NexPicture.cpp +++ b/NexPicture.cpp @@ -5,6 +5,8 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -15,15 +17,15 @@ #include "NexPicture.h" -NexPicture::NexPicture(uint8_t pid, uint8_t cid, const char *name) - :NexTouch(pid, cid, name) +NexPicture::NexPicture(uint8_t pid, uint8_t cid, const char *name, const NexObject* page) + :NexTouch(pid, cid, name, page) { } bool NexPicture::Get_background_image_pic(uint32_t *number) { String cmd = String("get "); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pic"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -35,7 +37,7 @@ bool NexPicture::Set_background_image_pic(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pic="; cmd += buf; @@ -46,7 +48,7 @@ bool NexPicture::Set_background_image_pic(uint32_t number) bool NexPicture::getPic(uint32_t *number) { String cmd = String("get "); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pic"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -58,7 +60,7 @@ bool NexPicture::setPic(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pic="; cmd += buf; diff --git a/NexPicture.h b/NexPicture.h index efa36a40..2f151729 100755 --- a/NexPicture.h +++ b/NexPicture.h @@ -5,6 +5,7 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n @@ -31,9 +32,9 @@ class NexPicture: public NexTouch { public: /* methods */ /** - * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name); + * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); */ - NexPicture(uint8_t pid, uint8_t cid, const char *name); + NexPicture(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); /** * Get picture's number. diff --git a/NexProgressBar.cpp b/NexProgressBar.cpp index 245dda09..8294eda0 100755 --- a/NexProgressBar.cpp +++ b/NexProgressBar.cpp @@ -5,6 +5,8 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -15,15 +17,15 @@ #include "NexProgressBar.h" -NexProgressBar::NexProgressBar(uint8_t pid, uint8_t cid, const char *name) - :NexObject(pid, cid, name) +NexProgressBar::NexProgressBar(uint8_t pid, uint8_t cid, const char *name, const NexObject* page) + :NexObject(pid, cid, name, page) { } bool NexProgressBar::getValue(uint32_t *number) { String cmd = String("get "); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".val"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -35,7 +37,7 @@ bool NexProgressBar::setValue(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".val="; cmd += buf; @@ -47,7 +49,7 @@ uint32_t NexProgressBar::Get_background_color_bco(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -59,14 +61,14 @@ bool NexProgressBar::Set_background_color_bco(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco="; cmd += buf; sendCommand(cmd.c_str()); cmd=""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -75,7 +77,7 @@ uint32_t NexProgressBar::Get_font_color_pco(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pco"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -87,14 +89,14 @@ bool NexProgressBar::Set_font_color_pco(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pco="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } diff --git a/NexProgressBar.h b/NexProgressBar.h index 1948518b..21124749 100755 --- a/NexProgressBar.h +++ b/NexProgressBar.h @@ -5,6 +5,7 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n @@ -31,9 +32,9 @@ class NexProgressBar: public NexObject { public: /* methods */ /** - * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name); + * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); */ - NexProgressBar(uint8_t pid, uint8_t cid, const char *name); + NexProgressBar(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); /** * Get the value of progress bar. diff --git a/NexRadio.cpp b/NexRadio.cpp index c80aae52..90e1dce3 100755 --- a/NexRadio.cpp +++ b/NexRadio.cpp @@ -5,6 +5,8 @@ * * @author huang xiaoming (email:) * @date 2016/9/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -14,15 +16,15 @@ */ #include "NexRadio.h" -NexRadio::NexRadio(uint8_t pid, uint8_t cid, const char *name) - :NexTouch(pid, cid, name) +NexRadio::NexRadio(uint8_t pid, uint8_t cid, const char *name, const NexObject* page) + :NexTouch(pid, cid, name, page) { } uint32_t NexRadio::getValue(uint32_t *number) { String cmd = String("get "); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".val"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -34,7 +36,7 @@ bool NexRadio::setValue(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".val="; cmd += buf; @@ -46,7 +48,7 @@ uint32_t NexRadio::Get_background_color_bco(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -58,14 +60,14 @@ bool NexRadio::Set_background_color_bco(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco="; cmd += buf; sendCommand(cmd.c_str()); cmd=""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -74,7 +76,7 @@ uint32_t NexRadio::Get_font_color_pco(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pco"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -86,14 +88,14 @@ bool NexRadio::Set_font_color_pco(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pco="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } \ No newline at end of file diff --git a/NexRadio.h b/NexRadio.h index c36dea71..8a08ae7b 100755 --- a/NexRadio.h +++ b/NexRadio.h @@ -5,6 +5,7 @@ * * @author huang xiaoming (email:) * @date 2016/9/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n @@ -37,9 +38,9 @@ class NexRadio:public NexTouch public: /* methods */ /** - * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name); + * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); */ - NexRadio(uint8_t pid, uint8_t cid, const char *name); + NexRadio(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); /** * Get val attribute of component diff --git a/NexRtc.cpp b/NexRtc.cpp index 4350acf1..2fad9a4b 100755 --- a/NexRtc.cpp +++ b/NexRtc.cpp @@ -5,6 +5,8 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -18,7 +20,6 @@ bool NexRtc::write_rtc_time(char *time) { char year[5],mon[3],day[3],hour[3],min[3],sec[3]; String cmd = String("rtc"); - int i; if(strlen(time) >= 19) { @@ -32,50 +33,68 @@ bool NexRtc::write_rtc_time(char *time) cmd += "0="; cmd += year; sendCommand(cmd.c_str()); - recvRetCommandFinished(); + if(!recvRetCommandFinished()) + { + return false; + } cmd = ""; cmd += "rtc1="; cmd += mon; sendCommand(cmd.c_str()); - recvRetCommandFinished(); + if(!recvRetCommandFinished()) + { + return false; + } cmd = ""; cmd += "rtc2="; cmd += day; sendCommand(cmd.c_str()); - recvRetCommandFinished(); + if(!recvRetCommandFinished()) + { + return false; + } cmd = ""; cmd += "rtc3="; cmd += hour; sendCommand(cmd.c_str()); - recvRetCommandFinished(); + if(!recvRetCommandFinished()) + { + return false; + } cmd = ""; cmd += "rtc4="; cmd += min; sendCommand(cmd.c_str()); - recvRetCommandFinished(); + if(!recvRetCommandFinished()) + { + return false; + } cmd = ""; cmd += "rtc5="; cmd += sec; sendCommand(cmd.c_str()); - recvRetCommandFinished(); + if(!recvRetCommandFinished()) + { + return false; + } } else { return false; } + return true; } bool NexRtc::write_rtc_time(uint32_t *time) { char year[5],mon[3],day[3],hour[3],min[3],sec[3]; String cmd = String("rtc"); - int i; utoa(time[0],year,10); utoa(time[1],mon, 10); @@ -88,38 +107,56 @@ bool NexRtc::write_rtc_time(uint32_t *time) cmd += "0="; cmd += year; sendCommand(cmd.c_str()); - recvRetCommandFinished(); + if(!recvRetCommandFinished()) + { + return false; + } cmd = ""; cmd += "rtc1="; cmd += mon; sendCommand(cmd.c_str()); - recvRetCommandFinished(); + if(!recvRetCommandFinished()) + { + return false; + } cmd = ""; cmd += "rtc2="; cmd += day; sendCommand(cmd.c_str()); - recvRetCommandFinished(); + if(!recvRetCommandFinished()) + { + return false; + } cmd = ""; cmd += "rtc3="; cmd += hour; sendCommand(cmd.c_str()); - recvRetCommandFinished(); + if(!recvRetCommandFinished()) + { + return false; + } cmd = ""; cmd += "rtc4="; cmd += min; sendCommand(cmd.c_str()); - recvRetCommandFinished(); + if(!recvRetCommandFinished()) + { + return false; + } cmd = ""; cmd += "rtc5="; cmd += sec; sendCommand(cmd.c_str()); - recvRetCommandFinished(); - + if(!recvRetCommandFinished()) + { + return false; + } + return true; } bool NexRtc::write_rtc_time(char *time_type,uint32_t number) @@ -163,7 +200,7 @@ bool NexRtc::write_rtc_time(char *time_type,uint32_t number) return recvRetCommandFinished(); } -uint32_t NexRtc::read_rtc_time(char *time,uint32_t len) +bool NexRtc::read_rtc_time(char *time,uint32_t len) { char time_buf[22] = {"0000/00/00 00:00:00 0"}; uint32_t year,mon,day,hour,min,sec,week; @@ -171,37 +208,58 @@ uint32_t NexRtc::read_rtc_time(char *time,uint32_t len) cmd = "get rtc0"; sendCommand(cmd.c_str()); - recvRetNumber(&year); + if(!recvRetNumber(&year)) + { + return false; + } cmd = ""; cmd = "get rtc1"; sendCommand(cmd.c_str()); - recvRetNumber(&mon); + if(recvRetNumber(&mon)) + { + return false; + } cmd = ""; cmd = "get rtc2"; sendCommand(cmd.c_str()); - recvRetNumber(&day); + if(!recvRetNumber(&day)) + { + return false; + } cmd = ""; cmd = "get rtc3"; sendCommand(cmd.c_str()); - recvRetNumber(&hour); - + if(recvRetNumber(&hour)) + { + return false; + } + cmd = ""; cmd = "get rtc4"; sendCommand(cmd.c_str()); - recvRetNumber(&min); + if(recvRetNumber(&min)) + { + return false; + } cmd = ""; cmd = "get rtc5"; sendCommand(cmd.c_str()); - recvRetNumber(&sec); + if(recvRetNumber(&sec)) + { + return false; + } cmd = ""; cmd = "get rtc6"; sendCommand(cmd.c_str()); - recvRetNumber(&week); + if(!recvRetNumber(&week)) + { + return false; + } time_buf[0] = year/1000 + '0'; time_buf[1] = (year/100)%10 + '0'; @@ -220,7 +278,6 @@ uint32_t NexRtc::read_rtc_time(char *time,uint32_t len) time_buf[20] = week + '0'; time_buf[21] = '\0'; - if(len >= 22) { for(int i=0;i<22;i++) @@ -229,66 +286,85 @@ uint32_t NexRtc::read_rtc_time(char *time,uint32_t len) } } else{ - for(int i=0;i) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n @@ -40,8 +41,7 @@ class NexRtc * @param time_type - To type in time (example:write_rtc_time("year",2016)) * @param number - the time value * @return true if success, false for failure - */ - + */ bool write_rtc_time(char *time_type,uint32_t number); /** @@ -50,7 +50,6 @@ class NexRtc * @param time - Time to write to the array * @return true if success, false for failure */ - bool write_rtc_time(uint32_t *time); @@ -61,8 +60,7 @@ class NexRtc * @param len - len of array * @return true if success, false for failure */ - - uint32_t read_rtc_time(char *time,uint32_t len); + bool read_rtc_time(char *time,uint32_t len); /** * read rtc times @@ -71,8 +69,7 @@ class NexRtc * @param number - the time value * @return true if success, false for failure */ - - uint32_t read_rtc_time(char *time_type,uint32_t *number); + bool read_rtc_time(char *time_type,uint32_t *number); /** * read rtc time @@ -81,8 +78,7 @@ class NexRtc * @param len - len of array * @return true if success, false for failure */ - - uint32_t read_rtc_time(uint32_t *time,uint32_t len); + bool read_rtc_time(uint32_t *time,uint32_t len); }; diff --git a/NexScrolltext.cpp b/NexScrolltext.cpp index faa207af..0bfa4bac 100755 --- a/NexScrolltext.cpp +++ b/NexScrolltext.cpp @@ -5,6 +5,8 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -14,16 +16,27 @@ */ #include "NexScrolltext.h" -NexScrolltext::NexScrolltext(uint8_t pid, uint8_t cid, const char *name) - :NexTouch(pid, cid, name) +NexScrolltext::NexScrolltext(uint8_t pid, uint8_t cid, const char *name, const NexObject* page) + :NexTouch(pid, cid, name, page) { } -uint16_t NexScrolltext::getText(char *buffer, uint16_t len) +bool NexScrolltext::getText(String &str) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); + cmd += ".txt"; + sendCommand(cmd.c_str()); + return recvRetString(str); +} + + +bool NexScrolltext::getText(char *buffer, uint16_t &len) +{ + String cmd; + cmd += "get "; + getObjGlobalPageName(cmd); cmd += ".txt"; sendCommand(cmd.c_str()); return recvRetString(buffer,len); @@ -32,7 +45,7 @@ uint16_t NexScrolltext::getText(char *buffer, uint16_t len) bool NexScrolltext::setText(const char *buffer) { String cmd; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".txt=\""; cmd += buffer; cmd += "\""; @@ -44,7 +57,7 @@ uint32_t NexScrolltext::Get_background_color_bco(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -56,14 +69,14 @@ bool NexScrolltext::Set_background_color_bco(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco="; cmd += buf; sendCommand(cmd.c_str()); cmd=""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -72,7 +85,7 @@ uint32_t NexScrolltext::Get_font_color_pco(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pco"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -84,14 +97,14 @@ bool NexScrolltext::Set_font_color_pco(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pco="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -100,7 +113,7 @@ uint32_t NexScrolltext::Get_place_xcen(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".xcen"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -112,14 +125,14 @@ bool NexScrolltext::Set_place_xcen(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".xcen="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -128,7 +141,7 @@ uint32_t NexScrolltext::Get_place_ycen(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".ycen"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -140,14 +153,14 @@ bool NexScrolltext::Set_place_ycen(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".ycen="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -156,7 +169,7 @@ uint32_t NexScrolltext::getFont(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".font"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -168,14 +181,14 @@ bool NexScrolltext::setFont(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".font="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -184,7 +197,7 @@ uint32_t NexScrolltext::Get_background_crop_picc(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".picc"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -196,14 +209,14 @@ bool NexScrolltext::Set_background_crop_picc(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".picc="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -211,7 +224,7 @@ bool NexScrolltext::Set_background_crop_picc(uint32_t number) uint32_t NexScrolltext::Get_background_image_pic(uint32_t *number) { String cmd = String("get "); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pic"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -223,14 +236,14 @@ bool NexScrolltext::Set_background_image_pic(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pic="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -238,7 +251,7 @@ bool NexScrolltext::Set_background_image_pic(uint32_t number) uint32_t NexScrolltext::Get_scroll_dir(uint32_t *number) { String cmd = String("get "); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".dir"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -250,14 +263,14 @@ bool NexScrolltext::Set_scroll_dir(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".dir="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -265,7 +278,7 @@ bool NexScrolltext::Set_scroll_dir(uint32_t number) uint32_t NexScrolltext::Get_scroll_distance(uint32_t *number) { String cmd = String("get "); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".dis"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -281,14 +294,14 @@ bool NexScrolltext::Set_scroll_distance(uint32_t number) number = 2; } utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".dis="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -296,7 +309,7 @@ bool NexScrolltext::Set_scroll_distance(uint32_t number) uint32_t NexScrolltext::Get_cycle_tim(uint32_t *number) { String cmd = String("get "); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".tim"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -311,14 +324,14 @@ bool NexScrolltext::Set_cycle_tim(uint32_t number) number = 8; } utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".tim="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -329,7 +342,7 @@ bool NexScrolltext::enable(void) char buf[10] = {0}; String cmd; utoa(1, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".en="; cmd += buf; @@ -342,7 +355,7 @@ bool NexScrolltext::disable(void) char buf[10] = {0}; String cmd; utoa(0, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".en="; cmd += buf; diff --git a/NexScrolltext.h b/NexScrolltext.h index caf7f1d2..5d40a046 100755 --- a/NexScrolltext.h +++ b/NexScrolltext.h @@ -5,6 +5,7 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n @@ -31,18 +32,31 @@ class NexScrolltext: public NexTouch { public: /* methods */ /** - * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name); + * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); */ - NexScrolltext(uint8_t pid, uint8_t cid, const char *name); + NexScrolltext(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); + /* + * Get text attribute of component. + * + * @param str - String storing text returned. + * + * @retval true - success. + * @retval false - failed. + * + */ + bool getText(String &str); + /** * Get text attribute of component. * * @param buffer - buffer storing text returned. - * @param len - length of buffer. - * @return The real length of text returned. + * @param len - in buffer len / out saved string len excluding null char. + * + * @retval true - success. + * @retval false - failed. */ - uint16_t getText(char *buffer, uint16_t len); + bool getText(char *buffer, uint16_t &len); /** * Set text attribute of component. diff --git a/NexSlider.cpp b/NexSlider.cpp index 43ace8c4..fede8d8a 100755 --- a/NexSlider.cpp +++ b/NexSlider.cpp @@ -5,6 +5,8 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -14,15 +16,15 @@ */ #include "NexSlider.h" -NexSlider::NexSlider(uint8_t pid, uint8_t cid, const char *name) - :NexTouch(pid, cid, name) +NexSlider::NexSlider(uint8_t pid, uint8_t cid, const char *name, const NexObject* page) + :NexTouch(pid, cid, name, page) { } bool NexSlider::getValue(uint32_t *number) { String cmd = String("get "); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".val"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -34,7 +36,7 @@ bool NexSlider::setValue(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".val="; cmd += buf; @@ -46,7 +48,7 @@ uint32_t NexSlider::Get_background_color_bco(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -58,14 +60,14 @@ bool NexSlider::Set_background_color_bco(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco="; cmd += buf; sendCommand(cmd.c_str()); cmd=""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -74,7 +76,7 @@ uint32_t NexSlider::Get_font_color_pco(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pco"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -86,14 +88,14 @@ bool NexSlider::Set_font_color_pco(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pco="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -102,7 +104,7 @@ uint32_t NexSlider::Get_pointer_thickness_wid(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".wid"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -114,14 +116,14 @@ bool NexSlider::Set_pointer_thickness_wid(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".wid="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -130,7 +132,7 @@ uint32_t NexSlider::Get_cursor_height_hig(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".hig"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -142,14 +144,14 @@ bool NexSlider::Set_cursor_height_hig(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".hig="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -158,7 +160,7 @@ uint32_t NexSlider::getMaxval(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".maxval"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -170,14 +172,14 @@ bool NexSlider::setMaxval(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".maxval="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -186,7 +188,7 @@ uint32_t NexSlider::getMinval(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".minval"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -198,14 +200,14 @@ bool NexSlider::setMinval(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".minval="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } \ No newline at end of file diff --git a/NexSlider.h b/NexSlider.h index 47cac688..05a6aec6 100755 --- a/NexSlider.h +++ b/NexSlider.h @@ -5,6 +5,7 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n @@ -31,9 +32,9 @@ class NexSlider: public NexTouch { public: /* methods */ /** - * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name); + * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name, const NexObject* page); */ - NexSlider(uint8_t pid, uint8_t cid, const char *name); + NexSlider(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); /** * Get the value of slider. diff --git a/NexText.cpp b/NexText.cpp index 25a2c868..210fa68c 100755 --- a/NexText.cpp +++ b/NexText.cpp @@ -5,6 +5,8 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -14,16 +16,27 @@ */ #include "NexText.h" -NexText::NexText(uint8_t pid, uint8_t cid, const char *name) - :NexTouch(pid, cid, name) +NexText::NexText(uint8_t pid, uint8_t cid, const char *name, const NexObject* page) + :NexTouch(pid, cid, name, page) { } -uint16_t NexText::getText(char *buffer, uint16_t len) +bool NexText::getText(String &str) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); + cmd += ".txt"; + sendCommand(cmd.c_str()); + return recvRetString(str); +} + + +bool NexText::getText(char *buffer, uint16_t &len) +{ + String cmd; + cmd += "get "; + getObjGlobalPageName(cmd); cmd += ".txt"; sendCommand(cmd.c_str()); return recvRetString(buffer,len); @@ -32,7 +45,7 @@ uint16_t NexText::getText(char *buffer, uint16_t len) bool NexText::setText(const char *buffer) { String cmd; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".txt=\""; cmd += buffer; cmd += "\""; @@ -40,11 +53,22 @@ bool NexText::setText(const char *buffer) return recvRetCommandFinished(); } +bool NexText::appendText(const char *buffer) +{ + String cmd; + getObjGlobalPageName(cmd); + cmd += ".txt+=\""; + cmd += buffer; + cmd += "\""; + sendCommand(cmd.c_str()); + return recvRetCommandFinished(); +} + uint32_t NexText::Get_background_color_bco(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -56,14 +80,14 @@ bool NexText::Set_background_color_bco(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco="; cmd += buf; sendCommand(cmd.c_str()); cmd=""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -72,7 +96,7 @@ uint32_t NexText::Get_font_color_pco(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pco"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -84,14 +108,14 @@ bool NexText::Set_font_color_pco(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pco="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -100,7 +124,7 @@ uint32_t NexText::Get_place_xcen(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".xcen"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -112,14 +136,14 @@ bool NexText::Set_place_xcen(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".xcen="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -128,7 +152,7 @@ uint32_t NexText::Get_place_ycen(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".ycen"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -140,14 +164,14 @@ bool NexText::Set_place_ycen(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".ycen="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -156,7 +180,7 @@ uint32_t NexText::getFont(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".font"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -168,14 +192,14 @@ bool NexText::setFont(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".font="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -184,7 +208,7 @@ uint32_t NexText::Get_background_crop_picc(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".picc"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -196,14 +220,14 @@ bool NexText::Set_background_crop_picc(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".picc="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } @@ -211,7 +235,7 @@ bool NexText::Set_background_crop_picc(uint32_t number) uint32_t NexText::Get_background_image_pic(uint32_t *number) { String cmd = String("get "); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pic"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -223,7 +247,7 @@ bool NexText::Set_background_image_pic(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".pic="; cmd += buf; diff --git a/NexText.h b/NexText.h index 592ce076..21c5096c 100755 --- a/NexText.h +++ b/NexText.h @@ -5,6 +5,7 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n @@ -13,7 +14,7 @@ * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. */ - + #ifndef __NEXTEXT_H__ #define __NEXTEXT_H__ @@ -27,54 +28,75 @@ /** * NexText component. */ -class NexText: public NexTouch +class NexText : public NexTouch { public: /* methods */ /** - * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name); + * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); */ - NexText(uint8_t pid, uint8_t cid, const char *name); - + NexText(uint8_t pid, uint8_t cid, const char *name, const NexObject *page = nullptr); + + /* + * Get text attribute of component. + * + * @param str - String storing text returned. + * + * @retval true - success. + * @retval false - failed. + * + */ + bool getText(String &str); + /** * Get text attribute of component. * * @param buffer - buffer storing text returned. - * @param len - length of buffer. - * @return The real length of text returned. + * @param len - in buffer len / out saved string len excluding null char. + * + * @retval true - success. + * @retval false - failed. */ - uint16_t getText(char *buffer, uint16_t len); - + bool 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); + + /** + * Append text to text attribute of component. + * + * @param buffer - text buffer terminated with '\0'. + * @return true if success, false for failure. + */ + bool appendText(const char *buffer); + /** * Get bco attribute of component * * @param number - buffer storing data retur * @return the length of the data */ - uint32_t Get_background_color_bco(uint32_t *number); - + uint32_t Get_background_color_bco(uint32_t *number); + /** * Set bco attribute of component * * @param number - To set up the data * @return true if success, false for failure */ - bool Set_background_color_bco(uint32_t number); - + bool Set_background_color_bco(uint32_t number); + /** * Get pco attribute of component * * @param number - buffer storing data retur * @return the length of the data */ - uint32_t Get_font_color_pco(uint32_t *number); + uint32_t Get_font_color_pco(uint32_t *number); /** * Set pco attribute of component @@ -82,15 +104,15 @@ class NexText: public NexTouch * @param number - To set up the data * @return true if success, false for failure */ - bool Set_font_color_pco(uint32_t number); - + bool Set_font_color_pco(uint32_t number); + /** * Get xcen attribute of component * * @param number - buffer storing data retur * @return the length of the data */ - uint32_t Get_place_xcen(uint32_t *number); + uint32_t Get_place_xcen(uint32_t *number); /** * Set xcen attribute of component @@ -98,15 +120,15 @@ class NexText: public NexTouch * @param number - To set up the data * @return true if success, false for failure */ - bool Set_place_xcen(uint32_t number); - + bool Set_place_xcen(uint32_t number); + /** * Get ycen attribute of component * * @param number - buffer storing data retur * @return the length of the data */ - uint32_t Get_place_ycen(uint32_t *number); + uint32_t Get_place_ycen(uint32_t *number); /** * Set ycen attribute of component @@ -114,31 +136,31 @@ class NexText: public NexTouch * @param number - To set up the data * @return true if success, false for failure */ - bool Set_place_ycen(uint32_t number); - + bool Set_place_ycen(uint32_t number); + /** * Get font attribute of component * * @param number - buffer storing data retur * @return the length of the data */ - uint32_t getFont(uint32_t *number); - + uint32_t getFont(uint32_t *number); + /** * Set font attribute of component * * @param number - To set up the data * @return true if success, false for failure */ - bool setFont(uint32_t number); - + bool setFont(uint32_t number); + /** * Get picc attribute of component * * @param number - buffer storing data retur * @return the length of the data */ - uint32_t Get_background_crop_picc(uint32_t *number); + uint32_t Get_background_crop_picc(uint32_t *number); /** * Set picc attribute of component @@ -146,15 +168,15 @@ class NexText: public NexTouch * @param number - To set up the data * @return true if success, false for failure */ - bool Set_background_crop_picc(uint32_t number); - + bool Set_background_crop_picc(uint32_t number); + /** * Get pic attribute of component * * @param number - buffer storing data retur * @return the length of the data */ - uint32_t Get_background_image_pic(uint32_t *number); + uint32_t Get_background_image_pic(uint32_t *number); /** * Set pic attribute of component @@ -162,8 +184,7 @@ class NexText: public NexTouch * @param number - To set up the data * @return true if success, false for failure */ - bool Set_background_image_pic(uint32_t number); - + bool Set_background_image_pic(uint32_t number); }; /** diff --git a/NexTimer.cpp b/NexTimer.cpp index 9d69527d..b66789fa 100755 --- a/NexTimer.cpp +++ b/NexTimer.cpp @@ -5,6 +5,8 @@ * * @author huang xianming (email:) * @date 2015/8/26 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -15,8 +17,8 @@ #include "NexTimer.h" -NexTimer::NexTimer(uint8_t pid, uint8_t cid, const char *name) - :NexTouch(pid, cid, name) +NexTimer::NexTimer(uint8_t pid, uint8_t cid, const char *name, const NexObject* page) + :NexTouch(pid, cid, name, page) { } @@ -33,7 +35,7 @@ void NexTimer::detachTimer(void) bool NexTimer::getCycle(uint32_t *number) { String cmd = String("get "); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".tim"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -48,7 +50,7 @@ bool NexTimer::setCycle(uint32_t number) number = 50; } utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".tim="; cmd += buf; @@ -62,7 +64,7 @@ bool NexTimer::enable(void) char buf[10] = {0}; String cmd; utoa(1, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".en="; cmd += buf; @@ -75,7 +77,7 @@ bool NexTimer::disable(void) char buf[10] = {0}; String cmd; utoa(0, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".en="; cmd += buf; @@ -86,7 +88,7 @@ bool NexTimer::disable(void) uint32_t NexTimer::Get_cycle_tim(uint32_t *number) { String cmd = String("get "); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".tim"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -101,14 +103,14 @@ bool NexTimer::Set_cycle_tim(uint32_t number) number = 8; } utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".tim="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } diff --git a/NexTimer.h b/NexTimer.h index 2bb24a61..9b4f7a2f 100755 --- a/NexTimer.h +++ b/NexTimer.h @@ -5,6 +5,7 @@ * * @author huang xianming (email:) * @date 2015/8/26 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n @@ -36,9 +37,9 @@ class NexTimer: public NexTouch public: /* methods */ /** - * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name); + * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); */ - NexTimer(uint8_t pid, uint8_t cid, const char *name); + NexTimer(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); /** * Attach an callback function of timer respond event. diff --git a/NexTouch.cpp b/NexTouch.cpp index a0af40ef..b35e28f0 100644 --- a/NexTouch.cpp +++ b/NexTouch.cpp @@ -5,6 +5,8 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -15,8 +17,8 @@ #include "NexTouch.h" -NexTouch::NexTouch(uint8_t pid, uint8_t cid, const char *name) - :NexObject(pid, cid, name) +NexTouch::NexTouch(uint8_t pid, uint8_t cid, const char *name, const NexObject* page) + :NexObject(pid, cid, name, page) { this->__cb_push = NULL; this->__cb_pop = NULL; @@ -64,7 +66,7 @@ void NexTouch::pop(void) } } -void NexTouch::iterate(NexTouch **list, uint8_t pid, uint8_t cid, int32_t event) +void NexTouch::iterate(NexTouch **list, uint8_t pid, uint8_t cid, uint8_t event) { NexTouch *e = NULL; uint16_t i = 0; diff --git a/NexTouch.h b/NexTouch.h index abce6fb2..ce0ad950 100644 --- a/NexTouch.h +++ b/NexTouch.h @@ -5,6 +5,7 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n @@ -53,14 +54,14 @@ typedef void (*NexTouchEventCb)(void *ptr); class NexTouch: public NexObject { public: /* static methods */ - static void iterate(NexTouch **list, uint8_t pid, uint8_t cid, int32_t event); + static void iterate(NexTouch **list, uint8_t pid, uint8_t cid, uint8_t event); public: /* methods */ /** - * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name); + * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); */ - NexTouch(uint8_t pid, uint8_t cid, const char *name); + NexTouch(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); /** * Attach an callback function of push touch event. diff --git a/NexUpload.cpp b/NexUpload.cpp index ff85eb92..9f36c0eb 100644 --- a/NexUpload.cpp +++ b/NexUpload.cpp @@ -5,6 +5,7 @@ * * @author Chen Zengpeng (email:) * @date 2016/3/29 + * @author Jyrki Berg 1/25/2020 (https://github.com/jyberg) * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -14,10 +15,9 @@ */ #include "NexUpload.h" -#include -//#define USE_SOFTWARE_SERIAL #ifdef USE_SOFTWARE_SERIAL +#include SoftwareSerial dbSerial(3, 2); /* RX:D3, TX:D2 */ #define DEBUG_SERIAL_ENABLE #endif @@ -133,7 +133,7 @@ void NexUpload::sendCommand(const char* cmd) nexSerial.write(0xFF); } -uint16_t NexUpload::recvRetString(String &string, uint32_t timeout,bool recv_flag) +uint16_t NexUpload::recvRetString(String &string, size_t timeout,bool recv_flag) { uint16_t ret = 0; uint8_t c = 0; diff --git a/NexUpload.h b/NexUpload.h index 71291282..6ff7216e 100755 --- a/NexUpload.h +++ b/NexUpload.h @@ -125,7 +125,7 @@ class NexUpload * @return the length of string buffer. * */ - uint16_t recvRetString(String &string, uint32_t timeout = 100,bool recv_flag = false); + uint16_t recvRetString(String &string, size_t timeout = 100,bool recv_flag = false); private: /* data */ uint32_t _baudrate; /*nextion serail baudrate*/ diff --git a/NexVariable.cpp b/NexVariable.cpp index 187ba114..8995d4c1 100755 --- a/NexVariable.cpp +++ b/NexVariable.cpp @@ -4,7 +4,9 @@ * The implementation of class NexText. * * @author huang xiaoming (email:) - * @date 2016/9/13 + * @date 2016/9/ + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -14,39 +16,48 @@ */ #include "NexVariable.h" -NexVariable::NexVariable(uint8_t pid, uint8_t cid, const char *name) - :NexTouch(pid, cid, name) +NexVariable::NexVariable(uint8_t pid, uint8_t cid, const char *name, const NexObject* page) + :NexTouch(pid, cid, name, page) { } -uint32_t NexVariable::getValue(uint32_t *number) +uint32_t NexVariable::getValue(int32_t *number) { String cmd = String("get "); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".val"; sendCommand(cmd.c_str()); return recvRetNumber(number); } -bool NexVariable::setValue(uint32_t number) +bool NexVariable::setValue(int number) { - char buf[10] = {0}; + char buf[12] = {0}; String cmd; - utoa(number, buf, 10); - cmd += getObjName(); + itoa(number, buf, 10); + getObjGlobalPageName(cmd); cmd += ".val="; cmd += buf; sendCommand(cmd.c_str()); return recvRetCommandFinished(); } +bool NexVariable::getText(String &str) +{ + String cmd; + cmd += "get "; + getObjGlobalPageName(cmd); + cmd += ".txt"; + sendCommand(cmd.c_str()); + return recvRetString(str); +} -uint32_t NexVariable::getText(char *buffer, uint32_t len) +bool NexVariable::getText(char *buffer, uint16_t &len) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".txt"; sendCommand(cmd.c_str()); return recvRetString(buffer,len); @@ -55,7 +66,7 @@ uint32_t NexVariable::getText(char *buffer, uint32_t len) bool NexVariable::setText(const char *buffer) { String cmd; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".txt=\""; cmd += buffer; cmd += "\""; diff --git a/NexVariable.h b/NexVariable.h index ebbba132..b11ce148 100755 --- a/NexVariable.h +++ b/NexVariable.h @@ -5,6 +5,7 @@ * * @author huang xiaoming (email:) * @date 2016/9/13 + * @author Jyrki Berg 2/17/2019 (https://github.com/jyberg) * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n @@ -37,18 +38,31 @@ class NexVariable: public NexTouch public: /* methods */ /** - * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name); + * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); */ - NexVariable(uint8_t pid, uint8_t cid, const char *name); + NexVariable(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); + + /* + * Get text attribute of component. + * + * @param str - String storing text returned. + * + * @retval true - success. + * @retval false - failed. + * + */ + bool getText(String &str); /** * Get text attribute of component. * * @param buffer - buffer storing text returned. - * @param len - length of buffer. - * @return The real length of text returned. + * @param len - in buffer len / out saved string len excluding null char. + * + * @retval true - success. + * @retval false - failed. */ - uint32_t getText(char *buffer, uint32_t len); + bool getText(char *buffer, uint16_t &len); /** * Set text attribute of component. @@ -64,7 +78,7 @@ class NexVariable: public NexTouch * @param number - buffer storing data retur * @return the length of the data */ - uint32_t getValue(uint32_t *number); + uint32_t getValue(int32_t *number); /** * Set val attribute of component @@ -72,7 +86,7 @@ class NexVariable: public NexTouch * @param number - To set up the data * @return true if success, false for failure */ - bool setValue(uint32_t number); + bool setValue(int number); }; /** * @} diff --git a/NexWaveform.cpp b/NexWaveform.cpp index c1fbe9ae..b156d0b1 100755 --- a/NexWaveform.cpp +++ b/NexWaveform.cpp @@ -5,6 +5,8 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 3/3/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -14,31 +16,32 @@ */ #include "NexWaveform.h" -NexWaveform::NexWaveform(uint8_t pid, uint8_t cid, const char *name) - :NexObject(pid, cid, name) +#ifdef STD_SUPPORT +#include +#endif + +NexWaveform::NexWaveform(uint8_t pid, uint8_t cid, const char *name, const NexObject* page): + NexTouch(pid, cid, name, page), m_minVal{0},m_maxVal{255},m_scale{1.0},m_hight{255} { } -bool NexWaveform::addValue(uint8_t ch, uint8_t number) +NexWaveform::NexWaveform(uint8_t pid, uint8_t cid, const char *name, + float minVal, float maxVal, uint8_t hight, + const NexObject* page):NexWaveform(pid, cid, name, page) { - char buf[15] = {0}; - - if (ch > 3) - { - return false; - } - - sprintf(buf, "add %u,%u,%u", getObjCid(), ch, number); + m_minVal = minVal; + m_maxVal = maxVal; + m_hight = hight; + m_scale =((float)hight)/(maxVal-minVal); +} - sendCommand(buf); - return true; -} -uint32_t NexWaveform::Get_background_color_bco(uint32_t *number) + +bool NexWaveform::Get_background_color_bco(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -50,23 +53,23 @@ bool NexWaveform::Set_background_color_bco(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".bco="; cmd += buf; sendCommand(cmd.c_str()); cmd=""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } -uint32_t NexWaveform::Get_grid_color_gdc(uint32_t *number) +bool NexWaveform::Get_grid_color_gdc(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".gdc"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -78,23 +81,23 @@ bool NexWaveform::Set_grid_color_gdc(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".gdc="; cmd += buf; sendCommand(cmd.c_str()); cmd=""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } -uint32_t NexWaveform::Get_grid_width_gdw(uint32_t *number) +bool NexWaveform::Get_grid_width_gdw(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".gdw"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -106,23 +109,23 @@ bool NexWaveform::Set_grid_width_gdw(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".gdw="; cmd += buf; sendCommand(cmd.c_str()); cmd=""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } -uint32_t NexWaveform::Get_grid_height_gdh(uint32_t *number) +bool NexWaveform::Get_grid_height_gdh(uint32_t *number) { String cmd; cmd += "get "; - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".gdh"; sendCommand(cmd.c_str()); return recvRetNumber(number); @@ -134,43 +137,64 @@ bool NexWaveform::Set_grid_height_gdh(uint32_t number) String cmd; utoa(number, buf, 10); - cmd += getObjName(); + getObjGlobalPageName(cmd); cmd += ".gdh="; cmd += buf; sendCommand(cmd.c_str()); cmd=""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } -uint32_t NexWaveform::Get_channel_0_color_pco0(uint32_t *number) +bool NexWaveform::Get_channel_color(uint8_t ch, uint32_t *number) { + char buf[4] = {0}; + utoa(ch, buf, 10); + String cmd; cmd += "get "; - cmd += getObjName(); - cmd += ".pco0"; + getObjGlobalPageName(cmd); + cmd += ".pco"; + cmd += buf; sendCommand(cmd.c_str()); return recvRetNumber(number); } -bool NexWaveform::Set_channel_0_color_pco0(uint32_t number) -{ +bool NexWaveform::Set_channel_color(uint8_t ch, uint32_t number) +{ char buf[10] = {0}; + utoa(ch, buf, 10); String cmd; + getObjGlobalPageName(cmd); + cmd += ".pco"; + cmd += buf; + cmd += "="; utoa(number, buf, 10); - cmd += getObjName(); - cmd += ".pco0="; cmd += buf; sendCommand(cmd.c_str()); cmd=""; cmd += "ref "; - cmd += getObjName(); + getObjGlobalPageName(cmd); sendCommand(cmd.c_str()); return recvRetCommandFinished(); } + bool NexWaveform::Clear(uint8_t ch) + { + char buf[4] = {0}; + utoa(getObjCid(), buf, 10); + String cmd; + cmd = "cle "; + cmd += buf; + cmd += ","; + utoa(ch, buf, 10); + cmd += buf; + sendCommand(cmd.c_str()); + return recvRetCommandFinished(); + } + diff --git a/NexWaveform.h b/NexWaveform.h index 52bdef99..7e486748 100755 --- a/NexWaveform.h +++ b/NexWaveform.h @@ -5,6 +5,7 @@ * * @author Wu Pengfei (email:) * @date 2015/8/13 + * @author Jyrki Berg 3/3/2019 (https://github.com/jyberg) * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n @@ -16,6 +17,10 @@ #ifndef __NEXWAVEFORM_H__ #define __NEXWAVEFORM_H__ +#ifdef STD_SUPPORT +#include +#endif + #include "NexTouch.h" #include "NexHardware.h" /** @@ -26,32 +31,181 @@ /** * NexWaveform component. */ -class NexWaveform: public NexObject +class NexWaveform: public NexTouch { public: /* methods */ /** - * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name); + * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); + */ + NexWaveform(uint8_t pid, uint8_t cid, const char *name, const NexObject* page=nullptr); + + /** + * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name, + * int32_t minVal, int32_t maxVal, uint8_t hight, + * const NexObject* page=nullptr); + * + * Constructor with value scaling parameters, Scales added value to set Waveform scale */ - NexWaveform(uint8_t pid, uint8_t cid, const char *name); - + NexWaveform(uint8_t pid, uint8_t cid, const char *name, + float minVal, float maxVal, uint8_t hight, + const NexObject* page=nullptr); + /** * Add value to show. * * @param ch - channel of waveform(0-3). - * @param number - the value of waveform. + * @param value - the value of waveform (value is scaled to nextion resolution 0-255 based on Min / Max component hight). * * @retval true - success. * @retval false - failed. */ - bool addValue(uint8_t ch, uint8_t number); - + template + bool addValue(uint8_t ch, T value) + { + #ifdef STD_SUPPORT + // compile time data type check + static_assert(std::is_arithmetic::value, "Not numeric type"); + #endif + char buf[15] = {0}; + + if (ch > 3) + { + return false; + } + + sprintf(buf, "add %u,%u,%u", getObjCid(), ch, ScaleToForm(value)); + sendCommand(buf); + return true; + } + + /** + * Add values to show. + * + * @param ch - channel of waveform(0-3). + * @param values - the values of waveform (values are scaled to nextion resolution 0-255 based on Min / Max component hight). + * + * @retval true - success. + * @retval false - failed. + */ + #ifdef STD_SUPPORT + template + bool addValues(uint8_t ch, std::vector &values) + { + // compile time data type check + static_assert(std::is_arithmetic::value, "Not numeric type"); + + bool ret=true; + + for(uint16_t offset{0}; offset < values.size() && ret;) + { + uint32_t sendBytes{values.size()-offset}; + if(sendBytes>124) + { + sendBytes=124; + } + { + char buf[4] = {0}; + utoa(getObjCid(), buf, 10); + String cmd; + cmd = "addt "; + cmd += buf; + cmd += ","; + utoa(ch, buf, 10); + cmd += buf; + cmd += ","; + utoa(sendBytes, buf, 10); + cmd += buf; + sendCommand(cmd.c_str()); + } + + if(!RecvTransparendDataModeReady()) + { + ret=false; + break; + } + for(uint16_t i{0}; i + bool addValues(uint8_t ch, T *values, uint16_t len) + { + #ifdef STD_SUPPORT + // compile time data type check + static_assert(std::is_arithmetic::value, "Not numeric type"); + #endif + + bool ret=true; + + for(uint16_t offset{0}; offset < len && ret;) + { + uint32_t sendBytes{len-offset}; + if(sendBytes>124) + { + sendBytes=124; + } + { + char buf[4] = {0}; + utoa(getObjCid(), buf, 10); + String cmd; + cmd = "addt "; + cmd += buf; + cmd += ","; + utoa(ch, buf, 10); + cmd += buf; + cmd += ","; + utoa(sendBytes, buf, 10); + cmd += buf; + sendCommand(cmd.c_str()); + } + + if(!RecvTransparendDataModeReady()) + { + ret=false; + break; + } + for(uint16_t i{0}; i attribute of component * + * @param ch - channel of waveform(0-3). * @param number - buffer storing data retur - * @return the length of the data + * @return true if success, false for failure */ - uint32_t Get_channel_0_color_pco0(uint32_t *number); + bool Get_channel_color(uint8_t ch, uint32_t *number); /** - * Set pco0 attribute of component + * Set pco attribute of component * + * @param ch - channel of waveform(0-3). * @param number - To set up the data * @return true if success, false for failure */ - bool Set_channel_0_color_pco0(uint32_t number); + bool Set_channel_color(uint8_t ch, uint32_t number); + + /** + * Clear waveform component + * @param ch - channel of waveform(0-3). 255 Clear all data + * @return true if success, false for failure + * */ + bool Clear(uint8_t ch); + +private: + + template + inline uint8_t ScaleToForm(T value) + { + if(value > m_maxVal){value=m_maxVal;} + else if(value < m_minVal){value=m_minVal;} + value-= m_minVal; + value *= m_scale; + uint8_t v = abs((int16_t)value); + return v; + } + float m_minVal; + float m_maxVal; + float m_scale; + uint8_t m_hight; }; /** diff --git a/examples/CompButton/CompButton_v0_32.HMI b/examples/CompButton/CompButton_v0_32.HMI index 3427061a..4bcef592 100755 Binary files a/examples/CompButton/CompButton_v0_32.HMI and b/examples/CompButton/CompButton_v0_32.HMI differ diff --git a/examples/CompButton/CompButton_v0_32.ino b/examples/CompButton/CompButton_v0_32.ino index 18652948..5563b6f1 100755 --- a/examples/CompButton/CompButton_v0_32.ino +++ b/examples/CompButton/CompButton_v0_32.ino @@ -9,6 +9,8 @@ * @date 2015/7/10 * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues * @convert by Patrick Martin, no other changes made + * @author Jyrki Berg 2/27/2019 (https://github.com/jyberg) + * * @copyright * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n * This program is free software; you can redistribute it and/or @@ -22,7 +24,7 @@ /* * Declare a button object [page id:0,component id:1, component name: "b0"]. */ -NexButton b0 = NexButton(0, 1, "b0"); +NexButton b0(0, 1, "b0"); char buffer[100] = {0}; @@ -50,7 +52,8 @@ void b0PopCallback(void *ptr) memset(buffer, 0, sizeof(buffer)); /* Get the text value of button component [the value is string type]. */ - btn->getText(buffer, sizeof(buffer)); + len = sizeof(buffer); + btn->getText(buffer, len ); number = atoi(buffer); number += 1; diff --git a/examples/CompCrop/CompCrop_v0_32.HMI b/examples/CompCrop/CompCrop_v0_43.HMI old mode 100755 new mode 100644 similarity index 71% rename from examples/CompCrop/CompCrop_v0_32.HMI rename to examples/CompCrop/CompCrop_v0_43.HMI index 926e6d38..e87aef38 Binary files a/examples/CompCrop/CompCrop_v0_32.HMI and b/examples/CompCrop/CompCrop_v0_43.HMI differ diff --git a/examples/CompCrop/CompCrop_v0_32.ino b/examples/CompCrop/CompCrop_v0_43.ino old mode 100755 new mode 100644 similarity index 93% rename from examples/CompCrop/CompCrop_v0_32.ino rename to examples/CompCrop/CompCrop_v0_43.ino index 9bd12874..c0192dee --- a/examples/CompCrop/CompCrop_v0_32.ino +++ b/examples/CompCrop/CompCrop_v0_43.ino @@ -1,61 +1,63 @@ -/** - * @example CompCrop.ino - * - * @par How to Use - * This example shows that when the crop component on the Nextion screen is released, - * the image of this component will be changed. - * - * @author Wu Pengfei (email:) - * @date 2015/7/10 - * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues - * @convert by Patrick Martin, no other changes made - * @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 "Nextion.h" - -/* - * Declare a crop object [page id:0,component id:1, component name: "q0"]. - */ -NexCrop q0 = NexCrop(0, 1, "q0"); - -NexTouch *nex_listen_list[] = -{ - &q0, - NULL -}; - -/* - * Crop component pop callback function. - * In this example,the image of current crop component will be changed every time when it is released. - */ -void q0PopCallback(void *ptr) -{ - uint32_t number = 0; - dbSerialPrintln("q0PopCallback"); - - q0.getPic(&number); - - number += 1; - number %= 2; - - q0.setPic(number); -} - -void setup(void) -{ - nexInit(); - q0.attachPop(q0PopCallback); - dbSerialPrintln("setup done"); -} - -void loop(void) -{ - nexLoop(nex_listen_list); -} - +/** + * @example CompCrop.ino + * + * @par How to Use + * This example shows that when the crop component on the Nextion screen is released, + * the image of this component will be changed. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues + * @convert by Patrick Martin, no other changes made + * @author Jyrki Berg 2/27/2019 (https://github.com/jyberg) + * + * @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 "Nextion.h" + +/* + * Declare a crop object [page id:0,component id:1, component name: "q0"]. + */ +NexCrop q0(0, 1, "q0"); + +NexTouch *nex_listen_list[] = +{ + &q0, + NULL +}; + +/* + * Crop component pop callback function. + * In this example,the image of current crop component will be changed every time when it is released. + */ +void q0PopCallback(void *ptr) +{ + uint32_t number = 0; + dbSerialPrintln("q0PopCallback"); + + q0.getPic(&number); + + number += 1; + number %= 2; + + q0.setPic(number); +} + +void setup(void) +{ + nexInit(); + q0.attachPop(q0PopCallback); + dbSerialPrintln("setup done"); +} + +void loop(void) +{ + nexLoop(nex_listen_list); +} + diff --git a/examples/CompDualStateButton/CompDualStateButton_v0_32.HMI b/examples/CompDualStateButton/CompDualStateButton_v0_32.HMI deleted file mode 100755 index 6865da97..00000000 Binary files a/examples/CompDualStateButton/CompDualStateButton_v0_32.HMI and /dev/null differ diff --git a/examples/CompDualStateButton/CompDualStateButton_v0_43.HMI b/examples/CompDualStateButton/CompDualStateButton_v0_43.HMI new file mode 100644 index 00000000..6d22a14a Binary files /dev/null and b/examples/CompDualStateButton/CompDualStateButton_v0_43.HMI differ diff --git a/examples/CompDualStateButton/CompDualStateButton_v0_32.ino b/examples/CompDualStateButton/CompDualStateButton_v0_43.ino old mode 100755 new mode 100644 similarity index 92% rename from examples/CompDualStateButton/CompDualStateButton_v0_32.ino rename to examples/CompDualStateButton/CompDualStateButton_v0_43.ino index 176a1c6a..d036863c --- a/examples/CompDualStateButton/CompDualStateButton_v0_32.ino +++ b/examples/CompDualStateButton/CompDualStateButton_v0_43.ino @@ -1,96 +1,97 @@ -/** - * @example CompDualStateButton.ino - * - * @par How to Use - * This example shows that when the dual state button component on the Nextion screen is released, - * the text of Text component will change one every time. - * - * @author huang xianming (email:) - * @date 2015/11/11 - * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues - * @convert by Patrick Martin, no other changes made - * @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 "Nextion.h" - -/* - * Declare a dual state button object [page id:0,component id:1, component name: "bt0"]. - */ -NexDSButton bt0 = NexDSButton(0, 1, "bt0"); - -NexText t0 = NexText(0, 2, "t0"); - - -char buffer[100] = {0}; - -/* - * Register a dual state button object to the touch event list. - */ -NexTouch *nex_listen_list[] = -{ - &bt0, - NULL -}; - -/* - * Dual state button component pop callback function. - * In this example,the button's text value will plus one every time when it is released. - */ -void bt0PopCallback(void *ptr) -{ - uint32_t dual_state; - NexDSButton *btn = (NexDSButton *)ptr; - dbSerialPrintln("b0PopCallback"); - dbSerialPrint("ptr="); - dbSerialPrintln((uint32_t)ptr); - memset(buffer, 0, sizeof(buffer)); - - /* Get the state value of dual state button component . */ - bt0.getValue(&dual_state); - if(dual_state) - { - t0.setText("HI! OPEN STATE"); - } - else - { - t0.setText("HI! OFF STATE"); - } -} - -void setup(void) -{ - /* Set the baudrate which is for debug and communicate with Nextion screen. */ - nexInit(); - - /* Register the pop event callback function of the dual state button component. */ - bt0.attachPop(bt0PopCallback, &bt0); - - dbSerialPrintln("setup done"); -} - -void loop(void) -{ - /* - * When a pop or push event occured every time, - * the corresponding component[right page id and component id] in touch event list will be asked. - */ - nexLoop(nex_listen_list); -} - - - - - - - - - - - - +/** + * @example CompDualStateButton.ino + * + * @par How to Use + * This example shows that when the dual state button component on the Nextion screen is released, + * the text of Text component will change one every time. + * + * @author huang xianming (email:) + * @date 2015/11/11 + * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues + * @convert by Patrick Martin, no other changes made + * @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 "Nextion.h" + +/* + * Declare a dual state button object [page id:0,component id:1, component name: "bt0"]. + */ + +NexDSButton bt0(0, 1, "bt0"); + +NexText t0(0, 2, "t0"); + + +char buffer[100] = {0}; + +/* + * Register a dual state button object to the touch event list. + */ +NexTouch *nex_listen_list[] = +{ + &bt0, + NULL +}; + +/* + * Dual state button component pop callback function. + * In this example,the button's text value will plus one every time when it is released. + */ +void bt0PopCallback(void *ptr) +{ + uint32_t dual_state; + NexDSButton *btn = (NexDSButton *)ptr; + dbSerialPrintln("b0PopCallback"); + dbSerialPrint("ptr="); + dbSerialPrintln((uint32_t)ptr); + memset(buffer, 0, sizeof(buffer)); + + /* Get the state value of dual state button component . */ + bt0.getValue(&dual_state); + if(dual_state) + { + t0.setText("HI! OPEN STATE"); + } + else + { + t0.setText("HI! OFF STATE"); + } +} + +void setup(void) +{ + /* Set the baudrate which is for debug and communicate with Nextion screen. */ + nexInit(); + + /* Register the pop event callback function of the dual state button component. */ + bt0.attachPop(bt0PopCallback, &bt0); + + dbSerialPrintln("setup done"); +} + +void loop(void) +{ + /* + * When a pop or push event occured every time, + * the corresponding component[right page id and component id] in touch event list will be asked. + */ + nexLoop(nex_listen_list); +} + + + + + + + + + + + + diff --git a/examples/CompGauge/CompGauge_v0_32.HMI b/examples/CompGauge/CompGauge_v0_32.HMI deleted file mode 100755 index 159582c8..00000000 Binary files a/examples/CompGauge/CompGauge_v0_32.HMI and /dev/null differ diff --git a/examples/CompGauge/CompGauge_v0_43.HMI b/examples/CompGauge/CompGauge_v0_43.HMI new file mode 100644 index 00000000..416fd226 Binary files /dev/null and b/examples/CompGauge/CompGauge_v0_43.HMI differ diff --git a/examples/CompGauge/CompGauge_v0_32.ino b/examples/CompGauge/CompGauge_v0_43.ino old mode 100755 new mode 100644 similarity index 87% rename from examples/CompGauge/CompGauge_v0_32.ino rename to examples/CompGauge/CompGauge_v0_43.ino index 9465cf40..89b3c3c5 --- a/examples/CompGauge/CompGauge_v0_32.ino +++ b/examples/CompGauge/CompGauge_v0_43.ino @@ -1,78 +1,80 @@ -/** - * @example CompGauge.ino - * - * @par How to Use - * This example shows that ,when the "btn_up" component on the Nextion screen is released, - * the value of gauge component will plus 5, when the "btn_down" component released, - * the value of gauge component will minus 5 every time. - * - * @author Wu Pengfei (email:) - * @date 2015/7/10 - * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues - * @convert by Patrick Martin, no other changes made - * @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 "Nextion.h" - -NexGauge pointer = NexGauge(0, 1, "pointer"); -NexButton btn_up = NexButton(0, 2, "btn_up"); -NexButton btn_down = NexButton(0, 3, "btn_down"); - -NexTouch *nex_listen_list[] = -{ - &btn_up, - &btn_down, - NULL -}; - -void buttonUpPopCallback(void *ptr) -{ - uint32_t number = 0; - dbSerialPrintln("buttonUpPopCallback"); - - pointer.getValue(&number); - - number += 5; - if (number >= 360) - { - number = 0; - } - - pointer.setValue(number); -} -void buttonDownPopCallback(void *ptr) -{ - uint32_t number = 0; - dbSerialPrintln("buttonDownPopCallback"); - - pointer.getValue(&number); - - if (number >= 5) - { - number -= 5; - } - - pointer.setValue(number); -} - - - -void setup(void) -{ - nexInit(); - btn_up.attachPop(buttonUpPopCallback); - btn_down.attachPop(buttonDownPopCallback); - dbSerialPrintln("setup done"); -} - -void loop(void) -{ - nexLoop(nex_listen_list); -} - +/** + * @example CompGauge.ino + * + * @par How to Use + * This example shows that ,when the "btn_up" component on the Nextion screen is released, + * the value of gauge component will plus 5, when the "btn_down" component released, + * the value of gauge component will minus 5 every time. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues + * @convert by Patrick Martin, no other changes made + * @author Jyrki Berg 2/27/2019 (https://github.com/jyberg) + * + * @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 "Nextion.h" + +NexGauge pointer(0, 1, "pointer"); +NexButton btn_up(0, 2, "btn_up"); +NexButton btn_down(0, 3, "btn_down"); + +NexTouch *nex_listen_list[] = +{ + &btn_up, + &btn_down, + NULL +}; + +void buttonUpPopCallback(void *ptr) +{ + uint32_t number = 0; + dbSerialPrintln("buttonUpPopCallback"); + + pointer.getValue(&number); + + number += 5; + if (number >= 360) + { + number = 0; + } + + pointer.setValue(number); +} +void buttonDownPopCallback(void *ptr) +{ + uint32_t number = 0; + dbSerialPrintln("buttonDownPopCallback"); + + pointer.getValue(&number); + + if (number >= 5) + { + number -= 5; + } + + pointer.setValue(number); +} + + + +void setup(void) +{ + nexInit(); + btn_up.attachPop(buttonUpPopCallback); + btn_down.attachPop(buttonDownPopCallback); + dbSerialPrintln("setup done"); +} + +void loop(void) +{ + nexLoop(nex_listen_list); +} + diff --git a/examples/CompHotspot/CompHotSpot_v0_32.HMI b/examples/CompHotspot/CompHotSpot_v0_32.HMI deleted file mode 100755 index 159582c8..00000000 Binary files a/examples/CompHotspot/CompHotSpot_v0_32.HMI and /dev/null differ diff --git a/examples/CompHotspot/CompHotSpot_v0_43.HMI b/examples/CompHotspot/CompHotSpot_v0_43.HMI new file mode 100644 index 00000000..416fd226 Binary files /dev/null and b/examples/CompHotspot/CompHotSpot_v0_43.HMI differ diff --git a/examples/CompHotspot/CompHotspot_v0_32.ino b/examples/CompHotspot/CompHotspot_v0_43.ino old mode 100755 new mode 100644 similarity index 96% rename from examples/CompHotspot/CompHotspot_v0_32.ino rename to examples/CompHotspot/CompHotspot_v0_43.ino index 41dccdce..88ab3c40 --- a/examples/CompHotspot/CompHotspot_v0_32.ino +++ b/examples/CompHotspot/CompHotspot_v0_43.ino @@ -1,73 +1,73 @@ -/** - * @example CompHotspot.ino - * - * @par How to Use - * This example shows that ,when the hot component on the Nextion screen is pressed or released, - * the debug serial will output the debug information every time. - * - * @author Wu Pengfei (email:) - * @date 2015/7/10 - * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues - * @convert by Patrick Martin, no other changes made - * @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 "Nextion.h" - -NexHotspot hot0 = NexHotspot(0, 1, "hot0"); -NexHotspot hot1 = NexHotspot(0, 2, "hot1"); - -NexTouch *nex_listen_list[] = -{ - &hot0, - &hot1, - NULL -}; - -void hot0PushCallback(void *ptr) -{ - dbSerialPrintln("hot0PushCallback"); - dbSerialPrint("ptr="); - dbSerialPrintln((uint32_t)ptr); -} - -void hot1PushCallback(void *ptr) -{ - dbSerialPrintln("hot1PushCallback"); - dbSerialPrint("ptr="); - dbSerialPrintln((uint32_t)ptr); -} - -void hot0PopCallback(void *ptr) -{ - dbSerialPrintln("hot0PopCallback"); - dbSerialPrint("ptr="); - dbSerialPrintln((uint32_t)ptr); -} - -void hot1PopCallback(void *ptr) -{ - dbSerialPrintln("hot1PopCallback"); - dbSerialPrint("ptr="); - dbSerialPrintln((uint32_t)ptr); -} - -void setup(void) -{ - nexInit(); - hot0.attachPush(hot0PushCallback, &hot0); - hot0.attachPop(hot0PopCallback, &hot0); - hot1.attachPush(hot1PushCallback, &hot1); - hot1.attachPop(hot1PopCallback, &hot1); - dbSerialPrintln("setup done"); -} - -void loop(void) -{ - nexLoop(nex_listen_list); -} +/** + * @example CompHotspot.ino + * + * @par How to Use + * This example shows that ,when the hot component on the Nextion screen is pressed or released, + * the debug serial will output the debug information every time. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues + * @convert by Patrick Martin, no other changes made + * @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 "Nextion.h" + +NexHotspot hot0 = NexHotspot(0, 1, "hot0"); +NexHotspot hot1 = NexHotspot(0, 2, "hot1"); + +NexTouch *nex_listen_list[] = +{ + &hot0, + &hot1, + NULL +}; + +void hot0PushCallback(void *ptr) +{ + dbSerialPrintln("hot0PushCallback"); + dbSerialPrint("ptr="); + dbSerialPrintln((uint32_t)ptr); +} + +void hot1PushCallback(void *ptr) +{ + dbSerialPrintln("hot1PushCallback"); + dbSerialPrint("ptr="); + dbSerialPrintln((uint32_t)ptr); +} + +void hot0PopCallback(void *ptr) +{ + dbSerialPrintln("hot0PopCallback"); + dbSerialPrint("ptr="); + dbSerialPrintln((uint32_t)ptr); +} + +void hot1PopCallback(void *ptr) +{ + dbSerialPrintln("hot1PopCallback"); + dbSerialPrint("ptr="); + dbSerialPrintln((uint32_t)ptr); +} + +void setup(void) +{ + nexInit(); + hot0.attachPush(hot0PushCallback, &hot0); + hot0.attachPop(hot0PopCallback, &hot0); + hot1.attachPush(hot1PushCallback, &hot1); + hot1.attachPop(hot1PopCallback, &hot1); + dbSerialPrintln("setup done"); +} + +void loop(void) +{ + nexLoop(nex_listen_list); +} diff --git a/examples/CompNumber/CompNumber_v0_32.HMI b/examples/CompNumber/CompNumber_v0_32.HMI deleted file mode 100755 index 51e9e339..00000000 Binary files a/examples/CompNumber/CompNumber_v0_32.HMI and /dev/null differ diff --git a/examples/CompNumber/CompNumber_v0_43.HMI b/examples/CompNumber/CompNumber_v0_43.HMI new file mode 100644 index 00000000..1adea871 Binary files /dev/null and b/examples/CompNumber/CompNumber_v0_43.HMI differ diff --git a/examples/CompNumber/CompNumber_v0_32.ino b/examples/CompNumber/CompNumber_v0_43.ino old mode 100755 new mode 100644 similarity index 96% rename from examples/CompNumber/CompNumber_v0_32.ino rename to examples/CompNumber/CompNumber_v0_43.ino index 10d4e0f4..1c5beadb --- a/examples/CompNumber/CompNumber_v0_32.ino +++ b/examples/CompNumber/CompNumber_v0_43.ino @@ -1,124 +1,124 @@ -/** - * @example CompNumber.ino - * - * @par How to Use - * This example shows that ,when the "+" component on the Nextion screen is released, - * the value of number component will plus 1,when the "-" component released ,the value of - * number component will minus 1 every time. - * - * @author huang xianming (email:) - * @date 2015/11/10 - * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues - * @convert by Patrick Martin, no other changes made - * @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 "Nextion.h" - -void n0PopCallback(void *ptr); -void b0PopCallback(void *ptr); -void b1PopCallback(void *ptr); - -/* - * Declare a number object [page id:0,component id:3, component name: "n0"]. - */ -NexNumber n0 = NexNumber(0, 3, "n0"); - -/* - * Declare a button object [page id:0,component id:1, component name: "b0"]. - */ -NexButton b0 = NexButton(0, 1, "b0"); - -/* - * Declare a button object [page id:0,component id:2, component name: "b1"]. - */ -NexButton b1 = NexButton(0, 2, "b1"); - -char buffer[100] = {0}; - -/* - * Register object n0, b0, b1, to the touch event list. - */ -NexTouch *nex_listen_list[] = -{ - &n0, - &b0, - &b1, - NULL -}; - -/* - * number component pop callback function. - */ -void n0PopCallback(void *ptr) -{ - dbSerialPrintln("n0PopCallback"); - n0.setValue(50); -} - -/* - * Button0 component pop callback function. - * In this example,the value of the number component will plus one every time when button0 is released. - */ -void b0PopCallback(void *ptr) -{ - uint32_t number; - - dbSerialPrintln("b0PopCallback"); - - n0.getValue(&number); - - number += 1; - - n0.setValue(number); -} - -/* - * Button1 component pop callback function. - * In this example,the value of the number component will minus one every time when button1 is released. - */ -void b1PopCallback(void *ptr) -{ - uint32_t number; - - dbSerialPrintln("b1PopCallback"); - - n0.getValue(&number); - - number -= 1; - - n0.setValue(number); -} - -void setup(void) -{ - /* Set the baudrate which is for debug and communicate with Nextion screen. */ - nexInit(); - - /* Register the pop event callback function of the current number component. */ - n0.attachPop(n0PopCallback); - - /* Register the pop event callback function of the current button0 component. */ - b0.attachPop(b0PopCallback); - - /* Register the pop event callback function of the current button1 component. */ - b1.attachPop(b1PopCallback); - - dbSerialPrintln("setup done"); -} - -void loop(void) -{ - /* - * When a pop or push event occured every time, - * the corresponding component[right page id and component id] in touch event list will be asked. - */ - nexLoop(nex_listen_list); -} - - +/** + * @example CompNumber.ino + * + * @par How to Use + * This example shows that ,when the "+" component on the Nextion screen is released, + * the value of number component will plus 1,when the "-" component released ,the value of + * number component will minus 1 every time. + * + * @author huang xianming (email:) + * @date 2015/11/10 + * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues + * @convert by Patrick Martin, no other changes made + * @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 "Nextion.h" + +void n0PopCallback(void *ptr); +void b0PopCallback(void *ptr); +void b1PopCallback(void *ptr); + +/* + * Declare a number object [page id:0,component id:3, component name: "n0"]. + */ +NexNumber n0 = NexNumber(0, 3, "n0"); + +/* + * Declare a button object [page id:0,component id:1, component name: "b0"]. + */ +NexButton b0 = NexButton(0, 1, "b0"); + +/* + * Declare a button object [page id:0,component id:2, component name: "b1"]. + */ +NexButton b1 = NexButton(0, 2, "b1"); + +char buffer[100] = {0}; + +/* + * Register object n0, b0, b1, to the touch event list. + */ +NexTouch *nex_listen_list[] = +{ + &n0, + &b0, + &b1, + NULL +}; + +/* + * number component pop callback function. + */ +void n0PopCallback(void *ptr) +{ + dbSerialPrintln("n0PopCallback"); + n0.setValue(50); +} + +/* + * Button0 component pop callback function. + * In this example,the value of the number component will plus one every time when button0 is released. + */ +void b0PopCallback(void *ptr) +{ + uint32_t number; + + dbSerialPrintln("b0PopCallback"); + + n0.getValue(&number); + + number += 1; + + n0.setValue(number); +} + +/* + * Button1 component pop callback function. + * In this example,the value of the number component will minus one every time when button1 is released. + */ +void b1PopCallback(void *ptr) +{ + uint32_t number; + + dbSerialPrintln("b1PopCallback"); + + n0.getValue(&number); + + number -= 1; + + n0.setValue(number); +} + +void setup(void) +{ + /* Set the baudrate which is for debug and communicate with Nextion screen. */ + nexInit(); + + /* Register the pop event callback function of the current number component. */ + n0.attachPop(n0PopCallback); + + /* Register the pop event callback function of the current button0 component. */ + b0.attachPop(b0PopCallback); + + /* Register the pop event callback function of the current button1 component. */ + b1.attachPop(b1PopCallback); + + dbSerialPrintln("setup done"); +} + +void loop(void) +{ + /* + * When a pop or push event occured every time, + * the corresponding component[right page id and component id] in touch event list will be asked. + */ + nexLoop(nex_listen_list); +} + + diff --git a/examples/CompPage/CompPage_v0_32.HMI b/examples/CompPage/CompPage_v0_32.HMI deleted file mode 100755 index b974d766..00000000 Binary files a/examples/CompPage/CompPage_v0_32.HMI and /dev/null differ diff --git a/examples/CompPage/CompPage_v0_43.HMI b/examples/CompPage/CompPage_v0_43.HMI new file mode 100644 index 00000000..910e4de5 Binary files /dev/null and b/examples/CompPage/CompPage_v0_43.HMI differ diff --git a/examples/CompPage/CompPage_v0_32.ino b/examples/CompPage/CompPage_v0_43.ino old mode 100755 new mode 100644 similarity index 95% rename from examples/CompPage/CompPage_v0_32.ino rename to examples/CompPage/CompPage_v0_43.ino index b728ca08..0497e8ec --- a/examples/CompPage/CompPage_v0_32.ino +++ b/examples/CompPage/CompPage_v0_43.ino @@ -1,75 +1,75 @@ -/** - * @example CompPage.ino - * - * @par How to Use - * Show how to use API of class NexPage. - * - * @author Wu Pengfei (email:) - * @date 2015/7/10 - * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues - * @convert by Patrick Martin, no other changes made - * @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 "Nextion.h" - -NexPage page0 = NexPage(0, 0, "page0"); -NexPage page1 = NexPage(1, 0, "page1"); -NexPage page2 = NexPage(2, 0, "page2"); -NexPage page3 = NexPage(3, 0, "page3"); - -NexTouch *nex_listen_list[] = -{ - &page0, - &page1, - &page2, - &page3, - NULL -}; - -void page0PopCallback(void *ptr) -{ - dbSerialPrintln("page0PopCallback"); - page1.show(); -} - -void page1PopCallback(void *ptr) -{ - dbSerialPrintln("page1PopCallback"); - page2.show(); -} - -void page2PopCallback(void *ptr) -{ - dbSerialPrintln("page2PopCallback"); - page3.show(); -} - -void page3PopCallback(void *ptr) -{ - dbSerialPrintln("page3PopCallback"); - page0.show(); -} - -void setup(void) -{ - nexInit(); - dbSerialPrintln("setup begin"); - - page0.attachPop(page0PopCallback); - page1.attachPop(page1PopCallback); - page2.attachPop(page2PopCallback); - page3.attachPop(page3PopCallback); - - dbSerialPrintln("setup end"); -} - -void loop(void) -{ - nexLoop(nex_listen_list); -} +/** + * @example CompPage.ino + * + * @par How to Use + * Show how to use API of class NexPage. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues + * @convert by Patrick Martin, no other changes made + * @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 "Nextion.h" + +NexPage page0 = NexPage(0, 0, "page0"); +NexPage page1 = NexPage(1, 0, "page1"); +NexPage page2 = NexPage(2, 0, "page2"); +NexPage page3 = NexPage(3, 0, "page3"); + +NexTouch *nex_listen_list[] = +{ + &page0, + &page1, + &page2, + &page3, + NULL +}; + +void page0PopCallback(void *ptr) +{ + dbSerialPrintln("page0PopCallback"); + page1.show(); +} + +void page1PopCallback(void *ptr) +{ + dbSerialPrintln("page1PopCallback"); + page2.show(); +} + +void page2PopCallback(void *ptr) +{ + dbSerialPrintln("page2PopCallback"); + page3.show(); +} + +void page3PopCallback(void *ptr) +{ + dbSerialPrintln("page3PopCallback"); + page0.show(); +} + +void setup(void) +{ + nexInit(); + dbSerialPrintln("setup begin"); + + page0.attachPop(page0PopCallback); + page1.attachPop(page1PopCallback); + page2.attachPop(page2PopCallback); + page3.attachPop(page3PopCallback); + + dbSerialPrintln("setup end"); +} + +void loop(void) +{ + nexLoop(nex_listen_list); +} diff --git a/examples/CompPicture/CompPicture_v0_32.HMI b/examples/CompPicture/CompPicture_v0_32.HMI deleted file mode 100755 index 5e478538..00000000 Binary files a/examples/CompPicture/CompPicture_v0_32.HMI and /dev/null differ diff --git a/examples/CompHotspot/CompHotspot_v0_32.HMI b/examples/CompPicture/CompPicture_v0_43.HMI old mode 100755 new mode 100644 similarity index 88% rename from examples/CompHotspot/CompHotspot_v0_32.HMI rename to examples/CompPicture/CompPicture_v0_43.HMI index 57278be1..906df8ff Binary files a/examples/CompHotspot/CompHotspot_v0_32.HMI and b/examples/CompPicture/CompPicture_v0_43.HMI differ diff --git a/examples/CompPicture/CompPicture_v0_32.ino b/examples/CompPicture/CompPicture_v0_43.ino old mode 100755 new mode 100644 similarity index 95% rename from examples/CompPicture/CompPicture_v0_32.ino rename to examples/CompPicture/CompPicture_v0_43.ino index 58028858..d674300b --- a/examples/CompPicture/CompPicture_v0_32.ino +++ b/examples/CompPicture/CompPicture_v0_43.ino @@ -1,65 +1,65 @@ -/** - * @example CompPicture.ino - * - * @par How to Use - * This example shows that ,when the picture component on the Nextion screen is released, - * the picture of current component will be changed every time. - * - * @author Wu Pengfei (email:) - * @date 2015/7/10 - * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues - * @convert by Patrick Martin, no other changes made - * @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 "Nextion.h" - -/* - * Declare a picture object [page id:0,component id:1, component name: "p0"]. - */ -NexPicture p0 = NexPicture(0, 1, "p0"); - -NexTouch *nex_listen_list[] = -{ - &p0, - NULL -}; - -void p0PopCallback(void *ptr) -{ - uint32_t number = 0; - dbSerialPrintln("p0PopCallback"); - - p0.getPic(&number); - - if (number == 1) - { - number = 2; - } - else - { - number = 1; - } - - p0.setPic(number); -} - - -void setup(void) -{ - nexInit(); - p0.attachPop(p0PopCallback); - dbSerialPrintln("setup done"); -} - -void loop(void) -{ - nexLoop(nex_listen_list); -} - +/** + * @example CompPicture.ino + * + * @par How to Use + * This example shows that ,when the picture component on the Nextion screen is released, + * the picture of current component will be changed every time. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues + * @convert by Patrick Martin, no other changes made + * @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 "Nextion.h" + +/* + * Declare a picture object [page id:0,component id:1, component name: "p0"]. + */ +NexPicture p0 = NexPicture(0, 1, "p0"); + +NexTouch *nex_listen_list[] = +{ + &p0, + NULL +}; + +void p0PopCallback(void *ptr) +{ + uint32_t number = 0; + dbSerialPrintln("p0PopCallback"); + + p0.getPic(&number); + + if (number == 1) + { + number = 2; + } + else + { + number = 1; + } + + p0.setPic(number); +} + + +void setup(void) +{ + nexInit(); + p0.attachPop(p0PopCallback); + dbSerialPrintln("setup done"); +} + +void loop(void) +{ + nexLoop(nex_listen_list); +} + diff --git a/examples/CompProgressBar/CompProgressBar_v0_32.HMI b/examples/CompProgressBar/CompProgressBar_v0_32.HMI deleted file mode 100755 index 7a4d7d3a..00000000 Binary files a/examples/CompProgressBar/CompProgressBar_v0_32.HMI and /dev/null differ diff --git a/examples/CompProgressBar/CompProgressBar_v0_43.HMI b/examples/CompProgressBar/CompProgressBar_v0_43.HMI new file mode 100644 index 00000000..02aa6bba Binary files /dev/null and b/examples/CompProgressBar/CompProgressBar_v0_43.HMI differ diff --git a/examples/CompProgressBar/CompProgressBar_v0_32.ino b/examples/CompProgressBar/CompProgressBar_v0_43.ino old mode 100755 new mode 100644 similarity index 95% rename from examples/CompProgressBar/CompProgressBar_v0_32.ino rename to examples/CompProgressBar/CompProgressBar_v0_43.ino index f5357a69..60670d3a --- a/examples/CompProgressBar/CompProgressBar_v0_32.ino +++ b/examples/CompProgressBar/CompProgressBar_v0_43.ino @@ -1,78 +1,78 @@ -/** - * @example CompProgressBar.ino - * - * @par How to Use - * This example shows that,when the "btn_up" component on the Nextion screen is released, - * the value of progress bar component will plus 5,when the "btn_down" component released ,the value of - * progress bar component will minus 5 every time. - * - * @author Wu Pengfei (email:) - * @date 2015/7/10 - * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues - * @convert by Patrick Martin, no other changes made - * @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 "Nextion.h" - -NexProgressBar j0 = NexProgressBar(0, 3, "j0"); -NexButton btn_up = NexButton(0, 1, "btn_up"); -NexButton btn_down = NexButton(0, 2, "btn_down"); - -NexTouch *nex_listen_list[] = -{ - &btn_up, - &btn_down, - NULL -}; - -void buttonUpPopCallback(void *ptr) -{ - uint32_t number = 0; - dbSerialPrintln("buttonUpPopCallback"); - - j0.getValue(&number); - - number += 5; - if (number >= 100) - { - number = 100; - } - - j0.setValue(number); -} - -void buttonDownPopCallback(void *ptr) -{ - uint32_t number = 0; - dbSerialPrintln("buttonDownPopCallback"); - - j0.getValue(&number); - - if (number >= 5) - { - number -= 5; - } - - j0.setValue(number); -} - -void setup(void) -{ - nexInit(); - btn_up.attachPop(buttonUpPopCallback); - btn_down.attachPop(buttonDownPopCallback); - dbSerialPrintln("setup done"); -} - -void loop(void) -{ - nexLoop(nex_listen_list); -} - +/** + * @example CompProgressBar.ino + * + * @par How to Use + * This example shows that,when the "btn_up" component on the Nextion screen is released, + * the value of progress bar component will plus 5,when the "btn_down" component released ,the value of + * progress bar component will minus 5 every time. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues + * @convert by Patrick Martin, no other changes made + * @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 "Nextion.h" + +NexProgressBar j0 = NexProgressBar(0, 3, "j0"); +NexButton btn_up = NexButton(0, 1, "btn_up"); +NexButton btn_down = NexButton(0, 2, "btn_down"); + +NexTouch *nex_listen_list[] = +{ + &btn_up, + &btn_down, + NULL +}; + +void buttonUpPopCallback(void *ptr) +{ + uint32_t number = 0; + dbSerialPrintln("buttonUpPopCallback"); + + j0.getValue(&number); + + number += 5; + if (number >= 100) + { + number = 100; + } + + j0.setValue(number); +} + +void buttonDownPopCallback(void *ptr) +{ + uint32_t number = 0; + dbSerialPrintln("buttonDownPopCallback"); + + j0.getValue(&number); + + if (number >= 5) + { + number -= 5; + } + + j0.setValue(number); +} + +void setup(void) +{ + nexInit(); + btn_up.attachPop(buttonUpPopCallback); + btn_down.attachPop(buttonDownPopCallback); + dbSerialPrintln("setup done"); +} + +void loop(void) +{ + nexLoop(nex_listen_list); +} + diff --git a/examples/CompSlider/CompSlider_v0_32.ino b/examples/CompSlider/2.ino old mode 100755 new mode 100644 similarity index 95% rename from examples/CompSlider/CompSlider_v0_32.ino rename to examples/CompSlider/2.ino index aed6e0f3..8ff803c9 --- a/examples/CompSlider/CompSlider_v0_32.ino +++ b/examples/CompSlider/2.ino @@ -1,54 +1,54 @@ -/** - * @example CompSlider.ino - * - * @par How to Use - * This example shows that ,when the slider component on the Nextion screen is released, - * the text value of text component will be changed every time. - * - * @author Wu Pengfei (email:) - * @date 2015/8/11 - * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues - * @convert by Patrick Martin, no other changes made - * @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 "Nextion.h" - -NexText t0 = NexText(0, 2, "t0"); -NexSlider h0 = NexSlider(0, 1, "h0"); - -NexTouch *nex_listen_list[] = -{ - &h0, - NULL -}; - -void h0PopCallback(void *ptr) -{ - uint32_t number = 0; - char temp[10] = {0}; - - dbSerialPrintln("h0PopCallback"); - - h0.getValue(&number); - utoa(number, temp, 10); - t0.setText(temp); -} - -void setup(void) -{ - nexInit(); - h0.attachPop(h0PopCallback); - dbSerialPrintln("setup done"); -} - -void loop(void) -{ - nexLoop(nex_listen_list); -} - +/** + * @example CompSlider.ino + * + * @par How to Use + * This example shows that ,when the slider component on the Nextion screen is released, + * the text value of text component will be changed every time. + * + * @author Wu Pengfei (email:) + * @date 2015/8/11 + * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues + * @convert by Patrick Martin, no other changes made + * @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 "Nextion.h" + +NexText t0 = NexText(0, 2, "t0"); +NexSlider h0 = NexSlider(0, 1, "h0"); + +NexTouch *nex_listen_list[] = +{ + &h0, + NULL +}; + +void h0PopCallback(void *ptr) +{ + uint32_t number = 0; + char temp[10] = {0}; + + dbSerialPrintln("h0PopCallback"); + + h0.getValue(&number); + utoa(number, temp, 10); + t0.setText(temp); +} + +void setup(void) +{ + nexInit(); + h0.attachPop(h0PopCallback); + dbSerialPrintln("setup done"); +} + +void loop(void) +{ + nexLoop(nex_listen_list); +} + diff --git a/examples/CompSlider/CompSlider.tft b/examples/CompSlider/CompSlider.tft deleted file mode 100755 index e7e9e052..00000000 Binary files a/examples/CompSlider/CompSlider.tft and /dev/null differ diff --git a/examples/CompSlider/CompSlider_v0_32.HMI b/examples/CompSlider/CompSlider_v0_32.HMI deleted file mode 100755 index 6930419e..00000000 Binary files a/examples/CompSlider/CompSlider_v0_32.HMI and /dev/null differ diff --git a/examples/CompSlider/CompSlider_v0_43.HMI b/examples/CompSlider/CompSlider_v0_43.HMI new file mode 100644 index 00000000..11bc2f33 Binary files /dev/null and b/examples/CompSlider/CompSlider_v0_43.HMI differ diff --git a/examples/CompSlider/CompSlider_v0_43.ino b/examples/CompSlider/CompSlider_v0_43.ino new file mode 100644 index 00000000..8ff803c9 --- /dev/null +++ b/examples/CompSlider/CompSlider_v0_43.ino @@ -0,0 +1,54 @@ +/** + * @example CompSlider.ino + * + * @par How to Use + * This example shows that ,when the slider component on the Nextion screen is released, + * the text value of text component will be changed every time. + * + * @author Wu Pengfei (email:) + * @date 2015/8/11 + * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues + * @convert by Patrick Martin, no other changes made + * @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 "Nextion.h" + +NexText t0 = NexText(0, 2, "t0"); +NexSlider h0 = NexSlider(0, 1, "h0"); + +NexTouch *nex_listen_list[] = +{ + &h0, + NULL +}; + +void h0PopCallback(void *ptr) +{ + uint32_t number = 0; + char temp[10] = {0}; + + dbSerialPrintln("h0PopCallback"); + + h0.getValue(&number); + utoa(number, temp, 10); + t0.setText(temp); +} + +void setup(void) +{ + nexInit(); + h0.attachPop(h0PopCallback); + dbSerialPrintln("setup done"); +} + +void loop(void) +{ + nexLoop(nex_listen_list); +} + diff --git a/examples/CompText/CompText_v0_32.HMI b/examples/CompText/CompText_v0_32.HMI deleted file mode 100755 index 959a6059..00000000 Binary files a/examples/CompText/CompText_v0_32.HMI and /dev/null differ diff --git a/examples/CompText/CompText_v0_43.HMI b/examples/CompText/CompText_v0_43.HMI new file mode 100644 index 00000000..bf6275d6 Binary files /dev/null and b/examples/CompText/CompText_v0_43.HMI differ diff --git a/examples/CompText/CompText_v0_32.ino b/examples/CompText/CompText_v0_43.ino old mode 100755 new mode 100644 similarity index 90% rename from examples/CompText/CompText_v0_32.ino rename to examples/CompText/CompText_v0_43.ino index 93f833e4..d4f48b6f --- a/examples/CompText/CompText_v0_32.ino +++ b/examples/CompText/CompText_v0_43.ino @@ -1,135 +1,139 @@ -/** - * @example CompText.ino - * - * @par How to Use - * This example shows that ,when the "+" component on the Nextion screen is released, - * the value of text component will plus 1,when the "-" component released ,the value of - * text component will minus 1 every time. - * - * @author Wu Pengfei (email:) - * @date 2015/7/10 - * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues - * @convert by Patrick Martin, no other changes made - * @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 "Nextion.h" - -void t0PopCallback(void *ptr); -void b0PopCallback(void *ptr); -void b1PopCallback(void *ptr); - -/* - * Declare a text object [page id:0,component id:1, component name: "t0"]. - */ -NexText t0 = NexText(0, 1, "t0"); - -/* - * Declare a button object [page id:0,component id:2, component name: "b0"]. - */ -NexButton b0 = NexButton(0, 2, "b0"); - -/* - * Declare a button object [page id:0,component id:3, component name: "b1"]. - */ -NexButton b1 = NexButton(0, 3, "b1"); - -char buffer[100] = {0}; - -/* - * Register object t0, b0, b1, to the touch event list. - */ -NexTouch *nex_listen_list[] = -{ - &t0, - &b0, - &b1, - NULL -}; - -/* - * Text component pop callback function. - */ -void t0PopCallback(void *ptr) -{ - dbSerialPrintln("t0PopCallback"); - t0.setText("50"); -} - -/* - * Button0 component pop callback function. - * In this example,the value of the text component will plus one every time when button0 is released. - */ -void b0PopCallback(void *ptr) -{ - uint16_t len; - uint16_t number; - - dbSerialPrintln("b0PopCallback"); - - memset(buffer, 0, sizeof(buffer)); - t0.getText(buffer, sizeof(buffer)); - - number = atoi(buffer); - number += 1; - - memset(buffer, 0, sizeof(buffer)); - itoa(number, buffer, 10); - - t0.setText(buffer); -} - -/* - * Button1 component pop callback function. - * In this example,the value of the text component will minus one every time when button1 is released. - */ -void b1PopCallback(void *ptr) -{ - uint16_t len; - uint16_t number; - - dbSerialPrintln("b1PopCallback"); - - memset(buffer, 0, sizeof(buffer)); - t0.getText(buffer, sizeof(buffer)); - - number = atoi(buffer); - number -= 1; - - memset(buffer, 0, sizeof(buffer)); - itoa(number, buffer, 10); - - t0.setText(buffer); -} - -void setup(void) -{ - /* Set the baudrate which is for debug and communicate with Nextion screen. */ - nexInit(); - - /* Register the pop event callback function of the current text component. */ - t0.attachPop(t0PopCallback); - - /* Register the pop event callback function of the current button0 component. */ - b0.attachPop(b0PopCallback); - - /* Register the pop event callback function of the current button1 component. */ - b1.attachPop(b1PopCallback); - - dbSerialPrintln("setup done"); -} - -void loop(void) -{ - /* - * When a pop or push event occured every time, - * the corresponding component[right page id and component id] in touch event list will be asked. - */ - nexLoop(nex_listen_list); -} - +/** + * @example CompText.ino + * + * @par How to Use + * This example shows that ,when the "+" component on the Nextion screen is released, + * the value of text component will plus 1,when the "-" component released ,the value of + * text component will minus 1 every time. + * + * @author Wu Pengfei (email:) + * @date 2015/7/10 + * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues + * @convert by Patrick Martin, no other changes made + * @author Jyrki Berg 2/27/2019 (https://github.com/jyberg) + * + * @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 "Nextion.h" + +void t0PopCallback(void *ptr); +void b0PopCallback(void *ptr); +void b1PopCallback(void *ptr); + +/* + * Declare a text object [page id:0,component id:1, component name: "t0"]. + */ +NexText t0(0, 1, "t0"); + +/* + * Declare a button object [page id:0,component id:2, component name: "b0"]. + */ +NexButton b0(0, 2, "b0"); + +/* + * Declare a button object [page id:0,component id:3, component name: "b1"]. + */ +NexButton b1(0, 3, "b1"); + +char buffer[100] = {0}; + +/* + * Register object t0, b0, b1, to the touch event list. + */ +NexTouch *nex_listen_list[] = +{ + &t0, + &b0, + &b1, + NULL +}; + +/* + * Text component pop callback function. + */ +void t0PopCallback(void *ptr) +{ + dbSerialPrintln("t0PopCallback"); + t0.setText("50"); +} + +/* + * Button0 component pop callback function. + * In this example,the value of the text component will plus one every time when button0 is released. + */ +void b0PopCallback(void *ptr) +{ + uint16_t len; + uint16_t number; + + dbSerialPrintln("b0PopCallback"); + + memset(buffer, 0, sizeof(buffer)); + len = sizeof(buffer); + t0.getText(buffer, len); + + number = atoi(buffer); + number += 1; + + memset(buffer, 0, sizeof(buffer)); + itoa(number, buffer, 10); + + t0.setText(buffer); +} + +/* + * Button1 component pop callback function. + * In this example,the value of the text component will minus one every time when button1 is released. + */ +void b1PopCallback(void *ptr) +{ + uint16_t len; + uint16_t number; + + dbSerialPrintln("b1PopCallback"); + + memset(buffer, 0, sizeof(buffer)); + len = sizeof(buffer); + t0.getText(buffer, len); + + number = atoi(buffer); + number -= 1; + + memset(buffer, 0, sizeof(buffer)); + itoa(number, buffer, 10); + + t0.setText(buffer); +} + +void setup(void) +{ + /* Set the baudrate which is for debug and communicate with Nextion screen. */ + nexInit(); + + /* Register the pop event callback function of the current text component. */ + t0.attachPop(t0PopCallback); + + /* Register the pop event callback function of the current button0 component. */ + b0.attachPop(b0PopCallback); + + /* Register the pop event callback function of the current button1 component. */ + b1.attachPop(b1PopCallback); + + dbSerialPrintln("setup done"); +} + +void loop(void) +{ + /* + * When a pop or push event occured every time, + * the corresponding component[right page id and component id] in touch event list will be asked. + */ + nexLoop(nex_listen_list); +} + diff --git a/examples/CompTimer/CompTimer_v0_32.HMI b/examples/CompTimer/CompTimer_v0_32.HMI deleted file mode 100755 index 5c3b37ea..00000000 Binary files a/examples/CompTimer/CompTimer_v0_32.HMI and /dev/null differ diff --git a/examples/CompTimer/CompTimer_v0_43.HMI b/examples/CompTimer/CompTimer_v0_43.HMI new file mode 100644 index 00000000..324b993f Binary files /dev/null and b/examples/CompTimer/CompTimer_v0_43.HMI differ diff --git a/examples/CompTimer/CompTimer_v0_32.ino b/examples/CompTimer/CompTimer_v0_43.ino old mode 100755 new mode 100644 similarity index 96% rename from examples/CompTimer/CompTimer_v0_32.ino rename to examples/CompTimer/CompTimer_v0_43.ino index f8442724..f2214adc --- a/examples/CompTimer/CompTimer_v0_32.ino +++ b/examples/CompTimer/CompTimer_v0_43.ino @@ -1,125 +1,125 @@ -/** - * @example CompTimer.ino - * - * @par How to Use - * This example shows that ,when the OFF button component on the Nextion screen is released, - * the timer will opened,the text will show number changed and push the ADDTIME button timer - * cycle value will increase,when push the DECTIME button timer cycle value will reduce. - * - * @author huang xianming (email:) - * @date 2015/8/25 - * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues - * @convert by Patrick Martin, no other changes made - * @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 "Nextion.h" - -NexButton b0 = NexButton(0, 2, "b0"); -NexButton b1 = NexButton(0, 5, "b1"); -NexButton b2 = NexButton(0, 6, "b2"); -NexText t0 = NexText(0, 3, "t0"); -NexText t1 = NexText(0, 4, "t1"); -NexTimer tm0 = NexTimer(0, 1, "tm0"); - - -char buffer[100] = {0}; -uint32_t number_timer = 0; -uint32_t number_enable = 0; -uint32_t number_cycle = 100; - - - -NexTouch *nex_listen_list[] = -{ - &b0, - &b1, - &b2, - &t0, - &t1, - &tm0, - NULL -}; -/* - * Button component pop callback function. - * In this example,the button can open the timer when it is released. - */ -void b0PopCallback(void *ptr) -{ - if(number_enable == 1) - { - tm0.enable(); - number_enable = 0; - b0.setText("ON"); - } - else if (number_enable ==0) - { - tm0.disable(); - number_enable =1; - b0.setText("OFF"); - } -} -/* - * Button component pop callback function. - * In this example,the timer's cycle value will increase when it is released. - */ -void b1PopCallback(void *ptr) -{ - tm0.getCycle(&number_cycle); - number_cycle = number_cycle + 100; - tm0.setCycle(number_cycle); - memset(buffer, 0, sizeof(buffer)); - itoa(number_cycle, buffer, 10); - t1.setText(buffer); -} - -/* - * Button component pop callback function. - * In this example,the timer's cycle value will reduce when it is released. - */ - -void b2PopCallback(void *ptr) -{ - tm0.getCycle(&number_cycle); - if (number_cycle >100) - { - number_cycle = number_cycle - 100; - } - tm0.setCycle(number_cycle); - memset(buffer, 0, sizeof(buffer)); - itoa(number_cycle, buffer, 10); - t1.setText(buffer); -} - -/* - * The timer respond function - * In this example,the timer will respond when set cycle time done and puls one for a variable. - */ - -void tm0TimerCallback(void *ptr) -{ - number_timer++; - memset(buffer, 0, sizeof(buffer)); - itoa(number_timer, buffer, 10); - t0.setText(buffer); -} -void setup(void) -{ - nexInit(); - b0.attachPop(b0PopCallback); - tm0.attachTimer(tm0TimerCallback); - b1.attachPop(b1PopCallback); - b2.attachPop(b2PopCallback); - dbSerialPrintln("setup done"); -} - -void loop(void) -{ - nexLoop(nex_listen_list); -} - +/** + * @example CompTimer.ino + * + * @par How to Use + * This example shows that ,when the OFF button component on the Nextion screen is released, + * the timer will opened,the text will show number changed and push the ADDTIME button timer + * cycle value will increase,when push the DECTIME button timer cycle value will reduce. + * + * @author huang xianming (email:) + * @date 2015/8/25 + * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues + * @convert by Patrick Martin, no other changes made + * @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 "Nextion.h" + +NexButton b0 = NexButton(0, 2, "b0"); +NexButton b1 = NexButton(0, 5, "b1"); +NexButton b2 = NexButton(0, 6, "b2"); +NexText t0 = NexText(0, 3, "t0"); +NexText t1 = NexText(0, 4, "t1"); +NexTimer tm0 = NexTimer(0, 1, "tm0"); + + +char buffer[100] = {0}; +uint32_t number_timer = 0; +uint32_t number_enable = 0; +uint32_t number_cycle = 100; + + + +NexTouch *nex_listen_list[] = +{ + &b0, + &b1, + &b2, + &t0, + &t1, + &tm0, + NULL +}; +/* + * Button component pop callback function. + * In this example,the button can open the timer when it is released. + */ +void b0PopCallback(void *ptr) +{ + if(number_enable == 1) + { + tm0.enable(); + number_enable = 0; + b0.setText("ON"); + } + else if (number_enable ==0) + { + tm0.disable(); + number_enable =1; + b0.setText("OFF"); + } +} +/* + * Button component pop callback function. + * In this example,the timer's cycle value will increase when it is released. + */ +void b1PopCallback(void *ptr) +{ + tm0.getCycle(&number_cycle); + number_cycle = number_cycle + 100; + tm0.setCycle(number_cycle); + memset(buffer, 0, sizeof(buffer)); + itoa(number_cycle, buffer, 10); + t1.setText(buffer); +} + +/* + * Button component pop callback function. + * In this example,the timer's cycle value will reduce when it is released. + */ + +void b2PopCallback(void *ptr) +{ + tm0.getCycle(&number_cycle); + if (number_cycle >100) + { + number_cycle = number_cycle - 100; + } + tm0.setCycle(number_cycle); + memset(buffer, 0, sizeof(buffer)); + itoa(number_cycle, buffer, 10); + t1.setText(buffer); +} + +/* + * The timer respond function + * In this example,the timer will respond when set cycle time done and puls one for a variable. + */ + +void tm0TimerCallback(void *ptr) +{ + number_timer++; + memset(buffer, 0, sizeof(buffer)); + itoa(number_timer, buffer, 10); + t0.setText(buffer); +} +void setup(void) +{ + nexInit(); + b0.attachPop(b0PopCallback); + tm0.attachTimer(tm0TimerCallback); + b1.attachPop(b1PopCallback); + b2.attachPop(b2PopCallback); + dbSerialPrintln("setup done"); +} + +void loop(void) +{ + nexLoop(nex_listen_list); +} + diff --git a/examples/CompVar/CompVar.ino b/examples/CompVar/CompVar.ino new file mode 100644 index 00000000..9e998196 --- /dev/null +++ b/examples/CompVar/CompVar.ino @@ -0,0 +1,37 @@ +#include "NexVar.h" + +NexVar nex_sel0 = NexVar(0, 1, "sel0"); + +int sel0; + +NexTouch *nexListenList[] = +{ + + NULL +}; + + +void setup() { + + dbSerial.begin(9600); + nexInit(); + + dbSerial.println("setup done"); + +} + +void loop() { + + delay(500); + + uint32_t number = 0; + nex_sel0.getValue(&number); + + sel0 = number; + + dbSerial.println(sel0); + + + nexLoop(nexListenList); + +} diff --git a/examples/CompWaveform/CompWaveform_v0_32.HMI b/examples/CompWaveform/CompWaveform_v0_32.HMI deleted file mode 100755 index a2d25418..00000000 Binary files a/examples/CompWaveform/CompWaveform_v0_32.HMI and /dev/null differ diff --git a/examples/CompWaveform/CompWaveform_v0_43.HMI b/examples/CompWaveform/CompWaveform_v0_43.HMI new file mode 100644 index 00000000..61129c45 Binary files /dev/null and b/examples/CompWaveform/CompWaveform_v0_43.HMI differ diff --git a/examples/CompWaveform/CompWaveform_v0_32.ino b/examples/CompWaveform/CompWaveform_v0_43.ino old mode 100755 new mode 100644 similarity index 96% rename from examples/CompWaveform/CompWaveform_v0_32.ino rename to examples/CompWaveform/CompWaveform_v0_43.ino index e1395a56..fbbb6402 --- a/examples/CompWaveform/CompWaveform_v0_32.ino +++ b/examples/CompWaveform/CompWaveform_v0_43.ino @@ -1,68 +1,68 @@ -/** - * @example CompWaveform.ino - * - * @par How to Use - * Show how to use API of class NexWaveform. - * - * @author Wu Pengfei (email:) - * @date 2015/8/11 - * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues - * @convert by Patrick Martin, no other changes made - * @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 "Nextion.h" - -#define LEVEL_HIGH (30) -#define LEVEL_LOW (0) - -#define CH0_OFFSET (40 - LEVEL_HIGH/2) -#define CH1_OFFSET (CH0_OFFSET + 40 * 1) -#define CH2_OFFSET (CH0_OFFSET + 40 * 2) -#define CH3_OFFSET (CH0_OFFSET + 40 * 3) - - -NexWaveform s0 = NexWaveform(0, 1, "s0"); - -static uint8_t ch0_data = LEVEL_LOW; -static uint8_t ch1_data = LEVEL_LOW; -static uint8_t ch2_data = LEVEL_LOW; -static uint8_t ch3_data = LEVEL_LOW; - -void setup(void) -{ - nexInit(); - dbSerialPrintln("setup done"); -} - -void loop(void) -{ - static uint32_t started = 0; - if (millis() - started >= 2000) - { - started = millis(); - if (LEVEL_HIGH == ch0_data) - { - ch0_data = LEVEL_LOW; - } - else - { - ch0_data = LEVEL_HIGH; - } - } - - ch1_data = ch0_data + random(0, 2); - ch2_data = ch0_data + random(0, 5); - ch3_data = ch0_data + random(0, 8); - - s0.addValue(0, CH0_OFFSET + ch0_data); - s0.addValue(1, CH1_OFFSET + ch1_data); - s0.addValue(2, CH2_OFFSET + ch2_data); - s0.addValue(3, CH3_OFFSET + ch3_data); - -} - +/** + * @example CompWaveform.ino + * + * @par How to Use + * Show how to use API of class NexWaveform. + * + * @author Wu Pengfei (email:) + * @date 2015/8/11 + * @updated 2016/12/25 bring HMI up to v0.32 to avoid too old issues + * @convert by Patrick Martin, no other changes made + * @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 "Nextion.h" + +#define LEVEL_HIGH (30) +#define LEVEL_LOW (0) + +#define CH0_OFFSET (40 - LEVEL_HIGH/2) +#define CH1_OFFSET (CH0_OFFSET + 40 * 1) +#define CH2_OFFSET (CH0_OFFSET + 40 * 2) +#define CH3_OFFSET (CH0_OFFSET + 40 * 3) + + +NexWaveform s0 = NexWaveform(0, 1, "s0"); + +static uint8_t ch0_data = LEVEL_LOW; +static uint8_t ch1_data = LEVEL_LOW; +static uint8_t ch2_data = LEVEL_LOW; +static uint8_t ch3_data = LEVEL_LOW; + +void setup(void) +{ + nexInit(); + dbSerialPrintln("setup done"); +} + +void loop(void) +{ + static uint32_t started = 0; + if (millis() - started >= 2000) + { + started = millis(); + if (LEVEL_HIGH == ch0_data) + { + ch0_data = LEVEL_LOW; + } + else + { + ch0_data = LEVEL_HIGH; + } + } + + ch1_data = ch0_data + random(0, 2); + ch2_data = ch0_data + random(0, 5); + ch3_data = ch0_data + random(0, 8); + + s0.addValue(0, CH0_OFFSET + ch0_data); + s0.addValue(1, CH1_OFFSET + ch1_data); + s0.addValue(2, CH2_OFFSET + ch2_data); + s0.addValue(3, CH3_OFFSET + ch3_data); + +} + diff --git a/html/_nex_hardware_8cpp.html b/html/_nex_hardware_8cpp.html index c6c35d07..71f8b7c8 100755 --- a/html/_nex_hardware_8cpp.html +++ b/html/_nex_hardware_8cpp.html @@ -147,16 +147,16 @@

Functions

-bool recvRetNumber (uint32_t *number, uint32_t timeout) +bool recvRetNumber (uint32_t *number, size_t timeout)   -uint16_t recvRetString (char *buffer, uint16_t len, uint32_t timeout) +uint16_t recvRetString (char *buffer, uint16_t len, size_t timeout)   void sendCommand (const char *cmd)   -bool recvRetCommandFinished (uint32_t timeout) +bool recvRetCommandFinished (size_t timeout)   bool nexInit (void)   diff --git a/html/_nex_hardware_8h.html b/html/_nex_hardware_8h.html index 721cbf4d..56688fdf 100755 --- a/html/_nex_hardware_8h.html +++ b/html/_nex_hardware_8h.html @@ -100,16 +100,16 @@ void nexLoop (NexTouch *nex_listen_list[])   -bool recvRetNumber (uint32_t *number, uint32_t timeout=100) +bool recvRetNumber (uint32_t *number, size_t timeout=100)   -uint16_t recvRetString (char *buffer, uint16_t len, uint32_t timeout=100) +uint16_t recvRetString (char *buffer, uint16_t len, size_t timeout=100)   void sendCommand (const char *cmd)   -bool recvRetCommandFinished (uint32_t timeout=100) +bool recvRetCommandFinished (size_t timeout=100)  

Detailed Description

diff --git a/html/_nex_hardware_8h_source.html b/html/_nex_hardware_8h_source.html index 463341d6..f8dd59d3 100755 --- a/html/_nex_hardware_8h_source.html +++ b/html/_nex_hardware_8h_source.html @@ -96,10 +96,10 @@
32 
44 void nexLoop(NexTouch *nex_listen_list[]);
45 
-
50 bool recvRetNumber(uint32_t *number, uint32_t timeout = 100);
-
51 uint16_t recvRetString(char *buffer, uint16_t len, uint32_t timeout = 100);
+
50 bool recvRetNumber(uint32_t *number, size_t timeout = 100);
+
51 uint16_t recvRetString(char *buffer, uint16_t len, size_t timeout = 100);
52 void sendCommand(const char* cmd);
-
53 bool recvRetCommandFinished(uint32_t timeout = 100);
+
53 bool recvRetCommandFinished(size_t timeout = 100);
54 
55 #endif /* #ifndef __NEXHARDWARE_H__ */
void nexLoop(NexTouch *nex_listen_list[])
Definition: NexHardware.cpp:235
diff --git a/html/_nex_upload_8h_source.html b/html/_nex_upload_8h_source.html index e3553e9d..2fe43e76 100755 --- a/html/_nex_upload_8h_source.html +++ b/html/_nex_upload_8h_source.html @@ -166,7 +166,7 @@
125  * @return the length of string buffer.
126  *
127  */
-
128  uint16_t recvRetString(String &string, uint32_t timeout = 100,bool recv_flag = false);
+
128  uint16_t recvRetString(String &string, size_t timeout = 100,bool recv_flag = false);
129 
130 private: /* data */
131  uint32_t _baudrate; /*nextion serail baudrate*/
diff --git a/readme.md b/readme.md index 4e579ec6..4df98f2f 100644 --- a/readme.md +++ b/readme.md @@ -1,59 +1,63 @@ -@mainpage Home Page +@mainpage Home Page -# Nextion +# Enhanced Nextion Library -------------------------------------------------------------------------------- +Jyrki Berg 4/5/2019 (https://github.com/jyberg) + +-Backward compatibility issue: functions timeout parameters datatype changed from uint32_t to size_t +- getValue and getText doesn't work #9 corrected + +Jyrki Berg 8/14/2019 + +-Backward compatibility issue: + - systemStartUpCallback function pointer name corrected to match Nextion functionality/documentation new name: nextionReadyCallback + +- Error code list updated (NexHardware.cpp) +- nextionStartupCallback function added. Called when when Nextion has started or reset + + +Jyrki Berg 2/17/2019 +Enhanced and corrected Nextion library version for Arduino/Esp8266/NodeMcu, based on original Nextion Arduino library. + +- Added support for NodeMcu/esp8266, Software serial, Software serial can be used with arduino +- Added support to define communication baud rate in nexInit functiono +- Added support for global Nextion objects. (Optional page parameter added in the components) +- NexVariable corrected to use int32_t data type +- NextText corrected to return tru/false, and string length is returned in len parameter +- NextText String object support added +- other small bug fixes done +- Added to support global Nextion events like CurrentPageIdCallback,systemStartUpCallback,... see NexHardware.h +- Waveform corrections: + - Inheritance to support toutch events + - return values corrected + - set/get channel colour corrected to support all channels +- Waveform enhancedments: + - Suport scaled values: + - define min and max values + coponent height in pixels (component support 255 pixel max height). When value is added to changell it is automatically scaled to component size and min/max value definitions. + - Add multiple values to line + - Clear component +- Added get component height/width function calls to NexObject +- examples Nextion editor projects corrected +- C++ std library usage made optional, (e.g std::vector) See NexConfig.h #define STD_SUPPORT +- C style versions added for functions that uses std::vector etc.. + +Nextion serial instruction set see: https://www.itead.cc/wiki/Nextion_Instruction_Set or https://nextion.itead.cc/resources/documents/instruction-set/ + +-For some reason I need to remove NexUpload.h & NexUpload.cpp when using the library in PlatformIO + some platform header files not found spontaneously when building, adding the libray path in platformio.ini did not help. # Introduction -Nextion Arduino library provides an easy-to-use way to manipulate Nextion serial -displays. Users can use the libarry freely, either in commerical projects or -open-source prjects, without any additional condiitons. +Nextion Arduino library provides an easy-to-use way to manipulate Nextion serial
+displays. Users can use the libarry freely, either in commerical projects or
+open-source prjects, without any additional condiitons.
+
+Nextion easy to use UI Editor: https://nextion.itead.cc/resources/download/nextion-editor/
+Enhanced easy to use Nextion Font Editor: https://github.com/hagronnestad/nextion-font-editor
-For more information about the Nextion display project, please visit -[the wiki。](http://wiki.iteadstudio.com/Nextion_HMI_Solution) -The wiki provdies all the necessary technical documnets, quick start guide, -tutorials, demos, as well as some useful resources. - -To get your Nextion display, please visit -[iMall.](http://imall.itead.cc/display/nextion.html) - -To discuss the project? Request new features? Report a BUG? please visit the -[Forums](http://support.iteadstudio.com/discussions/1000058038) - -# Download Source Code - -Latest version is unstable and a mass of change may be applied in a short time -without any notification for users. Commonly, it is for developers of this -library. - -**Release version is recommanded for you, unless you are one of developers of this -library.** - -**Release notes** is at -. - -## Latest(unstable) - -Latest source code(master branch) can be downloaded: - . - -You can also clone it via git: - - git clone https://github.com/itead/ITEADLIB_Arduino_Nextion - -## Releases(stable) - - - https://github.com/itead/ITEADLIB_Arduino_Nextion/archive/v0.7.0.zip - - https://github.com/itead/ITEADLIB_Arduino_Nextion/archive/v0.7.0.tar.gz - -All releases can be available from: -. - -# Documentation - -Offline Documentation's entry `doc/Documentation/index.html` shiped with source code -can be open in your browser such as Chrome, Firefox or any one you like. +For more information about the Nextion display project, please visit
+[the wiki。](http://wiki.iteadstudio.com/Nextion_HMI_Solution)
# Suppported Mainboards @@ -65,55 +69,38 @@ For example: - Iteaduino UNO - Arduino MEGA2560 - Arduino UNO + - NodeMcu + - Esp8266 # Configuration -In configuration file NexConfig.h, you can find two macros below: - - - dbSerial: Debug Serial (baudrate:9600), needed by beginners for debug your - nextion applications or sketches. If your complete your work, it will be a - wise choice to disable Debug Serial. - - - nexSerial: Nextion Serial, the bridge of Nextion and your mainboard. - -**Note:** the default configuration is for MEGA2560. +In configuration file NexConfig.h, you can configure Hardware / software, debug serial usage
-## Redirect dbSerial and nexSerial +In case of Hardware serial comment/undefine "// #define NEX_SOFTWARE_SERIAL" line and
+configure used Serial port on line "#define nexSerial Serial"
+by default Serial poirt used (NodeMcu/Esp8266 hardware serial) -If you want to change the default serial to debug or communicate with Nextion , -you need to modify the line in configuration file: +Software serial used if "#define NEX_SOFTWARE_SERIAL" when NEX_SOFTWARE_SERIAL is defined
+use NEX_RX and NEX_TX definitions to define used software serial ports.
+By default NodeMcu:
+ "#define NEX_RX D2" + "#define NEX_TX D1" +NodeMcu board pin numbers not match with Esp8266 pin numbers. So use D pin number definitions from pins_arduino.h +You need to remember that Software serial is not nessessary workin with out problmes at least when using NodeMcu/Esp8266 boards (See power tips...).
- #define dbSerial Serial ---> #define dbSerial Serialxxx - #define nexSerial Serial2 ---> #define nexSeria Serialxxx +If you want activate Debug messages, uncomment "//#define DEBUG_SERIAL_ENABLE" line and define serial port used for debug messges using line:
+"//#define dbSerial Serial", it is responsibiity of main program to initialize/open debug serial port. -## Disable Debug Serial +# Power tips -If you want to disable the debug information,you need to modify the line in -configuration file: +Nextion and NodeMcu/Esp8266 is sensitive with power quality and current. Especially when Software serial is used, (Serial message quality can be bad and then functionality is not stable...). Don't power Nextion display from NodeMcu board, because Nextion takes guite mutch of current, and NodeMcu internal power requlator is not good. Use separate power to power Nextion and connect Nextion and NodeMcu/Esp8266 board gnd to commond gnd point. - #define DEBUG_SERIAL_ENABLE ---> //#define DEBUG_SERIAL_ENABLE - -# UNO-like Mainboards - -If your board has only one hardware serial, such as UNO, you should disable -dbSerial and redirect nexSerial to Serial(Refer to section:`Serial configuration`). # Useful Links - - - -# License - -------------------------------------------------------------------------------- - - - The MIT License (MIT) - - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - -------------------------------------------------------------------------------- +- https://unofficialnextion.com/ +- https://nextion.itead.cc/resources/download/nextion-editor/ +- https://github.com/hagronnestad/nextion-font-editor +- http://blog.iteadstudio.com/nextion-tutorial-based-on-nextion-arduino-library/ +- https://www.itead.cc/wiki/Nextion_Instruction_Set +- https://nextion.itead.cc/resources/documents/instruction-set/ +- http://wiki.iteadstudio.com/Nextion_HMI_Solution diff --git a/release_notes.md b/release_notes.md index 56295407..7f053213 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,6 +1,40 @@ # Release Notes -------------------------------------------------------------------------------- +# Release v0.11.6 +Fix timeout for non-32bit processors + +# Release v0.11.3 +- getValue and getText doesn't work #9 +- timeout parameters chaned from uit32_t to size_t +- timeout check uses millis instead of micros + +# Release v0.11.1 +- NexVariable::setValue datatype corrected #2 +- DEBUG_SERIAL_ENABLE changed to NEX_DEBUG_SERIAL_ENABLE +- Serial.readBytes(...) implementation not used anymore, own implementation instead. Because of softwareSerial readBytes functionality is not reliable enough. + +# Release v0.11.0 + -Backward compatinility issue: + -systemStartUpCallback function pointer name corrected to match Nextion functionality/documentation new name: nextionReadyCallback + + -Error code list updated (NexHardware.cpp) +- nextionStartupCallback function added. Called when when Nextion has started or reset + +# Release v0.10.0 + + - version: v0.10.0 + - base: v0.9.0 +## Brief +Enhanced and corrected Nextion library version for Arduino/Esp8266/NodeMcu, based on original Nextion Arduino library + +- Added support for NodeMcu/esp8266, Software serial, Software serial can be used with arduino also +- Added support for global Nextion objects. (Optional page parameter added in the components) +- NexVariable corrected to use int32_t data type +- NextText corrected to return tru/false, and string length is returned in len parameter +- NextText String object support added +- other small bug fixes done +- Added to support global Nextion events like CurrentPageIdCallback,systemStartUpCallback,... # Release v0.9.0 diff --git a/version.txt b/version.txt index 6b4eb6f6..4b91517a 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.9.0 +0.11.6