Announcement

Collapse
No announcement yet.

String manipulation

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mark Kevin
    replied
    Good day huy373!

    The solution to your question can be broken down to these steps:

    1.) Button is pressed (Report message)
    2.) Increase value of the variable
    3.) Display value as string using the write str function

    Here is a sample code that you can use to your project:

    Code:
    #include <genieArduino.h>
    #define RESETLINE 4 
    
    Genie genie;    //Create genie object
    
    int x = 0;
    
    void setup(){
      pinMode(RESETLINE, OUTPUT);    // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset)
      digitalWrite(RESETLINE, 1);    // Reset the Display via D4
      delay(100);
      digitalWrite(RESETLINE, 0);    // unReset the Display via D4
    
      delay (3500);    //let the display start up after the reset (This is important)
    
      genie.AttachEventHandler(myGenieEventHandler); // Attach the user function Event Handler for processing events
    
    }
    
    void loop() {
    
    genie.DoEvents(); // This calls the library each loop to process the queued responses from the display
    
    }
    
    void myGenieEventHandler(void)
    {
      genieFrame Event;
      genie.DequeueEvent(&Event); // Remove the next queued event from the buffer, and process it below
    
    //If the cmd received is from a Reported Event (Events triggered from the Events tab of Workshop4 objects)
      if (Event.reportObject.cmd == GENIE_REPORT_EVENT)
      {
        if (Event.reportObject.object == GENIE_OBJ_4DBUTTON)              // If the Reported Message was from a 4D BUTTON
        {
          if (Event.reportObject.index == 0)                              // Place the index number of the 4D button
          {
            x += 1;             // Increase the value of the variable
            genie.WriteStr(0, x);                // Write to the string, (0 is the index number of the string, x is the variable to be displayed)
          }
        }
      }
    You can study further the Visi-Genie through the examples that can be found inside the Arduino Library.
    The strings implementation and report event implementation can be found in the examples.

    App notes and other tutorials regarding our products can be found in this link, just select the Visi-Genie
    in the Environment tick-box:
    http://www.4dsystems.com.au/appnotes

    Thank you,
    Kevin

    Leave a comment:


  • huy373
    replied
    HELLO,
    i have a problem with string and button. I want every time i touch the screen, string will increase 1 unit. Could anyone please tell me how to do that?
    Here is my project. my problem is at form3.

    Thank you so much
    Attached Files

    Leave a comment:


  • JRM
    replied


    Thanks Dave. I'm sure I'll have plenty of questions in the near future. I'll make an effort not to hijack a thread like I did here though.

    Leave a comment:


  • meldavia
    replied


    Glad you got it going Jeff,
    was trying to find a bit of time to do you a demo but it looks like you have cracked it.

    'to(mystring)' in 4DGL is approx the same as sprintf(mystring, "xyz

    and all strings are word aligned and packed 2 bytes per var location which is confusing at first

    Leave a comment:


  • JRM
    replied


    I've been playing around with uCs off and on since '98 and just spent a couple of days feeling like it was day one. You would think one of you basteds would have quit laughing long enough to tell me I was barking up the wrong tree

    I'm not sure how I got it in my head that writing to a variable required the to() statement in Picaso but I sure explored that path thoroughly.





    I'm sure this snippet has errors but I'll post it anyway in case some other poor soul stumbles across this thread.



    HTML Code:
    #platform "uLCD-32PT_GFX2"
    #inherit 
    "4DGL_16bitColours.fnc"
    
    
    var combuf[20];
    func main()
    var 
    n,p,num,col, ch;
    
    
    repeat
    
    gfx_Cls();
    txt_Set(FONT_ID, FONT2);
    
    txt_Set(TEXT_COLOUR, BLUE);
    
    txt_MoveCursor(1,0);
    com_Init(combuf, 14, 'S' 
    );                         
    //Set Comm with qualifier
    
    
    
    repeat
    if 
    (com_Sync())                             
    // Check for 
    qualifier
    
    txt_Set(TEXT_COLOUR, 
    RED);
    
    txt_MoveCursor(3,1);
    
    putstr("Station 
    Reporting");
    
    endif
    
    
    
    txt_MoveCursor(5,1);
    
    print("Buffered ", ( com_Count() ));        
    // Debug 
    Bufffer
    
    pause(100);
    
    until(com_Full());                              
    // Shift characters in loop until full
    
    p:=str_Ptr(combuf);                                 
    //Now that Buf is full create pointer
    
    txt_MoveCursor(7,1);
    pause(100);
    
    //putstr(p);                                          
    //debug p - prints but clips leading two characters ???
    
    num:= 
    (str_GetByte(p+8));                           
    //Pluck reporting Station number from p
    col:= 
    (str_GetByte(p+12));                          
    //Pluck reporting station color from p.
    
    txt_MoveCursor(9,1);
    
    
    
    n := 
    15;                                            
    //loop count to shift characters for print.
    
    while(n--)
    if( (ch := serin()) 
    < 0) ch := 
    '';              
    //print
    
    putch(ch);
    wend
    
    
    
    
    com_Reset();                                        
    //Clear combuf
    txt_MoveCursor(11,1);
    
    print("Station # 
    ",[CHR]num);                       
    //Vars should not be cleared with reset. Prints 0
    
    txt_MoveCursor(13,1);
    print("Color= 
    ",[CHR]col);
    txt_MoveCursor(15,1);
    
    
    
    ch := 0;
    
    while (ch != 13)
    if ((ch := 
    serin()) != -1)
    
    endif
    wend
    
    gfx_Cls();
    txt_Set(FONT_ID, FONT2);
    
    txt_Set(TEXT_COLOUR, YELLOW);
    
    print("Resetting");
    pause(1000);
    forever
    
    endfunc

    Leave a comment:


  • JRM
    replied


    #platform "uLCD-32PT_GFX2"

    var buffer[100];
    var p,n,num,col;

    func main()
    to(buffer); print("Station #3 = Yellow");
    p:=str_Ptr(buffer);
    n:=0;

    while (n

    Leave a comment:


  • ESPsupport
    replied


    Hopefully something here will help you http://4d.websitetoolbox.com/post?id=5681797

    Leave a comment:


  • ESPsupport
    replied


    It's not clear what you are after.



    There are also some string usage examples in the codebase http://www.4dsystems.com.au/code/index.php?node=78

    Leave a comment:


  • JRM
    replied


    Was this issue ever resolved?



    I need to do the same thing and I'm not having much luck storing the buffered serin string as a variable. I can print what I receive but that doesn't help me use it.

    I need to be able to receive a string that varies between 16 and 19 characters, pluck the important parts out and do some stuff to the GPIO according to what is received.



    I've spent the day scanning through every page on this sub forum, the serial examples, the programmers reference, and the the internal fuctions. I don't think I'm any farther along than where I started. ~)



    I'm not asking anyone to do it for me, but good god I could use a shove in the right direction.



    Thanks in advance.

    Leave a comment:


  • jeffkop
    replied


    meldavia wrote: Might be easiest to use buffered comms, and when the count gets to 14 just start pulling them out of the buffer with serin and do whatever you need to do with them.

    Have a look at this example, it should help:-
    http://www.4dsystems.com.au/code/index.php?node=66&id=79

    Hi again Dave
    Ok I have looked through that example. Im fine with it but it doesnt provide an example of parsing the stream only printing the entire received stream.

    A question I have is about the putch command. If used and directed to a variable does it append the variable ???

    My guess is no, as the PDF says "prints single characters to the currently selected output stream" .

    The only criteria in parsing a data stream is one of these two:

    Select a byte and

    1. write it to a variable.
    2. append a variable.

    Is there an easy way to do this ???

    I have done it but Im positive there would be an easier way.

    Thank you

    JEff

    Leave a comment:


  • meldavia
    replied


    Might be easiest to use buffered comms, and when the count gets to 14 just start pulling them out of the buffer with serin and do whatever you need to do with them.

    Have a look at this example, it should help:-
    http://www.4dsystems.com.au/code/index.php?node=66&id=79

    Leave a comment:


  • jeffkop
    replied


    meldavia wrote: Oh I see I think, you are just working with numbers
    ,
    print ( "year ",[STR] curryear);
    print ( "month ",[STR] currmonth);
    print ( "day ",[STR] currday);
    the code above will print stored strings

    If your just working with raw numbers the code should be just

    var curryear;
    var currmonth;
    var currday;

    print ( "year ",curryear); - prints year 2011
    print ( "month ",currmonth); - prints month 08
    print ( "day ",currday); - prints day 02

    or

    print (currday, "/" ,currmonth,"/", curryear);


    If the numbers are HEX, try this

    print ( "year ",[HEX4] curryear); - prints year 2011
    print ( "month ",[HEX2]currmonth); - prints month 08
    print ( "day ",[HEX2]currday); - prints day 02



    Dave .. while I have your attention.
    The data stream is 14 bytes of raw numbers.
    I am selecting 9 elements from the stream.

    Some I have to turn into printable data, others I have to use as raw numbers.
    Obviously I have manged to do it but if I could bother you for 5 secs, how would you go about parsing the stream .. especially for the raw number information.

    I dont want you to do into this indepth.
    I see you suggest using variables without [x]
    So what code would you use for that .. eg ... strGetWord etc etc.
    Sorry for taking the easy way out here .. but believe me .. I have been at this for a week.
    This is my first integration of this product .. hopefully it gets easier from here

    Thanks for your interest

    Jeff

    Leave a comment:


  • ESPsupport
    replied


    Why does it print them perfectly as I parse them but then when I recall them they are wrong ????
    I think that's because you are corrupting memory... eg.

    consider a linear bytewise memory model where your variables are in memory like this

    address variable length
    0 year 2
    2 month 2
    4 day 2
    6 unused

    If you assigned "2011" to year and printed it, you would get "2011", but you would have corrupted Month and Day as memory would contain "2011n" where n is 0x00

    If then assigned "08" to month and printed it, you would get "08", but you would have corrupted Day and the entire memory would contain "2008n" where n is 0x00

    If then assigned "01" to day and printed it, you would get "01", but you would have corrupted the unused area, the entire memory would contain "200801n" where n is 0x00

    So, if you then printed with

    print ([STR]currday, "/" ,[STR]currmonth,"/", [STR]curryear);

    You would get what you got.

    Have a look at some of the string examples, hopefully it will make sense in a little while

    Leave a comment:


  • meldavia
    replied


    I see our posts crossed, glad you got it working

    Leave a comment:


  • meldavia
    replied


    Oh I see I think, you are just working with numbers
    ,
    print ( "year ",[STR] curryear);
    print ( "month ",[STR] currmonth);
    print ( "day ",[STR] currday);
    the code above will print stored strings

    If your just working with raw numbers the code should be just

    var curryear;
    var currmonth;
    var currday;

    print ( "year ",curryear); - prints year 2011
    print ( "month ",currmonth); - prints month 08
    print ( "day ",currday); - prints day 02

    or

    print (currday, "/" ,currmonth,"/", curryear);


    If the numbers are HEX, try this

    print ( "year ",[HEX4] curryear); - prints year 2011
    print ( "month ",[HEX2]currmonth); - prints month 08
    print ( "day ",[HEX2]currday); - prints day 02

    Leave a comment:

Working...
X