initial commit with all the stuff
This commit is contained in:
225
3B/archive/root_5.bak/run.lua
Normal file
225
3B/archive/root_5.bak/run.lua
Normal file
@@ -0,0 +1,225 @@
|
||||
-- LUA default run file
|
||||
|
||||
-- LUA default run file
|
||||
|
||||
require "env"
|
||||
|
||||
periphery = require('periphery')
|
||||
Serial = periphery.Serial
|
||||
|
||||
COMMAND_POSITION = 0x19
|
||||
COMMAND_POSITION_X = 0x13
|
||||
COMMAND_POSITION_Y = 0x11
|
||||
|
||||
COMMAND_HOME = 0x0C
|
||||
|
||||
COMMAND_PASSWORD = 0x7F
|
||||
|
||||
COMMAND_01H = 0x01
|
||||
COMMAND_03H = 0x03
|
||||
|
||||
COMMAND_CURSOR_ON = 0x0F
|
||||
COMMAND_CURSOR_OFF = 0x0E
|
||||
|
||||
COMMAND_BLINK = 0x0B
|
||||
COMMAND_UNBLINK = 0x0C
|
||||
|
||||
COMMAND_CR = 0x0D
|
||||
COMMAND_LF = 0x0A
|
||||
|
||||
blinkFlag = false
|
||||
|
||||
posX = 0
|
||||
posY = 0
|
||||
|
||||
LOGING = 1
|
||||
|
||||
local function errLog(msg)
|
||||
io.stderr:write(msg)
|
||||
end
|
||||
|
||||
function logPrint(msg,aux)
|
||||
if ( LOGING ) then
|
||||
if aux then
|
||||
print(msg.." , "..aux)
|
||||
else
|
||||
print(msg);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function dbgPrint(msg,aux)
|
||||
if ( DEBUG ) then
|
||||
if aux then
|
||||
print(msg.." , "..aux)
|
||||
else
|
||||
print(msg);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function checkY(y)
|
||||
if y < 0 then
|
||||
y = 0
|
||||
end
|
||||
if y > 5 then
|
||||
y = 5
|
||||
end
|
||||
posY = y
|
||||
return y
|
||||
end
|
||||
|
||||
function checkX(x)
|
||||
if x < 0 then
|
||||
x = 39;
|
||||
posY = posY - 1
|
||||
checkY(posY)
|
||||
end
|
||||
if x > 39 then
|
||||
if posY == 5 then
|
||||
x = 39;
|
||||
else
|
||||
x = 0;
|
||||
posY = posY + 1
|
||||
checkY(posY);
|
||||
end
|
||||
end
|
||||
posX = x
|
||||
return x
|
||||
end
|
||||
|
||||
function gotoXY(x,y)
|
||||
checkX(x);
|
||||
checkY(y);
|
||||
end
|
||||
|
||||
function lineFeed(void)
|
||||
posY = posY + 1
|
||||
gotoXY(posX, checkY(posY));
|
||||
end
|
||||
|
||||
function carriageReturn(void)
|
||||
gotoXY(0, posY);
|
||||
end
|
||||
|
||||
function clearAndHome(void)
|
||||
for i=1, 6, 1 do
|
||||
for j=1, 40, 1 do
|
||||
line[i][j]:setTextColor(HMI.Color.green);
|
||||
line[i][j]:setBackground(HMI.Color.black);
|
||||
line[i][j]:setText(" ")
|
||||
line[i][j]:draw()
|
||||
end
|
||||
end
|
||||
posX = 1
|
||||
posY = 1
|
||||
end
|
||||
|
||||
|
||||
function doRead()
|
||||
local loops = 0
|
||||
while loops < 30 do
|
||||
loops = loops + 1
|
||||
if serial:poll(1) then
|
||||
local c = serial:read(1)
|
||||
if c:byte() == COMMAND_POSITION then
|
||||
local cmd = serial:read(1)
|
||||
if cmd:byte() == COMMAND_POSITION_X then
|
||||
local x = string.byte(serial:read(1))
|
||||
gotoXY(x,posY)
|
||||
elseif cmd:byte() == COMMAND_POSITION_Y then
|
||||
local y = string.byte(serial:read(1))
|
||||
gotoXY(posX,y)
|
||||
elseif cmd:byte() == COMMAND_HOME then
|
||||
clearAndHome();
|
||||
end
|
||||
elseif c:byte() == COMMAND_03H then
|
||||
serial:read(1)
|
||||
serial:read(1)
|
||||
elseif c:byte() == COMMAND_BLINK then
|
||||
blinkFlag = true
|
||||
elseif c:byte() == COMMAND_UNBLINK then
|
||||
blinkFlag = false
|
||||
elseif c:byte() == COMMAND_CURSOR_OFF then
|
||||
-- curs_set(0);
|
||||
elseif c:byte() == COMMAND_CURSOR_ON then
|
||||
-- curs_set(0);
|
||||
elseif c:byte() == COMMAND_CR then
|
||||
carriageReturn()
|
||||
elseif c:byte() == COMMAND_LF then
|
||||
lineFeed()
|
||||
else
|
||||
if c:byte() == COMMAND_PASSWORD then
|
||||
c = '*'
|
||||
end
|
||||
|
||||
if c:byte() >= 0x20 and c:byte() < 0x7F then
|
||||
--print(c.." at "..posX.." "..posY.."\n")
|
||||
posX = posX + 1
|
||||
checkX(posX)
|
||||
local label = line[posY+1][posX+1]
|
||||
label:setText(c)
|
||||
if blinkFlag then
|
||||
label:setTextColor(HMI.Color.black);
|
||||
label:setBackground(HMI.Color.green);
|
||||
else
|
||||
label:setTextColor(HMI.Color.green);
|
||||
label:setBackground(HMI.Color.black);
|
||||
end
|
||||
label:draw()
|
||||
else
|
||||
print("Unknown: "..c:byte().."\n");
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function setup()
|
||||
serial = Serial{device="/dev/ttyAMA0", baudrate=9600, databits=7, parity="odd", stopbits=1}
|
||||
instance = HMI.App.instance;
|
||||
layout = HMI.Layout(instance,200,48);
|
||||
|
||||
mono = HMI.Font("/root/font/mono.ttf",34)
|
||||
|
||||
line = {}
|
||||
for i=1, 6, 1 do
|
||||
line[i] = {}
|
||||
for j=1, 40, 1 do
|
||||
line[i][j] = HMI.Label(layout,5*(j-1),8+4*(i-1),5,4," ");
|
||||
line[i][j]:setTextColor(HMI.Color.green);
|
||||
line[i][j]:setBackground(HMI.Color.black);
|
||||
line[i][j]:setFont(mono)
|
||||
line[i][j]:draw()
|
||||
end
|
||||
end
|
||||
|
||||
number = {}
|
||||
for i=1, 10, 1 do
|
||||
number[i] = HMI.Cell(layout,1+20*(i-1),0,20,7,i-1);
|
||||
number[i]:setTextColor(HMI.Color.black);
|
||||
number[i]:setBackground(HMI.Color.grey);
|
||||
number[i]:setFont(mono)
|
||||
end
|
||||
|
||||
control = {}
|
||||
for j=0, 1, 1 do
|
||||
for i=1, 10, 1 do
|
||||
control[i+j] = HMI.Cell(layout,1+20*(i-1),34+j*7,20,7,i-1);
|
||||
control[i+j]:setTextColor(HMI.Color.black);
|
||||
control[i+j]:setBackground(HMI.Color.grey);
|
||||
control[i+j]:setFont(mono)
|
||||
end
|
||||
end
|
||||
|
||||
cnt = 0;
|
||||
end
|
||||
|
||||
function loop()
|
||||
doRead()
|
||||
end
|
||||
|
||||
io.stderr:write("Run LUA\n");
|
||||
|
||||
--------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user