User manual

Instruction set
8
Command Description Example LUA string
U Update screen: Depending on mode
the function automatic update is
disabled (mode = 0) or enabled (mode
= 1). When mode is equal to 2 or
omitted, the currently selected buffer
is copied onto screen.
ESC[modeU ESC[0U
ESC[1U ESC[2U
"\27[U"
W Blit source rectangle at [x0; y0] with
size [dx; dy] to [x1; y1]. Source buffer
is src, target buffer is dst.
ESC[src;x0;y0;dx;dy;
dst;x1;y1W
ESC[1;0;0;32;32;
0;10;15W
"\27[1;10;20;16;16;
0;0;0W"
Table3.3.Graphic functions
Here is a more complex example using graphic functions to draw an animated random
graph.
-- All commands will be sent using standard file IO
-- on the USB CDC port my LCD-Term is connected to.
-- On Linux it will be either "/dev/ttyACMx" or "/dev/ttyUSBx";
-- on Windows the device is "//./COMx".
f = io.open("/dev/ttyACM0", "wb")
function wait(seconds)
local start = os.clock()
repeat until os.clock() > start + seconds
end
math.randomseed(os.time())
graph_x = 10
graph_y = 10
graph_dx = 128 - 2 * graph_x
graph_dy = 64 - 2 * graph_y
variance = 5
steps = 4
pattern = 0xFF
values = {}
values[0] = math.random() * graph_dy
function calc_value(old_y)
y = old_y + (math.random() - 0.5) * variance, graph_dy
-- shrink value to graph size
y = math.max(math.min(y, graph_dy - 1), 0)
return y
end
function calc_graph(start_x, end_x)
for x = start_x + 1, end_x, 1 do
-- round value to the nearest integer
y = math.floor(calc_value(values[x - 1]) + 0.5)
values[x] = y
old_y = y
end
end
function draw_graph(f, start_x, end_x)
for x = start_x, end_x - 1, 1 do
-- draw a line between the two points
f:write(string.format("\27[%d;%d;%d;%d;%dy",
graph_y + values[x], graph_x + x,
graph_y + values[x + 1], graph_x + x + 1,
pattern))
f:flush()
-- here we don't use XON/XOFF, so make a little pause after
-- having drawn some lines