Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need your help/advice #54

Open
Electrik-rich546456 opened this issue Feb 7, 2021 · 0 comments
Open

Need your help/advice #54

Electrik-rich546456 opened this issue Feb 7, 2021 · 0 comments

Comments

@Electrik-rich546456
Copy link

Electrik-rich546456 commented Feb 7, 2021

Hi, I am still a bit of a noob with python and have managed to get the rpi-rf_receive.py to work.
So i have edited it as follows.
But I am having trouble working out how to add a debounce function.

#!/usr/bin/env python3

import argparse
import signal
import sys
import time
import logging
#from threading import Timer

from rpi_rf import RFDevice

rfdevice = None
debounce = 10

# pylint: disable=unused-argument
def exithandler(signal, frame):
    rfdevice.cleanup()
    sys.exit(0)

logging.basicConfig(level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S',
                    format='%(asctime)-15s - [%(levelname)s] %(module)s: %(message)s', )

parser = argparse.ArgumentParser(description='Receives a decimal code via a 433/315MHz GPIO device')
parser.add_argument('-g', dest='gpio', type=int, default=27,
                    help="GPIO pin (Default: 27)")
args = parser.parse_args()

signal.signal(signal.SIGINT, exithandler)
rfdevice = RFDevice(args.gpio)
rfdevice.enable_rx()
timestamp = None
now = time.time()-debounce
#logging.info("Listening for codes on GPIO " + str(args.gpio))
print(timestamp)
while True:
    if rfdevice.rx_code_timestamp != timestamp:
        timestamp = rfdevice.rx_code_timestamp
        print(timestamp)
        if ((str(rfdevice.rx_code) == '3764961')):
            print("yay")

#        logging.info(str(rfdevice.rx_code) +
#                     " [pulselength " + str(rfdevice.rx_pulselength) +
#                     ", protocol " + str(rfdevice.rx_proto) + "]")
    time.sleep(0.01)
rfdevice.cleanup()

The output if i keep the remote button down is

172923606303
yay
172923698146
yay
172923790101

What format are the numbers from line 38 print(timestamp) ???
I made some changes that did not work below.

#!/usr/bin/env python3

import argparse
import signal
import sys
import time
import logging
#from threading import Timer

from rpi_rf import RFDevice
#print(RFDevice)
rfdevice = None
debounce = 100000000000


#t = time.localtime()
#current_time = time.time()
#print(current_time)

# pylint: disable=unused-argument
def exithandler(signal, frame):
    rfdevice.cleanup()
    sys.exit(0)

logging.basicConfig(level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S',
                    format='%(asctime)-15s - [%(levelname)s] %(module)s: %(message)s', )

parser = argparse.ArgumentParser(description='Receives a decimal code via a 433/315MHz GPIO device')
parser.add_argument('-g', dest='gpio', type=int, default=27,
                    help="GPIO pin (Default: 27)")
args = parser.parse_args()

signal.signal(signal.SIGINT, exithandler)
rfdevice = RFDevice(args.gpio)
rfdevice.enable_rx()
timestamp = None
oldtime = time.time()
#print(oldtime)
#logging.info("Listening for codes on GPIO " + str(args.gpio))
#print(timestamp)
#start_time = time.time()


while True:
    if rfdevice.rx_code_timestamp != timestamp:
        timestamp = rfdevice.rx_code_timestamp
        print(timestamp)
        print(debounce)
#        print(rfdevice.rx_code_timestamp)
        if timestamp <= debounce:
            if ((str(rfdevice.rx_code) == '3764961')):
                print("yay")

#        logging.info(str(rfdevice.rx_code) +
#                     " [pulselength " + str(rfdevice.rx_pulselength) +
#                     ", protocol " + str(rfdevice.rx_proto) + "]")
    time.sleep(0.01)
rfdevice.cleanup()

There must be a way to display "yay" only once and ignore or sleep but in a thread the rest of the duplicate inputs.
Or if It is easier to make it respond to long press differently to short press.
Well any way can someone help me get the code right please.
Thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant