@@ -2245,7 +2245,7 @@ class TouchSensor(Sensor):
22452245 Touch Sensor
22462246 """
22472247
2248- __slots__ = ['auto_mode' , ' _poll' , '_value0' ]
2248+ __slots__ = ['_poll' , '_value0' ]
22492249
22502250 SYSTEM_CLASS_NAME = Sensor .SYSTEM_CLASS_NAME
22512251 SYSTEM_DEVICE_NAME_CONVENTION = Sensor .SYSTEM_DEVICE_NAME_CONVENTION
@@ -2256,7 +2256,6 @@ class TouchSensor(Sensor):
22562256
22572257 def __init__ (self , address = None , name_pattern = SYSTEM_DEVICE_NAME_CONVENTION , name_exact = False , ** kwargs ):
22582258 super (TouchSensor , self ).__init__ (address , name_pattern , name_exact , driver_name = ['lego-ev3-touch' , 'lego-nxt-touch' ], ** kwargs )
2259- self .auto_mode = True
22602259 self ._poll = None
22612260 self ._value0 = None
22622261
@@ -2266,10 +2265,7 @@ def is_pressed(self):
22662265 A boolean indicating whether the current touch sensor is being
22672266 pressed.
22682267 """
2269-
2270- if self .auto_mode :
2271- self .mode = self .MODE_TOUCH
2272-
2268+ self .mode = self .MODE_TOUCH
22732269 return self .value (0 )
22742270
22752271 @property
@@ -2320,7 +2316,7 @@ class ColorSensor(Sensor):
23202316 LEGO EV3 color sensor.
23212317 """
23222318
2323- __slots__ = ['auto_mode' , ' red_max' , 'green_max' , 'blue_max' ]
2319+ __slots__ = ['red_max' , 'green_max' , 'blue_max' ]
23242320
23252321 SYSTEM_CLASS_NAME = Sensor .SYSTEM_CLASS_NAME
23262322 SYSTEM_DEVICE_NAME_CONVENTION = Sensor .SYSTEM_DEVICE_NAME_CONVENTION
@@ -2385,7 +2381,6 @@ class ColorSensor(Sensor):
23852381
23862382 def __init__ (self , address = None , name_pattern = SYSTEM_DEVICE_NAME_CONVENTION , name_exact = False , ** kwargs ):
23872383 super (ColorSensor , self ).__init__ (address , name_pattern , name_exact , driver_name = ['lego-ev3-color' ], ** kwargs )
2388- self .auto_mode = True
23892384
23902385 # See calibrate_white() for more details
23912386 self .red_max = 300
@@ -2397,21 +2392,15 @@ def reflected_light_intensity(self):
23972392 """
23982393 Reflected light intensity as a percentage. Light on sensor is red.
23992394 """
2400-
2401- if self .auto_mode :
2402- self .mode = self .MODE_COL_REFLECT
2403-
2395+ self .mode = self .MODE_COL_REFLECT
24042396 return self .value (0 )
24052397
24062398 @property
24072399 def ambient_light_intensity (self ):
24082400 """
24092401 Ambient light intensity. Light on sensor is dimly lit blue.
24102402 """
2411-
2412- if self .auto_mode :
2413- self .mode = self .MODE_COL_AMBIENT
2414-
2403+ self .mode = self .MODE_COL_AMBIENT
24152404 return self .value (0 )
24162405
24172406 @property
@@ -2427,10 +2416,7 @@ def color(self):
24272416 - 6: White
24282417 - 7: Brown
24292418 """
2430-
2431- if self .auto_mode :
2432- self .mode = self .MODE_COL_COLOR
2433-
2419+ self .mode = self .MODE_COL_COLOR
24342420 return self .value (0 )
24352421
24362422 @property
@@ -2450,10 +2436,7 @@ def raw(self):
24502436
24512437 If this is an issue, check out the rgb() and calibrate_white() methods.
24522438 """
2453-
2454- if self .auto_mode :
2455- self .mode = self .MODE_RGB_RAW
2456-
2439+ self .mode = self .MODE_RGB_RAW
24572440 return self .value (0 ), self .value (1 ), self .value (2 )
24582441
24592442 def calibrate_white (self ):
@@ -2493,49 +2476,37 @@ def red(self):
24932476 """
24942477 Red component of the detected color, in the range 0-1020.
24952478 """
2496-
2497- if self .auto_mode :
2498- self .mode = self .MODE_RGB_RAW
2499-
2479+ self .mode = self .MODE_RGB_RAW
25002480 return self .value (0 )
25012481
25022482 @property
25032483 def green (self ):
25042484 """
25052485 Green component of the detected color, in the range 0-1020.
25062486 """
2507-
2508- if self .auto_mode :
2509- self .mode = self .MODE_RGB_RAW
2510-
2487+ self .mode = self .MODE_RGB_RAW
25112488 return self .value (1 )
25122489
25132490 @property
25142491 def blue (self ):
25152492 """
25162493 Blue component of the detected color, in the range 0-1020.
25172494 """
2518-
2519- if self .auto_mode :
2520- self .mode = self .MODE_RGB_RAW
2521-
2495+ self .mode = self .MODE_RGB_RAW
25222496 return self .value (2 )
25232497
2498+
25242499class UltrasonicSensor (Sensor ):
25252500
25262501 """
25272502 LEGO EV3 ultrasonic sensor.
25282503 """
25292504
2530- __slots__ = ['auto_mode' ]
2531-
25322505 SYSTEM_CLASS_NAME = Sensor .SYSTEM_CLASS_NAME
25332506 SYSTEM_DEVICE_NAME_CONVENTION = Sensor .SYSTEM_DEVICE_NAME_CONVENTION
25342507
25352508 def __init__ (self , address = None , name_pattern = SYSTEM_DEVICE_NAME_CONVENTION , name_exact = False , ** kwargs ):
25362509 super (UltrasonicSensor , self ).__init__ (address , name_pattern , name_exact , driver_name = ['lego-ev3-us' , 'lego-nxt-us' ], ** kwargs )
2537- self .auto_mode = True
2538-
25392510
25402511 #: Continuous measurement in centimeters.
25412512 MODE_US_DIST_CM = 'US-DIST-CM'
@@ -2568,10 +2539,7 @@ def distance_centimeters(self):
25682539 Measurement of the distance detected by the sensor,
25692540 in centimeters.
25702541 """
2571-
2572- if self .auto_mode :
2573- self .mode = self .MODE_US_DIST_CM
2574-
2542+ self .mode = self .MODE_US_DIST_CM
25752543 return self .value (0 ) * self ._scale ('US_DIST_CM' )
25762544
25772545 @property
@@ -2580,10 +2548,7 @@ def distance_inches(self):
25802548 Measurement of the distance detected by the sensor,
25812549 in inches.
25822550 """
2583-
2584- if self .auto_mode :
2585- self .mode = self .MODE_US_DIST_IN
2586-
2551+ self .mode = self .MODE_US_DIST_IN
25872552 return self .value (0 ) * self ._scale ('US_DIST_IN' )
25882553
25892554 @property
@@ -2592,27 +2557,21 @@ def other_sensor_present(self):
25922557 Value indicating whether another ultrasonic sensor could
25932558 be heard nearby.
25942559 """
2595-
2596- if self .auto_mode :
2597- self .mode = self .MODE_US_LISTEN
2598-
2560+ self .mode = self .MODE_US_LISTEN
25992561 return self .value (0 )
26002562
2563+
26012564class GyroSensor (Sensor ):
26022565
26032566 """
26042567 LEGO EV3 gyro sensor.
26052568 """
26062569
2607- __slots__ = ['auto_mode' ]
2608-
26092570 SYSTEM_CLASS_NAME = Sensor .SYSTEM_CLASS_NAME
26102571 SYSTEM_DEVICE_NAME_CONVENTION = Sensor .SYSTEM_DEVICE_NAME_CONVENTION
26112572
26122573 def __init__ (self , address = None , name_pattern = SYSTEM_DEVICE_NAME_CONVENTION , name_exact = False , ** kwargs ):
26132574 super (GyroSensor , self ).__init__ (address , name_pattern , name_exact , driver_name = ['lego-ev3-gyro' ], ** kwargs )
2614- self .auto_mode = True
2615-
26162575
26172576 #: Angle
26182577 MODE_GYRO_ANG = 'GYRO-ANG'
@@ -2645,32 +2604,23 @@ def angle(self):
26452604 The number of degrees that the sensor has been rotated
26462605 since it was put into this mode.
26472606 """
2648-
2649- if self .auto_mode :
2650- self .mode = self .MODE_GYRO_ANG
2651-
2607+ self .mode = self .MODE_GYRO_ANG
26522608 return self .value (0 )
26532609
26542610 @property
26552611 def rate (self ):
26562612 """
26572613 The rate at which the sensor is rotating, in degrees/second.
26582614 """
2659-
2660- if self .auto_mode :
2661- self .mode = self .MODE_GYRO_RATE
2662-
2615+ self .mode = self .MODE_GYRO_RATE
26632616 return self .value (0 )
26642617
26652618 @property
26662619 def rate_and_angle (self ):
26672620 """
26682621 Angle (degrees) and Rotational Speed (degrees/second).
26692622 """
2670-
2671- if self .auto_mode :
2672- self .mode = self .MODE_GYRO_G_A
2673-
2623+ self .mode = self .MODE_GYRO_G_A
26742624 return self .value (0 ), self .value (1 )
26752625
26762626
@@ -2733,8 +2683,6 @@ class InfraredSensor(Sensor, ButtonBase):
27332683 LEGO EV3 infrared sensor.
27342684 """
27352685
2736- __slots__ = ['auto_mode' ]
2737-
27382686 SYSTEM_CLASS_NAME = Sensor .SYSTEM_CLASS_NAME
27392687 SYSTEM_DEVICE_NAME_CONVENTION = Sensor .SYSTEM_DEVICE_NAME_CONVENTION
27402688
@@ -2893,15 +2841,11 @@ class SoundSensor(Sensor):
28932841 LEGO NXT Sound Sensor
28942842 """
28952843
2896- __slots__ = ['auto_mode' ]
2897-
28982844 SYSTEM_CLASS_NAME = Sensor .SYSTEM_CLASS_NAME
28992845 SYSTEM_DEVICE_NAME_CONVENTION = Sensor .SYSTEM_DEVICE_NAME_CONVENTION
29002846
29012847 def __init__ (self , address = None , name_pattern = SYSTEM_DEVICE_NAME_CONVENTION , name_exact = False , ** kwargs ):
29022848 super (SoundSensor , self ).__init__ (address , name_pattern , name_exact , driver_name = ['lego-nxt-sound' ], ** kwargs )
2903- self .auto_mode = True
2904-
29052849
29062850 #: Sound pressure level. Flat weighting
29072851 MODE_DB = 'DB'
@@ -2922,10 +2866,7 @@ def sound_pressure(self):
29222866 A measurement of the measured sound pressure level, as a
29232867 percent. Uses a flat weighting.
29242868 """
2925-
2926- if self .auto_mode :
2927- self .mode = self .MODE_DB
2928-
2869+ self .mode = self .MODE_DB
29292870 return self .value (0 ) * self ._scale ('DB' )
29302871
29312872 @property
@@ -2934,27 +2875,21 @@ def sound_pressure_low(self):
29342875 A measurement of the measured sound pressure level, as a
29352876 percent. Uses A-weighting, which focuses on levels up to 55 dB.
29362877 """
2937-
2938- if self .auto_mode :
2939- self .mode = self .MODE_DBA
2940-
2878+ self .mode = self .MODE_DBA
29412879 return self .value (0 ) * self ._scale ('DBA' )
29422880
2881+
29432882class LightSensor (Sensor ):
29442883
29452884 """
29462885 LEGO NXT Light Sensor
29472886 """
29482887
2949- __slots__ = ['auto_mode' ]
2950-
29512888 SYSTEM_CLASS_NAME = Sensor .SYSTEM_CLASS_NAME
29522889 SYSTEM_DEVICE_NAME_CONVENTION = Sensor .SYSTEM_DEVICE_NAME_CONVENTION
29532890
29542891 def __init__ (self , address = None , name_pattern = SYSTEM_DEVICE_NAME_CONVENTION , name_exact = False , ** kwargs ):
29552892 super (LightSensor , self ).__init__ (address , name_pattern , name_exact , driver_name = ['lego-nxt-light' ], ** kwargs )
2956- self .auto_mode = True
2957-
29582893
29592894 #: Reflected light. LED on
29602895 MODE_REFLECT = 'REFLECT'
@@ -2974,21 +2909,15 @@ def reflected_light_intensity(self):
29742909 """
29752910 A measurement of the reflected light intensity, as a percentage.
29762911 """
2977-
2978- if self .auto_mode :
2979- self .mode = self .MODE_REFLECT
2980-
2912+ self .mode = self .MODE_REFLECT
29812913 return self .value (0 ) * self ._scale ('REFLECT' )
29822914
29832915 @property
29842916 def ambient_light_intensity (self ):
29852917 """
29862918 A measurement of the ambient light intensity, as a percentage.
29872919 """
2988-
2989- if self .auto_mode :
2990- self .mode = self .MODE_AMBIENT
2991-
2920+ self .mode = self .MODE_AMBIENT
29922921 return self .value (0 ) * self ._scale ('AMBIENT' )
29932922
29942923
0 commit comments