Page 1 of 1

RequestAMatrix Example Modifications

Posted: Wed Jan 06, 2021 2:34 pm
by tabear
I am trying to modify the example sketch and interface panel "RequestAMatrix" to be able to read char text values in one of the five textboxes and int’s in the other four textboxes. I have changed p1 to:

CurConfig [CurRow - 1].p1 = Parameters.NextParameter(CurConfig [CurRow - 1].p1);

But I get an error message in the arduino IDE:

no matching function for call to 'CommandParameter::NextParameter(char&)'

I have tried making several changes to add a function call to 'CommandParameter::NextParameter(char&)', but I continue to get the same error message. First, is it possible to do what I want (mix char text and int textboxes in the same interface panel? And second, how would I modify the example code to achieve my goal? I’ve been working on this for 3 days and can’t seem to get what I want. I’ve been able to add checkboxes and numeric up down boxes and can retrieve the data I need, but I just can’t seem to get the textbox working with char text. Somebody please try to lead me in the right direction.

Thanks

TABEAR

Re: RequestAMatrix Example Modifications

Posted: Fri Jan 08, 2021 9:05 pm
by philr
Hmm thats trickier. I think you would need to adjust the structure to have character arrays and then use pstring to print the remaining parameters into those buffers.

pstring library can be found here http://arduiniana.org/libraries/pstring/

Cheers
Phil

Re: RequestAMatrix Example Modifications

Posted: Sun Jan 10, 2021 5:50 am
by philr
Something like this..

PString P1(CurConfig[CurRow - 1].p1, sizeof(CurConfig[CurRow - 1].p1));
const char* NewValue = Parameters.NextParameter();
if (NewValue != NULL)
{
P1.print(NewValue);
}

Re: RequestAMatrix Example Modifications

Posted: Sat Jan 23, 2021 9:47 pm
by tabear
Hi philr

Thanks for your previous replys. I've spent the last 2 weeks reading up on Pstrings, structs, characters and Strings, but I still haven't been able to get the text from the matrix UI textbox to print out correctly. I'm able to request the text and it shows up in the monitor correctly, but I can't get the text to be available for the arduino or to print out. I can get numbers from numeric up/down and whether or not checkboxes and radio buttons are checked but I'm stuck on the text. I'm showing my sketch code below and have attached the UI file. Could someone look this over and tell me what I am doing wrong. I'm a hobbyist and a cut and paste code writer, so examples with explanation would be really helpful.

Thanks

TABEAR

Code: Select all

/* ************************************************************************
RequestAMatrix_modified
This program demonstrates how MegunoLink's Interface Panel and our command
handler Arduino library can be used to query a matrix of text boxes to retrieve
a configuration that can be used by the program to execute instructions.

The example folder also contains a MegunoLink project, with an Interface
Panel to update the variables.
Visit:
* http://www.MegunoLink.com to download MegunoLink.
This example requires:
* The PString library http://arduiniana.org/libraries/pstring/
* Our MegunoLink Arduino library https://www.megunolink.com/documentation/arduino-library/
************************************************************************ */

#include <MegunoLink.h>
#include <CommandHandler.h>
#include <ArduinoTimer.h>
#include <PString.h>

#define Rows 2

InterfacePanel MyPanel;
CommandHandler<> SerialCommandHandler;
ArduinoTimer RequestRowTimer;

// Structure to store the values sent from MegunoLink
struct Config {
  char* p1;
  int p2;
  int p3;
  byte p4;
  byte p5;
};

String NewValue = "";

int CurrentRow = Rows + 1; //Start at 5 so it doesn't request anything at startup
Config CurConfig[Rows]; //Create array to store each config row


/*----------------Command Hanlder Functions--------------------------*/
//This function processes the row data sent from MegunoLink.
void Cmd_GetProcessTableRow(CommandParameter &Parameters)
{
  int CurRow = Parameters.NextParameterAsInteger();
  if (CurRow != -1 && CurRow <= Rows)
  {
    CurConfig[CurRow - 1].p1 = Parameters.NextParameterAsInteger(CurConfig[CurRow - 1].p1);
    CurConfig[CurRow - 1].p2 = Parameters.NextParameterAsInteger(CurConfig[CurRow - 1].p2);
    CurConfig[CurRow - 1].p3 = Parameters.NextParameterAsInteger(CurConfig[CurRow - 1].p3);
    CurConfig[CurRow - 1].p4 = Parameters.NextParameterAsInteger(CurConfig[CurRow - 1].p4);
    CurConfig[CurRow - 1].p5 = Parameters.NextParameterAsInteger(CurConfig[CurRow - 1].p5);
  }
}

void Cmd_SetText(CommandParameter &Parameters)
{
  int CurRowText = Parameters.NextParameter();
  if (CurRowText != -1 && CurRowText <= Rows)
  {
    PString array(CurConfig[CurRowText - 1].p1, sizeof(CurConfig[CurRowText - 1].p1));
    String NewValue = Parameters.NextParameter();
    if (NewValue != NULL)
    {
      array.print(NewValue);
    }
  }
}
void Cmd_StartConfigTransfer(CommandParameter &Parameters)
{
  RequestParameters();
  CurrentRow = 1; //By setting current row to 1 it will begin requesting row data from MegunoLink
}

void Cmd_ShowParameters(CommandParameter &Parameters)
{
  DumpCurConfig();
}


/*----------------------Main Program---------------------------*/
void setup()
{
  Serial.begin(9600);

  Serial.println(F("  "));
  Serial.println(F("      MatrixTest"));
  Serial.println(F("========================="));
  
  SerialCommandHandler.AddCommand(F("Table"), Cmd_GetProcessTableRow);
  SerialCommandHandler.AddCommand(F("SetText"), Cmd_SetText);
  SerialCommandHandler.AddCommand(F("StartCfgXfer"), Cmd_StartConfigTransfer);
  SerialCommandHandler.AddCommand(F("ShowParameters"), Cmd_ShowParameters);
}

void loop()
{
  SerialCommandHandler.Process();

  // This rate limits the row requests to MegunoLink. One every 100mS. 
  // This prevents the microcontroller from being overwhelmed.
  if (RequestRowTimer.TimePassed_Milliseconds(100))
  {
    if (CurrentRow <= Rows)
    {
      char buffer1[10];
      PString array(buffer1, sizeof(buffer1)); //Initialise PString object
      array.print("GetText");
      array.print(CurrentRow);
      MyPanel.CallCommand(array); //This sends the request message
      
      char buffer[4];
      PString cmd(buffer, sizeof(buffer));
      cmd.print("G");
      cmd.print(CurrentRow);
      MyPanel.CallCommand(cmd); //This sends the request message
      CurrentRow++;
    }
  }
}

void RequestParameters()
{
  Serial.println(F("Requesting parameters"));
  MyPanel.CallCommand(F("GetText"));
}

// Print out all of the rows in the current config
void DumpCurConfig()
{
  Serial.print("Index");
  Serial.print("\tP1");
  Serial.print("\tP2");
  Serial.print("\tP3");
  Serial.print("\tP4");
  Serial.println("\tP5");
  for (int i = 0; i < Rows; i++)
  {
    Serial.print(i + 1); Serial.print("\t");
    Serial.print(NewValue[i]); Serial.print("\t");
    Serial.print(CurConfig[i].p2); Serial.print("\t");
    Serial.print(CurConfig[i].p3); Serial.print("\t");
    Serial.print(CurConfig[i].p4); Serial.print("\t");
    Serial.println(CurConfig[i].p5);
  }
}

Re: RequestAMatrix Example Modifications

Posted: Sat Jan 23, 2021 10:42 pm
by philr
Hi, here is an example showing how this could work.
RequestAMatrixString.zip
(14.65 KiB) Downloaded 133 times
In this I have replaced the last column with Name and included some sample names. Check it out and see if this helps you make progress.

Cheers
Phil

Re: RequestAMatrix Example Modifications

Posted: Sun Jan 24, 2021 2:03 pm
by tabear
Thanks philr for the very timely response. It worked perfectly when I rearranged per your RequestAMatrixString.zip file. Now I need to compare my original with my modified to figure out what I was doing wrong. Thanks again !

TABEAR