File tree Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -686,6 +686,27 @@ async def send_block(self, data):
686686 self .expected_checksum = 0
687687
688688 async def run (self , py_path , wait = True , print_output = True ):
689- await asyncio .sleep (4 )
690- await self .send_block (b" " )
691- await asyncio .sleep (4 )
689+
690+ # Reset output buffer
691+ self .output = []
692+ self .print_output = print_output
693+
694+ # Compile the script to mpy format
695+ mpy = await compile_file (py_path )
696+
697+ # Get length of file and send it as bytes to hub
698+ length = len (mpy ).to_bytes (4 , byteorder = 'little' )
699+ await self .send_block (length )
700+
701+ # Divide script in chunks of bytes
702+ n = 100
703+ chunks = [mpy [i : i + n ] for i in range (0 , len (mpy ), n )]
704+
705+ # Send the data chunk by chunk
706+ for i , chunk in enumerate (chunks ):
707+ self .logger .info ("Sending: {0}%" .format (
708+ round ((i + 1 ) / len (chunks ) * 100 ))
709+ )
710+ await self .send_block (chunk )
711+
712+ # Wait for program to start and stop
You can’t perform that action at this time.
0 commit comments