Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 from abs_hand_command import AbsractHandCommand
00038
00039
00040 class HandlightCommand(AbsractHandCommand):
00041 '''
00042 Following Command design pattern, this class represents commands
00043 for turning hand lights.
00044 '''
00045
00046
00047 HANDLIGHT_ON = True
00048 HANDLIGHT_OFF = False
00049
00050 def __init__(self, hands, hand, dio_pins):
00051 super(HandlightCommand, self).__init__(hands, hand, dio_pins)
00052
00053 def _assign_dio_names(self, dio_pins):
00054 '''
00055 @see abs_hand_command.AbsractHandCommand._assign_dio_names
00056 '''
00057 self._DIO_LHAND = dio_pins[0]
00058 self._DIO_RHAND = dio_pins[1]
00059
00060 def execute(self, operation):
00061 '''
00062 @see abs_hand_command.AbsractHandCommand.execute
00063
00064 @param operation: param type:
00065 - 'True': Turn the light on.
00066 - 'False': Turn the light off.
00067 @rtype: bool
00068 @return: True if digital out was writable to the register.
00069 False otherwise.
00070 '''
00071 dout = []
00072 mask = []
00073 if self.HANDLIGHT_ON == operation:
00074 if self._hands.HAND_R == self._hand:
00075 dout = mask = [self._DIO_RHAND]
00076 elif self._hands.HAND_L == self._hand:
00077 dout = mask = [self._DIO_LHAND]
00078 elif not self._hand:
00079 dout = mask = [self._DIO_RHAND, self._DIO_LHAND]
00080 else:
00081 if self._hands.HAND_R == self._hand:
00082 mask = [self._DIO_RHAND]
00083 elif self._hands.HAND_L == self._hand:
00084 mask = [self._DIO_LHAND]
00085 elif not self._hand:
00086 mask = [self._DIO_RHAND, self._DIO_LHAND]
00087 return self._hands._dio_writer(dout, mask)
00088
00089 def turn_handlight(self, hand=None, on=True):
00090 '''
00091 @param hand: Both hands if None.
00092 @type on: bool
00093 @param on: Despite its type, it's handled as str in this method.
00094 @rtype: bool
00095 @return: True if the lights turned. False otherwise.
00096 '''
00097 _result = True
00098 if self._hands.HAND_L == hand:
00099
00100 self.execute(on)
00101 _result = False
00102 elif self._hands.HAND_R == hand:
00103 _result = self.execute(on)
00104 elif not hand:
00105 _result = self.turn_handlight(self._hands.HAND_L)
00106 _result = self.turn_handlight(self._hands.HAND_R) and _result
00107 return _result