From 6d1b66cf7d132cfb6c9eca06976e35868e4645ff Mon Sep 17 00:00:00 2001 From: zhangabc Date: Fri, 8 May 2015 14:10:45 +0800 Subject: [PATCH] /*code eidt*/ --- hmi.cpp | 279 ++++++++++++++++++++++++++------------------------- hmi.h | 292 +++++++++++++++++++++++++++--------------------------- readme.md | 10 +- 3 files changed, 294 insertions(+), 287 deletions(-) diff --git a/hmi.cpp b/hmi.cpp index 353d885..03b3fb1 100644 --- a/hmi.cpp +++ b/hmi.cpp @@ -1,30 +1,30 @@ /** - * @file hmi.cpp - * @brief The implementation of class HMI. - * @author laicheng.zhang@itead.cc - * @date 2015.04 - * - * @par Copyright: - * Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd. \n\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. \n\n - * 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. - */ + * @file hmi.cpp + * @brief The implementation of class HMI. + * @author laicheng.zhang@itead.cc + * @date 2015.04 + * + * @par Copyright: + * Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd. \n\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. \n\n + * 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. + */ #include "hmi.h" HMI::HMI(HMISerial &uart,uint32_t baud) { my_uart = &uart; - my_uart->begin(baud); - setRxEmpty(); + my_uart->begin(baud); + setRxEmpty(); } bool HMI::textEdit(char *text_id,char *value) @@ -36,36 +36,36 @@ bool HMI::textEdit(char *text_id,char *value) strcat(cmd,value); strcat(cmd,"\""); my_uart->print(cmd); - commandEnd(); - + commandEnd(); + if (returnIsRight() == 0) - return true; - else - return false; -} + return true; + else + return false; +} bool HMI::pictureEdit(char *picture_id,uint32_t value) { - /*p0.pic=6*/ - char cmd[50] = {0}; - char valuetemp[25] = {0}; - itoa(value,valuetemp,10); - strcat(cmd,picture_id); - strcat(cmd,".pic="); - strcat(cmd,valuetemp); - - my_uart->print(cmd); - commandEnd(); + /*p0.pic=6*/ + char cmd[50] = {0}; + char valuetemp[25] = {0}; + itoa(value,valuetemp,10); + strcat(cmd,picture_id); + strcat(cmd,".pic="); + strcat(cmd,valuetemp); + + my_uart->print(cmd); + commandEnd(); - if (returnIsRight() == 0) - return true; - else - return false; + if (returnIsRight() == 0) + return true; + else + return false; } bool HMI::progressBarEdit(char *bar_id,uint32_t value) { - char cmd[50] = {0}; + char cmd[50] = {0}; char valuetemp[25] = {0}; itoa(value,valuetemp,10); strcat(cmd,bar_id); @@ -73,30 +73,30 @@ bool HMI::progressBarEdit(char *bar_id,uint32_t value) strcat(cmd,valuetemp); my_uart->print(cmd); - commandEnd(); + commandEnd(); if (returnIsRight() == 0) - return true; - else - return false; + return true; + else + return false; } bool HMI::cutPicture(char *picture_id,uint32_t value) { - char cmd[50] = {0}; - char valuetemp[25] = {0}; - itoa(value,valuetemp,10); - strcat(cmd,picture_id); - strcat(cmd,".pic="); - strcat(cmd,valuetemp); + char cmd[50] = {0}; + char valuetemp[25] = {0}; + itoa(value,valuetemp,10); + strcat(cmd,picture_id); + strcat(cmd,".pic="); + strcat(cmd,valuetemp); my_uart->print(cmd); - commandEnd(); + commandEnd(); - if (returnIsRight() == 0) - return true; - else - return false; + if (returnIsRight() == 0) + return true; + else + return false; } bool HMI::pageChange(uint32_t page_id) @@ -109,124 +109,123 @@ bool HMI::pageChange(uint32_t page_id) strcat(cmd,page_idtemp); my_uart->print(cmd); - commandEnd(); - delay(200); - if (returnIsRight() == 0) - return true; - else - return false; + commandEnd(); + delay(200); + if (returnIsRight() == 0) + return true; + else + return false; } void HMI::readLcdData(unsigned char *data_buffer) { - delay(10); - cleanBuffer(); - uint32_t i = 0; - while(my_uart->available() <= 0); - while(my_uart->available() > 0) - { - delay(3); - buffer[i] = (unsigned char)my_uart->read(); - i++; - } + delay(10); + cleanBuffer(); + uint32_t i = 0; + while(my_uart->available() <= 0); + while(my_uart->available() > 0) + { + delay(3); + buffer[i] = (unsigned char)my_uart->read(); + i++; + } if (buffer[0] == 0x70) { uint32_t j = 0; uint32_t k = 1; for(j=0;javailable(); - uint32_t i = 0; - while(my_uart->available()) - { - temp[i] = (unsigned char)my_uart->read(); - i++; - } - if((tempid==4)&&(strncmp((char*)temp1,(char*)temp,4)==0)) - { - return 0; - } - else - { - return -1; - } + uint32_t tempid = 0; + unsigned char temp[20] = {0}; + unsigned char temp1[4] = {0x01,0xFF,0xFF,0xFF}; + + tempid = my_uart->available(); + uint32_t i = 0; + while(my_uart->available()) + { + temp[i] = (unsigned char)my_uart->read(); + i++; + } + if((tempid==4)&&(strncmp((char*)temp1,(char*)temp,4)==0)) + { + return 0; + } + else + { + return -1; + } } bool HMI::touchCalibration(void) { - /*Serial.println("touch Calibration");*/ - my_uart->print("touch_j"); - commandEnd(); - delay(5000); - if (returnIsRight() == 0) - return true; - else - return false; + /*Serial.println("touch Calibration");*/ + my_uart->print("touch_j"); + commandEnd(); + delay(5000); + if (returnIsRight() == 0) + return true; + else + return false; } bool HMI::disableTouchFocus(void) { - /*Serial.println("disableTouchFocus");*/ - my_uart->print("cle_c"); - commandEnd(); - if (returnIsRight() == 0) - return true; - else - return false; + /*Serial.println("disableTouchFocus");*/ + my_uart->print("cle_c"); + commandEnd(); + if (returnIsRight() == 0) + return true; + else + return false; } bool HMI::pauseSerialCommand(void) { - /*Serial.println("pauseSerialCommand");*/ - my_uart->print("com_stop"); + /*Serial.println("pauseSerialCommand");*/ + my_uart->print("com_stop"); commandEnd(); - if (returnIsRight() == 0) - return true; - else - return false; + if (returnIsRight() == 0) + return true; + else + return false; } bool HMI::recoverySerialCommand(void) { - /*Serial.println("recoverySerialCommand");*/ - my_uart->print("com_star"); - commandEnd(); - if (returnIsRight() == 0) - return true; - else - return false; + /*Serial.println("recoverySerialCommand");*/ + my_uart->print("com_star"); + commandEnd(); + if (returnIsRight() == 0) + return true; + else + return false; } bool HMI::emptySerialCommand(void) { - /*Serial.println("emptySerialCommand");*/ - my_uart->print("code_c"); - commandEnd(); - if (returnIsRight() == 0) - return true; - else - return false; + /*Serial.println("emptySerialCommand");*/ + my_uart->print("code_c"); + commandEnd(); + if (returnIsRight() == 0) + return true; + else + return false; } uint32_t HMI::returnPageId(void) { - my_uart->print("sendme"); - commandEnd(); + my_uart->print("sendme"); + commandEnd(); delay(50); unsigned char temp1[] = {0x66,0xFF,0xFF,0xFF}; @@ -241,18 +240,18 @@ uint32_t HMI::returnPageId(void) if(!strcmp((char*)temp1[0],(char*)temp[0])) { - return (uint32_t)temp[1]; + return (uint32_t)temp[1]; } else - return -1; + return -1; } void HMI::setRxEmpty(void) { while(my_uart->available() > 0) { - my_uart->read(); - } + my_uart->read(); + } } void HMI::cleanBuffer(void) @@ -263,8 +262,8 @@ void HMI::cleanBuffer(void) void HMI::commandEnd(void) { my_uart->write(0xFF); - my_uart->write(0xFF); - my_uart->write(0xFF); + my_uart->write(0xFF); + my_uart->write(0xFF); } diff --git a/hmi.h b/hmi.h index f52f088..d93f6eb 100644 --- a/hmi.h +++ b/hmi.h @@ -1,30 +1,30 @@ /** - * @file hmi.h - * @brief The definition of class HMI. - * @author laicheng.zhang@itead.cc - * @date 2015.04 - * - * @par Copyright: - * Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd. \n\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. \n\n - * 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. - */ + * @file hmi.h + * @brief The definition of class HMI. + * @author laicheng.zhang@itead.cc + * @date 2015.04 + * + * @par Copyright: + * Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd. \n\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. \n\n + * 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. + */ #ifndef __HMI_H__ #define __HMI_H__ #include "arduino.h" /** - * You can modify the macro to choose sofware serial or hardware serial. - */ + * You can modify the macro to choose sofware serial or hardware serial. + */ //#define HMI_SOFTWARE_SERIAL #ifdef HMI_SOFTWARE_SERIAL @@ -35,172 +35,172 @@ typedef HardwareSerial HMISerial; #endif /* #ifdef HMI_SOFTWARE_SERIAL */ /** - * HMI class. - * - * used to operate LCD touch screen. - */ + * HMI class. + * + * used to operate LCD touch screen. + */ class HMI { public: /** - * Constuctor. - * - * @param uart - an reference of user serial object. - * @param baud - the buad rate to communicate with LCD touch screen(default:9600). - * - */ + * Constuctor. + * + * @param uart - an reference of user serial object. + * @param baud - the buad rate to communicate with LCD touch screen(default:9600). + * + */ HMI(HMISerial &uart, uint32_t baud = 9600); - /** - * Edit text. - * - * @param text_id - text id. - * @param value - text value. - * @retval true - success. - * @retval false - failure. - * - */ + /** + * Edit text. + * + * @param text_id - text id. + * @param value - text value. + * @retval true - success. + * @retval false - failure. + * + */ bool textEdit(char *text_id,char *value); - /** - * Edit picture. - * - * @param picture_id - picture name. - * @param value - picture value. - * @retval true - success. - * @retval false - failure. - * - */ + /** + * Edit picture. + * + * @param picture_id - picture name. + * @param value - picture value. + * @retval true - success. + * @retval false - failure. + * + */ bool pictureEdit(char *picture_id,uint32_t value); - /** - * Progress bar edit. - * - * @param bar_id - progress bar name. - * @param value - progress bar value. - * @retval true - success. - * @retval false - failure. - * - */ - bool progressBarEdit(char *bar_id,uint32_t value); + /** + * Progress bar edit. + * + * @param bar_id - progress bar name. + * @param value - progress bar value. + * @retval true - success. + * @retval false - failure. + * + */ + bool progressBarEdit(char *bar_id,uint32_t value); - /** - * Cut picture. - * - * @param picture_id - picture name. - * @param value - picture value. - * @retval true - success. - * @retval false - failure. - * - */ - bool cutPicture(char *picture_id,uint32_t value); + /** + * Cut picture. + * + * @param picture_id - picture name. + * @param value - picture value. + * @retval true - success. + * @retval false - failure. + * + */ + bool cutPicture(char *picture_id,uint32_t value); - /** - * Page change. - * - * @param page_id - page id. - * @retval true - success. - * @retval false - failure. - * - */ + /** + * Page change. + * + * @param page_id - page id. + * @retval true - success. + * @retval false - failure. + * + */ bool pageChange(uint32_t page_id); /** - * The LCD touch screen calibration. - * - * @param data_buffer - get data from LCD ,it is a input parameter. - * - */ + * The LCD touch screen calibration. + * + * @param data_buffer - get data from LCD ,it is a input parameter. + * + */ void readLcdData(unsigned char *data_buffer); - /** - * The LCD touch screen calibration. - * - * @retval true - success. - * @retval false - failure. - * - */ + /** + * The LCD touch screen calibration. + * + * @retval true - success. + * @retval false - failure. + * + */ bool touchCalibration(void); - /** - * Disable touch focus. - * - * @retval true - success. - * @retval false - failure. - * - */ + /** + * Disable touch focus. + * + * @retval true - success. + * @retval false - failure. + * + */ bool disableTouchFocus(void); - /** - * Pause serial command from UNO. - * - * @retval true - success. - * @retval false - failure. - * - */ + /** + * Pause serial command from UNO. + * + * @retval true - success. + * @retval false - failure. + * + */ bool pauseSerialCommand(void); - /** - * Recovery serial command from UNO. - * - * @retval true - success. - * @retval false - failure. - * - */ + /** + * Recovery serial command from UNO. + * + * @retval true - success. + * @retval false - failure. + * + */ bool recoverySerialCommand(void); - /** - * Empty serial command from UNO. - * - * @retval true - success. - * @retval false - failure. - * - */ + /** + * Empty serial command from UNO. + * + * @retval true - success. + * @retval false - failure. + * + */ bool emptySerialCommand(void); - /** - * Return current page id. - * - * @retval >=0 - current page id. - * @retval <0 - return page id failure. - * - */ + /** + * Return current page id. + * + * @retval >=0 - current page id. + * @retval <0 - return page id failure. + * + */ uint32_t returnPageId(void); private: - /** - * The return value judgement. - * - * @retval true - success. - * @retval false - failure. - * - */ + /** + * The return value judgement. + * + * @retval true - success. + * @retval false - failure. + * + */ bool returnIsRight(void); - /** - * Clean data receive buffer,from LCD serial. - */ + /** + * Clean data receive buffer,from LCD serial. + */ void cleanBuffer(void); - /** - * Clear serial buffer. - */ + /** + * Clear serial buffer. + */ void setRxEmpty(void); /** - * Data receive buffer, from LCD serial. - */ - unsigned char buffer[100]; + * Data receive buffer, from LCD serial. + */ + unsigned char buffer[100]; - /** - * Command end flag. - */ + /** + * Command end flag. + */ void commandEnd(void); - /** - * Point to the current user serial. - */ + /** + * Point to the current user serial. + */ HMISerial *my_uart; }; #endif diff --git a/readme.md b/readme.md index b12a575..6edbeeb 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,14 @@ # HMI -A HMI library for Arduino providing an easy-to-use way to manipulate LCD touch screen. +A HMI library for Arduino providing an easy-to-use way to manipulate LCD touch screen. + +# Source + +Source can be download at https://github.com/itead/ITEADLIB_Arduino_Nextion. + +You can clone it by: + + git clone https://github.com/itead/ITEADLIB_Arduino_Nextion # How to get started