Author Topic: How to read field from drawTextField  (Read 170 times)

dal

  • RFduino Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
How to read field from drawTextField
« on: October 15, 2017, 07:39:43 AM »
Hi

This should be simple but I can't figured out how to get value of text field from drawTextField?

Dal

tolson

  • Global Moderator
  • *****
  • Posts: 870
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: How to read field from drawTextField
« Reply #1 on: October 15, 2017, 10:41:56 AM »
Show us how you are trying to do it.

Are you trying to read back what you already outputed to a textfield?
Or are you trying to get input via a text box?

Basics are...

uint8_t myTextFieldID = drawTextField(myX, myY, myW, myNumeral);
or
uint8_t myTextFieldID = drawTextField(myX, myY, myW, myText*);

When the field is changed on the smart device the ui_event callback is triggered.
If it was the textField that changed store it's value in a global if you want to use it elsewhere.

char myTextFieldBuffer[myTextFieldBufferSIZE];

void ui_event(event_t &event)
{

  if( event.id == myTextFieldID}
    {
      strcpy(myTextFieldBuffer,  event.text);
    }

}

 OR for numerals
int16_t myTextFieldNumeral;

void ui_event(event_t &event)
{

  if( event.id == myTextFieldID}
    {
      myTextFieldNumeral = event.value;
    }

}

Or some such!
« Last Edit: October 15, 2017, 11:39:30 AM by tolson »

dal

  • RFduino Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: How to read field from drawTextField
« Reply #2 on: October 15, 2017, 11:04:41 AM »
Hi

It is very simple, I have text field and send button.


    colorCodeText = SimbleeForMobile.drawTextField(leftMargin, topMargin, 110, "","Enter Color Code");
    toSendButtonID = SimbleeForMobile.drawButton(120, 500, 90, "Send");


No I would like to get value of text that user entered on mobile app once Send button is pressed.
I  tried to use event.text but this event is generated on Button not TextField!!

    if ((event.id == toSendButtonID) && (event.type == EVENT_PRESS))
    {
        // How to get value of Text Field????
    }

Dal

tolson

  • Global Moderator
  • *****
  • Posts: 870
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: How to read field from drawTextField
« Reply #3 on: October 15, 2017, 11:46:27 AM »
 To send the text field you have to hit enter in the text field in order to trigger the ui_event callback for the text field.

So, you enter in the data into your text field. Hit enter in the text field. The number gets sent to the ui_event callback where you will store it somewhere until you need it. You can then use your SEND button to initiate whatever routine you want to use to do something with the stored number/text.

« Last Edit: October 15, 2017, 11:48:50 AM by tolson »

dal

  • RFduino Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: How to read field from drawTextField
« Reply #4 on: October 15, 2017, 05:11:57 PM »
Hi

That helps, that was missing link, I did not press enter just Send button!

Thanks for help.
Dal