TLMoto / Nextion

Dependents:   Display

Files at this revision

API Documentation at this revision

Comitter:
franciscodias
Date:
Mon May 04 17:52:49 2020 +0000
Parent:
0:67bae57e0b73
Commit message:
1234

Changed in this revision

NexButton.cpp Show annotated file Show diff for this revision Revisions of this file
NexButton.h Show annotated file Show diff for this revision Revisions of this file
NexConfig.h Show annotated file Show diff for this revision Revisions of this file
NexHardware.cpp Show annotated file Show diff for this revision Revisions of this file
NexHardware.h Show annotated file Show diff for this revision Revisions of this file
NexNumber.cpp Show annotated file Show diff for this revision Revisions of this file
NexNumber.h Show annotated file Show diff for this revision Revisions of this file
NexObject.h Show annotated file Show diff for this revision Revisions of this file
NexPage.cpp Show annotated file Show diff for this revision Revisions of this file
NexPage.h Show annotated file Show diff for this revision Revisions of this file
NexText.cpp Show annotated file Show diff for this revision Revisions of this file
NexText.h Show annotated file Show diff for this revision Revisions of this file
NexTouch.cpp Show annotated file Show diff for this revision Revisions of this file
NexTouch.h Show annotated file Show diff for this revision Revisions of this file
Nextion.h Show annotated file Show diff for this revision Revisions of this file
Serial.cpp Show annotated file Show diff for this revision Revisions of this file
Serial.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NexButton.cpp	Mon May 04 17:52:49 2020 +0000
@@ -0,0 +1,352 @@
+/**
+ * @file NexButton.cpp
+ *
+ * The implementation of class NexButton. 
+ *
+ * @author  Wu Pengfei (email:<pengfei.wu@itead.cc>)
+ * @date    2015/8/13
+ * @copyright 
+ * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
+ * This program is free software); you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation); either version 2 of
+ * the License, or (at your option) any later version.
+ */
+
+#include "NexButton.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "Utilities.h"
+
+extern char cmd[64];
+extern char buf[12];
+
+uint16_t NexButton_getText(struct NexObject *button, char *buffer, uint16_t len)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, button->__name);
+    strcat(cmd, ".txt");
+    sendCommand(cmd);
+    return recvRetString(buffer, len);
+}
+
+uint8_t NexButton_setText(struct NexObject *button, const char *buffer)
+{
+    ClearString(cmd);
+    strcat(cmd, button->__name);
+    strcat(cmd, ".txt=\"");
+    strcat(cmd, (char*)buffer);
+    strcat(cmd, "\"");
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexButton_Get_background_color_bco(struct NexObject *button, uint32_t *number)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, button->__name);
+    strcat(cmd, ".bco");
+    sendCommand(cmd);
+    return recvRetNumber(number);
+}
+
+uint8_t NexButton_Set_background_color_bco(struct NexObject *button, uint32_t number)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, number, 10);
+    strcat(cmd, button->__name);
+    strcat(cmd, ".bco=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, button->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexButton_Get_press_background_color_bco2(struct NexObject *button, uint32_t *number)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, button->__name);
+    strcat(cmd, ".bco2");
+    sendCommand(cmd);
+    return recvRetNumber(number);
+}
+
+uint8_t NexButton_Set_press_background_color_bco2(struct NexObject *button, uint32_t number)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, number, 10);
+    strcat(cmd, button->__name);
+    strcat(cmd, ".bco2=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, button->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexButton_Get_font_color_pco(struct NexObject *button, uint32_t *number)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, button->__name);
+    strcat(cmd, ".pco");
+    sendCommand(cmd);
+    return recvRetNumber(number);
+}
+
+uint8_t NexButton_Set_font_color_pco(struct NexObject *button, uint32_t number)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, number, 10);
+    strcat(cmd, button->__name);
+    strcat(cmd, ".pco=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, button->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexButton_Get_press_font_color_pco2(struct NexObject *button, uint32_t *number)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, button->__name);
+    strcat(cmd, ".pco2");
+    sendCommand(cmd);
+    return recvRetNumber(number);
+}
+
+uint8_t NexButton_Set_press_font_color_pco2(struct NexObject *button, uint32_t number)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, number, 10);
+    strcat(cmd, button->__name);
+    strcat(cmd, ".pco2=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, button->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexButton_Get_place_xcen(struct NexObject *button, uint32_t *number)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, button->__name);
+    strcat(cmd, ".xcen");
+    sendCommand(cmd);
+    return recvRetNumber(number);
+}
+
+uint8_t NexButton_Set_place_xcen(struct NexObject *button, uint32_t number)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, number, 10);
+    strcat(cmd, button->__name);
+    strcat(cmd, ".xcen=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, button->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexButton_Get_place_ycen(struct NexObject *button, uint32_t *number)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, button->__name);
+    strcat(cmd, ".ycen");
+    sendCommand(cmd);
+    return recvRetNumber(number);
+}
+
+uint8_t NexButton_Set_place_ycen(struct NexObject *button, uint32_t number)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, number, 10);
+    strcat(cmd, button->__name);
+    strcat(cmd, ".ycen=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, button->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexButton_getFont(struct NexObject *button, uint32_t *number)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, button->__name);
+    strcat(cmd, ".font");
+    sendCommand(cmd);
+    return recvRetNumber(number);
+}
+
+uint8_t NexButton_setFont(struct NexObject *button, uint32_t number)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, number, 10);
+    strcat(cmd, button->__name);
+    strcat(cmd, ".font=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, button->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexButton_Get_background_cropi_picc(struct NexObject *button, uint32_t *number)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, button->__name);
+    strcat(cmd, ".picc");
+    sendCommand(cmd);
+    return recvRetNumber(number);
+}
+
+uint8_t NexButton_Set_background_crop_picc(struct NexObject *button, uint32_t number)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, number, 10);
+    strcat(cmd, button->__name);
+    strcat(cmd, ".picc=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, button->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexButton_Get_press_background_crop_picc2(struct NexObject *button, uint32_t *number)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, button->__name);
+    strcat(cmd, ".picc2");
+    sendCommand(cmd);
+    return recvRetNumber(number);
+}
+
+uint8_t NexButton_Set_press_background_crop_picc2(struct NexObject *button, uint32_t number)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, number, 10);
+    strcat(cmd, button->__name);
+    strcat(cmd, ".picc2=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, button->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexButton_Get_background_image_pic(struct NexObject *button, uint32_t *number)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, button->__name);
+    strcat(cmd, ".pic");
+    sendCommand(cmd);
+    return recvRetNumber(number);
+}
+
+uint8_t NexButton_Set_background_image_pic(struct NexObject *button, uint32_t number)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, number, 10);
+    strcat(cmd, button->__name);
+    strcat(cmd, ".pic=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, button->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexButton_Get_press_background_image_pic2(struct NexObject *button, uint32_t *number)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, button->__name);
+    strcat(cmd, ".pic2");
+    sendCommand(cmd);
+    return recvRetNumber(number);
+}
+
+uint8_t NexButton_Set_press_background_image_pic2(struct NexObject *button, uint32_t number)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, number, 10);
+    strcat(cmd, button->__name);
+    strcat(cmd, ".pic2=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, button->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
\ No newline at end of file
--- a/NexButton.h	Wed Apr 15 17:02:54 2020 +0000
+++ b/NexButton.h	Mon May 04 17:52:49 2020 +0000
@@ -1,242 +1,195 @@
-/**
- * @file NexButton.h
- *
- * The definition of class NexButton. 
- *
- * @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
- * @date 2015/8/13
- *
- * @copyright 
- * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- */
-
 #ifndef __NEXBUTTON_H__
 #define __NEXBUTTON_H__
 
+#include "mbed.h"
 #include "NexTouch.h"
 #include "NexHardware.h"
-/**
- * @addtogroup Component 
- * @{ 
- */
+#include "my_types.h"
+
+uint16_t NexButton_getText(struct NexObject *button, char *buffer, uint16_t len);
 
 /**
- * NexButton component. 
- *
- * Commonly, you want to do something after push and pop it. It is recommanded that only
- * call @ref NexTouch::attachPop to satisfy your purpose. 
- * 
- * @warning Please do not call @ref NexTouch::attachPush on this component, even though you can. 
- */
-class NexButton: public NexTouch
-{
-public: /* methods */
-
-    /**
-     * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name);
-     */
-    NexButton(uint8_t pid, uint8_t cid, const char *name);
-
-    /**
-     * Get text attribute of component.
-     *
-     * @param buffer - buffer storing text returned. 
-     * @param len - length of buffer. 
-     * @return The real length of text returned. 
-     */
-    uint16_t getText(char *buffer, uint16_t len);    
-
-    /**
      * Set text attribute of component.
      *
      * @param buffer - text buffer terminated with '\0'. 
      * @return true if success, false for failure. 
      */
-    bool setText(const char *buffer);   
+uint8_t NexButton_setText(struct NexObject *button, const char *buffer);
 
-    /**
+/**
      * Get bco attribute of component
      *
      * @param number - buffer storing data return
      * @return the length of the data 
      */
-    uint32_t Get_background_color_bco(uint32_t *number);
-    
-    /**
+uint32_t NexButton_Get_background_color_bco(struct NexObject *button, 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);
-    
-    /**
+uint8_t NexButton_Set_background_color_bco(struct NexObject *button, uint32_t number);
+
+/**
      * Get bco2 attribute of component
      *
      * @param number - buffer storing data return
      * @return the length of the data 
      */
-    uint32_t Get_press_background_color_bco2(uint32_t *number); 
+uint32_t NexButton_Get_press_background_color_bco2(struct NexObject *button, uint32_t *number);
 
-    /**
+/**
      * Set bco2 attribute of component
      *
      * @param number - To set up the data
      * @return true if success, false for failure
      */
-    bool Set_press_background_color_bco2(uint32_t number);          
-    
-    /**
+uint8_t NexButton_Set_press_background_color_bco2(struct NexObject *button, uint32_t number);
+
+/**
      * Get pco attribute of component
      *
      * @param number - buffer storing data return
      * @return the length of the data 
      */
-    uint32_t Get_font_color_pco(uint32_t *number);      
-    
-    /**
+uint32_t NexButton_Get_font_color_pco(struct NexObject *button, uint32_t *number);
+
+/**
      * Set pco attribute of component
      *
      * @param number - To set up the data
      * @return true if success, false for failure
      */
-    bool Set_font_color_pco(uint32_t number);           
-    
-    /**
+uint8_t NexButton_Set_font_color_pco(struct NexObject *button, uint32_t number);
+
+/**
      * Get pco2 attribute of component
      *
      * @param number - buffer storing data return
      * @return the length of the data 
      */
-    uint32_t Get_press_font_color_pco2(uint32_t *number);       
-    
-    /**
+uint32_t NexButton_Get_press_font_color_pco2(struct NexObject *button, uint32_t *number);
+
+/**
      * Set pco2 attribute of component
      *
      * @param number - To set up the data
      * @return true if success, false for failure
      */
-    bool Set_press_font_color_pco2(uint32_t number);            
-    
-    /**
+uint8_t NexButton_Set_press_font_color_pco2(struct NexObject *button, uint32_t number);
+
+/**
      * Get xcen attribute of component
      *
      * @param number - buffer storing data return
      * @return the length of the data 
      */
-    uint32_t Get_place_xcen(uint32_t *number);      
-    
-    /**
+uint32_t NexButton_Get_place_xcen(struct NexObject *button, uint32_t *number);
+
+/**
      * Set xcen attribute of component
      *
      * @param number - To set up the data
      * @return true if success, false for failure
      */
-    bool Set_place_xcen(uint32_t number);  
+uint8_t NexButton_Set_place_xcen(struct NexObject *button, uint32_t number);
 
-    /**
+/**
      * Get ycen attribute of component
      *
      * @param number - buffer storing data return
      * @return the length of the data 
      */
-    uint32_t Get_place_ycen(uint32_t *number);  
+uint32_t NexButton_Get_place_ycen(struct NexObject *button, uint32_t *number);
 
-    /**
+/**
      * Set ycen attribute of component
      *
      * @param number - To set up the data
      * @return true if success, false for failure
      */
-    bool Set_place_ycen(uint32_t number);           
-    
-    /**
+uint8_t NexButton_Set_place_ycen(struct NexObject *button, uint32_t number);
+
+/**
      * Get font attribute of component
      *
      * @param number - buffer storing data return
      * @return the length of the data 
      */
-    uint32_t getFont(uint32_t *number);     
-    
-    /**
+uint32_t NexButton_getFont(struct NexObject *button, 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);  
+uint8_t NexButton_setFont(struct NexObject *button, uint32_t number);
 
-    /**
+/**
      * Get picc attribute of component
      *
      * @param number - buffer storing data return
      * @return the length of the data 
      */
-    uint32_t Get_background_cropi_picc(uint32_t *number);   
+uint32_t NexButton_Get_background_cropi_picc(struct NexObject *button, uint32_t *number);
 
-    /**
+/**
      * Set picc attribute of component
      *
      * @param number - To set up the data
      * @return true if success, false for failure
      */
-    bool Set_background_crop_picc(uint32_t number); 
+uint8_t NexButton_Set_background_crop_picc(struct NexObject *button, uint32_t number);
 
-    /**
+/**
      * Get picc2 attribute of component
      *
      * @param number - buffer storing data return
      * @return the length of the data 
      */
-    uint32_t Get_press_background_crop_picc2(uint32_t *number); 
-    
-    /**
+uint32_t NexButton_Get_press_background_crop_picc2(struct NexObject *button, uint32_t *number);
+
+/**
      * Set picc2 attribute of component
      *
      * @param number - To set up the data
      * @return true if success, false for failure
      */
-    bool Set_press_background_crop_picc2(uint32_t number);      
+uint8_t NexButton_Set_press_background_crop_picc2(struct NexObject *button, uint32_t number);
 
-    /**
+/**
      * Get pic attribute of component
      *
      * @param number - buffer storing data return
      * @return the length of the data 
      */
-    uint32_t Get_background_image_pic(uint32_t *number);    
+uint32_t NexButton_Get_background_image_pic(struct NexObject *button, uint32_t *number);
 
-    /**
+/**
      * Set pic attribute of component
      *
      * @param number - To set up the data
      * @return true if success, false for failure
      */
-    bool Set_background_image_pic(uint32_t number);     
+uint8_t NexButton_Set_background_image_pic(struct NexObject *button, uint32_t number);
 
-    /**
+/**
      * Get pic2 attribute of component
      *
      * @param number - buffer storing data return
      * @return the length of the data 
-     */ 
-    uint32_t Get_press_background_image_pic2(uint32_t *number); 
+     */
+uint32_t NexButton_Get_press_background_image_pic2(struct NexObject *button, uint32_t *number);
 
-    /**
+/**
      * Set pic2 attribute of component
      *
      * @param number - To set up the data
      * @return true if success, false for failure
      */
-    bool Set_press_background_image_pic2(uint32_t number);              
-};
-/**
- * @}
- */
-
+uint8_t NexButton_Set_press_background_image_pic2(struct NexObject *button, uint32_t number);
 
 #endif /* #ifndef __NEXBUTTON_H__ */
\ No newline at end of file
--- a/NexConfig.h	Wed Apr 15 17:02:54 2020 +0000
+++ b/NexConfig.h	Mon May 04 17:52:49 2020 +0000
@@ -1,54 +1,15 @@
-/**
- * @file NexConfig.h
- *
- * Options for user can be found here. 
- *
- * @author  Wu Pengfei (email:<pengfei.wu@itead.cc>)
- * @date    2015/8/13
- * @copyright 
- * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- */
+
 #ifndef __NEXCONFIG_H__
 #define __NEXCONFIG_H__
-
-/**
- * @addtogroup Configuration 
- * @{ 
- */
-
-/** 
- * Define DEBUG_SERIAL_ENABLE to enable debug serial. 
- * Comment it to disable debug serial. 
- */
-#define DEBUG_SERIAL_ENABLE
-
-/**
- * Define dbSerial for the output of debug messages. 
- */
-#define dbSerial Serial
+#include "Serial.h"
+#include "mbed.h"
 
-/**
- * Define nexSerial for communicate with Nextion touch panel. 
- */
-#define nexSerial Serial2
-
+#define nexSerial_init(b)        Serial_Init(b)
+#define nexSerial_available()    Serial_Available()
+#define nexSerial_read()         Serial_Read()
+#define nexSerial_write(d)       Serial_Write(d)
+#define nexSerial_print(p)       Serial_Print(p) 
+#define nexSerial_readBytes(b,l) Serial_ReadBytes(b, l)
+#define nexDelay(d)              wait_ms(d)
 
-#ifdef DEBUG_SERIAL_ENABLE
-#define dbSerialPrint(a)    dbSerial.print(a)
-#define dbSerialPrintln(a)  dbSerial.println(a)
-#define dbSerialBegin(a)    dbSerial.begin(a)
-#else
-#define dbSerialPrint(a)    do{}while(0)
-#define dbSerialPrintln(a)  do{}while(0)
-#define dbSerialBegin(a)    do{}while(0)
-#endif
-
-/**
- * @}
- */
-
-#endif /* #ifndef __NEXCONFIG_H__ */
\ No newline at end of file
+#endif /* #ifndef __NEXCONFIG_H__ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NexHardware.cpp	Mon May 04 17:52:49 2020 +0000
@@ -0,0 +1,253 @@
+/**
+ * @file NexHardware.cpp
+ *
+ * The implementation of base API for using Nextion. 
+ *
+ * @author  Wu Pengfei (email:<pengfei.wu@itead.cc>)
+ * @date    2015/8/11
+ * @copyright 
+ * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ */
+#include "NexHardware.h"
+#include "Utilities.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)
+
+char txt[32];
+char cmd[64];
+char buf[12];
+char msg[32];
+unsigned char wrData;
+
+/*
+ * Receive uint32_t data. 
+ * 
+ * @param number - save uint32_t data. 
+ * @param 100 - set 100 time. 
+ *
+ * @retval 1 - success. 
+ * @retval 0 - failed.
+ *
+ */
+uint8_t recvRetNumber(uint32_t *number)
+{
+    uint8_t ret = 0;
+    char temp[8];
+
+    if (!number)
+    {
+        goto __return;
+    }
+
+    nexDelay(100);
+    if (8 != nexSerial_readBytes((char *)temp, 8))
+    {
+        goto __return;
+    }
+
+    if (temp[0] == NEX_RET_NUMBER_HEAD && temp[5] == 0xFF && temp[6] == 0xFF && temp[7] == 0xFF)
+    {
+        *number = ((uint32_t)temp[4] << 24) | ((uint32_t)temp[3] << 16) | (temp[2] << 8) | (temp[1]);
+        ret = 1;
+    }
+
+__return:
+
+    /*if (ret) 
+    {
+        dbSerialPrint("recvRetNumber :");
+        dbSerialPrintln(*number);
+    }
+    else
+    {
+        dbSerialPrintln("recvRetNumber err");
+    }*/
+
+    return ret;
+}
+
+/*
+ * Receive string data. 
+ * 
+ * @param buffer - save string data. 
+ * @param len - string buffer length. 
+ * @param 100 - set 100 time. 
+ *
+ * @return the length of string buffer.
+ *
+ */
+uint16_t recvRetString(char *buffer, uint16_t len)
+{
+    uint16_t ret = 0;
+    uint8_t str_start_flag = 0;
+    uint8_t cnt_0xff = 0;
+    char arr[32];
+    char *temp = arr;
+    uint8_t c = 0;
+    long start;
+
+    if (!buffer || len == 0)
+    {
+        goto __return;
+    }
+
+    start = 500;
+    while (start)
+    {
+        while (nexSerial_available())
+        {
+            c = nexSerial_read();
+            if (str_start_flag)
+            {
+                if (0xFF == c)
+                {
+                    cnt_0xff++;
+                    if (cnt_0xff >= 3)
+                    {
+                        break;
+                    }
+                }
+                else
+                {
+                    temp += (char)c;
+                }
+            }
+            else if (NEX_RET_STRING_HEAD == c)
+            {
+                str_start_flag = 1;
+            }
+        }
+
+        if (cnt_0xff >= 3)
+        {
+            break;
+        }
+        --start;
+    }
+
+    ret = ArrayLength(temp);
+    ret = ret > len ? len : ret;
+    strncpy(buffer, temp, ret);
+
+__return:
+    /*
+    dbSerialPrint("recvRetString[");
+    dbSerialPrint(temp.length());
+    dbSerialPrint(",");
+    dbSerialPrint(temp);
+    dbSerialPrintln("]");
+     */
+    return ret;
+}
+
+/*
+ * Command is executed successfully. 
+ *
+ * @param 100 - set 100 time.
+ *
+ * @retval 1 - success.
+ * @retval 0 - failed. 
+ *
+ */
+uint8_t recvRetCommandFinished()
+{
+    uint8_t ret = 0;
+    uint8_t temp[4] = {0};
+    // nexSerial.set100(100);
+    if (ArrayLength(temp) != nexSerial_readBytes((char *)temp, ArrayLength(temp)))
+    {
+        ret = 0;
+    }
+
+    if (temp[0] == NEX_RET_CMD_FINISHED && temp[1] == 0xFF && temp[2] == 0xFF && temp[3] == 0xFF)
+    {
+        ret = 1;
+    }
+    /*
+    if (ret) 
+    {
+        dbSerialPrintln("recvRetCommandFinished ok");
+    }
+    else
+    {
+        dbSerialPrintln("recvRetCommandFinished err");
+    }
+     */
+    return ret;
+}
+
+void sendCommand(char *command)
+{
+    nexSerial_print(command);
+    nexSerial_write(0xFF);
+    nexSerial_write(0xFF);
+    nexSerial_write(0xFF);
+}
+
+uint8_t nexInit(void)
+{
+    uint8_t ret1 = 0;
+    uint8_t ret2 = 0;
+
+    //dbSerialBegin(9600);
+    nexSerial_init(9600);
+    sendCommand("");
+    sendCommand("bkcmd=1");
+    ret1 = recvRetCommandFinished();
+    sendCommand("page 0");
+    ret2 = recvRetCommandFinished();
+    return ret1 && ret2;
+}
+
+void nexLoop(struct NexObject *nex_listen_list[])
+{
+    static uint8_t __buffer[10];
+
+    uint16_t i;
+    uint8_t limit = 20;
+    uint8_t c;
+
+    while (nexSerial_available() > 0)
+    {
+        nexDelay(10);
+        c = nexSerial_read();
+
+        if (NEX_RET_EVENT_TOUCH_HEAD == c)
+        {
+            if (nexSerial_available() >= 6)
+            {
+                __buffer[0] = c;
+                for (i = 1; i < 7; i++)
+                {
+                    __buffer[i] = nexSerial_read();
+                }
+                __buffer[i] = 0x00;
+
+                if (0xFF == __buffer[4] && 0xFF == __buffer[5] && 0xFF == __buffer[6])
+                {
+                    NexTouch_iterate(nex_listen_list, __buffer[1], __buffer[2], (int32_t)__buffer[3]);
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
--- a/NexHardware.h	Wed Apr 15 17:02:54 2020 +0000
+++ b/NexHardware.h	Mon May 04 17:52:49 2020 +0000
@@ -1,35 +1,16 @@
-/**
- * @file NexHardware.h
- *
- * The definition of base API for using Nextion. 
- *
- * @author  Wu Pengfei (email:<pengfei.wu@itead.cc>)
- * @date    2015/8/11
- * @copyright 
- * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- */
 #ifndef __NEXHARDWARE_H__
 #define __NEXHARDWARE_H__
-
-//#include <Arduino.h>
+#include "mbed.h"
 #include "NexConfig.h"
 #include "NexTouch.h"
-
-/**
- * @addtogroup CoreAPI 
- * @{ 
- */
-
+#include "NexObject.h"
+#include "Utilities.h"
 /**
  * Init Nextion.  
  * 
  * @return true if success, false for failure. 
  */
-bool nexInit(void);
+uint8_t nexInit(void);
 
 /**
  * Listen touch event and calling callbacks attached before.
@@ -42,15 +23,20 @@
  * @warning This function must be called repeatedly to response touch events
  *  from Nextion touch panel. Actually, you should place it in your loop function. 
  */
-void nexLoop(NexTouch *nex_listen_list[]);
+void nexLoop(struct NexObject *nex_listen_list[]);
 
 /**
  * @}
  */
+//timeout=100
+uint8_t recvRetNumber(uint32_t *number);
+uint16_t recvRetString(char *buffer, uint16_t len);
+uint8_t recvRetCommandFinished();
+void sendCommand(char *command);
 
-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);
+#define CreateNexObject(obj, pid, id, name) \
+    obj.__pid = pid;                        \
+    obj.__cid = id;                         \
+    StringCopy(obj.__name, name)
 
 #endif /* #ifndef __NEXHARDWARE_H__ */
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NexNumber.cpp	Mon May 04 17:52:49 2020 +0000
@@ -0,0 +1,269 @@
+/**
+ * @file NexNumber.cpp
+ *
+ * The implementation of class NexNumber. 
+ *
+ * @author  huang xianming (email:<xianming.huang@itead.cc>)
+ * @date    2015/8/13
+ * @copyright 
+ * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
+ * This program is free software); you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation); either version 2 of
+ * the License, or (at your option) any later version.
+ */
+#include "NexNumber.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "Utilities.h"
+
+extern char cmd[64];
+extern char buf[12];
+
+uint8_t NexNumber_getValue(struct NexObject *number, uint32_t *num)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, number->__name);
+    strcat(cmd, ".val");
+    sendCommand(cmd);
+    return recvRetNumber(num);
+}
+
+uint8_t NexNumber_setValue(struct NexObject *number, uint32_t num)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, num, 10);
+    strcat(cmd, number->__name);
+    strcat(cmd, ".val=");
+    strcat(cmd, buf);
+
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexNumber_Get_background_color_bco(struct NexObject *number, uint32_t *num)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, number->__name);
+    strcat(cmd, ".bco");
+    sendCommand(cmd);
+    return recvRetNumber(num);
+}
+
+uint8_t NexNumber_Set_background_color_bco(struct NexObject *number, uint32_t num)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, num, 10);
+    strcat(cmd, number->__name);
+    strcat(cmd, ".bco=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, number->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexNumber_Get_font_color_pco(struct NexObject *number, uint32_t *num)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, number->__name);
+    strcat(cmd, ".pco");
+    sendCommand(cmd);
+    return recvRetNumber(num);
+}
+
+uint8_t NexNumber_Set_font_color_pco(struct NexObject *number, uint32_t num)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, num, 10);
+    strcat(cmd, number->__name);
+    strcat(cmd, ".pco=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, number->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexNumber_Get_place_xcen(struct NexObject *number, uint32_t *num)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, number->__name);
+    strcat(cmd, ".xcen");
+    sendCommand(cmd);
+    return recvRetNumber(num);
+}
+
+uint8_t NexNumber_Set_place_xcen(struct NexObject *number, uint32_t num)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, num, 10);
+    strcat(cmd, number->__name);
+    strcat(cmd, ".xcen=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, number->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexNumber_Get_place_ycen(struct NexObject *number, uint32_t *num)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, number->__name);
+    strcat(cmd, ".ycen");
+    sendCommand(cmd);
+    return recvRetNumber(num);
+}
+
+uint8_t NexNumber_Set_place_ycen(struct NexObject *number, uint32_t num)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, num, 10);
+    strcat(cmd, number->__name);
+    strcat(cmd, ".ycen=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, number->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexNumber_getFont(struct NexObject *number, uint32_t *num)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, number->__name);
+    strcat(cmd, ".font");
+    sendCommand(cmd);
+    return recvRetNumber(num);
+}
+
+uint8_t NexNumber_setFont(struct NexObject *number, uint32_t num)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, num, 10);
+    strcat(cmd, number->__name);
+    strcat(cmd, ".font=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, number->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexNumber_Get_number_lenth(struct NexObject *number, uint32_t *num)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, number->__name);
+    strcat(cmd, ".lenth");
+    sendCommand(cmd);
+    return recvRetNumber(num);
+}
+
+uint8_t NexNumber_Set_number_lenth(struct NexObject *number, uint32_t num)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, num, 10);
+    strcat(cmd, number->__name);
+    strcat(cmd, ".lenth=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, number->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexNumber_Get_background_crop_picc(struct NexObject *number, uint32_t *num)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, number->__name);
+    strcat(cmd, ".picc");
+    sendCommand(cmd);
+    return recvRetNumber(num);
+}
+
+uint8_t NexNumber_Set_background_crop_picc(struct NexObject *number, uint32_t num)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, num, 10);
+    strcat(cmd, number->__name);
+    strcat(cmd, ".picc=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, number->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexNumber_Get_background_image_pic(struct NexObject *number, uint32_t *num)
+{
+    char cmd[32] = "get ";
+    strcat(cmd, number->__name);
+    strcat(cmd, ".pic");
+    sendCommand(cmd);
+    return recvRetNumber(num);
+}
+
+uint8_t NexNumber_Set_background_image_pic(struct NexObject *number, uint32_t num)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, num, 10);
+    strcat(cmd, number->__name);
+    strcat(cmd, ".pic=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, number->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NexNumber.h	Mon May 04 17:52:49 2020 +0000
@@ -0,0 +1,152 @@
+#ifndef __NEXNUMBER_H__
+#define __NEXNUMBER_H__
+
+#include "mbed.h"
+#include "NexTouch.h"
+#include "NexHardware.h"
+
+/**
+     * Get number attribute of component.
+     *
+     * @param number - buffer storing text returned. 
+     * @return The real length of text returned. 
+     */
+uint8_t NexNumber_getValue(struct NexObject *number, uint32_t *num);
+
+/**
+     * Set number attribute of component.
+     *
+     * @param number - number buffer. 
+     * @return true if success, false for failure. 
+     */
+uint8_t NexNumber_setValue(struct NexObject *number, uint32_t num);
+
+/**
+     * Get bco attribute of component
+     *
+     * @param number - buffer storing data retur
+     * @return the length of the data 
+     */
+uint32_t NexNumber_Get_background_color_bco(struct NexObject *number, uint32_t *num);
+
+/**
+     * Set bco attribute of component
+     *
+     * @param number - To set up the data
+     * @return true if success, false for failure
+     */
+uint8_t NexNumber_Set_background_color_bco(struct NexObject *number, uint32_t num);
+
+/**
+     * Get pco attribute of component
+     *
+     * @param number - buffer storing data retur
+     * @return the length of the data 
+     */
+uint32_t NexNumber_Get_font_color_pco(struct NexObject *number, uint32_t *num);
+
+/**
+     * Set pco attribute of component
+     *
+     * @param number - To set up the data
+     * @return true if success, false for failure
+     */
+uint8_t NexNumber_Set_font_color_pco(struct NexObject *number, uint32_t num);
+
+/**
+     * Get xcen attribute of component
+     *
+     * @param number - buffer storing data retur
+     * @return the length of the data 
+     */
+uint32_t NexNumber_Get_place_xcen(struct NexObject *number, uint32_t *num);
+
+/**
+     * Set xcen attribute of component
+     *
+     * @param number - To set up the data
+     * @return true if success, false for failure
+     */
+uint8_t NexNumber_Set_place_xcen(struct NexObject *number, uint32_t num);
+
+/**
+     * Get ycen attribute of component
+     *
+     * @param number - buffer storing data retur
+     * @return the length of the data 
+     */
+uint32_t NexNumber_Get_place_ycen(struct NexObject *number, uint32_t *num);
+
+/**
+     * Set ycen attribute of component
+     *
+     * @param number - To set up the data
+     * @return true if success, false for failure
+     */
+uint8_t NexNumber_Set_place_ycen(struct NexObject *number, uint32_t num);
+
+/**
+     * Get font attribute of component
+     *
+     * @param number - buffer storing data retur
+     * @return the length of the data 
+     */
+uint32_t NexNumber_getFont(struct NexObject *number, uint32_t *num);
+
+/**
+     * Set font attribute of component
+     *
+     * @param number - To set up the data
+     * @return true if success, false for failure
+     */
+uint8_t NexNumber_setFont(struct NexObject *number, uint32_t num);
+
+/**
+     * Get lenth attribute of component
+     *
+     * @param number - buffer storing data retur
+     * @return the length of the data 
+     */
+uint32_t NexNumber_Get_number_lenth(struct NexObject *number, uint32_t *num);
+
+/**
+     * Set lenth attribute of component
+     *
+     * @param number - To set up the data
+     * @return true if success, false for failure
+     */
+uint8_t NexNumber_Set_number_lenth(struct NexObject *number, uint32_t num);
+
+/**
+     * Get picc attribute of component
+     *
+     * @param number - buffer storing data retur
+     * @return the length of the data 
+     */
+uint32_t NexNumber_Get_background_crop_picc(struct NexObject *number, uint32_t *num);
+
+/**
+     * Set picc attribute of component
+     *
+     * @param number - To set up the data
+     * @return true if success, false for failure
+     */
+uint8_t NexNumber_Set_background_crop_picc(struct NexObject *number, uint32_t num);
+
+/**
+     * Get pic attribute of component
+     *
+     * @param number - buffer storing data retur
+     * @return the length of the data 
+     */
+uint32_t NexNumber_Get_background_image_pic(struct NexObject *number, uint32_t *num);
+
+/**
+     * Set pic attribute of component
+     *
+     * @param number - To set up the data
+     * @return true if success, false for failure
+     */
+uint8_t NexNumber_Set_background_image_pic(struct NexObject *number, uint32_t num);
+
+#endif /* #ifndef __NEXNUMBER_H__ */
--- a/NexObject.h	Wed Apr 15 17:02:54 2020 +0000
+++ b/NexObject.h	Mon May 04 17:52:49 2020 +0000
@@ -1,84 +1,20 @@
-/**
- * @file NexObject.h
- *
- * The definition of class NexObject. 
- *
- * @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
- * @date 2015/8/13
- *
- * @copyright 
- * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- */
 #ifndef __NEXOBJECT_H__
 #define __NEXOBJECT_H__
-//#include <Arduino.h>
+#include "mbed.h"
 #include "NexConfig.h"
-/**
- * @addtogroup CoreAPI 
- * @{ 
- */
+#include "Utilities.h"
 
-/**
- * Root class of all Nextion components. 
- *
- * Provides the essential attributes of a Nextion component and the methods accessing
- * them. At least, Page ID(pid), Component ID(pid) and an unique name are needed for
- * creating a component in Nexiton library. 
- */
-class NexObject 
-{
-public: /* methods */
-
-    /**
-     * Constructor. 
-     *
-     * @param pid - page id. 
-     * @param cid - component id.    
-     * @param name - pointer to an unique name in range of all components. 
-     */
-    NexObject(uint8_t pid, uint8_t cid, const char *name);
-
-    /**
-     * Print current object'address, page id, component id and name. 
-     *
-     * @warning this method does nothing, unless debug message enabled. 
-     */
-    void printObjInfo(void);
+typedef void (*NexTouchEventCb)(void *ptr);
 
-protected: /* methods */
-
-    /*
-     * Get page id.
-     *
-     * @return the id of page.  
-     */
-    uint8_t getObjPid(void);    
-
-    /*
-     * Get component id.
-     *
-     * @return the id of component.  
-     */
-    uint8_t getObjCid(void);
+struct NexObject
+{
+    uint8_t __pid;      /* Page ID */
+    uint8_t __cid;      /* Component ID */
+    char __name[16]; /* An unique name */
+    NexTouchEventCb __cb_push;
+    void *__cbpush_ptr;
+    NexTouchEventCb __cb_pop;
+    void *__cbpop_ptr;
+};
 
-    /*
-     * Get component name.
-     *
-     * @return the name of component. 
-     */
-    const char *getObjName(void);    
-    
-private: /* data */ 
-    uint8_t __pid; /* Page ID */
-    uint8_t __cid; /* Component ID */
-    const char *__name; /* An unique name */
-};
-/**
- * @}
- */
-
-#endif /* #ifndef __NEXOBJECT_H__ */
\ No newline at end of file
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NexPage.cpp	Mon May 04 17:52:49 2020 +0000
@@ -0,0 +1,22 @@
+#include "NexPage.h"
+#include <string.h>
+#include "Utilities.h"
+
+uint8_t buffer[4];
+extern char cmd[64];
+
+uint8_t NexPage_show(struct NexObject *page)
+{
+
+    ClearString(buffer);
+    if (!page->__name)
+    {
+        return 0;
+    }
+
+    ClearString(cmd);
+    strcat(cmd, "page ");
+    strcat(cmd, page->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
\ No newline at end of file
--- a/NexPage.h	Wed Apr 15 17:02:54 2020 +0000
+++ b/NexPage.h	Mon May 04 17:52:49 2020 +0000
@@ -1,51 +1,10 @@
-  
-/**
- * @file NexPage.h
- *
- * The definition of class NexPage. 
- *
- * @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
- * @date 2015/8/13
- *
- * @copyright 
- * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- */
-
 #ifndef __NEXPAGE_H__
 #define __NEXPAGE_H__
-
+#include "mbed.h"
 #include "NexTouch.h"
 #include "NexHardware.h"
-/**
- * @addtogroup Component 
- * @{ 
- */
+#include "Utilities.h"
 
-/**
- * A special component , which can contain other components such as NexButton, 
- * NexText and NexWaveform, etc. 
- */
-class NexPage: public NexTouch
-{
-public: /* methods */
-    /**
-     * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name);
-     */
-    NexPage(uint8_t pid, uint8_t cid, const char *name);
-    
-    /**
-     * Show itself. 
-     * 
-     * @return true if success, false for faileure.
-     */
-    bool show(void);
-};
-/**
- * @}
- */
+uint8_t NexPage_show(struct NexObject *);
 
 #endif /* #ifndef __NEXPAGE_H__ */
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NexText.cpp	Mon May 04 17:52:49 2020 +0000
@@ -0,0 +1,221 @@
+#include "NexText.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "Utilities.h"
+
+extern char buf[12];
+extern char cmd[64];
+
+uint16_t NexText_getText(struct NexObject *text, char *buffer, uint16_t len)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, text->__name);
+    strcat(cmd, ".txt");
+    sendCommand(cmd);
+    return recvRetString(buffer, len);
+}
+
+uint8_t NexText_setText(struct NexObject *text, char *buffer)
+{
+    ClearString(cmd);
+    strcat(cmd, text->__name);
+    strcat(cmd, ".txt=\"");
+    strcat(cmd, buffer);
+    strcat(cmd, "\"");
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexText_Get_background_color_bco(struct NexObject *text, uint32_t *number)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, text->__name);
+    strcat(cmd, ".bco");
+    sendCommand(cmd);
+    return recvRetNumber(number);
+}
+
+uint8_t NexText_Set_background_color_bco(struct NexObject *text, uint32_t number)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, number, 10);
+    strcat(cmd, text->__name);
+    strcat(cmd, ".bco=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, text->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexText_Get_font_color_pco(struct NexObject *text, uint32_t *number)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, text->__name);
+    strcat(cmd, ".pco");
+    sendCommand(cmd);
+    return recvRetNumber(number);
+}
+
+uint8_t NexText_Set_font_color_pco(struct NexObject *text, uint32_t number)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, number, 10);
+    strcat(cmd, text->__name);
+    strcat(cmd, ".pco=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, text->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexText_Get_place_xcen(struct NexObject *text, uint32_t *number)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, text->__name);
+    strcat(cmd, ".xcen");
+    sendCommand(cmd);
+    return recvRetNumber(number);
+}
+
+uint8_t NexText_Set_place_xcen(struct NexObject *text, uint32_t number)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, number, 10);
+    strcat(cmd, text->__name);
+    strcat(cmd, ".xcen=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, text->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexText_Get_place_ycen(struct NexObject *text, uint32_t *number)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, text->__name);
+    strcat(cmd, ".ycen");
+    sendCommand(cmd);
+    return recvRetNumber(number);
+}
+
+uint8_t NexText_Set_place_ycen(struct NexObject *text, uint32_t number)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, number, 10);
+    strcat(cmd, text->__name);
+    strcat(cmd, ".ycen=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, text->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexText_getFont(struct NexObject *text, uint32_t *number)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, text->__name);
+    strcat(cmd, ".font");
+    sendCommand(cmd);
+    return recvRetNumber(number);
+}
+
+uint8_t NexText_setFont(struct NexObject *text, uint32_t number)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, number, 10);
+    strcat(cmd, text->__name);
+    strcat(cmd, ".font=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, text->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexText_Get_background_crop_picc(struct NexObject *text, uint32_t *number)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, text->__name);
+    strcat(cmd, ".picc");
+    sendCommand(cmd);
+    return recvRetNumber(number);
+}
+
+uint8_t NexText_Set_background_crop_picc(struct NexObject *text, uint32_t number)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, number, 10);
+    strcat(cmd, text->__name);
+    strcat(cmd, ".picc=");
+    strcat(cmd, buf);
+    sendCommand(cmd);
+
+    ClearString(cmd);
+    strcat(cmd, "ref ");
+    strcat(cmd, text->__name);
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
+
+uint32_t NexText_Get_background_image_pic(struct NexObject *text, uint32_t *number)
+{
+    ClearString(cmd);
+    strcat(cmd, "get ");
+    strcat(cmd, text->__name);
+    strcat(cmd, ".pic");
+    sendCommand(cmd);
+    return recvRetNumber(number);
+}
+
+uint8_t NexText_Set_background_image_pic(struct NexObject *text, uint32_t number)
+{
+    ClearString(buf);
+    ClearString(cmd);
+
+    utoa(buf, number, 10);
+    strcat(cmd, text->__name);
+    strcat(cmd, ".pic=");
+    strcat(cmd, buf);
+
+    sendCommand(cmd);
+    return recvRetCommandFinished();
+}
\ No newline at end of file
--- a/NexText.h	Wed Apr 15 17:02:54 2020 +0000
+++ b/NexText.h	Mon May 04 17:52:49 2020 +0000
@@ -1,173 +1,136 @@
-/**
- * @file NexText.h
- *
- * The definition of class NexText. 
- *
- * @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
- * @date 2015/8/13
- *
- * @copyright 
- * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- */
- 
 #ifndef __NEXTEXT_H__
 #define __NEXTEXT_H__
