parameters: (self, c)
docstring: Implement a simple menu / settings
docstring_summary: Implement a simple menu / settings
docstring_tokens: Implement a simple menu / settings
function: def handle_menu_key(self, c):
          """Implement a simple menu / settings"""
          if c == self.menu_character or c == self.exit_character:
              # Menu/exit character again -> send itself
              self.serial.write(self.tx_encoder.encode(c))
              if self.echo:
                  self.console.write(c)
          elif c == '\x15':                       # CTRL+U -> upload file
              self.upload_file()
          elif c in '\x08hH?':                    # CTRL+H, h, H, ? -> Show help
              sys.stderr.write(self.get_help_text())
          elif c == '\x12':                       # CTRL+R -> Toggle RTS
              self.serial.rts = not self.serial.rts
              sys.stderr.write('--- RTS {} ---\n'.format('active' if self.serial.rts else 'inactive'))
          elif c == '\x04':                       # CTRL+D -> Toggle DTR
              self.serial.dtr = not self.serial.dtr
              sys.stderr.write('--- DTR {} ---\n'.format('active' if self.serial.dtr else 'inactive'))
          elif c == '\x02':                       # CTRL+B -> toggle BREAK condition
              self.serial.break_condition = not self.serial.break_condition
              sys.stderr.write('--- BREAK {} ---\n'.format('active' if self.serial.break_condition else 'inactive'))
          elif c == '\x05':                       # CTRL+E -> toggle local echo
              self.echo = not self.echo
              sys.stderr.write('--- local echo {} ---\n'.format('active' if self.echo else 'inactive'))
          elif c == '\x06':                       # CTRL+F -> edit filters
              self.change_filter()
          elif c == '\x0c':                       # CTRL+L -> EOL mode
              modes = list(EOL_TRANSFORMATIONS)  # keys
              eol = modes.index(self.eol) + 1
              if eol >= len(modes):
                  eol = 0
              self.eol = modes[eol]
              sys.stderr.write('--- EOL: {} ---\n'.format(self.eol.upper()))
              self.update_transformations()
          elif c == '\x01':                       # CTRL+A -> set encoding
              self.change_encoding()
          elif c == '\x09':                       # CTRL+I -> info
              self.dump_port_settings()
          #~ elif c == '\x01':                       # CTRL+A -> cycle escape mode
          #~ elif c == '\x0c':                       # CTRL+L -> cycle linefeed mode
          elif c in 'pP':                         # P -> change port
              self.change_port()
          elif c in 'sS':                         # S -> suspend / open port temporarily
              self.suspend_port()
          elif c in 'bB':                         # B -> change baudrate
              self.change_baudrate()
          elif c == '8':                          # 8 -> change to 8 bits
              self.serial.bytesize = serial.EIGHTBITS
              self.dump_port_settings()
          elif c == '7':                          # 7 -> change to 8 bits
              self.serial.bytesize = serial.SEVENBITS
              self.dump_port_settings()
          elif c in 'eE':                         # E -> change to even parity
              self.serial.parity = serial.PARITY_EVEN
              self.dump_port_settings()
          elif c in 'oO':                         # O -> change to odd parity
              self.serial.parity = serial.PARITY_ODD
              self.dump_port_settings()
          elif c in 'mM':                         # M -> change to mark parity
              self.serial.parity = serial.PARITY_MARK
              self.dump_port_settings()
          elif c in 'sS':                         # S -> change to space parity
              self.serial.parity = serial.PARITY_SPACE
              self.dump_port_settings()
          elif c in 'nN':                         # N -> change to no parity
              self.serial.parity = serial.PARITY_NONE
              self.dump_port_settings()
          elif c == '1':                          # 1 -> change to 1 stop bits
              self.serial.stopbits = serial.STOPBITS_ONE
              self.dump_port_settings()
          elif c == '2':                          # 2 -> change to 2 stop bits
              self.serial.stopbits = serial.STOPBITS_TWO
              self.dump_port_settings()
          elif c == '3':                          # 3 -> change to 1.5 stop bits
              self.serial.stopbits = serial.STOPBITS_ONE_POINT_FIVE
              self.dump_port_settings()
          elif c in 'xX':                         # X -> change software flow control
              self.serial.xonxoff = (c == 'X')
              self.dump_port_settings()
          elif c in 'rR':                         # R -> change hardware flow control
              self.serial.rtscts = (c == 'R')
              self.dump_port_settings()
          else:
              sys.stderr.write('--- unknown menu character {} --\n'.format(key_description(c)))
