Skip to content

Commit 8d901bc

Browse files
committed
Update examples for new screen messages
1 parent c13afaf commit 8d901bc

File tree

8 files changed

+71
-36
lines changed

8 files changed

+71
-36
lines changed

examples/modules/eink/bitmaps.toit

Whitespace-only changes.

examples/modules/eink/element-bitmap.toit

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@ import lightbug.services as services
33
import lightbug.messages.messages_gen as messages
44
import lightbug.util.bitmaps show lightbug-20-20 lightbug-30-30 lightbug-40-40
55

6-
/**
7-
A simple application that demonstrates drawing bitmaps on the E-ink display.
8-
This example shows how to display a Lightbug logo.
9-
*/
106
main:
117
// This example is setup to work with the RH2 device
128
device := devices.RtkHandheld2
139

1410
print "💬 Sending bitmap logo to device screen"
15-
print "📷 Drawing 40x40 logo at (0,0)"
1611
device.comms.send (messages.DrawElement.msg
1712
--data=(messages.DrawElement.data
1813
--page-id=(random 10 255)

examples/modules/eink/element-bitmaps.toit

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,30 @@ main:
1111
// This example is setup to work with the RH2 device
1212
device := devices.RtkHandheld2
1313

14-
print "💬 Sending bitmap logo to device screen"
1514
page := (random 10 255)
16-
17-
print "📷 Drawing 40x40 logo at (0,0) top left"
18-
device.comms.send (messages.DrawElement.msg
19-
--data=(messages.DrawElement.data
20-
--page-id=page
21-
--status-bar-enable=false
22-
--redraw-type=messages.DrawElement.REDRAW-TYPE_CLEARDONTDRAW
23-
--x=0
24-
--y=0
25-
--width=40
26-
--height=40
27-
--type=messages.DrawElement.TYPE_BITMAP
28-
--bitmap=lightbug-40-40))
15+
screen-width := 250
16+
screen-height := 122
17+
bitmap-dimension := 40
18+
positions := [
19+
[messages.DrawElement.REDRAW-TYPE_CLEARDONTDRAW, 0, 0], // Top left
20+
[messages.DrawElement.REDRAW-TYPE_BUFFERONLY, (screen-width - 1 - bitmap-dimension), 0], // Top right
21+
[messages.DrawElement.REDRAW-TYPE_BUFFERONLY, 0, (screen-height - 1 - bitmap-dimension)], // Bottom left
22+
[messages.DrawElement.REDRAW-TYPE_FULLREDRAWWITHOUTCLEAR, (screen-width - 1 - bitmap-dimension), (screen-height - 1 - bitmap-dimension)], // Bottom right
23+
]
2924

30-
print "📷 Drawing a second 40x40 logo at (210,0) top right"
31-
device.comms.send (messages.DrawElement.msg
32-
--data=(messages.DrawElement.data
33-
--page-id=page
34-
--status-bar-enable=false
35-
--redraw-type=messages.DrawElement.REDRAW-TYPE_FULLREDRAW
36-
--x=209
37-
--y=0
38-
--width=40
39-
--height=40
40-
--type=messages.DrawElement.TYPE_BITMAP
41-
--bitmap=lightbug-40-40))
25+
print "💬 Sending bitmap logos to device screen"
26+
positions.do: | p |
27+
device.comms.send (messages.DrawElement.msg
28+
--data=(messages.DrawElement.data
29+
--page-id=page
30+
--status-bar-enable=false
31+
--redraw-type=p[0]
32+
--x=p[1]
33+
--y=p[2]
34+
--width=bitmap-dimension
35+
--height=bitmap-dimension
36+
--type=messages.DrawElement.TYPE_BITMAP
37+
--bitmap=lightbug-40-40))
4238

4339
// Continue running to keep the app alive
4440
while true:

examples/modules/eink/element-box-text.toit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ main:
1515
--type=messages.DrawElement.TYPE_BOX
1616
--x=0
1717
--y=0
18-
--text="Lightbug"))
18+
--text="Lightbug..."))
1919

