bool nexInit(void) { bool ret1 = false; bool ret2 = false; sendCommand(""); sendCommand("bkcmd=1"); ret1 = recvRetCommandFinished(); sendCommand("page 0"); ret2 = recvRetCommandFinished(); return ret1 && ret2; }
bool NexDisplay::setNumeric(const char* varName, uint32_t value) { char cmd[32]; snprintf(cmd, sizeof(cmd), NexSETVAL, varName, value); sendCommand(cmd); return recvRetCommandFinished(); }
/** * Set current backlight brightness value. * * @param dimValue - current backlight brightness value. * * @retval true - success. * @retval false - failed. */ bool setCurrentBrightness(uint8_t dimValue) { bool ret = false; char buf[10] = {0}; String cmd; utoa(dimValue, buf, 10); cmd += "dim="; cmd += buf; sendCommand(cmd.c_str()); delay(10); if(recvRetCommandFinished()) { dbSerialPrint("setCurrentBrightness[ "); dbSerialPrint(dimValue); dbSerialPrintln("]ok "); ret = true; } else { dbSerialPrintln("setCurrentBrightness err "); } return ret; }
/** * Set baudrate. * * @param baudrate - baudrate, it supports 2400,4800,9600,19200,38400,57600,115200. * * @retval true - success. * @retval false - failed. */ bool NexDisplay::setBaudrate(uint32_t baudrate, bool setDefault) { bool ret = false; char cmd[16]; if (!baudrate) // no or zero baudrate -> use local __baud baudrate = __baud; else __baud = baudrate; if (setDefault) snprintf(cmd, sizeof(cmd), NexSETBAUDS, baudrate); else snprintf(cmd, sizeof(cmd), NexSETBAUD, baudrate); sendCommand(cmd); // send in new baudrate using the current baudrate delay(10); __serial->flush(); // dump all returned data, since not usable with new baudrate //__serial->end(); // close port (or pretend to ;-) delay(100); __serial->begin(baudrate); // activate new baudrate on MCU side too sendCommand(""); // trigger test transmission if (recvRetCommandFinished()) ret = true; return ret; }
bool NexDisplay::setString(const char* varName, const char* text) { char cmd[strlen(text) + 32]; memset(cmd, 0, sizeof(cmd)); snprintf(cmd, sizeof(cmd), NexSETSTRING, varName, text); sendCommand(cmd); return recvRetCommandFinished(); }
bool NexDisplay::init(uint32_t baudrate) { bool ret1 = false; bool ret2 = false; if (!baudrate) // no or zero baudrate -> use local __baud baudrate = __baud; else __baud = baudrate; __serial->begin(baudrate); sendCommand(NexCMDTERM); // flush buffer and reset command queue sendCommand(NexEXECRESPONSE, __bkCmd=1); // only return success results ret1 = recvRetCommandFinished(); sendCommand(NexPAGEID, 0); // show home page ret2 = recvRetCommandFinished(); return ret1 && ret2; }
bool NexButton::setText(const char *buffer) { String cmd; cmd += getObjName(); cmd += ".txt=\""; cmd += buffer; 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(); }
bool NexButton::setPIC(uint32_t number) { char buf[10] = {0}; String cmd; utoa(number, buf, 10); cmd += getObjName(); cmd += ".pic="; cmd += buf; sendCommand(cmd.c_str()); return recvRetCommandFinished(); }
bool NexText::setColor(uint32_t value) { char buf[10] = {0}; String cmd; utoa(value, buf, 10); cmd += getObjName(); cmd += ".pco="; cmd += buf; sendCommand(cmd.c_str()); return recvRetCommandFinished(); }
bool NexText::Set_background_image_pic(uint32_t number) { char buf[10] = {0}; String cmd; utoa(number, buf, 10); cmd += getObjName(); cmd += ".pic="; cmd += buf; sendCommand(cmd.c_str()); return recvRetCommandFinished(); }
bool NexNumber::setValue(uint32_t number) { char buf[10] = {0}; String cmd; utoa(number, buf, 10); cmd += getObjName(); cmd += ".val="; cmd += buf; sendCommand(cmd.c_str()); return recvRetCommandFinished(); }
bool NexPicture::setPic(uint32_t number) { char buf[10] = {0}; String cmd; sprintf(buf,"%d",number); //utoa(number, buf, 10); cmd += getObjName(); cmd += ".pic="; 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(); }
bool NexPage::show(void) { uint8_t buffer[4] = {0}; const char *name = getObjName(); if (!name) { return false; } String cmd = String("page "); cmd += name; sendCommand(cmd.c_str()); return recvRetCommandFinished(); }
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 NexText::Set_font_color_pco(uint32_t number) { char buf[10] = {0}; String cmd; utoa(number, buf, 10); cmd += getObjName(); cmd += ".pco="; cmd += buf; sendCommand(cmd.c_str()); cmd = ""; cmd += "ref "; cmd += getObjName(); sendCommand(cmd.c_str()); return recvRetCommandFinished(); }
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(); }
/** * Set backlight brightness value. * * @param dimValue - current backlight brightness value. * @param setDefault - store this value as default * * @retval true - success. * @retval false - failed. */ bool NexDisplay::setBrightness(uint8_t dimValue, bool setDefault) { bool ret = false; char cmd[16]; if (setDefault) snprintf(cmd, sizeof(cmd), NexSETDIMS, dimValue); else snprintf(cmd, sizeof(cmd), NexSETDIM, dimValue); sendCommand(cmd); delay(10); if (recvRetCommandFinished()) ret = true; return ret; }
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 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(); }
/** * Set default baudrate. * * @param defaultBaudrate - default baudrate,it supports 2400,4800,9600,19200,38400,57600,115200. * * @retval true - success. * @retval false - failed. */ bool setDefaultBaudrate(uint32_t defaultBaudrate) { bool ret = false; char buf[10] = {0}; String cmd; utoa(defaultBaudrate, buf, 10); cmd += "bauds="; cmd += buf; sendCommand(cmd.c_str()); delay(10); if(recvRetCommandFinished()) { dbSerialPrintln("setDefaultBaudrate ok "); ret = true; } else { dbSerialPrintln("setDefaultBaudrate err "); } return ret; }
bool NexDisplay::runCommand(const char* cmd) { sendCommand(cmd); return recvRetCommandFinished(); }