Need a Par4 int in the Event struct? (MY9291 / AI Light plugin)

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Justblair
Normal user
Posts: 63
Joined: 08 Aug 2016, 23:42

Need a Par4 int in the Event struct? (MY9291 / AI Light plugin)

#1 Post by Justblair » 20 Apr 2017, 15:47

Hi there. I am writing a plugin that hopefully will control a MY9291 equipped rgbw light bulb

I have been looking at the Neopixel plugin for inspiration and I have a rough idea how it is working. I thought I would ask this question here though, in case I am heading in the wrong direction.

I can see the event struct has 3 integers Par1, Par2, Par3 which as far as I can see allow values to be passed into plugins.

Code: Select all

struct EventStruct
{
  byte Source;
  byte TaskIndex; // index position in TaskSettings array, 0-11
  byte ControllerIndex; // index position in Settings.Controller, 0-3
  byte ProtocolIndex; // index position in protocol array, depending on which controller plugins are loaded.
  byte NotificationIndex; // index position in Settings.Notification, 0-3
  byte NotificationProtocolIndex; // index position in notification array, depending on which controller plugins are loaded.
  byte BaseVarIndex;
  int idx;
  byte sensorType;
  int Par1;
  int Par2;
  int Par3;
  int Par4;
  byte OriginTaskIndex;
  String String1;
  String String2;
  byte *Data;
};
This would be enough if all i needed to pass to the plugin was RGB values. But I want to pass RGBW.

I sat and wrote (untested so far) some code and I modified to the struct to add an extra integer Par4. I then changed the misc.ino file to add the Par4 to the parseCommandString function.

Code: Select all

void parseCommandString(struct EventStruct *event, String& string)
{
  char command[80];
  command[0] = 0;
  char TmpStr1[80];
  TmpStr1[0] = 0;

  string.toCharArray(command, 80);
  event->Par1 = 0;
  event->Par2 = 0;
  event->Par3 = 0;
  event->Par4 = 0;

  if (GetArgv(command, TmpStr1, 2)) event->Par1 = str2int(TmpStr1);
  if (GetArgv(command, TmpStr1, 3)) event->Par2 = str2int(TmpStr1);
  if (GetArgv(command, TmpStr1, 4)) event->Par3 = str2int(TmpStr1);
  if (GetArgv(command, TmpStr1, 5)) event->Par4 = str2int(TmpStr1);
}
It was at this point I realised that the author of the neopixel had faced the same issue, and had instead of attempting to modify the event struct, had instead created Par4 and Par5 integers within the plugin itself. Is this a better way to achieve this? I am guessing it was done this way because changing the event struct was going to break something else in the code?

Here is my code: https://github.com/Justblair/ESPEasy
This is the library I am using for the MY9291 https://github.com/xoseperez/my9291

Justblair
Normal user
Posts: 63
Joined: 08 Aug 2016, 23:42

Re: Need a Par4 int in the Event struct? (MY9291 / AI Light plugin)

#2 Post by Justblair » 21 Apr 2017, 23:25

OK....

So I have compiled the code, adding Par4 the way I have suggested.... And I have it working through the http interface.

Cant see any issues with adding the Par4 as before. Can anyone tell me if I have missed something here?

Justblair
Normal user
Posts: 63
Joined: 08 Aug 2016, 23:42

Re: Need a Par4 int in the Event struct? (MY9291 / AI Light plugin)

#3 Post by Justblair » 26 Apr 2017, 13:21

As far as i can see this adds no issues. I have submitted a pull request to add Par4 and Par5 to the eventStruct.

I have not adjusted the neopixel plugin yet (got a house move going on at the moment). But when I find an led to test I will submit a pull for that as well.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 21 guests