diff options
author | Jenna Fox <a@creativepony.com> | 2012-09-24 11:35:43 +1000 |
---|---|---|
committer | Jenna Fox <a@creativepony.com> | 2012-09-24 11:35:43 +1000 |
commit | 7da853db747d73ac798675038bfa567b6f2b5cc2 (patch) | |
tree | 78f6b7c85063395ea7cfc201b253ed59b70ba0df /firmware/upload.rb | |
parent | 3974acefcd51203c69f5432c8d29feb5d96fa007 (diff) | |
download | micronucleus-7da853db747d73ac798675038bfa567b6f2b5cc2.tar.gz micronucleus-7da853db747d73ac798675038bfa567b6f2b5cc2.tar.bz2 micronucleus-7da853db747d73ac798675038bfa567b6f2b5cc2.zip |
added more logging to upload.rb
Diffstat (limited to 'firmware/upload.rb')
-rw-r--r-- | firmware/upload.rb | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/firmware/upload.rb b/firmware/upload.rb index f49a94f..c245bb6 100644 --- a/firmware/upload.rb +++ b/firmware/upload.rb @@ -31,7 +31,8 @@ class MicroBoot @info = { flash_length: flash_length, page_size: page_size, - write_sleep: 0.020, #write_sleep.to_f / 1000.0, + write_sleep: write_sleep.to_f / 1000.0, + pages: (flash_length.to_f / page_size.to_f).ceil, version: "#{@device.bcdDevice >> 8}.#{@device.bcdDevice & 0xFF}", version_numeric: @device.bcdDevice } @@ -40,9 +41,14 @@ class MicroBoot end def erase! + puts "Erasing chip..." info = self.info control_transfer(function: :erase_application) - sleep(info[:write_sleep] * ((info[:flash_length] / info[:page_size]) + 1)) # sleep for as many pages as the chip has + + info[:pages].times do |index| + puts "Erasing: #{((index.to_f / info[:pages].to_f) * 100.0).round}%" if index % 5 == 0 + sleep(info[:write_sleep]) # sleep for as many pages as the chip has + end end # upload a new program @@ -54,16 +60,23 @@ class MicroBoot erase! address = 0 - bytes.each_slice(info[:page_size]) do |bytes| - control_transfer(function: :write_page, wIndex: address, wValue: bytes.length, dataOut: bytes.pack('C*')) + bytes.each_slice(info[:page_size]) do |slice| + puts "Uploading: #{(address.to_f / bytes.length.to_f * 100.0).round}%: @#{address} of #{bytes.length}" + control_transfer(function: :write_page, wIndex: address, wValue: slice.length, dataOut: slice.pack('C*')) sleep(info[:write_sleep]) - address += bytes.length + address += slice.length end end def finished + puts "Asking device to finish writing program..." control_transfer(function: :run_program) - sleep(info[:write_sleep]) # not sure if this is worth having? It's okay if USB fails now... + + # this could be shorter, relative to how many pages we uploaded.. + info[:pages].times do |index| + puts "Finishing Upload: #{((index.to_f / info[:pages].to_f) * 100.0).round}%" if index % 5 == 0 + sleep(info[:write_sleep]) # sleep for as many pages as the chip has + end @io.close @io = nil |