# 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
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
RC_ARM_CHANNEL = 6

# the debounce range value is used to ignore changes in rc input
# that are within the debounce range
DEBOUNCE_RANGE = 5


class RCControler(ApplicationSession):
    """Main entry point for controling the Mothership and AUV
    """

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.armed = False

# 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

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
RC_ARM_CHANNEL = 6

# the debounce range value is used to ignore changes in rc input
# that are within the debounce range
DEBOUNCE_RANGE = 5


class RCControler(ApplicationSession):
    """Main entry point for controling the Mothership and AUV
    """

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.armed = False

        self.rc_input = RCInput()