@@ -28,7 +28,6 @@ import (
2828 "errors"
2929 "fmt"
3030 "io"
31- "strconv"
3231 "time"
3332
3433 "github.com/arduino/go-paths-helper"
@@ -56,8 +55,9 @@ func NewWincFlasher(portAddress string) (*WincFlasher, error) {
5655}
5756
5857type WincFlasher struct {
59- port serial.Port
60- payloadSize int
58+ port serial.Port
59+ payloadSize int
60+ progressCallback func (int )
6161}
6262
6363func (f * WincFlasher ) FlashFirmware (firmwareFile * paths.Path , flasherOut io.Writer ) error {
@@ -74,7 +74,7 @@ func (f *WincFlasher) FlashFirmware(firmwareFile *paths.Path, flasherOut io.Writ
7474 return err
7575 }
7676 logrus .Infof ("Flashed all the things" )
77- flasherOut .Write ([]byte ("Flashed all the things \n " ))
77+ flasherOut .Write ([]byte ("Flashing progress: 100% \n " ))
7878 return nil
7979}
8080
@@ -277,7 +277,11 @@ func (f *WincFlasher) flashChunk(offset int, buffer []byte) error {
277277 }
278278
279279 for i := 0 ; i < bufferLength ; i += f .payloadSize {
280- logrus .Debugf ("Flashing chunk: %s%%" , strconv .Itoa ((i * 100 )/ bufferLength ))
280+ progress := ((i * 100 ) / bufferLength )
281+ logrus .Debugf ("Flashing chunk: %d%%" , progress )
282+ if f .progressCallback != nil {
283+ f .progressCallback (progress )
284+ }
281285 start := i
282286 end := i + f .payloadSize
283287 if end > bufferLength {
@@ -461,3 +465,7 @@ func (f *WincFlasher) erase(address uint32, length uint32) error {
461465 }
462466 return nil
463467}
468+
469+ func (f * WincFlasher ) SetProgressCallback (callback func (progress int )) {
470+ f .progressCallback = callback
471+ }
0 commit comments