Arithmetic in GPIO command with dummy values [solved]

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
mrh_icb
Normal user
Posts: 11
Joined: 08 Oct 2020, 04:15

Arithmetic in GPIO command with dummy values [solved]

#1 Post by mrh_icb » 27 Nov 2020, 04:48

I have a simple rule which sets 2 GPIOs to opposite polarity.
I am using a dummy device CFG with a value inv0 to configure the polarity, like this:

Code: Select all

gpio 0,1-[CFG#inv0]
gpio 2,[CFG#inv0]
CFG#inv0 is either 0 or 1, The second GPIO command works as expected, however the expression in the first GPIO command always evaluates to 1. I also tried brackets. What could be the problem?
Last edited by mrh_icb on 29 Nov 2020, 20:08, edited 2 times in total.

mrh_icb
Normal user
Posts: 11
Joined: 08 Oct 2020, 04:15

Re: Arithmetic with dummy values

#2 Post by mrh_icb » 27 Nov 2020, 05:05

Here is corresponding log output. CFG#inv0 was 1, so I'd expect GPIO-0 to be set to 0, but it ended up a 1:

Code: Select all

15473617: ACT : gpio 0,1-1
15473619: GPIO : port#0: set to 1
15473622: ACT : gpio 2,1
15473624: GPIO : port#2: set to 1
15473710: SW : GPIO=0 State=1 Output value=1
15473746: SW : GPIO=2 State=1 Output value=1

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Arithmetic with dummy values

#3 Post by grovkillen » 27 Nov 2020, 06:46

Code: Select all

gpio 0,(1-[CFG#inv0])
gpio 2,[CFG#inv0]
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Arithmetic with dummy values

#4 Post by TD-er » 27 Nov 2020, 15:04

See also documentation examples for doing these kind of simple operations by simply formatting the data.
https://espeasy.readthedocs.io/en/lates ... red-values

Code: Select all

[!CFG#inv0] // Added ! at the start

mrh_icb
Normal user
Posts: 11
Joined: 08 Oct 2020, 04:15

Re: Arithmetic with dummy values

#5 Post by mrh_icb » 28 Nov 2020, 00:27

Thanks for the replies, I tried both but neither worked:

With CFG#inv0=0, The first solution gave me:

Code: Select all

gpio 0,(1-[CFG#inv0])

log:
84991164: ACT : gpio 0,(1-0)
84991166: GPIO : port#0: set to 0
The second solution gave me:

Code: Select all

gpio 0,[!CFG#inv0]

log:
85147628: ACT : gpio 0,
85147630: GPIO : port#0: set to 0
Maybe the gpio command does support evaluation terms in the value argument. (I am using mega-20201022)

mrh_icb
Normal user
Posts: 11
Joined: 08 Oct 2020, 04:15

Re: Arithmetic with dummy values

#6 Post by mrh_icb » 28 Nov 2020, 01:03

I had a look at the source code, and wow, there was this little bugger:

Code: Select all

  // Only if TmpStr starts with '=' then call Calculate(). Otherwise do not call it
  if (TmpStr[0] != '=') {
    returnValue = str2int(TmpStr);
  } else {
So the following works:

Code: Select all

gpio 0,=1-[CFG#inv0]

log:
87328352: ACT : gpio 0,=1-1
87328354: GPIO : port#0: set to 0
Would be good to document this in the wiki!

Post Reply

Who is online

Users browsing this forum: No registered users and 36 guests