# mPy - test kit FKS0001 for IR-receiver development
# Provided by Anthony Vogelaar, Perth Scotland
# rev 0.10  2025-07-24  initial release

from	machine		import	Pin, freq;		freq(240_000_000)
import	time
from	collections	import	deque

# ============================= Test =================================

# Capture time between IR detector rising edges
def test():
    
    # rising edge IRQ
    def onIrq(sender):
        que.append(time.ticks_us())			# append current time to que

        
    que = deque((), 100)
    ir_rx = Pin(35, Pin.IN, Pin.PULL_UP)
    ir_rx.irq(onIrq, trigger=Pin.IRQ_RISING)
    while True:
        time.sleep_ms(100)
        if que:								# if data in que
            time.sleep_ms(100)				# time to collect remaining pulses
            break
    t_last = que.popleft()
    while que:								# print time between edges
        t_prev, t_last = t_last, que.popleft()
        print(time.ticks_diff(t_last, t_prev))

    
test()
    
# ============================ end ==================================
