From 0bc4582e91045f58d7af33181de462e947de6f55 Mon Sep 17 00:00:00 2001 From: MMMZZZZ Date: Wed, 2 Dec 2020 23:30:03 +0100 Subject: [PATCH] Fixed dodgy parsing! Slightly new CLI --- .../MIDI_Chn_Set.txt | 8 +- .../Syntherrupter_Nextion_Code/MIDI_Live.txt | 21 ++-- .../MIDI_TC_Set.txt | 64 ++++++++-- .../Other_Settings.txt | 8 +- Example/Syntherrupter_Nextion_Code/Simple.txt | 2 +- .../Syntherrupter_Nextion_Code/Startup.txt | 3 + .../TC_Settings.txt | 36 +++--- .../User_Settings.txt | 12 +- Nextion2Text.py | 113 ++++++++++-------- README.md | 23 ++-- 10 files changed, 176 insertions(+), 114 deletions(-) diff --git a/Example/Syntherrupter_Nextion_Code/MIDI_Chn_Set.txt b/Example/Syntherrupter_Nextion_Code/MIDI_Chn_Set.txt index 6207b88..c3b7cb8 100644 --- a/Example/Syntherrupter_Nextion_Code/MIDI_Chn_Set.txt +++ b/Example/Syntherrupter_Nextion_Code/MIDI_Chn_Set.txt @@ -670,7 +670,7 @@ Page MIDI_Chn_Set Number nNumCoarse Properties Scope : Local - Initial Value: 0 + Initial Value: 42 Events Touch Press Event @@ -748,7 +748,7 @@ Page MIDI_Chn_Set Number nDataCoarse Properties Scope : Local - Initial Value: 0 + Initial Value: 8364 Events Touch Press Event @@ -805,7 +805,7 @@ Page MIDI_Chn_Set Number nDataFine Properties Scope : Local - Initial Value: 0 + Initial Value: 8364 Events Touch Press Event @@ -1176,7 +1176,7 @@ Page MIDI_Chn_Set Properties Scope : Global Type : int32 - Initial Value : 0 + Initial Value : 704643072 Variable MIDIData Properties diff --git a/Example/Syntherrupter_Nextion_Code/MIDI_Live.txt b/Example/Syntherrupter_Nextion_Code/MIDI_Live.txt index 673e13e..46b0c3a 100644 --- a/Example/Syntherrupter_Nextion_Code/MIDI_Live.txt +++ b/Example/Syntherrupter_Nextion_Code/MIDI_Live.txt @@ -735,13 +735,11 @@ Page MIDI_Live Running : No Events - Touch Press Event - p - e - - Touch Release Event - p - e + Timer Event + tmTCButtonHold.en=0 + MIDI_TC_Set.origin.val=dp + covx sCoil.txt,MIDI_TC_Set.coilNum.val,0,0 + page MIDI_TC_Set Variable sCoil Properties @@ -872,13 +870,8 @@ Page MIDI_Live Running : No Events - Touch Press Event - p - e - - Touch Release Event - p - e + Timer Event + openEE.val=1 Variable openEE Properties diff --git a/Example/Syntherrupter_Nextion_Code/MIDI_TC_Set.txt b/Example/Syntherrupter_Nextion_Code/MIDI_TC_Set.txt index 5b286e7..14257e9 100644 --- a/Example/Syntherrupter_Nextion_Code/MIDI_TC_Set.txt +++ b/Example/Syntherrupter_Nextion_Code/MIDI_TC_Set.txt @@ -1034,13 +1034,63 @@ Page MIDI_TC_Set Running : No Events - Touch Press Event - p - e - - Touch Release Event - p - e + Timer Event + tmButtonHold.en=0 + MIDI_Chn_Set.origin.val=dp + covx sChnNum.txt,MIDI_Chn_Set.chnNum.val,0,0 + // Button has been hold, not pressed. Revert state change. + if(sChnNum.txt==btChn0.txt) + { + btChn0.val=1-btChn0.val + }else if(sChnNum.txt==btChn1.txt) + { + btChn1.val=1-btChn1.val + }else if(sChnNum.txt==btChn2.txt) + { + btChn2.val=1-btChn2.val + }else if(sChnNum.txt==btChn3.txt) + { + btChn3.val=1-btChn3.val + }else if(sChnNum.txt==btChn4.txt) + { + btChn4.val=1-btChn4.val + }else if(sChnNum.txt==btChn5.txt) + { + btChn5.val=1-btChn5.val + }else if(sChnNum.txt==btChn6.txt) + { + btChn6.val=1-btChn6.val + }else if(sChnNum.txt==btChn7.txt) + { + btChn7.val=1-btChn7.val + }else if(sChnNum.txt==btChn8.txt) + { + btChn8.val=1-btChn8.val + }else if(sChnNum.txt==btChn9.txt) + { + btChn9.val=1-btChn9.val + }else if(sChnNum.txt==btChn10.txt) + { + btChn10.val=1-btChn10.val + }else if(sChnNum.txt==btChn11.txt) + { + btChn11.val=1-btChn11.val + }else if(sChnNum.txt==btChn12.txt) + { + btChn12.val=1-btChn12.val + }else if(sChnNum.txt==btChn13.txt) + { + btChn13.val=1-btChn13.val + }else if(sChnNum.txt==btChn14.txt) + { + btChn14.val=1-btChn14.val + }else if(sChnNum.txt==btChn15.txt) + { + btChn15.val=1-btChn15.val + } + // Store settings before leaving the page + click fStore,1 + page MIDI_Chn_Set Variable sChnNum Properties diff --git a/Example/Syntherrupter_Nextion_Code/Other_Settings.txt b/Example/Syntherrupter_Nextion_Code/Other_Settings.txt index cda787d..b7f2fbe 100644 --- a/Example/Syntherrupter_Nextion_Code/Other_Settings.txt +++ b/Example/Syntherrupter_Nextion_Code/Other_Settings.txt @@ -111,7 +111,7 @@ Page Other_Settings Number nHoldTime Properties Scope : Global - Initial Value: 0 + Initial Value: 250 Events Touch Press Event @@ -477,7 +477,7 @@ Page Other_Settings Number nSleepMin Properties Scope : Local - Initial Value: 0 + Initial Value: 5 Events Touch Press Event @@ -498,7 +498,7 @@ Page Other_Settings Number nSleepS Properties Scope : Local - Initial Value: 0 + Initial Value: 30 Events Touch Press Event @@ -591,7 +591,7 @@ Page Other_Settings Number nBackOff Properties Scope : Global - Initial Value: 0 + Initial Value: 1 Events Touch Press Event diff --git a/Example/Syntherrupter_Nextion_Code/Simple.txt b/Example/Syntherrupter_Nextion_Code/Simple.txt index 8ce4653..ffdc528 100644 --- a/Example/Syntherrupter_Nextion_Code/Simple.txt +++ b/Example/Syntherrupter_Nextion_Code/Simple.txt @@ -429,7 +429,7 @@ Page Simple Number nBPS Properties Scope : Local - Initial Value: 0 + Initial Value: 100 Events Touch Press Event diff --git a/Example/Syntherrupter_Nextion_Code/Startup.txt b/Example/Syntherrupter_Nextion_Code/Startup.txt index e0174c7..469ba94 100644 --- a/Example/Syntherrupter_Nextion_Code/Startup.txt +++ b/Example/Syntherrupter_Nextion_Code/Startup.txt @@ -28,6 +28,9 @@ Page Startup click pStartup,0 Picture pStartup + Properties + Scope: Local + Events Touch Press Event diff --git a/Example/Syntherrupter_Nextion_Code/TC_Settings.txt b/Example/Syntherrupter_Nextion_Code/TC_Settings.txt index 8ee71dd..e407b39 100644 --- a/Example/Syntherrupter_Nextion_Code/TC_Settings.txt +++ b/Example/Syntherrupter_Nextion_Code/TC_Settings.txt @@ -607,7 +607,7 @@ Page TC_Settings Number nCoil1MinOff Properties Scope : Local - Initial Value: 0 + Initial Value: 101 Events Touch Press Event @@ -628,7 +628,7 @@ Page TC_Settings Float nCoil1Duty Properties Scope : Local - Initial Value : 0 + Initial Value : 101 Divide by [10^x]: 1 Events @@ -671,7 +671,7 @@ Page TC_Settings Number nCoil2MinOff Properties Scope : Local - Initial Value: 0 + Initial Value: 102 Events Touch Press Event @@ -692,7 +692,7 @@ Page TC_Settings Float nCoil2Duty Properties Scope : Local - Initial Value : 0 + Initial Value : 102 Divide by [10^x]: 1 Events @@ -735,7 +735,7 @@ Page TC_Settings Number nCoil3MinOff Properties Scope : Local - Initial Value: 0 + Initial Value: 103 Events Touch Press Event @@ -756,7 +756,7 @@ Page TC_Settings Float nCoil3Duty Properties Scope : Local - Initial Value : 0 + Initial Value : 103 Divide by [10^x]: 1 Events @@ -799,7 +799,7 @@ Page TC_Settings Number nCoil4MinOff Properties Scope : Local - Initial Value: 0 + Initial Value: 104 Events Touch Press Event @@ -820,7 +820,7 @@ Page TC_Settings Float nCoil4Duty Properties Scope : Local - Initial Value : 0 + Initial Value : 104 Divide by [10^x]: 1 Events @@ -863,7 +863,7 @@ Page TC_Settings Number nCoil5MinOff Properties Scope : Local - Initial Value: 0 + Initial Value: 105 Events Touch Press Event @@ -884,7 +884,7 @@ Page TC_Settings Float nCoil5Duty Properties Scope : Local - Initial Value : 0 + Initial Value : 105 Divide by [10^x]: 1 Events @@ -927,7 +927,7 @@ Page TC_Settings Number nCoil6MinOff Properties Scope : Local - Initial Value: 0 + Initial Value: 106 Events Touch Press Event @@ -948,7 +948,7 @@ Page TC_Settings Float nCoil6Duty Properties Scope : Local - Initial Value : 0 + Initial Value : 106 Divide by [10^x]: 1 Events @@ -1561,7 +1561,7 @@ Page TC_Settings Number nCoil1Voices Properties Scope : Local - Initial Value: 0 + Initial Value: 1 Events Touch Press Event @@ -1582,7 +1582,7 @@ Page TC_Settings Number nCoil2Voices Properties Scope : Local - Initial Value: 0 + Initial Value: 2 Events Touch Press Event @@ -1603,7 +1603,7 @@ Page TC_Settings Number nCoil3Voices Properties Scope : Local - Initial Value: 0 + Initial Value: 3 Events Touch Press Event @@ -1624,7 +1624,7 @@ Page TC_Settings Number nCoil4Voices Properties Scope : Local - Initial Value: 0 + Initial Value: 4 Events Touch Press Event @@ -1645,7 +1645,7 @@ Page TC_Settings Number nCoil5Voices Properties Scope : Local - Initial Value: 0 + Initial Value: 5 Events Touch Press Event @@ -1666,7 +1666,7 @@ Page TC_Settings Number nCoil6Voices Properties Scope : Local - Initial Value: 0 + Initial Value: 6 Events Touch Press Event diff --git a/Example/Syntherrupter_Nextion_Code/User_Settings.txt b/Example/Syntherrupter_Nextion_Code/User_Settings.txt index 8b618c3..3aa727a 100644 --- a/Example/Syntherrupter_Nextion_Code/User_Settings.txt +++ b/Example/Syntherrupter_Nextion_Code/User_Settings.txt @@ -509,7 +509,7 @@ Page User_Settings Float user0Duty Properties Scope : Local - Initial Value : 0 + Initial Value : 60 Divide by [10^x]: 1 Events @@ -543,7 +543,7 @@ Page User_Settings Number user0Ontime Properties Scope : Local - Initial Value: 0 + Initial Value: 100 Events Touch Press Event @@ -607,7 +607,7 @@ Page User_Settings Float user1Duty Properties Scope : Local - Initial Value : 0 + Initial Value : 80 Divide by [10^x]: 1 Events @@ -640,7 +640,7 @@ Page User_Settings Number user1Ontime Properties Scope : Local - Initial Value: 0 + Initial Value: 8211 Events Touch Press Event @@ -703,7 +703,7 @@ Page User_Settings Float user2Duty Properties Scope : Local - Initial Value : 0 + Initial Value : 100 Divide by [10^x]: 1 Events @@ -737,7 +737,7 @@ Page User_Settings Number user2Ontime Properties Scope : Local - Initial Value: 0 + Initial Value: 200 Events Touch Press Event diff --git a/Nextion2Text.py b/Nextion2Text.py index c21b586..fd2eaf6 100644 --- a/Nextion2Text.py +++ b/Nextion2Text.py @@ -3,6 +3,7 @@ import sys import struct from typing import List +import argparse class IndentList(list): def __init__(self, *args, **kwargs): @@ -58,8 +59,7 @@ class Component: 51: { "typeName": "Timer", "events": { - "codesdown": "Touch Press Event", - "codesup": "Touch Release Event", + "codestimer": "Timer Event", }, "properties": { "vscope": "Scope", @@ -479,41 +479,36 @@ def textLines(self, indentLevel=0, indent=4, recursive=True, emptyLinesLimit=1): result.appendIndentLine("") return result - def entryEnd(self, start): - end1 = self.raw.find("\x00\x00\x00\x00", start) - end2 = self.raw.find("\x00\x00\x00", start) - if end1 != end2: - end2 -= 1 - return end2 - def getProperty(self, property): # "normal" propertiy names are filled up with \x00 to a length of 16 bytes. - # "normal" properties end with a random caracter and 3x \x00 # Variable length properties have the length indicated after their name property: str if property in self.types[self.typeId]["events"]: + #rawBytes = self.raw.encode() propertyStr = property + "-" propertyIndex = self.raw.find(propertyStr) if propertyIndex >= 0: # Variable length property - propertyIndex += len(propertyStr) - propertyLengthEnd = self.entryEnd(propertyIndex) - propertyLength = int(self.raw[propertyIndex:propertyLengthEnd]) + propertyTitleLength = struct.unpack_from("= 0: - propertyEnd = self.entryEnd(propertyIndex) - return self.raw[propertyIndex:propertyEnd] + propertyLength = struct.unpack_from("