~ni/nxt-python

aade1c04513451ed32d01e1cc0fae2835de82792 — Nicolas Schodet 4 months ago 6621ea4
Simplify usage of super()
4 files changed, 25 insertions(+), 25 deletions(-)

M nxt/sensor/digital.py
M nxt/sensor/generic.py
M nxt/sensor/hitechnic.py
M nxt/sensor/mindsensors.py
M nxt/sensor/digital.py => nxt/sensor/digital.py +1 -1
@@ 64,7 64,7 @@ class BaseDigitalSensor(nxt.sensor.Sensor):
        the sensor for its name, and if a wrong sensor class was used, prints
        a warning.
        """
        super(BaseDigitalSensor, self).__init__(brick, port)
        super().__init__(brick, port)
        self.set_input_mode(nxt.sensor.Type.LOW_SPEED_9V, nxt.sensor.Mode.RAW)
        self.last_poll = time.time()
        self.poll_delay = 0.01

M nxt/sensor/generic.py => nxt/sensor/generic.py +6 -6
@@ 22,7 22,7 @@ class Touch(BaseAnalogSensor):
    """The LEGO touch sensor"""

    def __init__(self, brick, port):
        super(Touch, self).__init__(brick, port)
        super().__init__(brick, port)
        self.set_input_mode(Type.SWITCH, Mode.BOOL)

    def is_pressed(self):


@@ 36,7 36,7 @@ class Light(BaseAnalogSensor):
    used.
    """
    def __init__(self, brick, port, illuminated=True):
        super(Light, self).__init__(brick, port)
        super().__init__(brick, port)
        self.set_illuminated(illuminated)

    def set_illuminated(self, active):


@@ 56,7 56,7 @@ class Sound(BaseAnalogSensor):
    'Object for sound sensors'

    def __init__(self, brick, port, adjusted=True):
        super(Sound, self).__init__(brick, port)
        super().__init__(brick, port)
        self.set_adjusted(adjusted)

    def set_adjusted(self, active):


@@ 100,7 100,7 @@ class Ultrasonic(BaseDigitalSensor):
        REQUEST_WARM_RESET = 0x04

    def __init__(self, brick, port, check_compatible=True):
        super(Ultrasonic, self).__init__(brick, port, check_compatible)
        super().__init__(brick, port, check_compatible)

    def get_distance(self):
        'Function to get data from the ultrasonic sensor'


@@ 135,7 135,7 @@ Ultrasonic.add_compatible_sensor(None, 'LEGO', 'Sonar') #Tested with version 'V1

class Color(BaseAnalogSensor):
    def __init__(self, brick, port):
        super(Color, self).__init__(brick, port)
        super().__init__(brick, port)
        self.set_light_color(Type.COLOR_FULL)

    def set_light_color(self, color):


@@ 167,7 167,7 @@ class Temperature(BaseDigitalSensor):
        # This sensor does not follow the convention of having version/vendor/
        # product at I2C registers 0x00/0x08/0x10, so check_compatible is
        # always False
        super(Temperature, self).__init__(brick, port, False)
        super().__init__(brick, port, False)

    def _get_raw_value(self):
        """Returns raw unscaled value"""

M nxt/sensor/hitechnic.py => nxt/sensor/hitechnic.py +8 -8
@@ 98,7 98,7 @@ class Accelerometer(BaseDigitalSensor):
            self.x, self.y, self.z = x, y, z
    
    def __init__(self, brick, port, check_compatible=True):
        super(Accelerometer, self).__init__(brick, port, check_compatible)
        super().__init__(brick, port, check_compatible)

    def get_acceleration(self):
        """Returns the acceleration along x, y, z axes. 200 => 1g.


@@ 142,7 142,7 @@ whether this worked for you or not!
            self.channel_4 = (m4A, m4B)
    
    def __init__(self, brick, port, check_compatible=True):
        super(IRReceiver, self).__init__(brick, port, check_compatible)
        super().__init__(brick, port, check_compatible)

    def get_speeds(self):
        """Returns the motor speeds for motors A and B on channels 1-4.


