Page 1 of 1

4x20 LCD display, change names of day of week

Posted: 13 Sep 2019, 19:34
by mackowiakp
I try to display name on day of week in my language. Because of that I use such rule:

Code: Select all

On UpdateDisplay Do
 if %sysyear% > 2000 
  Let,1,0 
  Let,2,%sysweekday%
  if %v2% = 1
   LCD,1,1,%systm_hm% Niedz %sysday%/%sysmonth_0%/%sysyears%
  else
  if %v2% = 2
   LCD,1,1,%systm_hm% Pon. %sysday%/%sysmonth_0%/%sysyears%
  else
  if %v2% = 3
   LCD,1,1,%systm_hm% Wt. %sysday%/%sysmonth_0%/%sysyears%
  else
  if %v2% = 4
   LCD,1,1,%systm_hm% Sr. %sysday%/%sysmonth_0%/%sysyears%
  else
  if %v2% = 5
   LCD,1,1,%systm_hm% Czw. %sysday%/%sysmonth_0%/%sysyears%
  else
  if %v2% = 6
   LCD,1,1,%systm_hm% Pt. %sysday%/%sysmonth_0%/%sysyears%
  else
  if %v2% = 7
   LCD,1,1,%systm_hm% Sob. %sysday%/%sysmonth_0%/%sysyears%
  endif
  endif
  endif
  endif
  endif
  endif
  endif
  Let,1,1
 Endif
EndOn
But it does not work. Does anybody has an idea why?

Re: 4x20 LCD display, change names of day of week

Posted: 13 Sep 2019, 19:37
by TD-er
That's a lot of endif statements.
Have you tried with just one layer?
So many endif statements looks like it may be quite a number of levels deep, but the else statement tells it should be all in the same level.

Re: 4x20 LCD display, change names of day of week

Posted: 13 Sep 2019, 19:45
by mackowiakp
OK,then what do you suggest? I don't really know how to do it in the same level.

Re: 4x20 LCD display, change names of day of week

Posted: 13 Sep 2019, 19:50
by TD-er
Well, let's summon the Rules master @Grovkillen then :)

Re: 4x20 LCD display, change names of day of week

Posted: 13 Sep 2019, 19:56
by mackowiakp
OK. I sent him PM.

Re: 4x20 LCD display, change names of day of week

Posted: 13 Sep 2019, 22:17
by grovkillen
Nested if's aren't allowed. And %variable% isn't always treated as a float but as a string and try to always use the [VAR#n] syntax to make it transfer into a float.

So.... try this instead:

Code: Select all

On UpdateDisplay Do
  Let,2,%sysweekday%
  if [VAR#2] = 1
   LCD,1,1,%systm_hm% Niedz %sysday%/%sysmonth_0%/%sysyears%
  EndIf
  if [VAR#2] = 2
   LCD,1,1,%systm_hm% Pon. %sysday%/%sysmonth_0%/%sysyears%
  EndIf
  if [VAR#2] = 3
   LCD,1,1,%systm_hm% Wt. %sysday%/%sysmonth_0%/%sysyears%
  Endif
  if [VAR#2] = 4
   LCD,1,1,%systm_hm% Sr. %sysday%/%sysmonth_0%/%sysyears%
  EndIf
  if [VAR#2] = 5
   LCD,1,1,%systm_hm% Czw. %sysday%/%sysmonth_0%/%sysyears%
  EndIf
  if [VAR#2] = 6
   LCD,1,1,%systm_hm% Pt. %sysday%/%sysmonth_0%/%sysyears%
  EndIf
  if [VAR#2] = 7
   LCD,1,1,%systm_hm% Sob. %sysday%/%sysmonth_0%/%sysyears%
  Endif
EndOn


Re: 4x20 LCD display, change names of day of week

Posted: 14 Sep 2019, 06:45
by mackowiakp
Thanks @grovkillen ! Works as it should work. But I think about little improvement of this code. Bit complicated procedure of if/else statements is done every minute. I mean complicated because of limited processor capabilities. In fact running such procedure is necessary only after boot and first NTP sync and at midnight. Then LCD command executed every minute should have syntax something like this:

Code: Select all

LCD,1,1,%systm_hm% %day_of_week_name% %sysday%/%sysmonth_0%/%sysyears%
So my question is. Is it possible to assign text string to any user variable and use it in LCD command instead of explicit text string?

Re: 4x20 LCD display, change names of day of week

Posted: 14 Sep 2019, 07:03
by grovkillen
No strings are allowed, only floats. You may want to ask for an implementation to convert an integer to day/month which would be the nicest way about it.

Re: 4x20 LCD display, change names of day of week

Posted: 14 Sep 2019, 07:07
by mackowiakp
OK. Well, everything has its limits.

Re: 4x20 LCD display, change names of day of week

Posted: 14 Sep 2019, 09:00
by grovkillen
You could store the day number at the end of each if and look at it first thing. If it's the same value you don't need to check all the ifs. That way over once per day the unit has to go through them all.

Re: 4x20 LCD display, change names of day of week

Posted: 14 Sep 2019, 09:18
by mackowiakp
Good idea !

Re: 4x20 LCD display, change names of day of week

Posted: 14 Sep 2019, 09:19
by grovkillen
So if the value is not the same, send it to a custom event and have all the ifs there.