3333import socket # ip adr
3434import fcntl # ip adr
3535import struct # ip adr
36- from time import gmtime , strftime # Time display
36+ # from time import gmtime, strftime # Time display
37+ from time import strftime # Time display
3738
3839liste = []
40+ listetarget = []
3941global max_value_old
4042max_value_old = 0
4143global min_value_old
@@ -167,6 +169,7 @@ def writewave(kettleID):
167169 # rest name
168170 restn = restname ()
169171 NextionwriteString ("RestNameTxt" , restn )
172+ # build liste
170173 if len (liste ) < 406 :
171174 liste .append (temp0 )
172175 else :
@@ -175,44 +178,58 @@ def writewave(kettleID):
175178 cbpi .app .logger .info ('NextionDisplay - TempListe bigger 407:%s' % (len (liste )))
176179 # cbpi.app.logger.info('NextionDisplay - TempListe:%s' % (liste))
177180 cbpi .app .logger .info ('NextionDisplay - TempListe len(liste):%s' % (len (liste )))
178- max_value = (max (liste )+ 0.5 )
179- min_value = (min (liste )- 0.5 )
181+ # build liste targettemp
182+ if len (listetarget ) < 406 :
183+ listetarget .append (targettemp )
184+ else :
185+ del listetarget [0 ]
186+ listetarget .append (targettemp )
187+ cbpi .app .logger .info ('NextionDisplay - targetListe len(listetarget):%s' % (len (listetarget )))
188+ # min max labels at scale
189+ max_value = (max (liste )+ 0.2 )
190+ min_value = (min (liste )- 0.2 )
180191 NextionwriteString ("tmax" , "%s%s" % (max_value , (chr (176 )+ "C" )))
181192 NextionwriteString ("tmin" , "%s%s" % (min_value , (chr (176 )+ "C" )))
182193 NextionwriteString ("tavarage" , "%s%s" % (round (((max_value + min_value )/ 2 ), 2 ), (chr (176 )+ "C" )))
183194 # get the factor
184195 offset = (max_value - min_value )
185- xpixel = 202
196+ xpixel = 202 # the height of the wave on Nextion
186197 cbpi .app .logger .info ('NextionDisplay - check 1: offset: %s' % offset )
187198 factor2 = (xpixel / offset )
188199 cbpi .app .logger .info ('NextionDisplay - check 2: factor2: %s' % factor2 )
189200 global min_value_old
190201 global max_value_old
191202 if max_value != max_value_old or min_value != min_value_old :
192203 cbpi .app .logger .info ('NextionDisplay - rewrite check 3' )
193- NextionwriteClear (1 , 0 )
194- cbpi . app . logger . info ( 'NextionDisplay - rewrite check 4' )
204+ NextionwriteClear (1 , 0 ) # BrewTemp
205+ NextionwriteClear ( 1 , 2 ) # TargetTemp
195206 i = 0
196207 while i < len (liste ):
197208 cbpi .app .logger .info ('NextionDisplay - liste:%s' % (liste [i ]))
198- if float (liste [i ]) < 100 :
199- TextDigit = ("%5.2f" % float ((liste [i ] - min_value ) * factor2 ))
200- else :
201- TextDigit = ("%6.2f" % float ((liste [i ] - min_value ) * factor2 ))
202- pass
203- string = (str (round (float (TextDigit )))[:- 2 ])
209+ digit = (round (float ((liste [i ] - min_value ) * factor2 ), 2 ))
210+ string = (str (round (float (digit )))[:- 2 ])
204211 NextionwriteWave (1 , 0 , string )
212+ # targettemp
213+ target = (round (float ((listetarget [i ] - min_value ) * factor2 ), 2 ))
214+ tstring = (str (round (float (target )))[:- 2 ])
215+ if target < xpixel : #do not write target line if not in temp range
216+ NextionwriteWave (1 , 2 , tstring )
217+ else :
218+ pass
205219 i += 1
206- cbpi .app .logger .info ('NextionDisplay - Textdigit, Textdigit string: %s, %s' % (TextDigit , string ))
220+ cbpi .app .logger .info ('NextionDisplay - digit, string: %s, %s' % (digit , string ))
207221 else :
208- if temp0 < 100 :
209- TextDigit = ("%5.2f" % float ((temp0 - min_value ) * factor2 ))
210- else :
211- TextDigit = ("%6.2f" % float ((temp0 - min_value ) * factor2 ))
212- pass
213- string = (str (round (float (TextDigit )))[:- 2 ])
222+ digit = (round (float ((temp0 - min_value ) * factor2 ), 2 ))
223+ string = (str (round (float (digit )))[:- 2 ])
214224 NextionwriteWave (1 , 0 , string )
215- cbpi .app .logger .info ('NextionDisplay - Textdigit, Textdigit string: %s, %s' % (TextDigit , string ))
225+ cbpi .app .logger .info ('NextionDisplay - digit, string: %s, %s' % (digit , string ))
226+ # target Temp
227+ target = (round (float ((targettemp - min_value ) * factor2 ), 2 ))
228+ tstring = (str (round (float (target )))[:- 2 ])
229+ if target < xpixel : # do not write target line if not in temp range
230+ NextionwriteWave (1 , 2 , tstring )
231+ else :
232+ pass
216233 pass
217234 cbpi .app .logger .info ('NextionDisplay - max and min value: %s, %s' % (max_value , min_value ))
218235
@@ -222,11 +239,11 @@ def writewave(kettleID):
222239 min_value_old = min_value
223240
224241
225- def CurrentFermTemp ():
242+ def currentfermtemp ():
226243 pass
227244
228245
229- def TargetFernTemp ():
246+ def targetfermtemp ():
230247 pass
231248
232249
@@ -263,7 +280,10 @@ def restname():
263280def FermenterName ():
264281 pass
265282
283+
266284def Beername ():
285+ # beername = modules.fermenter.Fermenter.brewname
286+ # return beername
267287 pass
268288
269289
@@ -320,7 +340,7 @@ def initNextion(app):
320340
321341 # end of init
322342
323- @cbpi .backgroundtask (key = "Nexionjob" , interval = 2 )
343+ @cbpi .backgroundtask (key = "Nexionjob" , interval = 4 )
324344
325345 def Nextionjob (api ):
326346 # This is the main job
@@ -349,7 +369,6 @@ def Nextionjob(api):
349369 global kettleID
350370 kettleID = set_parameter_kettleID ()
351371
352- # writingBrewCharttoNexion(kettleID)
353372 writingDigittoNextion (kettleID )
354373 writewave (kettleID )
355374
0 commit comments