@@ 209,7 209,7 @@ but not tested. Please report whether this worked for you or not!
            
    
    def __init__(self, brick, port, check_compatible=True):
        super(IRSeekerv2, self).__init__(brick, port, check_compatible)
        super().__init__(brick, port, check_compatible)

    def get_dc_values(self):
        """Returns the unmodulated (DC) values.


@@ 247,7 247,7 @@ class EOPD(BaseAnalogSensor):
    _MAX_DISTANCE = 1023

    def __init__(self, brick, port):
        super(EOPD, self).__init__(brick, port)
        super().__init__(brick, port)
        from math import sqrt
        self.sqrt = sqrt



@@ 338,7 338,7 @@ but not tested. Please report whether this worked for you or not!"""
            self.red, self.green, self.blue, self.white = red, green, blue, white
    
    def __init__(self, brick, port, check_compatible=True):
        super(Colorv2, self).__init__(brick, port, check_compatible)
        super().__init__(brick, port, check_compatible)

    def get_active_color(self):
        """Returns color values when in active mode.


@@ 374,7 374,7 @@ class Gyro(BaseAnalogSensor):
#takes the currect value and uses it to offset subsequesnt ones.

    def __init__(self, brick, port):
        super(Gyro, self).__init__(brick, port)
        super().__init__(brick, port)
        self.set_input_mode(Type.ANGLE, Mode.RAW)
        self.offset = 0
    


@@ 483,7 483,7 @@ the sensor but not tested. Please report whether this worked for you or not!"""
        RUNNING = 0x01 #motor(s) moving

    def __init__(self, brick, port, check_compatible=True):
        super(ServoCon, self).__init__(brick, port, check_compatible)
        super().__init__(brick, port, check_compatible)

    def get_status(self):
        """Returns the status of the motors. 0 for all stopped, 1 for


@@ 541,7 541,7 @@ class MotorCon(BaseDigitalSensor):
            self.p, self.i, self.d = p, i, d
    
    def __init__(self, brick, port, check_compatible=True):
        super(MotorCon, self).__init__(brick, port, check_compatible)
        super().__init__(brick, port, check_compatible)
    
    def set_enc_target(self, mot, val):
        """Set the encoder target (-2147483648-2147483647) for a motor

M nxt/sensor/mindsensors.py => nxt/sensor/mindsensors.py +10 -10
@@ 44,7 44,7 @@ class SumoEyes(BaseAnalogSensor):
            return '(left: ' + str(self.left) + ', right: ' + str(self.right) + ')'

    def __init__(self, brick, port, long_range=False):
        super(SumoEyes, self).__init__(brick, port)
        super().__init__(brick, port)
        self.set_long_range(long_range)
        
    def set_long_range(self, val):


@@ 91,7 91,7 @@ To determine your sensor's version, use get_sensor_info().version"""
        LOAD_USER_CALIBRATION = 'L' # load user calibration value
    
    def __init__(self, brick, port, check_compatible=True):
        super(Compassv2, self).__init__(brick, port, check_compatible)
        super().__init__(brick, port, check_compatible)
        self.command(self.Commands.MAP_HEADING_INTEGER)

    def command(self, command):


@@ 169,7 169,7 @@ class RTC(BaseDigitalSensor):
    I2C_DEV = 0xD0

    def __init__(self, brick, port):
        super(RTC, self).__init__(brick, port, check_compatible=False)
        super().__init__(brick, port, check_compatible=False)

    def get_seconds(self):  
        gs = self.read_value('seconds')[0]


@@ 302,7 302,7 @@ class ACCL(BaseDigitalSensor):
        ADPA_OFF = 'O' #Set ADPA mode Off (default)
    
    def __init__(self, brick, port, check_compatible=True):
        super(ACCL, self).__init__(brick, port, check_compatible)
        super().__init__(brick, port, check_compatible)

    def command(self, command):
        value = ord(command)


@@ 368,7 368,7 @@ class MTRMUX(BaseDigitalSensor):
        BRAKE = 0x03    
    
    def __init__(self, brick, port, check_compatible=True):
        super(MTRMUX, self).__init__(brick, port, check_compatible)
        super().__init__(brick, port, check_compatible)

    def command(self, command):
        self.write_value('command', (command, )) 


@@ 447,7 447,7 @@ class LineLeader(BaseDigitalSensor):
        SNAPSHOT = 'S'
    
    def __init__(self, brick, port, check_compatible=True):
        super(LineLeader, self).__init__(brick, port, check_compatible)
        super().__init__(brick, port, check_compatible)

    def command(self, command):
        value = ord(command)


@@ 563,7 563,7 @@ class Servo(BaseDigitalSensor):
        PAUSE_MACRO = 'P'
    
    def __init__(self, brick, port, check_compatible=True):
        super(Servo, self).__init__(brick, port, check_compatible)
        super().__init__(brick, port, check_compatible)
        
    def command(self, command):
        value = self.COMMANDVALUES[command]


@@ 641,7 641,7 @@ class MMX(BaseDigitalSensor):
        MOTOR_2_ENC_RESET = 's'
    
    def __init__(self, brick, port, check_compatible=True):
        super(MMX, self).__init__(brick, port, check_compatible)
        super().__init__(brick, port, check_compatible)
    
    def command(self, command):
        value = ord(command)


@@ 729,7 729,7 @@ These are connected to a computer and look like a keyboard to it."""
        DIRECT_MODE = 'D'
    
    def __init__(self, brick, port, check_compatible=True):
        super(HID, self).__init__(brick, port, check_compatible)
        super().__init__(brick, port, check_compatible)
    
    def command(self, command):
        value = ord(command)


@@ 789,7 789,7 @@ class PS2(BaseDigitalSensor):
        ADPA_OFF = 'O'
    
    def __init__(self, brick, port, check_compatible=True):
        super(PS2, self).__init__(brick, port, check_compatible)
        super().__init__(brick, port, check_compatible)
    
    def command(self, command):
        value = ord(command)