How to correctly set up input / output pins in a plugin (changes during the last few months)?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
reinhold
Normal user
Posts: 15
Joined: 19 Jun 2017, 22:52
Location: Vienna, Austria
Contact:

How to correctly set up input / output pins in a plugin (changes during the last few months)?

#1 Post by reinhold » 25 May 2019, 22:58

Hello,
I'm currently trying to update a plugin to the latest espeasy mega branch. My plugin (P198_Venta) uses 6 input pins and 3 output pins.

Last year, I was simply using the following code (stripped down to a minimal example) in PLUGIN_INIT:

Code: Select all

        pinMode(cfg.pwr_led, INPUT); // PWR LED
        pinMode(cfg.pwr_btn, OUTPUT); // Power Button
        attachInterrupt(digitalPinToInterrupt(cfg.pwr_led), Plugin_198_ISR, CHANGE);
        setPinState(PLUGIN_ID_198, cfg.pwr_btn, PIN_MODE_OUTPUT, 0); // Power Button
and in PLUGIN_WRITE:

Code: Select all

        digitalWrite(pin, state);
        setPinState(PLUGIN_ID_198, pin, PIN_MODE_OUTPUT, state);
        SendStatus(event->Source, getPinStateJSON(SEARCH_PIN_STATE, PLUGIN_ID_198, pin, log, 0));
These code snippets were basically taken from the P001_Switch plugin and worked quite well so far.

However, now the above code does not compile any more, so I looked at the P001_Switch plugin again. These code parts appear to be much more complicated now with createKey, globalMapPortStatus, assigning all fields of a portStatusStruct and calling savePortStatus.

So, my questions are:
- Is there any documentation about how to correctly setup input/output pins and how to correctly read input pins and set output pins?
- If not, which parts of the P001_Switch are really required for espeasy to function properly, and which parts of PLUGIN_INIT and PLUGIN_WRITE can be removed. As I have 9 pins to set up, doing everything the switch plugin does in PLUGIN_INIT for one single pin would result in several hundreds of lines of code...


Unfortunately, the git log of the commit that removed setPinState (fda673ce9db2638a551a2c75c533c3dd47e22e73 on Nov 19, 2018) does not give any indication about possible replacements for setPinState...

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

Re: How to correctly set up input / output pins in a plugin (changes during the last few months)?

#2 Post by TD-er » 28 May 2019, 10:27

I guess P001 is not the best choice to look at for inspiration.
Why do you need to set the pin state for your plugin?
It was used to keep track of pins that could be shared among plugins.

reinhold
Normal user
Posts: 15
Joined: 19 Jun 2017, 22:52
Location: Vienna, Austria
Contact:

Re: How to correctly set up input / output pins in a plugin (changes during the last few months)?

#3 Post by reinhold » 28 May 2019, 11:55

Thanks for the confirmation.

Yesterday night, I took another look at my code and at the P001_Switch code. I also suspected that these data structures are not really required for the plugin itself to work properly, so I tried removing all traces of them (https://github.com/letscontrolit/ESPEas ... d/pull/135). And voilá, my P198_Venta plugin still worked.

In my Venta project (http://wiki.kainhofer.com/hardware/venta_connected) I'm using basically all available pins of the esp8266 anyway, so I suppose keeping track of the pin states for sharing among plugins is really not required for my case.

Best regards,
Reinhold

Post Reply

Who is online

Users browsing this forum: No registered users and 49 guests