-
+#include "mbed.h"
 #include "NexTouch.h"
 #include "NexHardware.h"
-/**
- * @addtogroup Component 
- * @{ 
- */
-
+#include "Utilities.h"
 /**
- * NexText component.
- */
-class NexText: public NexTouch
-{
-public: /* methods */
-    /**
-     * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name);
-     */
-    NexText(uint8_t pid, uint8_t cid, const char *name);
-    
-    /**
      * Get text attribute of component.
      *
      * @param buffer - buffer storing text returned. 
      * @param len - length of buffer. 
      * @return The real length of text returned. 
      */
-    uint16_t getText(char *buffer, uint16_t len);
-    
-    /**
+uint16_t NexText_getText(struct NexObject *text, 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);    
-    
-    /**
+uint8_t NexText_setText(struct NexObject *text, 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 NexText_Get_background_color_bco(struct NexObject *text, 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);           
-    
-    /**
+uint8_t NexText_Set_background_color_bco(struct NexObject *text, 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 NexText_Get_font_color_pco(struct NexObject *text, uint32_t *number);
 
-    /**
+/**
      * Set pco attribute of component
      *
      * @param number - To set up the data
      * @return true if success, false for failure
      */
-    bool Set_font_color_pco(uint32_t number);           
-    
-    /**
+uint8_t NexText_Set_font_color_pco(struct NexObject *text, 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 NexText_Get_place_xcen(struct NexObject *text, uint32_t *number);
 
-    /**
+/**
      * Set xcen attribute of component
      *
      * @param number - To set up the data
      * @return true if success, false for failure
      */
-    bool Set_place_xcen(uint32_t number);           
-    
-    /**
+uint8_t NexText_Set_place_xcen(struct NexObject *text, 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 NexText_Get_place_ycen(struct NexObject *text, uint32_t *number);
 
-    /**
+/**
      * Set ycen attribute of component
      *
      * @param number - To set up the data
      * @return true if success, false for failure
      */
-    bool Set_place_ycen(uint32_t number);           
-    
-    /**
+uint8_t NexText_Set_place_ycen(struct NexObject *text, 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 NexText_getFont(struct NexObject *text, 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);          
-    
-    /**
+uint8_t NexText_setFont(struct NexObject *text, 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 NexText_Get_background_crop_picc(struct NexObject *text, uint32_t *number);
 
-    /**
+/**
      * Set picc attribute of component
      *
      * @param number - To set up the data
      * @return true if success, false for failure
      */
-    bool Set_background_crop_picc(uint32_t number);         
-    
-    /**
+uint8_t NexText_Set_background_crop_picc(struct NexObject *text, 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 NexText_Get_background_image_pic(struct NexObject *text, uint32_t *number);
 
-    /**
+/**
      * Set pic attribute of component
      *
      * @param number - To set up the data
      * @return true if success, false for failure
      */
-    bool Set_background_image_pic(uint32_t number); 
-    
-};
-
-/**
- * @}
- */
+uint8_t NexText_Set_background_image_pic(struct NexObject *text, uint32_t number);
 
 #endif /* #ifndef __NEXTEXT_H__ */
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NexTouch.cpp	Mon May 04 17:52:49 2020 +0000
@@ -0,0 +1,81 @@
+#include "NexTouch.h"
+
+NexTouchEventCb __cb_push;
+void *__cbpush_ptr;
+NexTouchEventCb __cb_pop;
+void *__cbpop_ptr;
+
+void NexTouch_attachPush(struct NexObject *touch, NexTouchEventCb push, void *ptr)
+{
+    touch->__cb_push = push;
+    touch->__cbpush_ptr = ptr;
+}
+
+void NexTouch_detachPush(struct NexObject *touch)
+{
+    touch->__cb_push = 0;
+    touch->__cbpush_ptr = 0;
+}
+
+void NexTouch_attachPop(struct NexObject *touch, NexTouchEventCb pop, void *ptr)
+{
+    touch->__cb_pop = pop;
+    touch->__cbpop_ptr = ptr;
+}
+
+void NexTouch_detachPop(struct NexObject *touch)
+{
+    touch->__cb_pop = 0;
+    touch->__cbpop_ptr = 0;
+}
+
+void NexTouch_push(struct NexObject *touch)
+{
+    if (touch->__cb_push)
+    {
+        touch->__cb_push(__cbpush_ptr);
+    }
+}
+
+void NexTouch_pop(struct NexObject *touch)
+{
+    if (touch->__cb_pop)
+    {
+        touch->__cb_pop(__cbpop_ptr);
+    }
+}
+
+void NexTouch_iterate(struct NexObject **list, uint8_t pid, uint8_t cid, int32_t event)
+{
+    struct NexObject *e = 0;
+    uint16_t i = 0;
+
+    if (0 == list)
+    {
+        return;
+    }
+
+    for (i = 0; (e = list[i]) != 0; i++)
+    {
+        if (e->__pid == pid && e->__cid == cid)
+        {
+            //e->printObjInfo();
+            if (NEX_EVENT_PUSH == event)
+            {
+                if (e->__cb_push)
+                {
+                    e->__cb_push(e->__cbpush_ptr);
+                }
+            }
+            else if (NEX_EVENT_POP == event)
+            {
+                if (e->__cb_pop)
+                {
+                    e->__cb_pop(e->__cbpop_ptr);
+                }
+            }
+
+            break;
+        }
+    }
+}
\ No newline at end of file
--- a/NexTouch.h	Wed Apr 15 17:02:54 2020 +0000
+++ b/NexTouch.h	Mon May 04 17:52:49 2020 +0000
@@ -1,116 +1,26 @@
-/**
- * @file NexTouch.h
- *
- * The definition of class NexTouch. 
- *
- * @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
- * @date 2015/8/13
- *
- * @copyright 
- * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- */
-
 #ifndef __NEXTOUCH_H__
 #define __NEXTOUCH_H__
 
