fixed sleep timer

This commit is contained in:
joBr99
2022-03-11 18:54:56 +01:00
parent b415e6c4e5
commit c5414c066d
3 changed files with 473 additions and 215 deletions

View File

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

Binary file not shown.

Binary file not shown.