Shop OBEX P1 Docs P2 Docs Learn Events
Prop Backpack overlay question — Parallax Forums

Prop Backpack overlay question

SeekerSeeker Posts: 58
edited 2013-03-05 19:17 in Propeller 1
I am using the Prop Backpack as a standalone board to read a few sensors and overlay the variables and some text on a screen with a live video feed. I can get the overlay to work fine if I am outputting strings, but I can't figure out how to output an integer variable (bytes, words and longs). I have read through the docs and through posts in the forum but can't seem to find the info.

Of course the search function in the forum is not the best so I might have missed it. ;)

But I swear I have looked... so now I am asking... is there a way to display variables when using the Prop Backpack as a standalone board to overlay onto a video source?

Thanks!

Comments

  • John AbshierJohn Abshier Posts: 1,116
    edited 2013-03-05 16:57
    In the Propeller library that comes with the Prop Tool is a file numbers.spin that will convert longs to strings. Sign Extend 7 and Sign Extend 15 will convert byte and words to longs (page 156 of the manual. Numbers.spin is a Swiss army knife object. If you search for number to string (I use Google instead of the forum's search "site:forums.parallax.com number to string" returns 13k results) you may find something simpler.

    John Abshier
  • SeekerSeeker Posts: 58
    edited 2013-03-05 17:04
    Great! That should work.

    I wasn't sure if there was something in the built-in code I could use... I had a feeling there wasn't. But numbers.spin sounds like it will do the job.

    And thanks for the quick answer. Now I just have to do a bit of preening to keep the memory footprint down, or compile with BST...
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-03-05 17:15
    I didn't see an easy way of displaying numbers in the my copy of the overlay object.

    You should be able to use a "Dec" method from one of the serial objects to output numbers.

    Here's PST's Dec method adapted for the Backpack.
    PUB Dec(value) | i, x{{Send value as decimal characters.
      Parameter:
        value - byte, word, or long value to send as decimal characters.}}
    
    
      x := value == NEGX                                                            'Check for max negative
      if value < 0
        value := ||(value+x)                                                        'If negative, make positive; adjust for max negative
        print("-")                                                                   'and output sign
    
    
      i := 1_000_000_000                                                            'Initialize divisor
    
    
      repeat 10                                                                     'Loop for 10 digits
        if value => i                                                               
          print(value / i + "0" + x*(i == 1))                                        'If non-zero digit, output digit; adjust for max negative
          value //= i                                                               'and digit from value
          result~~                                                                  'flag non-zero found
        elseif result or i == 1
          print("0")                                                                 'If zero digit (or only digit) output it
        i /= 10                                                                     'Update divisor
    
    
    

    Just paste the above method into the overlay object. I haven't tested it but I'm bet a QuickStart label it works.

    It assumes there's a method "print" that allows characters to be displayed on the overlay. The above code should also work if the method "out" is used instead of "print".
  • SeekerSeeker Posts: 58
    edited 2013-03-05 17:42
    Duane Degn wrote: »
    I didn't see an easy way of displaying numbers in the my copy of the overlay object.

    You should be able to use a "Dec" method from one of the serial objects to output numbers.

    Here's PST's Dec method adapted for the Backpack.
    PUB Dec(value) | i, x{{Send value as decimal characters.
      Parameter:
        value - byte, word, or long value to send as decimal characters.}}
    
    
      x := value == NEGX                                                            'Check for max negative
      if value < 0
        value := ||(value+x)                                                        'If negative, make positive; adjust for max negative
        print("-")                                                                   'and output sign
    
    
      i := 1_000_000_000                                                            'Initialize divisor
    
    
      repeat 10                                                                     'Loop for 10 digits
        if value => i                                                               
          print(value / i + "0" + x*(i == 1))                                        'If non-zero digit, output digit; adjust for max negative
          value //= i                                                               'and digit from value
          result~~                                                                  'flag non-zero found
        elseif result or i == 1
          print("0")                                                                 'If zero digit (or only digit) output it
        i /= 10                                                                     'Update divisor
    
    
    

    Just paste the above method into the overlay object. I haven't tested it but I'm bet a QuickStart label it works.

    It assumes there's a method "print" that allows characters to be displayed on the overlay. The above code should also work if the method "out" is used instead of "print".

    Actually, this was my original fallback plan... or something similar. I had looked at the PST code briefly and thought I could adapt it if I had to.

    I will try both and see what works best.

    Thanks again to both of you!

    And I am still open to any other suggestions if anyone has any. One thing I have learned is that there are many ways to accomplish the goal. Half the fun is finding the one you like best. And it is a GREAT learning experience.
  • SeekerSeeker Posts: 58
    edited 2013-03-05 19:17
    I tried both... but Duane, you owe me a Quickstart. :) I think the limitation is in the "print". It is just a "send literal string", not really a print. And "out" is a single character. More used for sending commands from what I can see. If I worked at it, I might get it figured out... but then I would need to figure out how to break up large numbers for better formatting.

    Numbers.spin seems like the best bet for me. I like that I can alter the format for larger numbers, and since I will be adding a GPS, this will come in handy. The only problem is it comes with a lot of "baggage". But in BST I can save 256 longs. If I edit it I am sure I can get that in the Prop tool too.
Sign In or Register to comment.