-//#include <Arduino.h>
+#include "mbed.h"
 #include "NexConfig.h"
 #include "NexObject.h"
-
-/**
- * @addtogroup TouchEvent 
- * @{ 
- */
-
-/**
- * Push touch event occuring when your finger or pen coming to Nextion touch pannel. 
- */
-#define NEX_EVENT_PUSH  (0x01)
-
-/**
- * Pop touch event occuring when your finger or pen leaving from Nextion touch pannel. 
- */
-#define NEX_EVENT_POP   (0x00)  
+#include <string.h>
+#include "Utilities.h"
 
-/**
- * Type of callback funciton when an touch event occurs. 
- * 
- * @param ptr - user pointer for any purpose. Commonly, it is a pointer to a object. 
- * @return none. 
- */
-typedef void (*NexTouchEventCb)(void *ptr);
+#define NEX_EVENT_PUSH (0x01)
+#define NEX_EVENT_POP (0x00)
 
-/**
- * Father class of the components with touch events.  
- *
- * Derives from NexObject and provides methods allowing user to attach
- * (or detach) a callback function called when push(or pop) touch event occurs.
- */
-class NexTouch: public NexObject
-{
-public: /* static methods */    
-    static void iterate(NexTouch **list, uint8_t pid, uint8_t cid, int32_t event);
+void NexTouch_iterate(struct NexObject **list, uint8_t pid, uint8_t cid, int32_t event);
 
-public: /* methods */
-
-    /**
-     * @copydoc NexObject::NexObject(uint8_t pid, uint8_t cid, const char *name);
-     */
-    NexTouch(uint8_t pid, uint8_t cid, const char *name);
+void NexTouch_attachPush(struct NexObject *touch, NexTouchEventCb push, void *ptr);
 
-    /**
-     * Attach an callback function of push touch event. 
-     *
-     * @param push - callback called with ptr when a push touch event occurs. 
-     * @param ptr - parameter passed into push[default:NULL]. 
-     * @return none. 
-     *
-     * @note If calling this method multiply, the last call is valid. 
-     */
-    void attachPush(NexTouchEventCb push, void *ptr = NULL);
+void NexTouch_detachPush(struct NexObject *touch);
 
-    /**
-     * Detach an callback function. 
-     * 
-     * @return none. 
-     */
-    void detachPush(void);
+void NexTouch_attachPop(struct NexObject *touch, NexTouchEventCb pop, void *ptr);
 
-    /**
-     * Attach an callback function of pop touch event. 
-     *
-     * @param pop - callback called with ptr when a pop touch event occurs. 
-     * @param ptr - parameter passed into pop[default:NULL]. 
-     * @return none. 
-     *
-     * @note If calling this method multiply, the last call is valid. 
-     */
-    void attachPop(NexTouchEventCb pop, void *ptr = NULL);
+void NexTouch_detachPop(struct NexObject *touch);
 
-    /**
-     * Detach an callback function. 
-     * 
-     * @return none. 
-     */
-    void detachPop(void);
-    
-private: /* methods */ 
-    void push(void);
-    void pop(void);
-    
-private: /* data */ 
-    NexTouchEventCb __cb_push;
-    void *__cbpush_ptr;
-    NexTouchEventCb __cb_pop;
-    void *__cbpop_ptr;
-};
+void NexTouch_push(struct NexObject *touch);
+void NexTouch_pop(struct NexObject *touch);
 
