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

Python examples rework #27

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
python: navio: Navio: add RCInput Navio+ support
Make new RCInput module for Navio+ in add this module in __init__ file
  • Loading branch information
Igor Anokhin committed Jan 10, 2018
commit 44e25f28cd9e661e88d82d158d98f093141f50c2
42 changes: 42 additions & 0 deletions Python/navio/Navio/RCInput.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import RPi.GPIO as GPIO
import pigpio

class RCInput():

PPM_SYNC_LENGTH = 4000

CHANNEL_COUNT = 8
channels = [0,0,0,0,0,0,0,0]

def cbf(self, gpio, level, tick):
if (level == 0):
deltaTime = tick - self.previousTick
self.previousTick = tick

if (deltaTime >= self.PPM_SYNC_LENGTH):
self.currentchannel = 0
else:
if (self.currentchannel < self.CHANNEL_COUNT):
self.channels[self.currentchannel] = deltaTime
self.currentchannel += 1

def __init__(self):

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(27, GPIO.OUT)
GPIO.output(27, GPIO.LOW)

self.pi = pigpio.pi()
self.pi.set_mode(4, pigpio.INPUT)

self.currentchannel = 0
self.previousTick = self.pi.get_current_tick()
self.cb1 = self.pi.callback(4, pigpio.EITHER_EDGE, self.cbf)

def read(self, ch):
try:
return self.channels[ch]
except IndexError:
print("Channel number too large")
exit(1)
1 change: 1 addition & 0 deletions Python/navio/Navio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .adafruit_ads1x15 import ADS1x15
from .Led import Led
from .ADC import ADC
from .RCInput import RCInput