-
Notifications
You must be signed in to change notification settings - Fork 18
/
ir.py
49 lines (40 loc) · 1.02 KB
/
ir.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import machine
import gc
@micropython.viper
def loop(n:int):
for i in range(n):
pass
@micropython.viper
def do_toggle(n:int):
GPIO_OUT = ptr32(0x60000300) # GPIO base register
for i in range(n):
GPIO_OUT[1] = 0x10 # set bit 4
for j in range(51):
pass
GPIO_OUT[2] = 0x10 # clear bit 4
for j in range(51):
pass
@micropython.viper
def output_ir_command(data, n:int):
cnt = ptr16(data)
for i in range(0, n, 2):
do_toggle(cnt[i])
loop(cnt[i+1]*10)
data = bytearray(2000)
pin = machine.Pin(4, machine.Pin.OUT, value=0)
Commands = [
# here is a list of IR command files
"cmd0.bin",
"cmd1.bin",
"cmd1.bin",
]
def send_ir_command(index):
with open(Commands[index], "rb") as f:
length = f.readinto(data)
gc.disable()
isr = machine.disable_irq()
try:
output_ir_command(data, length // 2)
finally:
machine.enable_irq(isr)
gc.enable()