J L
/
Neptune_170620
Neptune_170620
NextionLCD.cpp@0:20b4b057fa7f, 2020-06-17 (annotated)
- Committer:
- Picmon
- Date:
- Wed Jun 17 10:11:19 2020 +0000
- Revision:
- 0:20b4b057fa7f
Neptune;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Picmon | 0:20b4b057fa7f | 1 | #include <cstdlib> |
Picmon | 0:20b4b057fa7f | 2 | #include <string> |
Picmon | 0:20b4b057fa7f | 3 | #include "main.h" |
Picmon | 0:20b4b057fa7f | 4 | #include "Functions.h" |
Picmon | 0:20b4b057fa7f | 5 | #include "Definitions.h" |
Picmon | 0:20b4b057fa7f | 6 | #include "Boolean.h" |
Picmon | 0:20b4b057fa7f | 7 | #include "NextionLCD.h" |
Picmon | 0:20b4b057fa7f | 8 | #include "mbed.h" |
Picmon | 0:20b4b057fa7f | 9 | #include "Languages.h" |
Picmon | 0:20b4b057fa7f | 10 | #include "NVM.h" |
Picmon | 0:20b4b057fa7f | 11 | #include "Controls.h" |
Picmon | 0:20b4b057fa7f | 12 | #include "FastPWM.h" |
Picmon | 0:20b4b057fa7f | 13 | #include <cstring> |
Picmon | 0:20b4b057fa7f | 14 | |
Picmon | 0:20b4b057fa7f | 15 | /////////////////////////////////////////////////////////////////////////////// |
Picmon | 0:20b4b057fa7f | 16 | // MBED |
Picmon | 0:20b4b057fa7f | 17 | /////////////////////////////////////////////////////////////////////////////// |
Picmon | 0:20b4b057fa7f | 18 | |
Picmon | 0:20b4b057fa7f | 19 | /////////////////////////////////////////////////////////////////////////////// |
Picmon | 0:20b4b057fa7f | 20 | // VARIABLES |
Picmon | 0:20b4b057fa7f | 21 | /////////////////////////////////////////////////////////////////////////////// |
Picmon | 0:20b4b057fa7f | 22 | bool scrnUpdate = true;//Update the Nexion screen |
Picmon | 0:20b4b057fa7f | 23 | |
Picmon | 0:20b4b057fa7f | 24 | volatile bool keyScanFlag; |
Picmon | 0:20b4b057fa7f | 25 | |
Picmon | 0:20b4b057fa7f | 26 | uint8_t nexDataLSB; |
Picmon | 0:20b4b057fa7f | 27 | uint8_t nexDataMSB; |
Picmon | 0:20b4b057fa7f | 28 | volatile uint8_t page = 0; |
Picmon | 0:20b4b057fa7f | 29 | volatile uint8_t id= 0; |
Picmon | 0:20b4b057fa7f | 30 | volatile bool pushPop = 0; |
Picmon | 0:20b4b057fa7f | 31 | |
Picmon | 0:20b4b057fa7f | 32 | /////////////////////////////////////////////////////////////////////////////// |
Picmon | 0:20b4b057fa7f | 33 | // CONSTANTS |
Picmon | 0:20b4b057fa7f | 34 | /////////////////////////////////////////////////////////////////////////////// |
Picmon | 0:20b4b057fa7f | 35 | bool push = 1; |
Picmon | 0:20b4b057fa7f | 36 | bool pop = 0; |
Picmon | 0:20b4b057fa7f | 37 | |
Picmon | 0:20b4b057fa7f | 38 | /////////////////////////////////////////////////////////////////////////////// |
Picmon | 0:20b4b057fa7f | 39 | // DEBUG |
Picmon | 0:20b4b057fa7f | 40 | /////////////////////////////////////////////////////////////////////////////// |
Picmon | 0:20b4b057fa7f | 41 | volatile char dbgNexMsg[20]; |
Picmon | 0:20b4b057fa7f | 42 | volatile int dbgMRxIdx; |
Picmon | 0:20b4b057fa7f | 43 | volatile bool debugFlag; |
Picmon | 0:20b4b057fa7f | 44 | volatile bool tx_true; |
Picmon | 0:20b4b057fa7f | 45 | |
Picmon | 0:20b4b057fa7f | 46 | NextionLCD::NextionLCD(PinName Tx, PinName Rx) : lcd(Tx, Rx){ |
Picmon | 0:20b4b057fa7f | 47 | lcd.baud(9600); |
Picmon | 0:20b4b057fa7f | 48 | mTouch=false; |
Picmon | 0:20b4b057fa7f | 49 | mRxIdx=0; |
Picmon | 0:20b4b057fa7f | 50 | lcd.printf("rest%c%c%c", 0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 51 | lcd.printf("rest%c%c%c", 0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 52 | |
Picmon | 0:20b4b057fa7f | 53 | #ifdef DEBUG_LCD |
Picmon | 0:20b4b057fa7f | 54 | pc.printf("\r\n\r\nNextionLCD Rst\r\n"); |
Picmon | 0:20b4b057fa7f | 55 | #endif |
Picmon | 0:20b4b057fa7f | 56 | |
Picmon | 0:20b4b057fa7f | 57 | wait(1.0); |
Picmon | 0:20b4b057fa7f | 58 | lcd.attach(callback(this,&NextionLCD::RxInterrupt),Serial::RxIrq); |
Picmon | 0:20b4b057fa7f | 59 | } |
Picmon | 0:20b4b057fa7f | 60 | |
Picmon | 0:20b4b057fa7f | 61 | void NextionLCD::nexRst(void){ |
Picmon | 0:20b4b057fa7f | 62 | lcd.printf("rest%c%c%c", 0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 63 | lcd.printf("rest%c%c%c", 0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 64 | |
Picmon | 0:20b4b057fa7f | 65 | #ifdef DEBUG_LCD |
Picmon | 0:20b4b057fa7f | 66 | pc.printf("\r\n\r\nnexRst\r\n"); |
Picmon | 0:20b4b057fa7f | 67 | #endif |
Picmon | 0:20b4b057fa7f | 68 | } |
Picmon | 0:20b4b057fa7f | 69 | |
Picmon | 0:20b4b057fa7f | 70 | void NextionLCD::nexSetFont(string id, uint8_t val){ |
Picmon | 0:20b4b057fa7f | 71 | static string newId = 0; |
Picmon | 0:20b4b057fa7f | 72 | static uint8_t newVal = 0; |
Picmon | 0:20b4b057fa7f | 73 | |
Picmon | 0:20b4b057fa7f | 74 | if((id != newId)||(val != newVal)){ |
Picmon | 0:20b4b057fa7f | 75 | lcd.printf("%s.font=%d%c%c%c",id.c_str(),val, 0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 76 | newId = id; |
Picmon | 0:20b4b057fa7f | 77 | newVal = val; |
Picmon | 0:20b4b057fa7f | 78 | |
Picmon | 0:20b4b057fa7f | 79 | #ifdef DEBUG_LCD |
Picmon | 0:20b4b057fa7f | 80 | pc.printf("\r\n\r\nnexSetFont %s %d\r\n",id.c_str(),val); |
Picmon | 0:20b4b057fa7f | 81 | #endif |
Picmon | 0:20b4b057fa7f | 82 | } |
Picmon | 0:20b4b057fa7f | 83 | } |
Picmon | 0:20b4b057fa7f | 84 | |
Picmon | 0:20b4b057fa7f | 85 | void NextionLCD::nexSetBckLite(uint8_t val){//ok |
Picmon | 0:20b4b057fa7f | 86 | /* |
Picmon | 0:20b4b057fa7f | 87 | dim : use dim to instanteniously change backlight intensity, this is not saved in NVM and forgotten once power cycled |
Picmon | 0:20b4b057fa7f | 88 | dims: use dims to instanteniously change backlight intensity, this is saved in NVM and remembered after power cycle. |
Picmon | 0:20b4b057fa7f | 89 | */ |
Picmon | 0:20b4b057fa7f | 90 | static uint8_t newVal = 0; |
Picmon | 0:20b4b057fa7f | 91 | |
Picmon | 0:20b4b057fa7f | 92 | if(val != newVal){ |
Picmon | 0:20b4b057fa7f | 93 | lcd.printf("dims=%d%c%c%c",val, 0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 94 | newVal = val; |
Picmon | 0:20b4b057fa7f | 95 | |
Picmon | 0:20b4b057fa7f | 96 | #ifdef DEBUG_LCD |
Picmon | 0:20b4b057fa7f | 97 | pc.printf("\r\n\r\nnexSetBcklite = %d\r\n",val); |
Picmon | 0:20b4b057fa7f | 98 | #endif |
Picmon | 0:20b4b057fa7f | 99 | } |
Picmon | 0:20b4b057fa7f | 100 | } |
Picmon | 0:20b4b057fa7f | 101 | |
Picmon | 0:20b4b057fa7f | 102 | void NextionLCD::nexSetBaud(uint32_t baud){//ok |
Picmon | 0:20b4b057fa7f | 103 | static uint32_t newBaud = 0; |
Picmon | 0:20b4b057fa7f | 104 | |
Picmon | 0:20b4b057fa7f | 105 | if(baud != newBaud){ |
Picmon | 0:20b4b057fa7f | 106 | lcd.printf("baud=%d%c%c%c",baud, 0xff, 0xff, 0xff);//Set Nextion display to high baud |
Picmon | 0:20b4b057fa7f | 107 | wait(0.5); |
Picmon | 0:20b4b057fa7f | 108 | lcd.baud(baud);//Set Mbed target to high baud |
Picmon | 0:20b4b057fa7f | 109 | wait(0.5); |
Picmon | 0:20b4b057fa7f | 110 | newBaud = baud; |
Picmon | 0:20b4b057fa7f | 111 | |
Picmon | 0:20b4b057fa7f | 112 | #ifdef DEBUG_LCD |
Picmon | 0:20b4b057fa7f | 113 | pc.printf("\r\n\r\nnexSetBaud = %u\r\n",baud); |
Picmon | 0:20b4b057fa7f | 114 | #endif |
Picmon | 0:20b4b057fa7f | 115 | } |
Picmon | 0:20b4b057fa7f | 116 | } |
Picmon | 0:20b4b057fa7f | 117 | |
Picmon | 0:20b4b057fa7f | 118 | void NextionLCD::nexChgPage(uint8_t nexPage){//ok |
Picmon | 0:20b4b057fa7f | 119 | lcd.printf("page %d%c%c%c",nexPage,0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 120 | |
Picmon | 0:20b4b057fa7f | 121 | #ifdef DEBUG_LCD |
Picmon | 0:20b4b057fa7f | 122 | pc.printf("\r\n\r\nnexChgPage = %d\r\n",nexPage); |
Picmon | 0:20b4b057fa7f | 123 | #endif |
Picmon | 0:20b4b057fa7f | 124 | } |
Picmon | 0:20b4b057fa7f | 125 | |
Picmon | 0:20b4b057fa7f | 126 | void NextionLCD::nexSetDSBtn(string id, uint8_t on_off){ |
Picmon | 0:20b4b057fa7f | 127 | |
Picmon | 0:20b4b057fa7f | 128 | if(on_off == ON) |
Picmon | 0:20b4b057fa7f | 129 | lcd.printf("%s.val=1%c%c%c",id.c_str(),0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 130 | else |
Picmon | 0:20b4b057fa7f | 131 | if(on_off == OFF) |
Picmon | 0:20b4b057fa7f | 132 | lcd.printf("%s.val=0%c%c%c",id.c_str(),0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 133 | |
Picmon | 0:20b4b057fa7f | 134 | #ifdef DEBUG_LCD |
Picmon | 0:20b4b057fa7f | 135 | pc.printf("\r\n\r\nnexSetDSBtn %s %d\r\n",id.c_str(),on_off); |
Picmon | 0:20b4b057fa7f | 136 | #endif |
Picmon | 0:20b4b057fa7f | 137 | } |
Picmon | 0:20b4b057fa7f | 138 | |
Picmon | 0:20b4b057fa7f | 139 | void NextionLCD::nexRotArrow(bool on_off){//ok |
Picmon | 0:20b4b057fa7f | 140 | static bool newOnOff = 0; |
Picmon | 0:20b4b057fa7f | 141 | |
Picmon | 0:20b4b057fa7f | 142 | if(on_off != newOnOff){ |
Picmon | 0:20b4b057fa7f | 143 | |
Picmon | 0:20b4b057fa7f | 144 | if(on_off == ON){ |
Picmon | 0:20b4b057fa7f | 145 | lcd.printf("arrow.picc=19%c%c%c", 0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 146 | lcd.printf("arrowTimer.en=1%c%c%c", 0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 147 | } |
Picmon | 0:20b4b057fa7f | 148 | else |
Picmon | 0:20b4b057fa7f | 149 | if(on_off == OFF){ |
Picmon | 0:20b4b057fa7f | 150 | lcd.printf("arrowTimer.en=0%c%c%c", 0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 151 | lcd.printf("arrow.picc=18%c%c%c", 0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 152 | } |
Picmon | 0:20b4b057fa7f | 153 | |
Picmon | 0:20b4b057fa7f | 154 | newOnOff = on_off; |
Picmon | 0:20b4b057fa7f | 155 | |
Picmon | 0:20b4b057fa7f | 156 | |
Picmon | 0:20b4b057fa7f | 157 | #ifdef DEBUG_LCD |
Picmon | 0:20b4b057fa7f | 158 | pc.printf("\r\n\r\nnexRotArrow = %d\r\n", on_off); |
Picmon | 0:20b4b057fa7f | 159 | #endif |
Picmon | 0:20b4b057fa7f | 160 | } |
Picmon | 0:20b4b057fa7f | 161 | } |
Picmon | 0:20b4b057fa7f | 162 | |
Picmon | 0:20b4b057fa7f | 163 | void NextionLCD::nexDispSymbol(string id, bool on_off){ |
Picmon | 0:20b4b057fa7f | 164 | static string newId = 0; |
Picmon | 0:20b4b057fa7f | 165 | static bool newOnOff = 0; |
Picmon | 0:20b4b057fa7f | 166 | |
Picmon | 0:20b4b057fa7f | 167 | if((id != newId)||(on_off!= newOnOff)){ |
Picmon | 0:20b4b057fa7f | 168 | |
Picmon | 0:20b4b057fa7f | 169 | if(on_off == ON) |
Picmon | 0:20b4b057fa7f | 170 | nexSetCrop(id, 1);//display symbol |
Picmon | 0:20b4b057fa7f | 171 | else |
Picmon | 0:20b4b057fa7f | 172 | if(on_off == OFF) |
Picmon | 0:20b4b057fa7f | 173 | nexSetCrop(id, 16);//white page |
Picmon | 0:20b4b057fa7f | 174 | |
Picmon | 0:20b4b057fa7f | 175 | newId = id; |
Picmon | 0:20b4b057fa7f | 176 | newOnOff = on_off; |
Picmon | 0:20b4b057fa7f | 177 | |
Picmon | 0:20b4b057fa7f | 178 | #ifdef DEBUG_LCD |
Picmon | 0:20b4b057fa7f | 179 | pc.printf("\r\n\r\nnexDispSymbol %s %d\r\n", id.c_str(),on_off ); |
Picmon | 0:20b4b057fa7f | 180 | #endif |
Picmon | 0:20b4b057fa7f | 181 | } |
Picmon | 0:20b4b057fa7f | 182 | } |
Picmon | 0:20b4b057fa7f | 183 | |
Picmon | 0:20b4b057fa7f | 184 | void NextionLCD::nexSetCrop(string id, uint16_t picc){//ok |
Picmon | 0:20b4b057fa7f | 185 | /* |
Picmon | 0:20b4b057fa7f | 186 | q0 = arrow crop image |
Picmon | 0:20b4b057fa7f | 187 | picc = 1//Turn rotation arrow off |
Picmon | 0:20b4b057fa7f | 188 | picc = 2// pos1 displayed |
Picmon | 0:20b4b057fa7f | 189 | picc = 3// pos2 displayed |
Picmon | 0:20b4b057fa7f | 190 | picc = 4// pos3 displayed |
Picmon | 0:20b4b057fa7f | 191 | picc = 5// pos4 displayed |
Picmon | 0:20b4b057fa7f | 192 | |
Picmon | 0:20b4b057fa7f | 193 | */ |
Picmon | 0:20b4b057fa7f | 194 | static string newId = 0; |
Picmon | 0:20b4b057fa7f | 195 | static uint16_t newPicc = 0; |
Picmon | 0:20b4b057fa7f | 196 | |
Picmon | 0:20b4b057fa7f | 197 | if((id != newId)||(picc!= newPicc)){ |
Picmon | 0:20b4b057fa7f | 198 | lcd.printf("%s.picc=%d%c%c%c",id.c_str(),picc,0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 199 | newId = id; |
Picmon | 0:20b4b057fa7f | 200 | newPicc = picc; |
Picmon | 0:20b4b057fa7f | 201 | |
Picmon | 0:20b4b057fa7f | 202 | #ifdef DEBUG_LCD |
Picmon | 0:20b4b057fa7f | 203 | pc.printf("\r\n\r\nnexSetCrop %s %d\r\n", id.c_str(),picc); |
Picmon | 0:20b4b057fa7f | 204 | #endif |
Picmon | 0:20b4b057fa7f | 205 | } |
Picmon | 0:20b4b057fa7f | 206 | } |
Picmon | 0:20b4b057fa7f | 207 | |
Picmon | 0:20b4b057fa7f | 208 | void NextionLCD::nexSetTimer(string id,uint16_t tim, uint16_t on_off){//ok |
Picmon | 0:20b4b057fa7f | 209 | lcd.printf("%s.tim=%d%c%c%c",id.c_str(),tim,0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 210 | lcd.printf("%s.en=%d%c%c%c",id.c_str(),on_off,0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 211 | |
Picmon | 0:20b4b057fa7f | 212 | #ifdef DEBUG_LCD |
Picmon | 0:20b4b057fa7f | 213 | pc.printf("\r\n\r\nnexSetTimer %s %d %d \r\n", id.c_str(),tim,on_off); |
Picmon | 0:20b4b057fa7f | 214 | #endif |
Picmon | 0:20b4b057fa7f | 215 | } |
Picmon | 0:20b4b057fa7f | 216 | |
Picmon | 0:20b4b057fa7f | 217 | void NextionLCD::nexSetSlider(string id, uint16_t sliderVal){//ok |
Picmon | 0:20b4b057fa7f | 218 | static string newId = 0; |
Picmon | 0:20b4b057fa7f | 219 | static uint16_t newSliderVal = 0; |
Picmon | 0:20b4b057fa7f | 220 | |
Picmon | 0:20b4b057fa7f | 221 | if((id != newId)||(sliderVal!= newSliderVal)){ |
Picmon | 0:20b4b057fa7f | 222 | lcd.printf("%s.val=%d%c%c%c",id.c_str(),sliderVal,0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 223 | newId = id; |
Picmon | 0:20b4b057fa7f | 224 | newSliderVal = sliderVal; |
Picmon | 0:20b4b057fa7f | 225 | |
Picmon | 0:20b4b057fa7f | 226 | #ifdef DEBUG_LCD |
Picmon | 0:20b4b057fa7f | 227 | pc.printf("\r\n\r\nnexSetSlider %s %d\r\n", id.c_str(),sliderVal); |
Picmon | 0:20b4b057fa7f | 228 | #endif |
Picmon | 0:20b4b057fa7f | 229 | } |
Picmon | 0:20b4b057fa7f | 230 | } |
Picmon | 0:20b4b057fa7f | 231 | |
Picmon | 0:20b4b057fa7f | 232 | void NextionLCD::nexSetPrgBar(string id, uint16_t progBarVal){//ok |
Picmon | 0:20b4b057fa7f | 233 | static string newId = 0; |
Picmon | 0:20b4b057fa7f | 234 | static uint16_t newProgBarVal = 0; |
Picmon | 0:20b4b057fa7f | 235 | |
Picmon | 0:20b4b057fa7f | 236 | if((id != newId)||(progBarVal!= newProgBarVal)){ |
Picmon | 0:20b4b057fa7f | 237 | lcd.printf("%s.val=%d%c%c%c",id.c_str(),progBarVal,0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 238 | newId = id; |
Picmon | 0:20b4b057fa7f | 239 | newProgBarVal = progBarVal; |
Picmon | 0:20b4b057fa7f | 240 | |
Picmon | 0:20b4b057fa7f | 241 | #ifdef DEBUG_LCD |
Picmon | 0:20b4b057fa7f | 242 | pc.printf("\r\n\r\nnexSetPrgBar %s %d\r\n", id.c_str(),progBarVal); |
Picmon | 0:20b4b057fa7f | 243 | #endif |
Picmon | 0:20b4b057fa7f | 244 | } |
Picmon | 0:20b4b057fa7f | 245 | } |
Picmon | 0:20b4b057fa7f | 246 | |
Picmon | 0:20b4b057fa7f | 247 | void NextionLCD::nexSendTxt(string id,string txt){//ok |
Picmon | 0:20b4b057fa7f | 248 | static string newId = 0; |
Picmon | 0:20b4b057fa7f | 249 | static string newTxt = 0; |
Picmon | 0:20b4b057fa7f | 250 | |
Picmon | 0:20b4b057fa7f | 251 | if((id != newId)||(txt != newTxt)){ |
Picmon | 0:20b4b057fa7f | 252 | lcd.printf("%s.txt=\"%s\"%c%c%c",id.c_str(),txt.c_str(),0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 253 | newId = id; |
Picmon | 0:20b4b057fa7f | 254 | newTxt = txt; |
Picmon | 0:20b4b057fa7f | 255 | |
Picmon | 0:20b4b057fa7f | 256 | #ifdef DEBUG_LCD |
Picmon | 0:20b4b057fa7f | 257 | pc.printf("\r\n\r\nnexSendTxt %s %s\r\n",id.c_str(),txt.c_str()); |
Picmon | 0:20b4b057fa7f | 258 | #endif |
Picmon | 0:20b4b057fa7f | 259 | } |
Picmon | 0:20b4b057fa7f | 260 | } |
Picmon | 0:20b4b057fa7f | 261 | |
Picmon | 0:20b4b057fa7f | 262 | void NextionLCD::nexSendFloat(string id, float val ,uint8_t precision){ |
Picmon | 0:20b4b057fa7f | 263 | /* |
Picmon | 0:20b4b057fa7f | 264 | In C, the printf() statement allows the precision lengths to be supplied in the parameter list. |
Picmon | 0:20b4b057fa7f | 265 | |
Picmon | 0:20b4b057fa7f | 266 | printf("%*.*f", 7, 3, floatValue); |
Picmon | 0:20b4b057fa7f | 267 | |
Picmon | 0:20b4b057fa7f | 268 | where the asterisks are replaced with first and second values, respectively. |
Picmon | 0:20b4b057fa7f | 269 | */ |
Picmon | 0:20b4b057fa7f | 270 | static string newId = 0; |
Picmon | 0:20b4b057fa7f | 271 | static float newVal = 0; |
Picmon | 0:20b4b057fa7f | 272 | |
Picmon | 0:20b4b057fa7f | 273 | if((id != newId)||(val != newVal)){ |
Picmon | 0:20b4b057fa7f | 274 | lcd.printf("%s.txt=\"%.*f\"%c%c%c",id.c_str(), precision, val, 0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 275 | newId = id; |
Picmon | 0:20b4b057fa7f | 276 | newVal = val; |
Picmon | 0:20b4b057fa7f | 277 | |
Picmon | 0:20b4b057fa7f | 278 | #ifdef DEBUG_LCD |
Picmon | 0:20b4b057fa7f | 279 | pc.printf("\r\n\r\nnexSendFloat string=%s, pre=%d, val=%f\r\n",id.c_str(), precision, val); |
Picmon | 0:20b4b057fa7f | 280 | #endif |
Picmon | 0:20b4b057fa7f | 281 | } |
Picmon | 0:20b4b057fa7f | 282 | } |
Picmon | 0:20b4b057fa7f | 283 | |
Picmon | 0:20b4b057fa7f | 284 | void NextionLCD::nexSetFontCol(string id, uint16_t color){ |
Picmon | 0:20b4b057fa7f | 285 | static string newId = 0; |
Picmon | 0:20b4b057fa7f | 286 | static uint16_t newColor = 0; |
Picmon | 0:20b4b057fa7f | 287 | |
Picmon | 0:20b4b057fa7f | 288 | if((id != newId)||(color!= newColor)){ |
Picmon | 0:20b4b057fa7f | 289 | lcd.printf("%s.pco=%d%c%c%c",id.c_str(),color,0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 290 | newId = id; |
Picmon | 0:20b4b057fa7f | 291 | newColor = color; |
Picmon | 0:20b4b057fa7f | 292 | |
Picmon | 0:20b4b057fa7f | 293 | #ifdef DEBUG_LCD |
Picmon | 0:20b4b057fa7f | 294 | pc.printf("\r\n\r\nnexSetFontCol %s %d\r\n", id.c_str(),color); |
Picmon | 0:20b4b057fa7f | 295 | #endif |
Picmon | 0:20b4b057fa7f | 296 | } |
Picmon | 0:20b4b057fa7f | 297 | } |
Picmon | 0:20b4b057fa7f | 298 | |
Picmon | 0:20b4b057fa7f | 299 | void NextionLCD::nexSendVal(string id,uint16_t val){ |
Picmon | 0:20b4b057fa7f | 300 | static string newId = 0; |
Picmon | 0:20b4b057fa7f | 301 | static uint16_t newVal = 0; |
Picmon | 0:20b4b057fa7f | 302 | |
Picmon | 0:20b4b057fa7f | 303 | if((id != newId)||(val!= newVal)){ |
Picmon | 0:20b4b057fa7f | 304 | lcd.printf("%s.txt=\"%d\"%c%c%c",id.c_str(), val, 0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 305 | newId = id; |
Picmon | 0:20b4b057fa7f | 306 | newVal = val; |
Picmon | 0:20b4b057fa7f | 307 | |
Picmon | 0:20b4b057fa7f | 308 | #ifdef DEBUG_LCD |
Picmon | 0:20b4b057fa7f | 309 | pc.printf("\r\n\r\nnexSendVal %s %d\r\n", id.c_str(),val); |
Picmon | 0:20b4b057fa7f | 310 | #endif |
Picmon | 0:20b4b057fa7f | 311 | } |
Picmon | 0:20b4b057fa7f | 312 | } |
Picmon | 0:20b4b057fa7f | 313 | |
Picmon | 0:20b4b057fa7f | 314 | void NextionLCD::nexSendGetVal(string id){ |
Picmon | 0:20b4b057fa7f | 315 | static string newId = 0; |
Picmon | 0:20b4b057fa7f | 316 | |
Picmon | 0:20b4b057fa7f | 317 | if(id != newId){ |
Picmon | 0:20b4b057fa7f | 318 | lcd.printf("get %s.val%c%c%c",id.c_str(),0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 319 | newId = id; |
Picmon | 0:20b4b057fa7f | 320 | |
Picmon | 0:20b4b057fa7f | 321 | #ifdef DEBUG_LCD |
Picmon | 0:20b4b057fa7f | 322 | pc.printf("\r\n\r\nnexSendGetVal %s\r\n",id.c_str()); |
Picmon | 0:20b4b057fa7f | 323 | #endif |
Picmon | 0:20b4b057fa7f | 324 | } |
Picmon | 0:20b4b057fa7f | 325 | } |
Picmon | 0:20b4b057fa7f | 326 | |
Picmon | 0:20b4b057fa7f | 327 | void NextionLCD::ClrScr(uint16_t color){//ok |
Picmon | 0:20b4b057fa7f | 328 | lcd.printf("cls %d%c%c%c", color, 0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 329 | |
Picmon | 0:20b4b057fa7f | 330 | #ifdef DEBUG_LCD |
Picmon | 0:20b4b057fa7f | 331 | pc.printf("\r\n\r\nClrScr %d\r\n",color); |
Picmon | 0:20b4b057fa7f | 332 | #endif |
Picmon | 0:20b4b057fa7f | 333 | } |
Picmon | 0:20b4b057fa7f | 334 | |
Picmon | 0:20b4b057fa7f | 335 | void NextionLCD::nexLoadSD(void){ |
Picmon | 0:20b4b057fa7f | 336 | nexPwrCont = ON;//Nextion power is on |
Picmon | 0:20b4b057fa7f | 337 | wait(0.50); |
Picmon | 0:20b4b057fa7f | 338 | nexSetBckLite(5);//program backlight to be off at power up |
Picmon | 0:20b4b057fa7f | 339 | wait(5.0); |
Picmon | 0:20b4b057fa7f | 340 | nexPwrCont = OFF; |
Picmon | 0:20b4b057fa7f | 341 | wait(5.0); |
Picmon | 0:20b4b057fa7f | 342 | nexPwrCont = ON;//Nextion power is on |
Picmon | 0:20b4b057fa7f | 343 | wait(0.25); |
Picmon | 0:20b4b057fa7f | 344 | |
Picmon | 0:20b4b057fa7f | 345 | #ifdef DEBUG_LCD |
Picmon | 0:20b4b057fa7f | 346 | pc.printf("\r\n\r\nnexLoadSD\r\n"); |
Picmon | 0:20b4b057fa7f | 347 | #endif |
Picmon | 0:20b4b057fa7f | 348 | } |
Picmon | 0:20b4b057fa7f | 349 | |
Picmon | 0:20b4b057fa7f | 350 | void NextionLCD::nexDrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) { |
Picmon | 0:20b4b057fa7f | 351 | static uint16_t newX1,newY1,newX2,newY2,newColor = 0; |
Picmon | 0:20b4b057fa7f | 352 | |
Picmon | 0:20b4b057fa7f | 353 | if((x1 != newX1)||(y1 != newY1)||(x2 != newX2)||(y2 != newY2)||(color != newColor)){ |
Picmon | 0:20b4b057fa7f | 354 | lcd.printf("line %d,%d,%d,%d,%d%c%c%c", x1, y1, x2, y2, color, 0xff, 0xff, 0xff); |
Picmon | 0:20b4b057fa7f | 355 | newX1 = x1; |
Picmon | 0:20b4b057fa7f | 356 | newY1 = y1; |
Picmon | 0:20b4b057fa7f | 357 | newX2 = x2; |
Picmon | 0:20b4b057fa7f | 358 | newY2 = y2; |
Picmon | 0:20b4b057fa7f | 359 | newColor = color; |
Picmon | 0:20b4b057fa7f | 360 | |
Picmon | 0:20b4b057fa7f | 361 | #ifdef DEBUG_LCD |
Picmon | 0:20b4b057fa7f | 362 | pc.printf("\r\n\r\nnexDrawLine x1=%d y1=%d x2=%d y2=%d col=%d\r\n",x1, y1, x2, y2, color); |
Picmon | 0:20b4b057fa7f | 363 | #endif |
Picmon | 0:20b4b057fa7f | 364 | } |
Picmon | 0:20b4b057fa7f | 365 | } |
Picmon | 0:20b4b057fa7f | 366 | |
Picmon | 0:20b4b057fa7f | 367 | void NextionLCD::RxInterrupt(void){ |
Picmon | 0:20b4b057fa7f | 368 | /* |
Picmon | 0:20b4b057fa7f | 369 | Decode Nextion messages |
Picmon | 0:20b4b057fa7f | 370 | */ |
Picmon | 0:20b4b057fa7f | 371 | char c; |
Picmon | 0:20b4b057fa7f | 372 | |
Picmon | 0:20b4b057fa7f | 373 | if(lcd.readable()){ |
Picmon | 0:20b4b057fa7f | 374 | |
Picmon | 0:20b4b057fa7f | 375 | debugFlag = true;//Debug all |
Picmon | 0:20b4b057fa7f | 376 | |
Picmon | 0:20b4b057fa7f | 377 | c = lcd.getc(); |
Picmon | 0:20b4b057fa7f | 378 | mRxMsg[mRxIdx] = c; |
Picmon | 0:20b4b057fa7f | 379 | dbgNexMsg[mRxIdx] = c;//make a copy of the message in dbgNexMsg[] |
Picmon | 0:20b4b057fa7f | 380 | dbgMRxIdx = mRxIdx++;//Save a copy of the index counter in dbgMRxIdx |
Picmon | 0:20b4b057fa7f | 381 | |
Picmon | 0:20b4b057fa7f | 382 | |
Picmon | 0:20b4b057fa7f | 383 | /* |
Picmon | 0:20b4b057fa7f | 384 | These are touch screen evernt and by there nature slow so |
Picmon | 0:20b4b057fa7f | 385 | it should no be necessary to have to process these received touch event that quickly |
Picmon | 0:20b4b057fa7f | 386 | so no need to just set a flag in the RX ISR and let a thread do the processing it can |
Picmon | 0:20b4b057fa7f | 387 | ALL be done with the RX ISR |
Picmon | 0:20b4b057fa7f | 388 | */ |
Picmon | 0:20b4b057fa7f | 389 | |
Picmon | 0:20b4b057fa7f | 390 | |
Picmon | 0:20b4b057fa7f | 391 | if((mRxIdx >= 3) && (mRxMsg[mRxIdx-1] == 0xff) && (mRxMsg[mRxIdx-2] == 0xff) && (mRxMsg[mRxIdx-3] == 0xff)){//valid rx message |
Picmon | 0:20b4b057fa7f | 392 | |
Picmon | 0:20b4b057fa7f | 393 | mRxIdx=0; |
Picmon | 0:20b4b057fa7f | 394 | //////////////////////////////debugFlag = true; |
Picmon | 0:20b4b057fa7f | 395 | |
Picmon | 0:20b4b057fa7f | 396 | //led1=1; |
Picmon | 0:20b4b057fa7f | 397 | |
Picmon | 0:20b4b057fa7f | 398 | if(mRxMsg[0] == TOUCH_EVENT){//Nextion RX Touch Event |
Picmon | 0:20b4b057fa7f | 399 | |
Picmon | 0:20b4b057fa7f | 400 | page = mRxMsg[PAGE];//get the page |
Picmon | 0:20b4b057fa7f | 401 | id = mRxMsg[ID];//get the component ID |
Picmon | 0:20b4b057fa7f | 402 | pushPop = mRxMsg[PUSHPOP];//get the push/pop state |
Picmon | 0:20b4b057fa7f | 403 | |
Picmon | 0:20b4b057fa7f | 404 | keyScanFlag = true;//set key scn flag for main routine |
Picmon | 0:20b4b057fa7f | 405 | |
Picmon | 0:20b4b057fa7f | 406 | } |
Picmon | 0:20b4b057fa7f | 407 | |
Picmon | 0:20b4b057fa7f | 408 | if(mRxMsg[0] == 0x71){//Nextion RX Numeric Data |
Picmon | 0:20b4b057fa7f | 409 | //led1=1; |
Picmon | 0:20b4b057fa7f | 410 | scrnUpdate = true; |
Picmon | 0:20b4b057fa7f | 411 | nexDataLSB = mRxMsg[1]; |
Picmon | 0:20b4b057fa7f | 412 | nexDataMSB = mRxMsg[2]; |
Picmon | 0:20b4b057fa7f | 413 | } |
Picmon | 0:20b4b057fa7f | 414 | } |
Picmon | 0:20b4b057fa7f | 415 | } |
Picmon | 0:20b4b057fa7f | 416 | } |