Update README.md

This commit is contained in:
joBr99
2022-03-11 20:27:32 +01:00
committed by GitHub
parent 62e52801ad
commit ff5d8290e0

View File

@@ -1,473 +1,214 @@
// data available # NSPanel Lovelance UI
if(usize>1)
{ The general idea is that the Nextion Display cycles though a page counter and the esp32 tells the display what to do.
bufferPos=0 If you are changeing the page the nextion display will send and event to the esp32 and it has to answer with the messages, that will update the current page with it's desired components. This enables easy changes, without touching the HMI Project.
while(bufferPos<usize)
{ # Message Flow
// check for 0x55 0xBB - Command Init Secuence
if(u[bufferPos]==187&&u[bufferPos-1]==85) HomeAssistant / NodeRed -- MQTT -- Tasmota -- Nextion Screen
{
//remove garbage at the start of the buffer if there's any to free buffer for command See the following picture to get an Idea for the messages send and recived from the screen during cycling though pages.
if(u[bufferPos]!=1)
{ ![message_flow](../doc-pics/message-flow.png)
udelete bufferPos-1
}
//instruction is now aligned with buffer, because we deleted garbage before instrcution # Custom Protocol
//get length after init sequence (check if there are more than to bytes in buffer) ```
if(2<usize) 55 BB [payload length] [payload] [crc] [crc]
{ ```
// check if serial buffer has reached the announced length
payloadLength=u[2] Payload length contains the number of bytes of the payload.
// we are only checking payload length so we have to skip first 3 bytes (init+payload length) (-1 because of < instead of <=)
payloadLength+=2 CRC is "CRC-16 (MODBUS) Big Endian" calculated over the whole message
// payload length does also not contain crc, so we are adding another 2 bytes for crc
payloadLength+=2 This protocol does not try to implement broken JSON Commands with a specified type (lol).
if(payloadLength<usize) Instead the commands are plain text commands with parameters.
{
// calculate crc ## Example for valid Message
crcrest 1,0xFFFF This message has to be generated for the Message "1337" (1337 is not a valid command, this is just an example)
// u[2] contains payload legth at 3rd pos in buffer, we are calculating crc from 3rd pos with number of bytes from payload length ```
//crcputu 3,u[2] 55 BB 04 31 33 33 37 5F 5B
// u[2] cotnains payload length, we are calculating a crc over the whole message, so we have to add 3 to the length from u[2] ```
crcputu 0,u[2]+3 ## Messages to Nextion Display
// get recived crc to be able to compare it
ucopy recvCrc,u[2]+3,2,0 The following message should be implemented on all pages
// compare crc with recived value
if(crcval==recvCrc) wake screen:
{
// crc is okay wake
// here is the location where acual code should be
// write command to variable strCommand set brightness of screensaver:
ucopy strCommand.txt,3,u[2],0
// write instruction to tInstuction (debug output, but used as variable here, ui elements will be disabled by default) dimmode,0 - (screen off)
spstr strCommand.txt,tInstruction.txt,",",0 dimmode,100 - (screen on with full brightness)
if(tInstruction.txt=="entityUpdHeading")
{ set current time:
spstr strCommand.txt,tHeading.txt,",",1
} time,22 : 26
if(tInstruction.txt=="entityUpd")
{ set current date:
// command format: entityUpd,id,icon,name,type,optionalValue
// write id to tId (debug output, but used as variable here, ui elements will be disabled by default) date,?Di 24. Februar
spstr strCommand.txt,tId.txt,",",1
// id 1 set screensaver timeout (set time in ms limited from 50 to 65535:
if(tId.txt=="1")
{ timeout,15 - timeout after 15 seconds
// get Type timeout,0 - disable screensaver
spstr strCommand.txt,type1.txt,",",2
// get internal name change the page type:
spstr strCommand.txt,entn1.txt,",",3
if(type1.txt=="delete") pageType,pageStartup
{
vis bUp1,0 pageType,cardEntities
vis bStop1,0
vis bDown1,0 pageType,cardThermo
vis btOnOff1,0
vis tEntity1,0 pageType,cardMedia
vis tIcon1,0
vis bText1,0 pageType,popupLight,Schreibtischlampe
}else
{ ### screensaver page
// change icon
spstr strCommand.txt,tTmp.txt,",",4 weatherUpdate,? tMainIcon? tMainText? tMRIcon? tMR? tForecast1? tF1Icon? tForecast1Val? tForecast2? tF2Icon? tForecast2Val
covx tTmp.txt,sys0,0,0
substr pageIcons.tIcons.txt,tIcon1.txt,sys0,1 weatherUpdate,?0?2,3 C?0?0 mm?Mi?0?9,3 C?Do?0?11,5 C
vis tIcon1,1
// set name ### cardEntities Page
spstr strCommand.txt,tEntity1.txt,",",5
vis tEntity1,1 The following message can be used to update the content on the cardEntities Page
}
if(type1.txt=="shutter") entityUpdHeading,heading1337
{
vis bUp1,1 entityUpd,*id*,*type*,*internalNameEntity*,*iconId*,*displayNameEntity*,*optionalValue*
vis bStop1,1
vis bDown1,1 entityUpd,1,light,light.entityName,1,Light1,0
vis btOnOff1,0
vis bText1,0 entityUpd,2,shutter,cover.entityName,0,Shutter2
}
if(type1.txt=="light") entityUpd,3,delete
{
vis bUp1,0 entityUpd,4,text,sensor.entityName,3,Temperature,content
vis bStop1,0
vis bDown1,0 entityUpd,4,button,button.entityName,3,bt-name,bt-text
vis btOnOff1,1
vis bText1,0 entityUpd,1,switch,switch.entityName,4,Switch1,0
// get Button State (optional Value)
spstr strCommand.txt,tTmp.txt,",",6 ### popupLight Page
covx tTmp.txt,sys0,0,0
btOnOff1.val=sys0 entityUpdateDetail,*buttonState*,*sliderBrightnessPos*,*sliderColorTempPos*
}
if(type1.txt=="switch") entityUpdateDetail,1,100,78
{
vis bUp1,0 entityUpdateDetail,1,100,disable
vis bStop1,0
vis bDown1,0 ### popupShutter Page
vis btOnOff1,1
vis bText1,0 entityUpdateDetail,*ignored*,*sliderPos*
// get Button State (optional Value)
spstr strCommand.txt,tTmp.txt,",",6 entityUpdateDetail,1,77
covx tTmp.txt,sys0,0,0
btOnOff1.val=sys0 ### cardThermo Page
}
if(type1.txt=="text") entityUpd,*internalNameEntiy*,*heading*,*currentTemp*,*destTemp*,*status*,*minTemp*,*maxTemp*,*stepTemp*
{
vis bUp1,0 ### cardMedia Page
vis bStop1,0
vis bDown1,0 entityUpd,|*internalNameEntiy*|*heading*|*icon*|*title*|*author*|*volume*|*playpauseicon*
vis btOnOff1,0
vis bText1,1 ## Messages from Nextion Display
tsw bText1,0
bText1.pco=65535 ### startup page
bText1.pco2=65535
// get Text (optional Value) event,startup,version
spstr strCommand.txt,bText1.txt,",",6
} ### screensaver page
if(type1.txt=="button")
{ event,screensaverOpen
vis bUp1,0
vis bStop1,0 ### cardEntities Page
vis bDown1,0
vis btOnOff1,0 event,*eventName*,*PageNumber*,*PageHeading*,*entityName*,*buttonId*,*actionName*,*optionalValue*
vis bText1,1
tsw bText1,1 event,pageOpen,0
bText1.pco=1374
bText1.pco2=1374 event,buttonPress,1,tHeading,internalNameEntity,1,up
// get Text (optional Value)
spstr strCommand.txt,bText1.txt,",",6 event,buttonPress,1,tHeading,internalNameEntity,1,down
}
} event,buttonPress,1,tHeading,internalNameEntity,1,stop
// id 2
if(tId.txt=="2") event,buttonPress,1,tHeading,internalNameEntity,1,OnOff,1
{
// get Type event,buttonPress,1,tHeading,internalNameEntity,1,button
spstr strCommand.txt,type2.txt,",",2
// get internal name ### popupLight Page
spstr strCommand.txt,entn2.txt,",",3
if(type2.txt=="delete") event,pageOpenDetail,popupLight,internalNameEntity
{
vis bUp2,0 event,buttonPress,D,nameEntity,internalNameEntity,1,OnOff,1
vis bStop2,0
vis bDown2,0 event,buttonPress,D,nameEntity,internalNameEntity,1,brightnessSlider,50
vis btOnOff2,0
vis tEntity2,0 event,buttonPress,D,nameEntity,internalNameEntity,1,colorTempSlider,50
vis tIcon2,0
vis bText2,0 ### popupShutter Page
}else
{ event,pageOpenDetail,popupShutter,internalNameEntity
//change icon
spstr strCommand.txt,tTmp.txt,",",4 event,buttonPress,D,nameEntity,internalNameEntity,1,positionSlider,50
covx tTmp.txt,sys0,0,0
substr pageIcons.tIcons.txt,tIcon2.txt,sys0,1 ### cardThermo Page
vis tIcon2,1
// set name event,pageOpen,0
spstr strCommand.txt,tEntity2.txt,",",5
vis tEntity2,1 event,tempUpd,*pageNumber*,*entityName*,*temperature*
}
if(type2.txt=="shutter") ### cardMedia Page
{
vis bUp2,1 event,buttonPress,1,tHeading,internalNameEntity,1,media-back
vis bStop2,1
vis bDown2,1 event,buttonPress,1,tHeading,internalNameEntity,1,media-pause
vis btOnOff2,0
vis bText2,0 event,buttonPress,1,tHeading,internalNameEntity,1,media-next
}
if(type2.txt=="light") event,buttonPress,1,tHeading,internalNameEntity,1,volumeSlider,75
{
vis bUp2,0 # Icons IDs
vis bStop2,0
vis bDown2,0 ID | Icon
vis btOnOff2,1 -- | ----
vis bText2,0 0 | ![window-open](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/window-open.svg)
// get Button State (optional Value) 1 | ![lightbulb](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/lightbulb.svg)
spstr strCommand.txt,tTmp.txt,",",6 2 | ![thermometer](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/thermometer.svg)
covx tTmp.txt,sys0,0,0 3 | ![gesture-tap-button](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/gesture-tap-button.svg)
btOnOff2.val=sys0 4 | ![flash](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/flash.svg)
} 5 | ![music](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/music.svg)
if(type2.txt=="switch") 6 | ![check-circle-outline](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/check-circle-outline.svg)
{ 7 | ![close-circle-outline](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/close-circle-outline.svg)
vis bUp2,0 8 | ![pause](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/pause.svg)
vis bStop2,0 9 | ![play](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/play.svg)
vis bDown2,0 10 | ![palette](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/palette.svg)
vis btOnOff2,1 11 | ![alert-circle-outline](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/alert-circle-outline.svg)
vis bText2,0 12 | ![weather-cloudy](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/weather-cloudy.svg)
// get Button State (optional Value) 13 | ![weather-fog](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/weather-fog.svg)
spstr strCommand.txt,tTmp.txt,",",6 14 | ![weather-hail](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/weather-hail.svg)
covx tTmp.txt,sys0,0,0 15 | ![weather-lightning](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/weather-lightning.svg)
btOnOff2.val=sys0 16 | ![weather-lightning-rainy](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/weather-lightning-rainy.svg)
} 17 | ![weather-night](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/weather-night.svg)
if(type2.txt=="text") 18 | ![weather-partly-cloudy](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/weather-partly-cloudy.svg)
{ 19 | ![weather-pouring](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/weather-pouring.svg)
vis bUp2,0 20 | ![weather-rainy](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/weather-rainy.svg)
vis bStop2,0 21 | ![weather-snowy](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/weather-snowy.svg)
vis bDown2,0 22 | ![weather-snowy-rainy](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/weather-snowy-rainy.svg)
vis btOnOff2,0 23 | ![weather-sunny](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/weather-sunny.svg)
vis bText2,1 24 | ![weather-windy](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/weather-windy.svg)
tsw bText2,0 25 | ![weather-windy-variant](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/weather-windy-variant.svg)
bText2.pco=65535 26 | ![water-percent](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/water-percent.svg)
bText2.pco2=65535
// get Text (optional Value) # Design Guidelines for Nextion HMI Project
spstr strCommand.txt,bText2.txt,",",6
} Background Color is
if(type2.txt=="button") - RGB565: 6371 [18e3] (HEX: #1C1C1C, RGB: 28,28,28)
{
vis bUp2,0 Source for Icons is the Material Design Font, used by HASPone
vis bStop2,0 https://github.com/HASwitchPlate/HASPone
vis bDown2,0
vis btOnOff2,0
vis bText2,1
tsw bText2,1
bText2.pco=1374
bText2.pco2=1374
// get Text (optional Value)
spstr strCommand.txt,bText2.txt,",",6
}
}
// id 3
if(tId.txt=="3")
{
// get Type
spstr strCommand.txt,type3.txt,",",2
// get internal name
spstr strCommand.txt,entn3.txt,",",3
if(type3.txt=="delete")
{
vis bUp3,0
vis bStop3,0
vis bDown3,0
vis btOnOff3,0
vis tEntity3,0
vis tIcon3,0
vis bText3,0
}else
{
//change icon
spstr strCommand.txt,tTmp.txt,",",4
covx tTmp.txt,sys0,0,0
substr pageIcons.tIcons.txt,tIcon3.txt,sys0,1
vis tIcon3,1
// set name
spstr strCommand.txt,tEntity3.txt,",",5
vis tEntity3,1
}
if(type3.txt=="shutter")
{
vis bUp3,1
vis bStop3,1
vis bDown3,1
vis btOnOff3,0
vis bText3,0
}
if(type3.txt=="light")
{
vis bUp3,0
vis bStop3,0
vis bDown3,0
vis bText3,0
vis btOnOff3,1
// get Button State (optional Value)
spstr strCommand.txt,tTmp.txt,",",6
covx tTmp.txt,sys0,0,0
btOnOff3.val=sys0
}
if(type3.txt=="switch")
{
vis bUp3,0
vis bStop3,0
vis bDown3,0
vis bText3,0
vis btOnOff3,1
// get Button State (optional Value)
spstr strCommand.txt,tTmp.txt,",",6
covx tTmp.txt,sys0,0,0
btOnOff3.val=sys0
}
if(type3.txt=="text")
{
vis bUp3,0
vis bStop3,0
vis bDown3,0
vis btOnOff3,0
vis bText3,1
tsw bText3,0
bText3.pco=65535
bText3.pco2=65535
// get Text (optional Value)
spstr strCommand.txt,bText3.txt,",",6
}
if(type3.txt=="button")
{
vis bUp3,0
vis bStop3,0
vis bDown3,0
vis btOnOff3,0
vis bText3,1
tsw bText3,1
bText3.pco=1374
bText3.pco2=1374
// get Text (optional Value)
spstr strCommand.txt,bText3.txt,",",6
}
}
// id 2
if(tId.txt=="4")
{
// get Type
spstr strCommand.txt,type4.txt,",",2
// get internal name
spstr strCommand.txt,entn4.txt,",",3
if(type4.txt=="delete")
{
vis bUp4,0
vis bStop4,0
vis bDown4,0
vis btOnOff4,0
vis tEntity4,0
vis tIcon4,0
vis bText4,0
}else
{
//change icon
spstr strCommand.txt,tTmp.txt,",",4
covx tTmp.txt,sys0,0,0
substr pageIcons.tIcons.txt,tIcon4.txt,sys0,1
vis tIcon4,1
// set name
spstr strCommand.txt,tEntity4.txt,",",5
vis tEntity4,1
}
if(type4.txt=="shutter")
{
vis bUp4,1
vis bStop4,1
vis bDown4,1
vis btOnOff4,0
vis bText4,0
}
if(type4.txt=="light")
{
vis bUp4,0
vis bStop4,0
vis bDown4,0
vis bText4,0
vis btOnOff4,1
// get Button State (optional Value)
spstr strCommand.txt,tTmp.txt,",",6
covx tTmp.txt,sys0,0,0
btOnOff4.val=sys0
}
if(type4.txt=="switch")
{
vis bUp4,0
vis bStop4,0
vis bDown4,0
vis bText4,0
vis btOnOff4,1
// get Button State (optional Value)
spstr strCommand.txt,tTmp.txt,",",6
covx tTmp.txt,sys0,0,0
btOnOff4.val=sys0
}
if(type4.txt=="text")
{
vis bUp4,0
vis bStop4,0
vis bDown4,0
vis btOnOff4,0
vis bText4,1
tsw bText4,0
bText4.pco=65535
bText4.pco2=65535
// get Text (optional Value)
spstr strCommand.txt,bText4.txt,",",6
}
if(type4.txt=="button")
{
vis bUp4,0
vis bStop4,0
vis bDown4,0
vis btOnOff4,0
vis bText4,1
tsw bText4,1
bText4.pco=1374
bText4.pco2=1374
// get Text (optional Value)
spstr strCommand.txt,bText4.txt,",",6
}
}
}
if(tInstruction.txt=="pageType")
{
//command format pageType,specialPageName
//write name of speical page to tId
spstr strCommand.txt,tId.txt,",",1
//save second arg if there's one
spstr strCommand.txt,tTmp.txt,",",2
if(tId.txt=="cardEntities")
{
//yay, we are already on the correct page
}else
{
//we are going to exit this page with this command, so we have to clear the buffer, so we are not getting into a stupid loop ...
udelete u[2]+3
bufferPos=0
}
if(tId.txt=="popupLight")
{
pageIcons.tTmp1.txt=tTmp.txt
page popupLight
}
if(tId.txt=="cardThermo")
{
page cardThermo
}
if(tId.txt=="cardMedia")
{
page cardMedia
}
if(tId.txt=="pageStartup")
{
page pageStartup
}
}
if(tInstruction.txt=="time")
{
// get set time to global variable
spstr strCommand.txt,screensaver.vaTime.txt,",",1
}
if(tInstruction.txt=="date")
{
// get set date to global variable
spstr strCommand.txt,screensaver.vaDate.txt,"?",1
}
if(tInstruction.txt=="dimmode")
{
// get value
spstr strCommand.txt,tTmp.txt,",",1
covx tTmp.txt,dimValue,0,0
}
if(tInstruction.txt=="timeout")
{
// set timeout to global var
spstr strCommand.txt,tTmp.txt,",",1
covx tTmp.txt,sleepTimeout,0,0
}
// end of user code
udelete u[2]+3
bufferPos=0
}
}
}
}
// next character
bufferPos++
}
if(bufferPos==usize)
{
// copy whole buffer to t1.txt, for debugging
//ucopy t2.txt,0,usize,0
// ucopy n2.val,0,usize,0
// clear whole buffer
//code_c
//bufferPos=0
}
}