2020
while true:
2121
sleep --ms=10000
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import lightbug.devices as devices
2+
import lightbug.services as services
3+
import lightbug.messages.messages_gen as messages
4+
5+
// A simple application that draws a simple bit of text on the E-ink display
6+
main:
7+
// This example is setup to work with the RH2 device
8+
device := devices.RtkHandheld2
9+
10+
page := (random 10 255)
11+
12+
while true:
13+
print "💬 Sending circle to device"
14+
size := (random 1 25)
15+
16+
device.comms.send (messages.DrawElement.msg
17+
--data=(messages.DrawElement.data
18+
--page-id=page
19+
--status-bar-enable=false
20+
--type=messages.DrawElement.TYPE_CIRCLE
21+
--x=(random 0 (250 - 1 - size)) - (size/2)
22+
--y=(random 0 (250 - 1 - size)) - (size/2)
23+
--width=size
24+
--height=size
25+
))
26+
sleep --ms=2000

examples/modules/eink/element-line.toit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ main:
1515
--type=messages.DrawElement.TYPE_LINE
1616
--x=0
1717
--y=(122/2)
18-
--width=250
19-
--height=0
18+
--x2=(250 - 1)
19+
--y2=(122/2)
2020
))
2121

2222
while true:

examples/modules/eink/menu.toit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ main:
1212
--data=(messages.MenuPage.data
1313
--page-id=(random 10 255)
1414
--item-count=4
15-
--selected-item=3
15+
--selected-item=1
1616
--item-1="Option 1"
1717
--item-2="Option 2"
1818
--item-3="Option 3"

src/messages/m10011_draw_element_gen.toit

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ class DrawElement extends protocol.Data:
107107
static linetype-from-int value/int -> string:
108108
return LINETYPE_STRINGS.get value --if-absent=(: "unknown")
109109

110+
static X2 := 19
111+
static Y2 := 20
110112
static BITMAP := 25
111113
static TEXT := 100
112114

@@ -124,7 +126,7 @@ class DrawElement extends protocol.Data:
124126
125127
Returns: A protocol.Data object with the specified field values
126128
*/
127-
static data --page-id/int?=null --status-bar-enable/bool?=null --redraw-type/int?=null --x/int?=null --y/int?=null --width/int?=null --height/int?=null --type/int?=null --style/int?=null --fontsize/int?=null --textalign/int?=null --linewidth/int?=null --padding/int?=null --radius/int?=null --linetype/int?=null --bitmap/ByteArray?=null --text/string?=null --base-data/protocol.Data?=protocol.Data -> protocol.Data:
129+
static data --page-id/int?=null --status-bar-enable/bool?=null --redraw-type/int?=null --x/int?=null --y/int?=null --width/int?=null --height/int?=null --type/int?=null --style/int?=null --fontsize/int?=null --textalign/int?=null --linewidth/int?=null --padding/int?=null --radius/int?=null --linetype/int?=null --x2/int?=null --y2/int?=null --bitmap/ByteArray?=null --text/string?=null --base-data/protocol.Data?=protocol.Data -> protocol.Data:
128130
data := base-data
129131
if page-id != null: data.add-data-uint PAGE-ID page-id
130132
if status-bar-enable != null: data.add-data-bool STATUS-BAR-ENABLE status-bar-enable
@@ -141,6 +143,8 @@ class DrawElement extends protocol.Data:
141143
if padding != null: data.add-data-uint PADDING padding
142144
if radius != null: data.add-data-uint RADIUS radius
143145
if linetype != null: data.add-data-uint LINETYPE linetype
146+
if x2 != null: data.add-data-uint X2 x2
147+
if y2 != null: data.add-data-uint Y2 y2
144148
if bitmap != null: data.add-data BITMAP bitmap
145149
if text != null: data.add-data-ascii TEXT text
146150
return data
@@ -297,6 +301,18 @@ Requires x, y (top left corner), width, height and bitmap data.
297301
linetype -> int:
298302
return get-data-uint LINETYPE
299303

304+
/**
305+
Second X coordinate, primarily for lines.
306+
*/
307+
x2 -> int:
308+
return get-data-uint X2
309+
310+
/**
311+
Second Y coordinate, primarily for lines.
312+
*/
313+
y2 -> int:
314+
return get-data-uint Y2
315+
300316
/**
301317
Bitmap
302318
*/
@@ -326,6 +342,8 @@ Requires x, y (top left corner), width, height and bitmap data.
326342
"Padding": padding,
327343
"Radius": radius,
328344
"LineType": linetype,
345+
"X2": x2,
346+
"Y2": y2,
329347
"Bitmap": bitmap,
330348
"Text": text,
331349
}.stringify

0 commit comments

Comments
 (0)