- fait de l'ordre dans les scripts ir_send*

- fait le script ir_send qui permet d'envoyer un code IR de 4 bits en zproto
- fait un tableau de calculs pour le protocole zproto
This commit is contained in:
Christian Zufferey
2018-09-16 17:11:13 +02:00
parent e4601dcbd4
commit 04f7369cfc
9 changed files with 74 additions and 16 deletions

11
IR/oldies/ir_send1.lua Normal file
View File

@@ -0,0 +1,11 @@
-- Petit script pour faire clignoter la LED IR
print("\n ir_send1.lua zf180906.1709 \n")
pin_ir_send = 8
gpio.mode(pin_ir_send,gpio.OUTPUT)
gpio.write(pin_ir_send,gpio.HIGH)
pwm.setup(pin_ir_send,50,512)
pwm.start(pin_ir_send)

80
IR/oldies/ir_send2.lua Normal file
View File

@@ -0,0 +1,80 @@
-- Petit script pour des codes NEC à la LED IR
-- source: https://github.com/nodemcu/nodemcu-firmware/blob/master/lua_examples/irsend.lua
print("\n ir_send2.lua zf180907.1418 \n")
------------------------------------------------------------------------------
-- IR send module
--
-- LICENCE: http://opensource.org/licenses/MIT
-- Vladimir Dronnikov <dronnikov@gmail.com>
--
-- Example:
-- dofile("irsend.lua").nec(4, 0x00ff00ff)
------------------------------------------------------------------------------
local M
do
-- const
local NEC_PULSE_US = 1000000 / 38000
local NEC_HDR_MARK = 9000
local NEC_HDR_SPACE = 4500
local NEC_BIT_MARK = 560
local NEC_ONE_SPACE = 1600
local NEC_ZERO_SPACE = 560
local NEC_RPT_SPACE = 2250
-- cache
local gpio, bit = gpio, bit
local mode, write = gpio.mode, gpio.write
local waitus = tmr.delay
local isset = bit.isset
-- NB: poorman 38kHz PWM with 1/3 duty. Touch with care! )
local carrier = function(pin, c)
c = c / NEC_PULSE_US
while c > 0 do
write(pin, 1)
write(pin, 0)
c = c + 0
c = c + 0
c = c + 0
c = c + 0
c = c + 0
c = c + 0
c = c * 1
c = c * 1
c = c * 1
c = c - 1
end
end
-- tsop signal simulator
local pull = function(pin, c)
write(pin, 0)
waitus(c)
write(pin, 1)
end
-- NB: tsop mode allows to directly connect pin
-- inplace of TSOP input
local nec = function(pin, code, tsop)
local pulse = tsop and pull or carrier
-- setup transmitter
mode(pin, 1)
write(pin, tsop and 1 or 0)
-- header
pulse(pin, NEC_HDR_MARK)
waitus(NEC_HDR_SPACE)
-- sequence, lsb first
for i = 31, 0, -1 do
pulse(pin, NEC_BIT_MARK)
waitus(isset(code, i) and NEC_ONE_SPACE or NEC_ZERO_SPACE)
end
-- trailer
pulse(pin, NEC_BIT_MARK)
-- done transmitter
--mode(pin, 0, tsop and 1 or 0)
end
-- expose
M = {
nec = nec,
}
end
return M

24
IR/oldies/ir_send3.lua Normal file
View File

@@ -0,0 +1,24 @@
-- Petit script pour faire clignoter la LED IR à 38kHz
-- ATTENTION, on utilise ici une superbe astuce pour faire la pulse, on
-- précharge dans une variable locale le gpio.write, car on n'arrive pas avec
-- le gpio.write à faire une pulse plus courte que 400uS
print("\n ir_send3.lua zf180909.1256 \n")
local pin_ir_send = 8
gpio.mode(pin_ir_send,gpio.OUTPUT)
local write = gpio.write
write(pin_ir_send, 0)
function pulse_ir()
local i,a
for i = 1,10 do
write(pin_ir_send, 1)
a=1 a=1 a=1 a=1
write(pin_ir_send, 0)
a=1 a=1 a=1
end
end
sendir_tmr1=tmr.create()
tmr.alarm(sendir_tmr1, 1, tmr.ALARM_AUTO, pulse_ir)

16
IR/oldies/ir_send4.lua Normal file
View File

@@ -0,0 +1,16 @@
-- Petit script pour faire clignoter la LED IR à 38kHz
-- ATTENTION, on utilise ici l'astuce du gpio.serout pour faire la pulse,
-- car on n'arrive pas avec le gpio.write à faire une pulse plus courte que 400uS
print("\n ir_send4.lua zf180915.1330 \n")
pin_ir_send = 7
gpio.mode(pin_ir_send,gpio.OUTPUT)
gpio.write(pin_ir_send,gpio.HIGH)
function pulse_ir()
gpio.serout(pin_ir_send,gpio.LOW,{1,25},38)
end
sendir_tmr1=tmr.create()
tmr.alarm(sendir_tmr1, 10, tmr.ALARM_AUTO, pulse_ir)