Is there a P2 PST guide
Ludis
Posts: 69
in Propeller 2
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
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
...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"
As always. Thanks for your time and help.
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