pi3d: TextBlock data input failure

2 posts
by AshPowers » Wed May 10, 2017 2:46 am
While reading just a single byte of data sent from an Android through bluetooth serial, setting a variable in the data object to the received value, attempting to draw the textblock with that value fails with code 1:

I suspect some sort of data mismatch although not sure why, if so.

A check:
If I set the pterm data object to the inWaiting bytes value, it works just fine and the value on the screen shows when anything has been received.

If I ## out all of the newtext..... to .... text.add, the program doesn't bomb out, but obviously it doesn't display any data on the screen either.

In a terminal program receiving bytes from the Android, the data comes through as expected.. Numbers pressed on the phone come out as numbers in the terminal, letters are letters, etc. The Android by default uses the UTF-8 encoding as well.

Code: Select all
class EgClass(object):
  pterm = 0
eg_object = EgClass()

BACKGROUND_COLOR = (0.0, 0.0, 0.0, 1.0)
DISPLAY = pi3d.Display.create(background=BACKGROUND_COLOR)
HWIDTH, HHEIGHT = DISPLAY.width / 2.0, DISPLAY.height / 2.0

QWIDTH = HWIDTH/2 # quarter width
shader = pi3d.Shader("uv_flat")
flatsh = pi3d.Shader("uv_flat")

#CAMERA = pi3d.Camera.instance()
CAMERA = pi3d.Camera(is_3d=False)
pointFont = pi3d.Font('fonts/ethnocentric.ttf', font_colourwhite, codepoints=list(range(32,128)))

text = pi3d.PointText(pointFont, CAMERA, max_chars=200, point_size=86)

newtext = pi3d.TextBlock(-70, 70, 0, 0.0, 15, data_obj=eg_object, attr="pterm",
    text_format="{:4.0f}", size=0.50, spacing="C", space=.7,
    colour=(.733, .812, .776, 1.0))

while DISPLAY.loop_running():
if btcon == True:
      conn = serial.Serial("/dev/rfcomm0", baudrate=9600)
      btdatabytes = conn.inWaiting()
      if btdatabytes == 1:
         btdata = conn.read(btdatabytes)
         eg_object.pterm = btdata

Posts: 65
Joined: Thu Apr 20, 2017 12:10 am
Location: Ormond Beach, FL
by AshPowers » Wed May 10, 2017 5:12 am
Problem Solved:

The issue is in the formatting within the TextBlock definition. Characters coming from the phone are strings and the formatting in the TextBlock was expecting integer values.

text_format="{:4.0f}", size=0.50, spacing="C", space=.7,
Posts: 65
Joined: Thu Apr 20, 2017 12:10 am
Location: Ormond Beach, FL