-/**
- * @}
- */
-
-#endif /* #ifndef __NEXTOUCH_H__ */
\ No newline at end of file
+#endif
\ No newline at end of file
--- a/Nextion.h	Wed Apr 15 17:02:54 2020 +0000
+++ b/Nextion.h	Mon May 04 17:52:49 2020 +0000
@@ -16,30 +16,15 @@
  */
 #ifndef __NEXTION_H__
 #define __NEXTION_H__
-
-
+#include "NexObject.h"
 #include "NexConfig.h"
 #include "NexTouch.h"
 #include "NexHardware.h"
-
+#include "NexNumber.h"
 #include "NexButton.h"
-//#include "NexCrop.h"
-//#include "NexGauge.h"
-//#include "NexHotspot.h"
 #include "NexPage.h"
-//#include "NexPicture.h"
 //#include "NexProgressBar.h"
 //#include "NexSlider.h"
 #include "NexText.h"
-//#include "NexWaveform.h"
-//#include "NexTimer.h"
-//#include "NexNumber.h"
-//#include "NexDualStateButton.h"
-//#include "NexVariable.h"
-//#include "NexCheckbox.h"
-//#include "NexRadio.h"
-//#include "NexScrolltext.h"
-//#include "NexGpio.h"
-//#include "NexRtc.h"
 
 #endif /* #ifndef __NEXTION_H__ */
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Serial.cpp	Mon May 04 17:52:49 2020 +0000
@@ -0,0 +1,99 @@
+#include "Serial.h"
+#include "Utilities.h"
+
+unsigned char rxBuff[64];
+char rxHead, rxTail;
+void UART1interrupt( iv IVT_UART_1 ilevel 6 ics ICS_AUTO)
+{
+    rxBuff[rxHead++] = UART1_Read(); // read the received data
+    U1RXIF_bit = 0;
+}
+
+void Serial_Init(long baudrate)
+{
+    AD1PCFG = 0xFFFF; // Configure AN pins as digital I/O
+    UART1_Init(9600);
+    rxHead = 0;
+    rxTail = 0;
+
+    U1IP0_bit = 0; // Set UART2 interrupt
+    U1IP1_bit = 1; // Set interrupt priorities
+    U1IP2_bit = 1; // Set UART2 interrupt to level 6
+
+    U1RXIE_bit = 1; // Set UART Receive Interrupt
+    U1RXIF_bit = 0;
+    EnableInterrupts(); // Enable interruts as previously set
+}
+
+unsigned char Serial_Write(unsigned char c)
+{
+    UART1_Write(c);
+    return 1;
+}
+
+unsigned char Serial_Read()
+{
+    unsigned char c;
+    if (rxTail < rxHead)
+    {
+        c = rxBuff[rxTail++];
+        if (rxTail == rxHead)
+        {
+            rxHead = 0;
+            rxTail = 0;
+        }
+    }
+    else
+    {
+        rxHead = 0;
+        rxTail = 0;
+        c = -1;
+    }
+    return c;
+}
+
+unsigned char Serial_Available()
+{
+    return rxHead - rxTail;
+}
+
+unsigned char Serial_ReadBytes(char *buf, unsigned char len)
+{
+    unsigned char cnt = 0;
+    if (len < rxHead - rxTail)
+    {
+        ArrayCopy(buf, &rxBuff[rxTail], len);
+        rxTail += len;
+        cnt = len;
+    }
+    else if (len == rxHead - rxTail)
+    {
+        ArrayCopy(buf, &rxBuff[rxTail], len);
+        rxTail = 0;
+        rxHead = 0;
+        cnt = len;
+    }
+    else
+    {
+        ArrayCopy(buf, &rxBuff[rxTail], rxHead - rxTail);
+        cnt = rxHead - rxTail;
+        rxTail = 0;
+        rxHead = 0;
+    }
+    return cnt;
+}
+
+void Serial_Print(unsigned char *txt)
+{
+    short i = strlen(txt);
+    while (1)
+    {
+        UART1_Write(*txt);
+        ++txt;
+        --i;
+        if (i == 0)
+        {
+            break;
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Serial.h	Mon May 04 17:52:49 2020 +0000
@@ -0,0 +1,19 @@
+#ifndef SERIAL_H
+#define SERIAL_H
+/*************************************************************************
+* MACROS
+*************************************************************************/
+#define RX_BUFFER_SIZE 64
+#define TX_BUFFER_SIZE 64
+#define RX_Flush() _rx_buffer_head=0;_rx_buffer_tail=0
+#define TX_Flush() _tx_buffer_head=0;_tx_buffer_tail=0
+/*************************************************************************
+* FUNCTIONS
+*************************************************************************/
+void Serial_Init(long baudrate);
+unsigned char Serial_Write(unsigned char c);
+unsigned char Serial_Read();
+unsigned char Serial_Available();
+unsigned char Serial_ReadBytes(char *buf, unsigned char len);
+void Serial_Print(unsigned char *txt);
+#endif
\ No newline at end of file