diff --git a/NexGpio.cpp b/NexGpio.cpp new file mode 100755 index 00000000..2a63d35f --- /dev/null +++ b/NexGpio.cpp @@ -0,0 +1,105 @@ +/** + * @file NexGpio.cpp + * + * The implementation of class NexGpio. + * + * @author Wu Pengfei (email:) + * @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 "NexGpio.h" + +bool NexGpio::pin_mode(uint32_t port,uint32_t mode,uint32_t control_id) +{ + char buf; + String cmd; + + cmd += "cfgpio "; + buf = port + '0'; + cmd += buf; + cmd += ','; + buf = mode + '0'; + cmd += buf; + cmd += ','; + buf = control_id = '0'; + cmd += buf; + + sendCommand(cmd.c_str()); + return recvRetCommandFinished(); + +} + +bool NexGpio::digital_write(uint32_t port,uint32_t value) +{ + String cmd; + char buf; + + cmd += "pio"; + buf = port + '0'; + cmd += buf; + cmd += '='; + buf = value + '0'; + cmd += buf; + + sendCommand(cmd.c_str()); + return recvRetCommandFinished(); +} + +uint32_t NexGpio::digital_read(uint32_t port) +{ + uint32_t number; + char buf; + + String cmd = String("get "); + cmd += "pio"; + buf = port + '0'; + cmd += buf; + + sendCommand(cmd.c_str()); + recvRetNumber(&number); + return number; +} + +bool NexGpio::analog_write(uint32_t port,uint32_t value) +{ + char buf[10] = {0}; + char c; + String cmd; + + utoa(value, buf, 10); + cmd += "pwm"; + c = port + '0'; + cmd += c; + cmd += '='; + cmd += buf; + + Serial.print(cmd); + sendCommand(cmd.c_str()); + return recvRetCommandFinished(); +} + +bool NexGpio::set_pwmfreq(uint32_t value) +{ + char buf[10] = {0}; + String cmd; + + utoa(value, buf, 10); + cmd += "pwmf"; + cmd += '='; + cmd += buf; + + sendCommand(cmd.c_str()); + return recvRetCommandFinished(); +} + +uint32_t NexGpio::get_pwmfreq(uint32_t *number) +{ + String cmd = String("get pwmf"); + sendCommand(cmd.c_str()); + return recvRetNumber(number); +} \ No newline at end of file diff --git a/NexGpio.h b/NexGpio.h new file mode 100755 index 00000000..d67b2c89 --- /dev/null +++ b/NexGpio.h @@ -0,0 +1,102 @@ +/** + * @file NexGpio.h + * + * The definition of class NexGpio. + * + * @author Wu Pengfei (email:) + * @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 _NEXGPIO_H +#define _NEXGPIO_H + +#include "NexTouch.h" +#include "NexHardware.h" +/** + * @addtogroup Component + * @{ + */ + +/** + * NexGpio component. + */ + +class NexGpio +{ +public: + /** + * Set gpio mode + * + * @param port - the gpio port number + * @param mode - set gpio port mode(0--Pull on the input + * 1--the control input binding + * 2--Push-pull output + * 3--pwm output + * 4--open mode leakage) + * @param control_id - nextion controls id ,when the modeel is 1 to be valid + * @return true if success, false for failure + */ + + bool pin_mode(uint32_t port,uint32_t mode,uint32_t control_id); + + /** + * write a HIGH or a LOW value to a digital pin + * + * @param port - the gpio port number + * @param value - HIGH or LOW + * @return true if success, false for failure + */ + + bool digital_write(uint32_t port,uint32_t value); + + /** + * read a HIGH or a LOW value to a digital pin + * + * @param port - the gpio port number + * @return the value from a specified digital pin, either high or low + */ + + uint32_t digital_read(uint32_t port); + + /** + * writes an analog value (PWM wave) to a pin + * + * @param port - the gpio port number + * @param value - the duty cycle: between 0 (always off) and 100 (always on). + * @return true if success, false for failure + */ + + bool analog_write(uint32_t port,uint32_t value); + + /** + * writes pwm output frequency + * + * @param value - the frequency: between 1 and 65535 + * @return true if success, false for failure + */ + + bool set_pwmfreq(uint32_t value); + + /** + * read pwm output frequency + * + * @param number - the frequency + * @return true if success, false for failure + */ + + uint32_t get_pwmfreq(uint32_t *number); + +}; + +/** + * @} + */ + +#endif /* #ifndef __NEXGPIO_H__ */ \ No newline at end of file diff --git a/NexRtc.cpp b/NexRtc.cpp new file mode 100755 index 00000000..4350acf1 --- /dev/null +++ b/NexRtc.cpp @@ -0,0 +1,327 @@ +/** + * @file NexRtc.cpp + * + * The implementation of class NexRtc. + * + * @author Wu Pengfei (email:) + * @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 "NexRtc.h" + +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) + { + year[0]=time[0];year[1]=time[1];year[2]=time[2];year[3]=time[3];year[4]='\0'; + mon[0]=time[5];mon[1]=time[6];mon[2]='\0'; + day[0]=time[8];day[1]=time[9];day[2]='\0'; + hour[0]=time[11];hour[1]=time[12];hour[2]='\0'; + min[0]=time[14];min[1]=time[15];min[2]='\0'; + sec[0]=time[17];sec[1]=time[18];sec[2]='\0'; + + cmd += "0="; + cmd += year; + sendCommand(cmd.c_str()); + recvRetCommandFinished(); + + cmd = ""; + cmd += "rtc1="; + cmd += mon; + sendCommand(cmd.c_str()); + recvRetCommandFinished(); + + cmd = ""; + cmd += "rtc2="; + cmd += day; + sendCommand(cmd.c_str()); + recvRetCommandFinished(); + + cmd = ""; + cmd += "rtc3="; + cmd += hour; + sendCommand(cmd.c_str()); + recvRetCommandFinished(); + + cmd = ""; + cmd += "rtc4="; + cmd += min; + sendCommand(cmd.c_str()); + recvRetCommandFinished(); + + cmd = ""; + cmd += "rtc5="; + cmd += sec; + sendCommand(cmd.c_str()); + recvRetCommandFinished(); + + } + else + { + return false; + } +} + +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); + utoa(time[2],day, 10); + utoa(time[3],hour,10); + utoa(time[4],min, 10); + utoa(time[5],sec, 10); + + + cmd += "0="; + cmd += year; + sendCommand(cmd.c_str()); + recvRetCommandFinished(); + + cmd = ""; + cmd += "rtc1="; + cmd += mon; + sendCommand(cmd.c_str()); + recvRetCommandFinished(); + + cmd = ""; + cmd += "rtc2="; + cmd += day; + sendCommand(cmd.c_str()); + recvRetCommandFinished(); + + cmd = ""; + cmd += "rtc3="; + cmd += hour; + sendCommand(cmd.c_str()); + recvRetCommandFinished(); + + cmd = ""; + cmd += "rtc4="; + cmd += min; + sendCommand(cmd.c_str()); + recvRetCommandFinished(); + + cmd = ""; + cmd += "rtc5="; + cmd += sec; + sendCommand(cmd.c_str()); + recvRetCommandFinished(); + +} + +bool NexRtc::write_rtc_time(char *time_type,uint32_t number) +{ + String cmd = String("rtc"); + char buf[10] = {0}; + + utoa(number, buf, 10); + if(strstr(time_type,"year")) + { + cmd += "0="; + cmd += buf; + } + if(strstr(time_type,"mon")) + { + cmd += "1="; + cmd += buf; + } + if(strstr(time_type,"day")) + { + cmd += "2="; + cmd += buf; + } + if(strstr(time_type,"hour")) + { + cmd += "3="; + cmd += buf; + } + if(strstr(time_type,"min")) + { + cmd += "4="; + cmd += buf; + } + if(strstr(time_type,"sec")) + { + cmd += "5="; + cmd += buf; + } + + sendCommand(cmd.c_str()); + return recvRetCommandFinished(); +} + +uint32_t 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; + String cmd; + + cmd = "get rtc0"; + sendCommand(cmd.c_str()); + recvRetNumber(&year); + + cmd = ""; + cmd = "get rtc1"; + sendCommand(cmd.c_str()); + recvRetNumber(&mon); + + cmd = ""; + cmd = "get rtc2"; + sendCommand(cmd.c_str()); + recvRetNumber(&day); + + cmd = ""; + cmd = "get rtc3"; + sendCommand(cmd.c_str()); + recvRetNumber(&hour); + + cmd = ""; + cmd = "get rtc4"; + sendCommand(cmd.c_str()); + recvRetNumber(&min); + + cmd = ""; + cmd = "get rtc5"; + sendCommand(cmd.c_str()); + recvRetNumber(&sec); + + cmd = ""; + cmd = "get rtc6"; + sendCommand(cmd.c_str()); + recvRetNumber(&week); + + time_buf[0] = year/1000 + '0'; + time_buf[1] = (year/100)%10 + '0'; + time_buf[2] = (year/10)%10 + '0'; + time_buf[3] = year%10 + '0'; + time_buf[5] = mon/10 + '0'; + time_buf[6] = mon%10 + '0'; + time_buf[8] = day/10 + '0'; + time_buf[9] = day%10 + '0'; + time_buf[11] = hour/10 + '0'; + time_buf[12] = hour%10 + '0'; + time_buf[14] = min/10 + '0'; + time_buf[15] = min%10 + '0'; + time_buf[17] = sec/10 + '0'; + time_buf[18] = sec%10 + '0'; + time_buf[20] = week + '0'; + time_buf[21] = '\0'; + + + if(len >= 22) + { + for(int i=0;i<22;i++) + { + time[i] = time_buf[i]; + } + } + else{ + for(int i=0;i) + * @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 _NEXRTC_H +#define _NEXRTC_H + +#include "NexTouch.h" +#include "NexHardware.h" +/** + * @addtogroup Component + * @{ + */ + +/** + * NexRtc component. + */ + +class NexRtc +{ + public: + + bool write_rtc_time(char *time); + + /** + * write rtc times + * + * @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); + + /** + * write rtc times + * + * @param time - Time to write to the array + * @return true if success, false for failure + */ + + bool write_rtc_time(uint32_t *time); + + + /** + * read rtc time + * + * @param time - Access data array + * @param len - len of array + * @return true if success, false for failure + */ + + uint32_t read_rtc_time(char *time,uint32_t len); + + /** + * read rtc times + * + * @param time_type - To type in time + * @param number - the time value + * @return true if success, false for failure + */ + + uint32_t read_rtc_time(char *time_type,uint32_t *number); + + /** + * read rtc time + * + * @param time - Access data array + * @param len - len of array + * @return true if success, false for failure + */ + + uint32_t read_rtc_time(uint32_t *time,uint32_t len); + +}; + +/** + * @} + */ + +#endif /* #ifndef __NEXRTC_H__ */ \ No newline at end of file diff --git a/NexText.cpp b/NexText.cpp index 0f1e4d46..25a2c868 100755 --- a/NexText.cpp +++ b/NexText.cpp @@ -232,3 +232,5 @@ bool NexText::Set_background_image_pic(uint32_t number) } + + diff --git a/NexText.h b/NexText.h index d2f47876..592ce076 100755 --- a/NexText.h +++ b/NexText.h @@ -162,7 +162,8 @@ 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/Nextion.h b/Nextion.h index 3848db14..9d6aac5a 100755 --- a/Nextion.h +++ b/Nextion.h @@ -39,6 +39,7 @@ #include "NexCheckbox.h" #include "NexRadio.h" #include "NexScrolltext.h" - +#include "NexGpio.h" +#include "NexRtc.h" #endif /* #ifndef __NEXTION_H__ */ diff --git a/doc/Documentation/_comp_button_8ino-example.html b/doc/Documentation/_comp_button_8ino-example.html index 9be747d4..7ebf7324 100755 --- a/doc/Documentation/_comp_button_8ino-example.html +++ b/doc/Documentation/_comp_button_8ino-example.html @@ -152,7 +152,7 @@