Jump to content

OLED 128x64 API. Conventional primitive functions.


JavaLaurence
 Share

Recommended Posts

I just checked the API, expecting to find a plot(x,y) as an absolute minimum, but couldn't find this.

 

To be honest, I think the following would be really appreciated by lots of people:

- plot(x,y)

- fillRect(x,y,w,h)

- clearRect(x,y,w,h)

- line(x1,y1, x2,y2)

 

Could Tinkerforge team please indicate whether these will be added at a later date, or should we tackle this ourselves?

 

Thanks!

 

  Laurence

Link to comment
Share on other sites

If I may express my opinion on this, I think Tinkerforge should be given a medal for supporting a broad variety of programming languages, and in so doing help people with possibly very little programming experience so far.

 

But it is exactly in this beginner-friendly approach that ultra low-level APIs don't fit. Experienced programmers can deal with APIs that expose little more than what the hardware natively exposes.. but that's a tough learning curve for a beginner.

 

Having to implement Bresenham's line drawing algorithm to obtain a drawLine(x,y, x,y) API is in my opinion not compatible with the whole rapid "tinker" philosophy.

Link to comment
Share on other sites

We will add more examples for the OLED API, they are already in the making. Let me explain this a bit more:

 

 

Each Bricklet has 4kb flash and 256 byte RAM to implement the API. So having a function like drawLine(xy, xy) on the Bricklet is simply not possible. Just saving the whole 128x64 image would use 1kb of RAM.

 

The fixed size 7x5 font that we provide already uses up 1.25kb of the available flash (https://github.com/Tinkerforge/oled-128x64-bricklet/blob/master/software/src/font.inc).

 

So it is technically just not possible to add much more API to the Bricklet.

 

 

Knowing the above, we obviously need to draw to a buffer on the PC and then transfer the buffer to the Bricklet.

 

Now again, it doesn't make any sense to implement an image draw API in all of the programming languages that we provide. Every high level language already has a image drawing library that is much better then anything we could provide.

 

So the way to go is to provide more complex examples for the languages that use image libraries which are native to the language, which is what we intend to do.

 

I hope this explanation makes it more understandable why the API is how it is.

 

For example the whole drawing code for this video (

) is this:

 

# Create angle text
angle_str = str(angle) + u'°'
if angle >= 0:
    angle_str = ' ' + angle_str

# Draw servo position line
img = Image.new('1', (128, 64), 0)
draw = ImageDraw.Draw(img)
draw.line(line_at_angle(32, 32, angle - 90, 32), 1, 6)

# Draw bar graph
draw.line((90, 4, 90 + angle*30//90, 4), 1, 6)

# Draw angle text
font = ImageFont.truetype("./share/fonts/truetype/dejavu/DejaVuSans.ttf", 25)
draw.text((70, 22), angle_str, font=font, fill=1)

# Move data from PIL image into matrix of bools
data = img.load()
pixel_matrix = [[False]*SCREEN_WIDTH for i in range(SCREEN_HEIGHT)]
for x in range(SCREEN_WIDTH):
    for y in range(SCREEN_HEIGHT):
        pixel_matrix[y][x] = data[x, y] == 1

 

After that the pixel_matrix is drawn to the display with the draw_pixel_matrix function that we have as an example for all of the available programming languages. This seems very much high level to me :D.

Link to comment
Share on other sites

Thanks for the explanation. Given the technical limitations, the current API does indeed make more sense. But if you do have half a K of spare flash, I think adding the plot(), fill() and clear() APIs would be very simple for you to add... and it would give people a way to avoid the complexity of an intermediate render on the host, as shown in your examples.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...