# Path: navio/rcinput.py
# class RCInput():
#     CHANNEL_COUNT = 14
#     channels = []
# 
#     def __init__(self):
#         for i in range(0, self.CHANNEL_COUNT):
#             try:
#                 f = open("/sys/kernel/rcio/rcin/ch%d" % i, "r")
#                 self.channels.append(f)
#             except:
#                 print ("Can't open file /sys/kernel/rcio/rcin/ch%d" % i)
# 
#     def read(self, ch):
#         value = self.channels[ch].read()
#         position = self.channels[ch].seek(0, 0)
#         return value[:-1]


import asyncio
import logging
import time
from autobahn.asyncio.wamp import ApplicationSession
from navio.rcinput import RCInput


logger = logging.getLogger(__name__)

RC_LOW = 999  # the lower limit of rc input vlaues
RC_HIGH = 1999  # the upper limit of rc input values

# the stop range sets the width within the rc input values
# that are considered a stop command (in the case of forward/reverse throttle)
# and a no turn command (in the case of left/right turn input)
STOP_RANGE = 50

# forward and reverse thresholds set the limit on when a command will begin
# to increse the throttle in the forward and reverse direction respectively
FORWARD_THRESHOLD = 1500 + STOP_RANGE
REVERSE_THRESHOLD = 1500 - STOP_RANGE

# left and right thresholds set the limit on when a command will begin
# to increse the turn command in the left and right direction respectively
LEFT_THRESHOLD = 1500 - STOP_RANGE
RIGHT_THRESHOLD = 1500 + STOP_RANGE

# RC input below the armed threshold will disarm the rc controller
# and it will not respond to any control input
# RC input above the armed threshold will arm the rc controller and thus
# respond to subsequent commands
ARMED_THRESHOLD = 1500

# define the channels for rc input
RC_THROTTLE_CHANNEL = 2

# Path: navio/rcinput.py
# class RCInput():
#     CHANNEL_COUNT = 14
#     channels = []
# 
#     def __init__(self):
#         for i in range(0, self.CHANNEL_COUNT):
#             try:
#                 f = open("/sys/kernel/rcio/rcin/ch%d" % i, "r")
#                 self.channels.append(f)
#             except:
#                 print ("Can't open file /sys/kernel/rcio/rcin/ch%d" % i)
# 
#     def read(self, ch):
#         value = self.channels[ch].read()
#         position = self.channels[ch].seek(0, 0)
#         return value[:-1]


# Path: auv_control_pi/components/rc_controller.py
import asyncio
import logging
import time
from autobahn.asyncio.wamp import ApplicationSession
from navio.rcinput import RCInput



logger = logging.getLogger(__name__)

RC_LOW = 999  # the lower limit of rc input vlaues
RC_HIGH = 1999  # the upper limit of rc input values

# the stop range sets the width within the rc input values
# that are considered a stop command (in the case of forward/reverse throttle)
# and a no turn command (in the case of left/right turn input)
STOP_RANGE = 50

# forward and reverse thresholds set the limit on when a command will begin
# to increse the throttle in the forward and reverse direction respectively
FORWARD_THRESHOLD = 1500 + STOP_RANGE
REVERSE_THRESHOLD = 1500 - STOP_RANGE

# left and right thresholds set the limit on when a command will begin
# to increse the turn command in the left and right direction respectively
LEFT_THRESHOLD = 1500 - STOP_RANGE
RIGHT_THRESHOLD = 1500 + STOP_RANGE

# RC input below the armed threshold will disarm the rc controller
# and it will not respond to any control input
# RC input above the armed threshold will arm the rc controller and thus
# respond to subsequent commands
ARMED_THRESHOLD = 1500

# define the channels for rc input
RC_THROTTLE_CHANNEL = 2

RC_TURN_CHANNEL = 0