function_tokens: def handle_menu_key ( self , c ) : if c == self . menu_character or c == self . exit_character : # Menu/exit character again -> send itself self . serial . write ( self . tx_encoder . encode ( c ) ) if self . echo : self . console . write ( c ) elif c == '\x15' : # CTRL+U -> upload file self . upload_file ( ) elif c in '\x08hH?' : # CTRL+H, h, H, ? -> Show help sys . stderr . write ( self . get_help_text ( ) ) elif c == '\x12' : # CTRL+R -> Toggle RTS self . serial . rts = not self . serial . rts sys . stderr . write ( '--- RTS {} ---\n' . format ( 'active' if self . serial . rts else 'inactive' ) ) elif c == '\x04' : # CTRL+D -> Toggle DTR self . serial . dtr = not self . serial . dtr sys . stderr . write ( '--- DTR {} ---\n' . format ( 'active' if self . serial . dtr else 'inactive' ) ) elif c == '\x02' : # CTRL+B -> toggle BREAK condition self . serial . break_condition = not self . serial . break_condition sys . stderr . write ( '--- BREAK {} ---\n' . format ( 'active' if self . serial . break_condition else 'inactive' ) ) elif c == '\x05' : # CTRL+E -> toggle local echo self . echo = not self . echo sys . stderr . write ( '--- local echo {} ---\n' . format ( 'active' if self . echo else 'inactive' ) ) elif c == '\x06' : # CTRL+F -> edit filters self . change_filter ( ) elif c == '\x0c' : # CTRL+L -> EOL mode modes = list ( EOL_TRANSFORMATIONS ) # keys eol = modes . index ( self . eol ) + 1 if eol >= len ( modes ) : eol = 0 self . eol = modes [ eol ] sys . stderr . write ( '--- EOL: {} ---\n' . format ( self . eol . upper ( ) ) ) self . update_transformations ( ) elif c == '\x01' : # CTRL+A -> set encoding self . change_encoding ( ) elif c == '\x09' : # CTRL+I -> info self . dump_port_settings ( ) #~ elif c == '\x01':                       # CTRL+A -> cycle escape mode #~ elif c == '\x0c':                       # CTRL+L -> cycle linefeed mode elif c in 'pP' : # P -> change port self . change_port ( ) elif c in 'sS' : # S -> suspend / open port temporarily self . suspend_port ( ) elif c in 'bB' : # B -> change baudrate self . change_baudrate ( ) elif c == '8' : # 8 -> change to 8 bits self . serial . bytesize = serial . EIGHTBITS self . dump_port_settings ( ) elif c == '7' : # 7 -> change to 8 bits self . serial . bytesize = serial . SEVENBITS self . dump_port_settings ( ) elif c in 'eE' : # E -> change to even parity self . serial . parity = serial . PARITY_EVEN self . dump_port_settings ( ) elif c in 'oO' : # O -> change to odd parity self . serial . parity = serial . PARITY_ODD self . dump_port_settings ( ) elif c in 'mM' : # M -> change to mark parity self . serial . parity = serial . PARITY_MARK self . dump_port_settings ( ) elif c in 'sS' : # S -> change to space parity self . serial . parity = serial . PARITY_SPACE self . dump_port_settings ( ) elif c in 'nN' : # N -> change to no parity self . serial . parity = serial . PARITY_NONE self . dump_port_settings ( ) elif c == '1' : # 1 -> change to 1 stop bits self . serial . stopbits = serial . STOPBITS_ONE self . dump_port_settings ( ) elif c == '2' : # 2 -> change to 2 stop bits self . serial . stopbits = serial . STOPBITS_TWO self . dump_port_settings ( ) elif c == '3' : # 3 -> change to 1.5 stop bits self . serial . stopbits = serial . STOPBITS_ONE_POINT_FIVE self . dump_port_settings ( ) elif c in 'xX' : # X -> change software flow control self . serial . xonxoff = ( c == 'X' ) self . dump_port_settings ( ) elif c in 'rR' : # R -> change hardware flow control self . serial . rtscts = ( c == 'R' ) self . dump_port_settings ( ) else : sys . stderr . write ( '--- unknown menu character {} --\n' . format ( key_description ( c ) ) )