Shop OBEX P1 Docs P2 Docs Learn Events
Is there a P2 PST guide — Parallax Forums

Is there a P2 PST guide

Hello,

Is there any guide or for P2 PST coding? How to display dec, binary, text, formats.. etc. Coming from the P1.

I was able to get this code working from various code examples but struggling to find a comprehensive list of code examples or capabilities.

repeat
      term.tx(term.HOME)
      term.fstr0(string("PINREAD TESTING \r\r"))
      term.fstr1(string("input1 %f \r"),  input1)
      term.fstr1(string("input2 %f \r"),  input2)
      term.fstr1(string("input3 %f \r"),  input3)
      term.fstr1(string("input4 %f \r"),  input4)
      waitms(10)

Thanks

Comments

  • JonnyMacJonnyMac Posts: 9,158
    edited 2021-07-31 16:51

    PST is just a terminal. It does have a few control constants, but nothing having to do with formatting -- that is up to the application. It looks like you may be using jm_fullduplexserial.spin2, which uses jm_nstr.spin2 to help with numeric formatting. The best thing to do is put the code into summary mode and scan the method names, then double-click on what interests you to read the documentation comments. There is a con block with details about using formatting strings. I did my best to follow conventions used by other languages. Unfortunately, we don't have method overloading, hence the fstr1, fstr2, fst3, etc. methods.

    The latest code from my system is attached. If found a couple gotchas when working with a serial LCD.

    The %f formatter is used to treat an integer like a fixed point number. If x is 12345, then this line

      term.fstr1(string("$%.2f\r"), x)
    

    ...would print $123.45 and a carriage return. In PST, a linefeed is added to a carriage return.

    Also note: some of my methods differ from Chip's original fullduplexserial. Again, scan the comments in the listing; I have tried to document differences.

  • @JonnyMac

    Yes I am using your jm_fullduplexserial.spin2. Thanks for clarifying about both files. Making more sense. I have been reviewing the file more closely in summary mode. I see a lot of the similar outputs from P1 for binary "bin(value)"and decimal "dec(value)" outputs. I can replace pst.newline from P1 with a blank string using /r. I think i'm pretty close to having the same capability i did on the P1. Still reviewing the file in more detail.

    I do have one question regarding fstr2-6. May I ask if you could provide a one line code that provides an example how to use fstr2?

    arg1 = 15
    arg2 = 1

    I don't understand how multiple arguments are used. Is it intended to be used something like this?
    "The value 15 in binary is 1111 and in hex is 0F and the value 1 in binary is 0001 and in hex is 01"

    fstr2(string("The value 15 in binary is %.4b and in hex is %.2x and the value 1 in binary is %.4b and in hex is %.1x"), arg1, arg2) 
    
    {{
        Escaped characters
    
          \\          backslash char
          \%          percent char
          \q          double quote
          \b          backspace
          \t          tab (horizontal)
          \n          new line (vertical tab)
          \r          carriage return
          \nnn        arbitrary ASCII value (nnn is decimal)
    
        Formatted arguments
    
          %w.pf       print argument as decimal width decimal point
          %[w[.p]]d   print argument as decimal
          %[w[.p]]u   print argument as unsigned decimal
          %[w[.p]]x   print argument as hex
          %[w[.p]]o   print argument as octal
          %[w[.p]]q   print argument as quarternary
          %[w[.p]]b   print argument as binary
          %[w]s       print argument as string
          %[w]c       print argument as character (
    
                      -- w is field width
                         * positive w causes right alignment in field
                         * negative w causes left alignment in field
                      -- %ws aligns s in field (may truncate)
                      -- %wc prints w copies of c
                      -- p is precision characters
                         * number of characters to use, aligned in field
                           -- prefix with 0 if needed to match p
                           -- for %w.pf, p is number of digits after decimal point
    }}
    

    As always. Thanks for your time and help.

  • JonnyMacJonnyMac Posts: 9,158
    edited 2021-08-02 18:31

    I don't understand how multiple arguments are used. Is it intended to be used something like this?

    Yes. In standard Spin we don't have method overloading which is why there is separately named methods for different number of arguments.

    What I tried to do is mimic -- to a degree -- the features of C's printf() function. Some features are different (%f, for example). You might find the attached program helpful. I used this for testing the formatting features.

  • perfect. this is very helpful. Got it! Thanks

Sign In or Register to comment.