Extending toggle procedure to boolean

  • 1
  • 2
  • 3
  • Page 1 of 3
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1372
Registered: 03 / 2005
Subject:

Extending toggle procedure to boolean

 · 
Posted: 06.03.2019 - 12:12  ·  #1
Toggle( x ) applies to byte, bits and bitfields. Other structures including boolean are prohibited. I would like to see toggle( boolean ) implemented. I would be happy for it to be identical to toggle(byte).
Lschreyer
Schreiberling
Avatar
Gender: n/a
Posts: 526
Registered: 02 / 2007
Subject:

Re: Extending toggle procedure to boolean

 · 
Posted: 13.03.2019 - 09:45  ·  #2
I wrote a

procedure toggleb(b: Boolean);
begin
if b then
b:=false;
else
b:=true;
endif;
end;

to do just that :-)
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: Extending toggle procedure to boolean

 · 
Posted: 13.03.2019 - 14:05  ·  #3
Oder
b:= Not b;

Aber was solls. Toggle(boolean) ist jetzt implementiert!
Sie readme File
rolf
Gunter
Administrator
Avatar
Gender:
Location: Frankfurt Main / Germany
Posts: 1697
Registered: 02 / 2003
Subject:

Re: Extending toggle procedure to boolean

 · 
Posted: 13.03.2019 - 17:34  ·  #4
oder letztlich nix weiter als ein
b := b XOR $FF

Gunter
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1372
Registered: 03 / 2005
Subject:

Re: Extending toggle procedure to boolean

 · 
Posted: 30.04.2019 - 14:33  ·  #5
Hi Gunter.

I wasn't meaning to ask to toggle byte - I thought that was already there (I misread the manual).

Often I have something like

Code
var
MyVar[@MyByte, 3] : bit


and then in several places

Code

Toggle(MyVar);


I had occasion to redefine my bits as boolean by redefining MyVar as
Code
var
MyVar : boolean


For the most part that was all I needed to do, because largely bit and boolean are treated the same, but

Code

Toggle(MyVar);


was not valid. Hence my request.
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: Extending toggle procedure to boolean

 · 
Posted: 30.04.2019 - 14:58  ·  #6
Hello Merlin
a BIT is handled more as a Funktion than a simple VAR. This makes it impossible for using the toggle Funktion.
rolf
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1372
Registered: 03 / 2005
Subject:

Re: Extending toggle procedure to boolean

 · 
Posted: 30.04.2019 - 16:35  ·  #7
Hello Rolf.

Sorry, I don't understand. I use toggle with bits all the time.

E.g. from actual code:

Code
var
  External_Watchdog [ @PortG, 4 ] : bit;

...

  Toggle( External_Watchdog );




Ahhh... you mean the BIT( var, n) function. No I did not mean that.
Harry
Moderator
Avatar
Gender:
Location: zwischen Augsburg und Ulm
Age: 59
Posts: 2078
Registered: 03 / 2003
Subject:

Re: Extending toggle procedure to boolean

 · 
Posted: 10.05.2019 - 22:43  ·  #8
Hi Rolf,

ich hab grad eben
Code

    If DispInvDo=true
      then
        DispInvDo:=false;
        Toggle(DispInv);
        SetMode(DispInv);
      EndIf;

getestet und es funktioniert nicht.

So geht es aber:
Code

    If DispInvDo=true
      then
        DispInvDo:=false;
        If DispInv=true
          then
            DispInv:=false;
          else
            DispInv:=true;
          EndIf;
        SetMode(DispInv);
      EndIf;


Mit deinem, wie oben geschrieben
Code

DispInv:=not DispInv;

funktioniert es auch.

XMega256A3U
Version 5.10.01

Gruss
Harry
  • 1
  • 2
  • 3
  • Page 1 of 3
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 15 · Cache Hits: 14   137   151 · Page-Gen-Time: 0.023819s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI