blob: e70b69cb60341e834d119e7bb1b4c819ef5f987b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
local device = _G
-- descripción: permite conocer el estado el botón en un momento dado.
-- entrada: no tiene.
-- salida: estado del botón. Posibles estados: 1 presionado, 0 libre.
api={}
api.getCampo = {}
api.getCampo.parameters = {} -- no tiene parámetros de entrada
api.getCampo.returns = {[1]={rname="par1", rtype="int"}} -- 1 = presionado, 0 = libre
api.getCampo.call = function ()
device:send(string.char(0x00)) -- codigo de operacion = 0
local sen_dig_response = device:read(3) -- leo 2 bytes (opcode, data)
local raw_val
if not sen_dig_response or string.byte(sen_dig_response or "00000000", 2) == nil or string.byte(sen_dig_response or "00000000", 3) == nil
then
raw_val = "nil value"
else
raw_val = 1 - (string.byte(sen_dig_response, 3) % 2)
end
return raw_val
end
|