#NEWLINE# def BeforeUpload( target , source , env ) : #NEWLINE# #INDENT# env . AutodetectUploadPort ( ) #NEWLINE# board_type = env . subst ( '$BOARD' ) #NEWLINE# if ( 'zero' not in board_type ) : #NEWLINE# #INDENT# env . Append ( UPLOADERFLAGS = [ '-U' , ( 'true' if ( ( 'usb' in board_type . lower ( ) ) or ( board_type == 'digix' ) ) else 'false' ) ] ) #NEWLINE# #UNINDENT# upload_options = env . get ( 'BOARD_OPTIONS' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) . get ( 'upload' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# if ( not upload_options . get ( 'disable_flushing' , False ) ) : #NEWLINE# #INDENT# env . FlushSerialBuffer ( '$UPLOAD_PORT' ) #NEWLINE# #UNINDENT# before_ports = [ i [ 'port' ] for i in get_serialports ( ) ] #NEWLINE# if upload_options . get ( 'use_1200bps_touch' , False ) : #NEWLINE# #INDENT# env . TouchSerialPort ( '$UPLOAD_PORT' , 1200 ) #NEWLINE# #UNINDENT# if upload_options . get ( 'wait_for_upload_port' , False ) : #NEWLINE# #INDENT# env . Replace ( UPLOAD_PORT = env . WaitForNewSerialPort ( before_ports ) ) #NEWLINE# #UNINDENT# if ( '/' in env . subst ( '$UPLOAD_PORT' ) ) : #NEWLINE# #INDENT# env . Replace ( UPLOAD_PORT = basename ( env . subst ( '$UPLOAD_PORT' ) ) )